Expression Tree¶
This page documents the structure of the Expression object as returned by roll(...).expr
. If you’re looking
for the Expression object returned by parse(...)
, check out Abstract Syntax Tree.
-
class
d20.
Number
(kept=True, annotation=None)[source]¶ Bases:
abc.ABC
,d20.diceast.ChildMixin
The base class for all expression objects.
Note that Numbers implement all the methods of a
ChildMixin
.-
property
children
¶ (read-only) The children of this Number, usually used for traversing the expression tree.
-
property
left
¶ The leftmost child of this Number, usually used for traversing the expression tree.
- Return type
-
property
right
¶ The rightmost child of this Number, usually used for traversing the expression tree.
- Return type
-
property
keptset
¶ Returns the set representation of this object, but only including children whose values were not dropped.
-
property
-
class
d20.
Expression
(roll, comment, **kwargs)[source]¶ Bases:
d20.expression.Number
Expressions are usually the root of all Number trees.
-
roll
: d20.Number¶ The roll of this expression.
-
-
class
d20.
Literal
(value, **kwargs)[source]¶ Bases:
d20.expression.Number
A literal integer or float.
-
class
d20.
UnOp
(op, value, **kwargs)[source]¶ Bases:
d20.expression.Number
Represents a unary operation.
-
value
: d20.Number¶ The subtree that the operation operates on.
-
-
class
d20.
BinOp
(left, op, right, **kwargs)[source]¶ Bases:
d20.expression.Number
Represents a binary operation.
-
left
: d20.Number¶ The left subtree that the operation operates on.
-
right
: d20.Number¶ The right subtree that the operation operates on.
-
-
class
d20.
Parenthetical
(value, operations=None, **kwargs)[source]¶ Bases:
d20.expression.Number
Represents a value inside parentheses.
-
value
: d20.Number¶ The subtree inside the parentheses.
-
-
class
d20.
Set
(values, operations=None, **kwargs)[source]¶ Bases:
d20.expression.Number
Represents a set of values.
-
values
: list[d20.Number]¶ The elements of the set.
-
-
class
d20.
Dice
(num, size, values, operations=None, context=None, **kwargs)[source]¶ Bases:
d20.expression.Set
A set of Die.
-
class
d20.
Die
(size, values, context=None)[source]¶ Bases:
d20.expression.Number
Represents a single die.
-
values
: list[d20.Literal]¶ The history of values this die has rolled.
-
-
class
d20.
SetOperator
(op, sels)[source]¶ Represents an operation on a set.
-
sels
: list[d20.SetSelector]¶ The selectors that describe how to select operands.
-