@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. |
| ComputedDropNode | A drop quantity preserved as an unevaluated parenthesised expression. |
| ComputedKeepNode | A keep quantity preserved as an unevaluated parenthesised expression. |
| ConditionalNode | A conditional expression; null preserves the omitted true-branch shorthand. |
| 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. |
| ExplodeMatchingBatchNode | !m[limit][comparePoint][f failureComparePoint] |
| 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. |
| MapNode | map(expression). |
| 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. |
| ReferenceNode | A reference to a caller data path or an externally supplied system binding. |
| ReRollNode | r, ro and numeric re-roll limits. |
| SortNode | s, sa, sd. |
| TargetNode | Success / failure counting, e.g. >=8:2f<=2. The last matching rule in the block wins. |
| TargetRule | A target comparison; amount is a whole number from 1 to 10 and defaults to 1. |
| UnaryNode | A unary minus, e.g. -2. |
| UniqueNode | u, uo and numeric uniqueness limits. |
Type Aliases โ
| Type Alias | Description |
|---|---|
| BinaryOperator | A supported binary operator. |
| BuiltInDieName | A built-in die factory name; registries can also contain custom names. |
| 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. |
| ReferenceNamespace | The namespace used to resolve a reference. |
| 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). |
| comparison | A numeric comparison, e.g. comparison(">=", pool(2, 6), 8). |
| conditional | A conditional expression, using null for the shorthand's omitted true branch. |
| conditionReference | A convenience builder for the system binding condition. |
| 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; valid literal range and face dice use brace notation, while custom names and unsupported arguments have display-only notation. |
| drop | Drop qty highest (h) or lowest (l) items; quantity defaults to 1. |
| explode | Explode matching rolls. An optional positive safe-integer limit bounds generations per initial die and is capped by the roll context's maxIterations; amount is the positive safe-integer number of child dice generated per match and defaults to 1. |
| explodeMatchingBatch | Explodes complete pool batches whose dice all match; an optional failure comparison stops !m. |
| 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. |
| map | Map each die or group member through an expression. |
| 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")). |
| reference | A caller-data or system reference, e.g. reference("data", "character", "level"). |
| reRoll | Re-roll matching dice. once is the ro alias; numeric limit: 1 has the same budget but retains r1 notation. Limits count generations per die and cannot exceed the context cap; amount is the positive safe-integer number of replacement dice generated per match and defaults to 1. |
| sort | Sort ascending (a, the default) or descending (d). |
| target | A target block starts with a success and can contain further success or failure rules. Amounts are 1โ10 and default to 1; the last matching rule wins. |
| unique | Re-roll duplicate dice. once is the uo alias; numeric limit: 1 has the same budget but retains u1 notation. Limits count additional rolls per die and cannot exceed the context cap. |
References โ
CompareOperator โ
Re-exports CompareOperator
ComparisonNode โ
Re-exports ComparisonNode
ExpressionNode โ
Re-exports ExpressionNode