Skip to content

RainsSoft/Code2Xml

master
Switch branches/tags
Code
This branch is 11 commits behind exKAZUu:master.
Contribute

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

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.

About

Code2Xml is a set of parsers for inter-converting between source code and xml supporting multiple programming languages. The NuGet package is also available from https://nuget.org/packages/Code2Xml .

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 91.4%
  • Ruby 5.4%
  • ANTLR 2.3%
  • GAP 0.9%
  • Python 0.0%
  • Batchfile 0.0%