Execution¶
Warning
If you are using this package to implement dice rolling, you should never have to directly interact with these classes. These are only documented to help with maintenance.
For yadr, execution is the act of executing a tree of
tokens to produce a result.
There are two types of trees.
- class yadr.parser.Tree(kind: Token, value: int | bool | str | tuple[int, ...] | tuple[str, dict[int, int | str]], left: Tree | None = None, right: Tree | None = None, dice_map: dict[str, dict[int, int | str]] | None = None)[source]¶
A binary tree used to execute parsed YADN.
- Parameters:
kind – The type of token to be executed.
value – The specific value of the token for execution.
left – (Optional.) The branch of tokens to be executed first.
right – (Optional.) The branch of tokens to be executed last.
dice_map – (Optional.) Dice maps to use during execution.
- Returns:
None.
- Return type:
NoneType
- class yadr.parser.Unary(kind: Token, value: int | bool | str | tuple[int, ...] | tuple[str, dict[int, int | str]], child: Tree | None = None)[source]¶
A unary tree used to execute parsed YADN.
- Parameters:
kind – The type of token to be executed.
value – The specific value of the token for execution.
child – (Optional.) The branch of tokens to be executed first.
- Returns:
None.
- Return type:
NoneType
- compute()[source]¶
Execute the tree.
- Returns:
The result of the identity or operation token.
- Return type:
Result
Warning
This is not type annotated to remain consistent with
yadr.parser.Tree.compute(). See the docstring there for why.