module languages.antlr_grammar_use
¶
Short summary¶
module pyensae.languages.antlr_grammar_use
Use grammar This module requires antlr4-python3-runtime.
Functions¶
function |
truncated documentation |
---|---|
Returns two classes, a parser and a lexer from antlr4. |
|
Returns a graph with networkx. |
|
Returns a string which shows the parsed tree. |
|
Parses a code and returns a tree. |
Documentation¶
Use grammar This module requires antlr4-python3-runtime.
-
pyensae.languages.antlr_grammar_use.
get_parser_lexer
(language)[source]¶ Returns two classes, a parser and a lexer from antlr4.
- Parameters
language – to analyse
- Returns
Parser, Lexer
-
pyensae.languages.antlr_grammar_use.
get_tree_graph
(tree, parser, format=<class 'pyensae.languages.tree_graph_listener.TreeGraphListener'>)[source]¶ Returns a graph with networkx.
- Parameters
tree – from
parse_code
parser – the parser used to build the tree, output of
parse_code
format – None or a class ParseTreeListener
- Returns
string
-
pyensae.languages.antlr_grammar_use.
get_tree_string
(tree, parser, format=<class 'pyensae.languages.tree_string_listener.TreeStringListener'>)[source]¶ Returns a string which shows the parsed tree.
- Parameters
tree – from
parse_code
parser – the parser used to build the tree, output of
parse_code
format –
None or a class ParseTreeListener
- Returns
string
-
pyensae.languages.antlr_grammar_use.
parse_code
(code, class_parser, class_lexer)[source]¶ Parses a code and returns a tree.
- Parameters
code – code to parse
class_parser – parser
class_lexer – lexer
- Returns
parsed code
Check the syntax of a script PIG
code = ''' A = LOAD 'filename.txt' USING PigStorage(' '); STORE A INTO 'samefile.txt' ; ''' clparser, cllexer = get_parser_lexer("Pig") parser = parse_code(code, clparser, cllexer) tree = parser.compilation_unit() st = get_tree_string(tree, parser, None) print(st)