module languages.antlr_grammar_use

Short summary

module pyensae.languages.antlr_grammar_use

Use grammar This module requires antlr4-python3-runtime.

source on GitHub

Functions

function

truncated documentation

get_parser_lexer

Returns two classes, a parser and a lexer from antlr4.

get_tree_graph

Returns a graph with networkx.

get_tree_string

Returns a string which shows the parsed tree.

parse_code

Parses a code and returns a tree.

Documentation

Use grammar This module requires antlr4-python3-runtime.

source on GitHub

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

source on GitHub

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
Returns

string

source on GitHub

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
Returns

string

source on GitHub

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.parse()
st = get_tree_string(tree, parser, None)
print(st)

source on GitHub