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.
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.
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.
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.
ReRollNoder, ro.
SortNodes, sa, sd.
TargetNodeSuccess / failure counting, e.g. >=8f<=2.
UnaryNodeA unary minus, e.g. -2.
UniqueNodeu, uo.

Type Aliases ​

Type AliasDescription
BinaryOperatorA supported binary operator.
BuiltInDieNameA built-in die factory name; registries can also contain custom names.
CompareOperatorAn operator accepted by a compare point.
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.
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).
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; custom dice and some built-ins have display-only notation.
dropDrop qty highest (h) or lowest (l) items; quantity defaults to 1.
explodeExplode matching rolls; compound and penetrate default to false, and the handler supplies the default compare point.
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.
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")).
reRollRe-roll matching dice; once defaults to false and an omitted compare point uses the handler default.
sortSort ascending (a, the default) or descending (d).
targetCount successes and optional failures; the built-in handler gives successes precedence on overlap.
uniqueRe-roll duplicate dice with the built-in handler, optionally restricted by a compare point; once defaults to false.

References ​

ExpressionNode ​

Re-exports ExpressionNode

MIT Licensed · Credits