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
,ChildMixin
The base class for all expression objects.
Note that Numbers implement all the methods of a
ChildMixin
.- children: list[Number]
(read-only) The children of this Number, usually used for traversing the expression tree.
- property keptset
Returns the set representation of this object, but only including children whose values were not dropped.
- class d20.Expression(roll, comment, **kwargs)[source]
Bases:
Number
Expressions are usually the root of all Number trees.
- roll: d20.Number
The roll of this expression.
- class d20.UnOp(op, value, **kwargs)[source]
Bases:
Number
Represents a unary operation.
- value: d20.Number
The subtree that the operation operates on.
- class d20.BinOp(left, op, right, **kwargs)[source]
Bases:
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:
Number
Represents a value inside parentheses.
- value: d20.Number
The subtree inside the parentheses.
- class d20.Set(values, operations=None, **kwargs)[source]
Bases:
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:
Set
A set of Die.
- class d20.Die(size, values, context=None)[source]
Bases:
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.