1996v / CodeParser

Parse code using antlr.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CodeParser

Parse code using antlr.

  • The lexer and parser classes in CodeParser are generated by Antlr grammar file.
  • The CodeParser.Test demonstrates how to parse source code file to extract class and interface with their properties and methods. By now, the Java, C#, Python, PHP, JavaScript, C++, C language and MySql have been included.
  • The CodeParser.Viewer is a visual tool to analyse the parser rules.

Example

1. Python

  • source code
#!/usr/bin/python3
 
class HelloWorld():   
    owner = ""
    target = ""
    def sayHello(self, word):
        print(word)

x = HelloWorld() 

x.sayHello("Hello")
  • parser test output
Class:HelloWorld
{
Field:owner
Field:target
Method:sayHello
}

2. PHP

  • source code
<?
namespace demo;
use ArrayObject;

$count = 0;

class HelloWorld {
    public string $owner;
    public string $target;

	function sayHello(?string $word)
	{
	    echo $word;
	}
}

function test()
{
   $helloWorld = new HelloWorld();
   $helloWorld->sayHello();
}

?>
  • parser test output
Namespace:demo
Use:ArrayObject
Field:$count
Class:HelloWorld
{
Field:$owner
Field:$target
Method:sayHello
}
Function:test

Viewer

CodePaser Viewer

CodePaser Viewer

Use Case

The library SqlAnalyser.Core of DatabaseManager project uses the TSqlParser, MySqlParser and PlSqlParser to parse and translate view, function, procedure and table trigger between SqlServer, MySql and Oracle.

About

Parse code using antlr.


Languages

Language:C# 100.0%Language:Java 0.0%Language:JavaScript 0.0%Language:C++ 0.0%Language:PHP 0.0%Language:C 0.0%Language:Python 0.0%