@dice-roller/rpg-dice-roller / ast
ast
Expression tree nodes and notation helpers for inspecting or constructing rolls.
Interfaces
| Interface | Description |
|---|---|
| BinaryNode | A binary maths operation, e.g. 2d6 + 3. |
| ComparePoint | A comparison against a value, e.g. the >=8 in 8d10>=8. |
| CriticalFailureNode | cf. |
| CriticalSuccessNode | cs. |
| DescriptionNode | A roll description. |
| DieNode | The die of a pool: a reference to a die factory in the DieRegistry, and its arguments. |
| DropNode | d, dh, dl. |
| ExplodeNode | !, !! (compound), !p (penetrate), !!p. |
| FunctionNode | A maths function call, e.g. floor(2d6 / 2). |
| GroupNode | A roll group, e.g. {4d6+2d8, 3d20}k1. |
| KeepNode | k, kh, kl. |
| MaxNode | max5. |
| MinNode | min2. |
| ModifiableOptions | Options shared by pools and groups. |
| NumberNode | A literal number, e.g. 4 or -2.5. |
| ParenNode | A parenthesised expression, e.g. (2+3). Kept so the notation round-trips. |
| PoolNode | A pool of dice, e.g. 4d6kh3. |
| ReRollNode | r, ro. |
| SortNode | s, sa, sd. |
| TargetNode | Success / failure counting, e.g. >=8f<=2. |
| UnaryNode | A unary minus, e.g. -2. |
| UniqueNode | u, uo. |
Type Aliases
| Type Alias | Description |
|---|---|
| BinaryOperator | A supported binary operator. |
| BuiltInDieName | A built-in die factory name; registries can also contain custom names. |
| CompareOperator | An operator accepted by a compare point. |
| DescriptionStyle | - inline: // text or # text - block: /* text */ or [text] |
| DieInput | The die of a pool: a number of sides or an expression (a standard die, e.g. 6 or paren(binary("+", 2, 3))), or a DieNode from die(). |
| ExpressionInput | A number or an expression node. |
| ExpressionNodeType | The type of every expression node. |
| MathFunctionName | A supported maths function name. |
| ModifierName | The name of every modifier node. |
| ModifierNode | A modifier selected by name; an omitted compare point uses the registered handler's default. |
| ModifierNodeOf | The modifier node with the given name. |
| PoolEnd | Which end of the sorted rolls to keep / drop: highest or lowest. |
| SortDirection | ascending or descending. |
Variables
| Variable | Description |
|---|---|
| BINARY_OPERATORS | The binary maths operators. ** is parsed as ^. |
| BUILT_IN_DIE_NAMES | The names of the built-in die factories in the DieRegistry. |
| COMPARE_OPERATORS | Operators accepted by compare points; != and <> both mean not equal. |
| MATH_FUNCTION_NAMES | The supported maths functions. |
Functions
| Function | Description |
|---|---|
| binary | A binary operation, e.g. binary("+", pool(2, 6), 3) for 2d6+3. |
| compare | A compare point, e.g. compare(">=", 8). |
| criticalFailure | Flag critical failures using the supplied compare point or the handler default. |
| criticalSuccess | Flag critical successes using the supplied compare point or the handler default. |
| die | A reference to a die factory, e.g. die("percentile") for d%, or die("range", -2, 3). Register custom names in the die registry used by the evaluator before rolling. Registration is not checked here; custom dice and some built-ins have display-only notation. |
| drop | Drop qty highest (h) or lowest (l) items; quantity defaults to 1. |
| explode | Explode matching rolls; compound and penetrate default to false, and the handler supplies the default compare point. |
| fn | A maths function call, e.g. fn("floor", binary("/", pool(2, 6), 2)). Arity is checked at evaluation. |
| group | A roll group, e.g. group([pool(4, 6), pool(2, 8)]) for {4d6, 2d8}. |
| keep | Keep qty highest (h) or lowest (l) items; quantity defaults to 1. |
| max | Cap die values at value with the built-in handler. |
| min | Raise die values to at least value with the built-in handler. |
| negate | A unary minus. |
| nodeToNotation | Converts an expression to canonical notation, e.g. a pool to 4d6kh3. |
| num | A literal number. |
| paren | A parenthesised expression. |
| pool | A pool of dice, e.g. pool(4, 6) for 4d6, or pool(2, die("fib")). |
| reRoll | Re-roll matching dice; once defaults to false and an omitted compare point uses the handler default. |
| sort | Sort ascending (a, the default) or descending (d). |
| target | Count successes and optional failures; the built-in handler gives successes precedence on overlap. |
| unique | Re-roll duplicate dice with the built-in handler, optionally restricted by a compare point; once defaults to false. |
References
ExpressionNode
Re-exports ExpressionNode