Skip to content

@dice-roller/rpg-dice-roller / ast

ast โ€‹

Expression tree nodes and notation helpers for inspecting or constructing rolls.

Interfaces โ€‹

InterfaceDescription
BinaryNodeA binary maths operation, e.g. 2d6 + 3.
ComparePointA comparison against a value, e.g. the >=8 in 8d10>=8.
ComputedDropNodeA drop quantity preserved as an unevaluated parenthesised expression.
ComputedKeepNodeA keep quantity preserved as an unevaluated parenthesised expression.
ConditionalNodeA conditional expression; null preserves the omitted true-branch shorthand.
CriticalFailureNodecf.
CriticalSuccessNodecs.
DescriptionNodeA roll description.
DieNodeThe die of a pool: a reference to a die factory in the DieRegistry, and its arguments.
DropNoded, dh, dl.
ExplodeMatchingBatchNode!m[limit][comparePoint][f failureComparePoint]
ExplodeNode!, !! (compound), !p (penetrate), !!p.
FunctionNodeA maths function call, e.g. floor(2d6 / 2).
GroupNodeA roll group, e.g. {4d6+2d8, 3d20}k1.
KeepNodek, kh, kl.
MapNodemap(expression).
MaxNodemax5.
MinNodemin2.
ModifiableOptionsOptions shared by pools and groups.
NumberNodeA literal number, e.g. 4 or -2.5.
ParenNodeA parenthesised expression, e.g. (2+3). Kept so the notation round-trips.
PoolNodeA pool of dice, e.g. 4d6kh3.
ReferenceNodeA reference to a caller data path or an externally supplied system binding.
ReRollNoder, ro and numeric re-roll limits.
SortNodes, sa, sd.
TargetNodeSuccess / failure counting, e.g. >=8:2f<=2. The last matching rule in the block wins.
TargetRuleA target comparison; amount is a whole number from 1 to 10 and defaults to 1.
UnaryNodeA unary minus, e.g. -2.
UniqueNodeu, uo and numeric uniqueness limits.

Type Aliases โ€‹

Type AliasDescription
BinaryOperatorA supported binary operator.
BuiltInDieNameA built-in die factory name; registries can also contain custom names.
DescriptionStyle- inline: // text or # text - block: /* text */ or [text]
DieInputThe 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().
ExpressionInputA number or an expression node.
ExpressionNodeTypeThe type of every expression node.
MathFunctionNameA supported maths function name.
ModifierNameThe name of every modifier node.
ModifierNodeA modifier selected by name; an omitted compare point uses the registered handler's default.
ModifierNodeOfThe modifier node with the given name.
PoolEndWhich end of the sorted rolls to keep / drop: highest or lowest.
ReferenceNamespaceThe namespace used to resolve a reference.
SortDirectionascending or descending.

Variables โ€‹

VariableDescription
BINARY_OPERATORSThe binary maths operators. ** is parsed as ^.
BUILT_IN_DIE_NAMESThe names of the built-in die factories in the DieRegistry.
COMPARE_OPERATORSOperators accepted by compare points; != and <> both mean not equal.
MATH_FUNCTION_NAMESThe supported maths functions.

Functions โ€‹

FunctionDescription
binaryA binary operation, e.g. binary("+", pool(2, 6), 3) for 2d6+3.
compareA compare point, e.g. compare(">=", 8).
comparisonA numeric comparison, e.g. comparison(">=", pool(2, 6), 8).
conditionalA conditional expression, using null for the shorthand's omitted true branch.
conditionReferenceA convenience builder for the system binding condition.
criticalFailureFlag critical failures using the supplied compare point or the handler default.
criticalSuccessFlag critical successes using the supplied compare point or the handler default.
dieA 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.
dropDrop qty highest (h) or lowest (l) items; quantity defaults to 1.
explodeExplode 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.
explodeMatchingBatchExplodes complete pool batches whose dice all match; an optional failure comparison stops !m.
fnA maths function call, e.g. fn("floor", binary("/", pool(2, 6), 2)). Arity is checked at evaluation.
groupA roll group, e.g. group([pool(4, 6), pool(2, 8)]) for {4d6, 2d8}.
keepKeep qty highest (h) or lowest (l) items; quantity defaults to 1.
mapMap each die or group member through an expression.
maxCap die values at value with the built-in handler.
minRaise die values to at least value with the built-in handler.
negateA unary minus.
nodeToNotationConverts an expression to canonical notation, e.g. a pool to 4d6kh3.
numA literal number.
parenA parenthesised expression.
poolA pool of dice, e.g. pool(4, 6) for 4d6, or pool(2, die("fib")).
referenceA caller-data or system reference, e.g. reference("data", "character", "level").
reRollRe-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.
sortSort ascending (a, the default) or descending (d).
targetA 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.
uniqueRe-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

MIT Licensed ยท Credits