Abstract Syntax Tree
This page documents the structure of the Expression object as returned by parse(...)
. If you’re looking
for the Expression object returned by roll(...)expr
, check out Expression Tree.
- class d20.ast.ChildMixin
A mixin that tree nodes must implement to support tree traversal utilities.
- set_child(index, value)
Sets the ith child of this object.
- Parameters:
index (int) – The index of the value to set.
value (ChildMixin) – The new value to set it to.
- class d20.ast.Node
Bases:
ABC
,ChildMixin
The base class for all AST nodes.
A Node has no specific attributes, but supports all the methods in
ChildMixin
for traversal.
- class d20.ast.Expression(roll, comment=None)
Bases:
Node
Expressions are usually the root of all ASTs.
- roll: d20.ast.Node
The subtree representing the expression’s roll.
- class d20.ast.AnnotatedNumber(value, *annotations)
Bases:
Node
Represents a value with an annotation.
- value: d20.ast.Node
The subtree representing the annotated value.
- class d20.ast.Parenthetical(value)
Bases:
Node
- value: d20.ast.Node
The subtree inside the parentheses.
- class d20.ast.UnOp(op, value)
Bases:
Node
- value: d20.ast.Node
The subtree that the operation operates on.
- class d20.ast.BinOp(left, op, right)
Bases:
Node
- left: d20.ast.Node
The left subtree that the operation operates on.
- right: d20.ast.Node
The right subtree that the operation operates on.
- class d20.ast.OperatedSet(the_set, *operations)
Bases:
Node
- value: d20.ast.NumberSet
The set to be operated on.
- class d20.ast.NumberSet(values)
Bases:
Node
- values: list[d20.ast.NumberSet]
The elements of the set.
- class d20.ast.OperatedDice(the_dice, *operations)
Bases:
OperatedSet
- class d20.ast.SetOperator(op, sels)
-
- sels: list[d20.SetSelector]
The selectors that describe how to select operands.