Skip to content

Latest commit

 

History

History
95 lines (76 loc) · 3.82 KB

README.md

File metadata and controls

95 lines (76 loc) · 3.82 KB

Code2Xml Build Status

Overview

Code2Xml is a parser collection that inter-converts source code and XML-based concrete syntax trees (CSTs) supporting multiple programming languages.

How to Use

Sample Code using CstGenerator

[Test] public void ParseJavaText() {
    const string originalCode = @"class Klass {}";
    var gen = CstGenerators.JavaUsingAntlr3;

    /*** Code <=> CST ***/
    var cst = gen.GenerateTreeFromCodeText(originalCode);
    Assert.That(cst.Code, Is.EqualTo(originalCode));
    // GenerateCodeFromTree() invokes Code
    Assert.That(gen.GenerateCodeFromTree(cst), Is.EqualTo(originalCode));

    /*** CST <=> XML ***/
    var xml = cst.ToXml();
    Assert.That(CstNode.FromXml(xml).Code, Is.EqualTo(originalCode));
    // GenerateXmlFromTree() invokes ToXml()
    Assert.That(gen.GenerateXmlFromTree(cst).ToString(),
        Is.EqualTo(xml.ToString()));
    // GenerateTreeFromXml() invokes CstNode.FromXml()
    Assert.That(gen.GenerateTreeFromXml(xml).Code,
        Is.EqualTo(originalCode));

    /*** Code <=> XML (via CST) ***/
    // GenerateXmlFromCodeText() invokes GenerateTreeFromCodeText() and ToXml()
    Assert.That(gen.GenerateXmlFromCodeText(originalCode).ToString(),
        Is.EqualTo(xml.ToString()));
    // GenerateCodeFromXml() invokes CstNode.FromXml() and Code
    Assert.That(gen.GenerateCodeFromXml(xml),
        Is.EqualTo(originalCode));
}

Sample Tools

Requirements

Project Structure

  • Code2Xml.Core.Generators.ANTLRv3 Provides CstGenerator classes for C, C#, Java, JavaScript, Lua and PHP.

  • Code2Xml.Core.Generators.ANTLRv4 Provides CstGenerator classes for C, Clojure, ECMAScript, Erlang, GarryLua, Java, Lua, ObjectiveC, Python3, R, Smalltalk, Switft and Verilog2001.

  • Code2Xml.Core.Generators.ExternalGenerators Provides CstGenerator classes for Python and Ruby.

Other Information

How to Develop / Contribute

How to Build

  1. git submodule update --init at the root directory
  2. Open Code2Xml.sln
  3. Right click the Code2Xml solution in Solution Explorer.
  4. Select Enable NuGet Package Restore.
  5. Build the solution.