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.
-
property
children
¶ (read-only) The children of this object, usually used for traversing a tree.
-
property
left
¶ The leftmost child of this object, usually used for traversing a tree.
- Return type
-
property
right
¶ The rightmost child of this object, usually used for traversing a tree..
- Return type
-
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.
-
property
-
class
d20.ast.
Node
¶ Bases:
abc.ABC
,d20.diceast.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:
d20.diceast.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:
d20.diceast.Node
Represents a value with an annotation.
-
value
: d20.ast.Node¶ The subtree representing the annotated value.
-
-
class
d20.ast.
Literal
(value)¶ Bases:
d20.diceast.Node
-
class
d20.ast.
Parenthetical
(value)¶ Bases:
d20.diceast.Node
-
value
: d20.ast.Node¶ The subtree inside the parentheses.
-
-
class
d20.ast.
UnOp
(op, value)¶ Bases:
d20.diceast.Node
-
value
: d20.ast.Node¶ The subtree that the operation operates on.
-
-
class
d20.ast.
BinOp
(left, op, right)¶ Bases:
d20.diceast.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:
d20.diceast.Node
-
value
: d20.ast.NumberSet¶ The set to be operated on.
-
-
class
d20.ast.
NumberSet
(values)¶ Bases:
d20.diceast.Node
-
values
: list[d20.ast.NumberSet]¶ The elements of the set.
-
-
class
d20.ast.
OperatedDice
(the_dice, *operations)¶ Bases:
d20.diceast.OperatedSet
-
class
d20.ast.
Dice
(num, size)¶ Bases:
d20.diceast.Node
-
class
d20.ast.
SetOperator
(op, sels)¶ -
-
sels
: list[d20.SetSelector]¶ The selectors that describe how to select operands.
-