Example of using the Abstract Syntax Tree (AST). More...
Go to the source code of this file.
Namespaces | |
examples.ast.main | |
Variables | |
string | examples.ast.main.title |
string | examples.ast.main.abnf_syntax = 'S = alt1 / alt2\n' |
examples.ast.main.api = Api() | |
examples.ast.main.grammar = api.generate(abnf_syntax) | |
examples.ast.main.parser = Parser(grammar) | |
list | examples.ast.main.data = [] |
string | examples.ast.main.input_string = 'xyzbbb' |
examples.ast.main.result = parser.parse(utils.string_to_tuple(input_string), user_data=data) | |
examples.ast.main.end | |
examples.ast.main.ast = Ast(parser) | |
Example of using the Abstract Syntax Tree (AST).
The AST can be considered a sub-tree of the full parse tree. It only has nodes for named phrases (rule name and UDT name). The user has control over which rule and UDT names to retain on the AST and the parser only retains those nodes with successful phrase matches. This means that when traversing the AST, as opposed to the full parse tree during parsing, only named nodes of interest are encountered and the matched phrase is available in both the downward and upward directions. This avoids reporting information from rules that are matched but exist on parse tree branches that ultimately fail.
Definition in file main.py.