ast
¶
This module contains the nodes which comprise the abstract syntax tree generated from parsed grammar text.
Warning
The content of this module should be treated as private.
While the code within this module is documented, it is not meant to be used by consumers of the package. Directly accessing and using any object or function within this module should be done with care. Breaking API changes within this module may not always cause a major version bump. The reason for this is that it is often necessary to update the AST in an API breaking way in order to add new features.
Classes¶
-
class
Assignment
(name, *, value=UNDEFINED, value_type=None)[source]¶ Bases:
object
An internal assignment where by a symbol is populated with a value of the specified type.
-
name
¶
-
value
¶
-
value_type
¶
-
-
class
Statement
(context, expression)[source]¶ Bases:
rule_engine.ast.ASTNodeBase
A class representing the top level statement of the grammar text.
Base Classes¶
-
class
ExpressionBase
[source]¶ Bases:
rule_engine.ast.ASTNodeBase
-
result_type
= UNDEFINED¶ The data type of the result of successful evaluation.
-
-
class
LeftOperatorRightExpressionBase
(context, type_, left, right)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A base class for representing complex expressions composed of a left side and a right side, separated by an operator.
-
compatible_types
¶ A tuple containing the compatible data types that the left and right expressions must return. This can for example be used to indicate that arithmetic operations are compatible with
FLOAT
but notSTRING
values.
-
__init__
(context, type_, left, right)[source]¶ - Parameters
context (
Context
) – The context to use for evaluating the expression.type (str) – The grammar type of operator at the center of the expression. Subclasses must define operator methods to handle evaluation based on this value.
left (
ExpressionBase
) – The expression to the left of the operator.right (
ExpressionBase
) – The expression to the right of the operator.
-
-
class
LiteralExpressionBase
(context, value)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A base class for representing literal values from the grammar text.
Left-Operator-Right Expressions¶
-
class
ArithmeticExpression
(context, type_, left, right)[source]¶ Bases:
rule_engine.ast.LeftOperatorRightExpressionBase
A class for representing arithmetic expressions from the grammar text such as addition and subtraction.
-
result_type
= FLOAT¶
-
-
class
ArithmeticComparisonExpression
(*args, **kwargs)[source]¶ Bases:
rule_engine.ast.ComparisonExpression
A class for representing arithmetic comparison expressions from the grammar text such as less-than-or-equal-to and greater-than.
-
result_type
= BOOLEAN¶
-
-
class
BitwiseExpression
(*args, **kwargs)[source]¶ Bases:
rule_engine.ast.LeftOperatorRightExpressionBase
A class for representing bitwise arithmetic expressions from the grammar text such as XOR and shifting operations.
-
result_type
= UNDEFINED¶
-
-
class
BitwiseShiftExpression
(*args, **kwargs)[source]¶ Bases:
rule_engine.ast.BitwiseExpression
-
result_type
= FLOAT¶
-
-
class
ComparisonExpression
(context, type_, left, right)[source]¶ Bases:
rule_engine.ast.LeftOperatorRightExpressionBase
A class for representing comparison expressions from the grammar text such as equality checks.
-
result_type
= BOOLEAN¶
-
-
class
LogicExpression
(context, type_, left, right)[source]¶ Bases:
rule_engine.ast.LeftOperatorRightExpressionBase
A class for representing logical expressions from the grammar text such as “and” and “or”.
-
result_type
= BOOLEAN¶
-
-
class
FuzzyComparisonExpression
(*args, **kwargs)[source]¶ Bases:
rule_engine.ast.ComparisonExpression
A class for representing regular expression comparison expressions from the grammar text such as search and does not match.
-
result_type
= BOOLEAN¶
-
Literal Expressions¶
-
class
ArrayExpression
(*args, **kwargs)[source]¶ Bases:
rule_engine.ast._CollectionMixin
,rule_engine.ast.LiteralExpressionBase
Literal array expressions containing 0 or more sub-expressions.
-
result_type
= ARRAY¶
-
-
class
BooleanExpression
(context, value)[source]¶ Bases:
rule_engine.ast.LiteralExpressionBase
Literal boolean expressions representing True or False.
-
result_type
= BOOLEAN¶
-
-
class
DatetimeExpression
(context, value)[source]¶ Bases:
rule_engine.ast.LiteralExpressionBase
Literal datetime expressions representing a specific point in time. This expression type always evaluates to true.
-
result_type
= DATETIME¶
-
-
class
FloatExpression
(context, value, **kwargs)[source]¶ Bases:
rule_engine.ast.LiteralExpressionBase
Literal float expressions representing numerical values.
-
result_type
= FLOAT¶
-
-
class
MappingExpression
(context, value, **kwargs)[source]¶ Bases:
rule_engine.ast.LiteralExpressionBase
Literal mapping expression representing a set of associations between keys and values.
-
result_type
= MAPPING¶
-
-
class
NullExpression
(context, value=None)[source]¶ Bases:
rule_engine.ast.LiteralExpressionBase
Literal null expressions representing null values. This expression type always evaluates to false.
-
result_type
= NULL¶
-
-
class
SetExpression
(*args, **kwargs)[source]¶ Bases:
rule_engine.ast._CollectionMixin
,rule_engine.ast.LiteralExpressionBase
Literal set expressions containing 0 or more sub-expressions.
-
result_type
= SET¶
-
-
class
StringExpression
(context, value)[source]¶ Bases:
rule_engine.ast.LiteralExpressionBase
Literal string expressions representing an array of characters.
-
result_type
= STRING¶
-
Miscellaneous Expressions¶
-
class
ComprehensionExpression
(context, result, variable, iterable, condition=None)[source]¶ Bases:
rule_engine.ast.ExpressionBase
-
result_type
= ARRAY¶
-
-
class
ContainsExpression
(context, container, member)[source]¶ Bases:
rule_engine.ast.ExpressionBase
An expression used to test whether an item exists within a container.
-
result_type
= BOOLEAN¶
-
-
class
GetAttributeExpression
(context, object_, name, safe=False)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A class representing an expression in which name is retrieved as an attribute of object.
-
result_type
= UNDEFINED¶
-
-
class
GetItemExpression
(context, container, item, safe=False)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A class representing an expression in which an item is retrieved from a container object.
-
result_type
= UNDEFINED¶
-
-
class
GetSliceExpression
(context, container, start=None, stop=None, safe=False)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A class representing an expression in which a range of items is retrieved from a container object.
-
result_type
= UNDEFINED¶
-
-
class
SymbolExpression
(context, name, scope=None)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A class representing a symbol name to be resolved at evaluation time with the help of a
Context
object.-
result_type
¶
-
-
class
TernaryExpression
(context, condition, case_true, case_false)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A class for representing ternary expressions from the grammar text. These involve evaluating
condition
before evaluating eithercase_true
orcase_false
based on the results.-
result_type
= UNDEFINED¶
-
-
class
UnaryExpression
(context, type_, right)[source]¶ Bases:
rule_engine.ast.ExpressionBase
A class for representing unary expressions from the grammar text. These involve a single operator on the left side.
-
result_type
= UNDEFINED¶
-