parser
This module contains the parsing logic for taking rule text in the specified grammar and converting it to an abstract syntax tree that can later be evaluated.
Classes
- class Parser(debug=False)[source]
Bases:
ParserBase
The parser class for the rule grammar. This class contains many ply specific members to define the various components of the grammar allowing it to be parsed and reduced into an abstract syntax tree (AST). Once the AST has been constructed it can then be evaluated multiple times. To make the evaluation more efficient, nodes within the AST that are able to be reduced are while the parsing is taking place. This reduction phase involves evaluation, causing
EvaluationError
exceptions to be raised during parsing.
- class ParserBase(debug=False)[source]
Bases:
object
A base class for parser objects to inherit from. This does not provide any grammar related definitions.
- __init__(debug=False)[source]
- Parameters:
debug (bool) – Whether or not to enable debugging features when using the ply API.
- parse(text, context, **kwargs)[source]
Parse the specified text in an abstract syntax tree of nodes that can later be evaluated. This is done in two phases. First, the syntax is parsed and a tree of deferred / uninitialized AST nodes are constructed. Next each node is built recursively using it’s respective
rule_engine.ast.ASTNodeBase.build()
.
- precedence = ()
The precedence for operators.
- reserved_words = {}
A mapping of literal words which are reserved to their corresponding grammar names.