datacamp / antlr-ast Goto Github PK
View Code? Open in Web Editor NEWLibrary for building abstract syntax trees from antlr parsers
License: GNU Affero General Public License v3.0
Library for building abstract syntax trees from antlr parsers
License: GNU Affero General Public License v3.0
Please add a propera(short) readme,how to run it.I am trying to build a parser and lexer for vbscript,
>>> pip install antlr-ast; python -c 'import antlr4'
Collecting antlr-ast
Collecting antlr4-python3-runtime (from antlr-ast)
Installing collected packages: antlr4-python3-runtime, antlr-ast
Successfully installed antlr-ast-0.2.0 antlr4-python3-runtime-4.7
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/tom/.local/lib/python2.7/site-packages/antlr4/__init__.py", line 1, in <mo
dule>
from antlr4.Token import Token
File "/home/tom/.local/lib/python2.7/site-packages/antlr4/Token.py", line 59
def text(self, text:str):
^
SyntaxError: invalid syntax
There is a question of whether you want to still support python2. Though one imagines you might want to more clearly exclude it.
This came up when working on latex2sympy.
For example, the tsql grammar has this little devil:
def visitSql_clauses(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
def visitSelect_list(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
def visitBracket_expression(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
def visitSubquery_expression(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
def visitBracket_search_expression(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
def visitBracket_query_expression(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
def visitBracket_table_source(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
def visitTable_alias(self, ctx):
return self.visitChildren(ctx, predicate = lambda n: not isinstance(n, Tree.TerminalNode) )
Currently, a common pattern is to repeat visitor methods like below. But could be collapsed easily.
def visitQuery_specification(self, ctx):
return SelectStmt._from_fields(self, ctx)
def visitInsert_statement(self, ctx):
return InsertStmt._from_fields(self, ctx)
def visitDelete_statement(self, ctx):
return DeleteStmt._from_fields(self, ctx)
def visitUpdate_statement(self, ctx):
return UpdateStmt._from_fields(self, ctx)
def visitUnion_query_expression(self, ctx):
return Union._from_fields(self, ctx)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.