roll-parser 3.0.0-beta.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +142 -9
- package/MIGRATION.md +219 -0
- package/README.md +1026 -154
- package/dist/cli/args.d.ts +1 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +81 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/format.d.ts +15 -3
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.js +18 -0
- package/dist/cli/format.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +14 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/main.d.ts +36 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +83 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/errors.d.ts +332 -17
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +141 -0
- package/dist/errors.js.map +1 -0
- package/dist/evaluator/die.d.ts +27 -0
- package/dist/evaluator/die.d.ts.map +1 -0
- package/dist/evaluator/die.js +19 -0
- package/dist/evaluator/die.js.map +1 -0
- package/dist/evaluator/env.d.ts +89 -0
- package/dist/evaluator/env.d.ts.map +1 -0
- package/dist/evaluator/env.js +11 -0
- package/dist/evaluator/env.js.map +1 -0
- package/dist/evaluator/evaluator.d.ts +41 -75
- package/dist/evaluator/evaluator.d.ts.map +1 -1
- package/dist/evaluator/evaluator.js +914 -0
- package/dist/evaluator/evaluator.js.map +1 -0
- package/dist/evaluator/modifiers/compare.js +15 -0
- package/dist/evaluator/modifiers/compare.js.map +1 -0
- package/dist/evaluator/modifiers/crit-threshold.d.ts +57 -5
- package/dist/evaluator/modifiers/crit-threshold.d.ts.map +1 -1
- package/dist/evaluator/modifiers/crit-threshold.js +42 -0
- package/dist/evaluator/modifiers/crit-threshold.js.map +1 -0
- package/dist/evaluator/modifiers/die-bound.d.ts +29 -0
- package/dist/evaluator/modifiers/die-bound.d.ts.map +1 -0
- package/dist/evaluator/modifiers/die-bound.js +17 -0
- package/dist/evaluator/modifiers/die-bound.js.map +1 -0
- package/dist/evaluator/modifiers/explode.d.ts +13 -5
- package/dist/evaluator/modifiers/explode.d.ts.map +1 -1
- package/dist/evaluator/modifiers/explode.js +105 -0
- package/dist/evaluator/modifiers/explode.js.map +1 -0
- package/dist/evaluator/modifiers/flags.d.ts +47 -0
- package/dist/evaluator/modifiers/flags.d.ts.map +1 -0
- package/dist/evaluator/modifiers/flags.js +25 -0
- package/dist/evaluator/modifiers/flags.js.map +1 -0
- package/dist/evaluator/modifiers/keep-drop.d.ts +15 -29
- package/dist/evaluator/modifiers/keep-drop.d.ts.map +1 -1
- package/dist/evaluator/modifiers/keep-drop.js +82 -0
- package/dist/evaluator/modifiers/keep-drop.js.map +1 -0
- package/dist/evaluator/modifiers/reroll.d.ts +12 -4
- package/dist/evaluator/modifiers/reroll.d.ts.map +1 -1
- package/dist/evaluator/modifiers/reroll.js +68 -0
- package/dist/evaluator/modifiers/reroll.js.map +1 -0
- package/dist/evaluator/modifiers/sort.d.ts +5 -1
- package/dist/evaluator/modifiers/sort.d.ts.map +1 -1
- package/dist/evaluator/modifiers/sort.js +13 -0
- package/dist/evaluator/modifiers/sort.js.map +1 -0
- package/dist/evaluator/modifiers/success-count.d.ts +6 -7
- package/dist/evaluator/modifiers/success-count.d.ts.map +1 -1
- package/dist/evaluator/modifiers/success-count.js +25 -0
- package/dist/evaluator/modifiers/success-count.js.map +1 -0
- package/dist/index.d.ts +33 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2560
- package/dist/index.js.map +1 -26
- package/dist/lexer/lexer.d.ts +50 -5
- package/dist/lexer/lexer.d.ts.map +1 -1
- package/dist/lexer/lexer.js +260 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/lexer/tokens.d.ts +31 -6
- package/dist/lexer/tokens.d.ts.map +1 -1
- package/dist/lexer/tokens.js +42 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/parser/ast.d.ts +324 -165
- package/dist/parser/ast.d.ts.map +1 -1
- package/dist/parser/ast.js +52 -0
- package/dist/parser/ast.js.map +1 -0
- package/dist/parser/guards.d.ts +106 -0
- package/dist/parser/guards.d.ts.map +1 -0
- package/dist/parser/guards.js +121 -0
- package/dist/parser/guards.js.map +1 -0
- package/dist/parser/parser.d.ts +118 -14
- package/dist/parser/parser.d.ts.map +1 -1
- package/dist/parser/parser.js +751 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/render.d.ts +95 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +227 -0
- package/dist/render.js.map +1 -0
- package/dist/rng/mock.d.ts +73 -12
- package/dist/rng/mock.d.ts.map +1 -1
- package/dist/rng/mock.js +30 -0
- package/dist/rng/mock.js.map +1 -0
- package/dist/rng/seeded.d.ts +141 -9
- package/dist/rng/seeded.d.ts.map +1 -1
- package/dist/rng/seeded.js +138 -0
- package/dist/rng/seeded.js.map +1 -0
- package/dist/rng/types.d.ts +57 -0
- package/dist/rng/types.d.ts.map +1 -1
- package/dist/rng/types.js +2 -0
- package/dist/rng/types.js.map +1 -0
- package/dist/roll.d.ts +58 -28
- package/dist/roll.d.ts.map +1 -1
- package/dist/roll.js +8 -0
- package/dist/roll.js.map +1 -0
- package/dist/testing.d.ts +5 -4
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +2 -41
- package/dist/testing.js.map +1 -11
- package/dist/types.d.ts +349 -47
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +93 -34
- package/src/cli/args.ts +66 -10
- package/src/cli/format.ts +37 -26
- package/src/cli/index.ts +27 -84
- package/src/cli/main.ts +129 -0
- package/src/errors.ts +480 -27
- package/src/evaluator/die.ts +51 -0
- package/src/evaluator/env.ts +105 -0
- package/src/evaluator/evaluator.ts +693 -434
- package/src/evaluator/modifiers/crit-threshold.ts +96 -14
- package/src/evaluator/modifiers/die-bound.ts +48 -0
- package/src/evaluator/modifiers/explode.ts +70 -62
- package/src/evaluator/modifiers/flags.ts +78 -0
- package/src/evaluator/modifiers/keep-drop.ts +129 -127
- package/src/evaluator/modifiers/reroll.ts +44 -56
- package/src/evaluator/modifiers/sort.ts +21 -2
- package/src/evaluator/modifiers/success-count.ts +24 -12
- package/src/index.ts +56 -35
- package/src/lexer/lexer.ts +107 -34
- package/src/lexer/tokens.ts +31 -6
- package/src/parser/ast.ts +333 -346
- package/src/parser/guards.ts +248 -0
- package/src/parser/parser.ts +419 -242
- package/src/render.ts +392 -0
- package/src/rng/mock.ts +74 -13
- package/src/rng/seeded.ts +299 -64
- package/src/rng/types.ts +57 -0
- package/src/roll.ts +64 -47
- package/src/testing.ts +5 -9
- package/src/types.ts +353 -46
- package/src/version.ts +2 -0
- package/dist/cli.js +0 -2608
- package/dist/cli.js.map +0 -28
- package/dist/evaluator/index.d.ts +0 -8
- package/dist/evaluator/index.d.ts.map +0 -1
- package/dist/rng/index.d.ts +0 -8
- package/dist/rng/index.d.ts.map +0 -1
- package/src/evaluator/index.ts +0 -14
- package/src/rng/index.ts +0 -8
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-evaluation shared environment.
|
|
3
|
+
*
|
|
4
|
+
* Lives in its own module so the modifier implementations under
|
|
5
|
+
* `./modifiers/*` can type their `env` parameter without importing
|
|
6
|
+
* `./evaluator.js`, which imports them back.
|
|
7
|
+
*
|
|
8
|
+
* @module evaluator/env
|
|
9
|
+
*/
|
|
10
|
+
import type { ASTNode } from '../parser/ast.js';
|
|
11
|
+
import type { DieResult, ResolvedCritThreshold } from '../types.js';
|
|
12
|
+
/**
|
|
13
|
+
* A resolved `cs`/`cf` pair, recorded per die so that dice minted later by
|
|
14
|
+
* explode or reroll can be judged by the rule the user declared instead of
|
|
15
|
+
* the built-in default.
|
|
16
|
+
*/
|
|
17
|
+
export type CritRule = {
|
|
18
|
+
readonly success: readonly ResolvedCritThreshold[];
|
|
19
|
+
readonly fail: readonly ResolvedCritThreshold[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Per-evaluation shared environment (created once, shared across all branches).
|
|
23
|
+
*
|
|
24
|
+
* Exported for use by modifier implementations under `./modifiers/*`. Not part
|
|
25
|
+
* of the public library API.
|
|
26
|
+
*/
|
|
27
|
+
export type EvalEnv = {
|
|
28
|
+
readonly maxDice: number;
|
|
29
|
+
readonly maxExplodeIterations: number;
|
|
30
|
+
readonly maxRerollIterations: number;
|
|
31
|
+
totalDiceRolled: number;
|
|
32
|
+
/**
|
|
33
|
+
* Set to `true` by `evalSuccessCount`. Propagates through the shared env
|
|
34
|
+
* so `evaluate()` can include `successes`/`failures` fields even when no
|
|
35
|
+
* die was tagged (impossible threshold).
|
|
36
|
+
*/
|
|
37
|
+
hasSuccessCount: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* `true` while the evaluator is inside a `VersusNode`'s roll or DC
|
|
40
|
+
* sub-evaluation. `evalVersus` rejects nesting via this flag — catches
|
|
41
|
+
* paren-nested versus (`1d20 vs (5 vs 3)`) that slip past the parser's
|
|
42
|
+
* left-chain check.
|
|
43
|
+
*/
|
|
44
|
+
insideVersus: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* `true` once a `vs` has tagged its DC dice `'dc'`. Lets every pool
|
|
47
|
+
* operation skip its per-die `isVersusDc` check outright — the tag exists in
|
|
48
|
+
* a small minority of notation, and the call inside the loop cost 11-38% on
|
|
49
|
+
* keep/drop, success, and sort notation that can never carry one (#281).
|
|
50
|
+
*
|
|
51
|
+
* ! Monotonic: set by `evalVersus`, never cleared. `insideVersus` is not a
|
|
52
|
+
* ! model for it — that flag resets in a `finally`, and it is false exactly
|
|
53
|
+
* ! when the tagged DC dice become visible to the enclosing pool.
|
|
54
|
+
*/
|
|
55
|
+
hasVersusDc: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Crit rule per die, keyed on the `DieResult` object itself. Populated by
|
|
58
|
+
* `applyCritThresholds`; read by explode and reroll so a die they mint
|
|
59
|
+
* inherits the rule of the die it descended from.
|
|
60
|
+
*
|
|
61
|
+
* Out of band rather than a `DieResult` field because `DieResult` is public
|
|
62
|
+
* and serialized. `undefined` until the first `cs`/`cf` node — declared here
|
|
63
|
+
* so the shape stays stable for notation that has none.
|
|
64
|
+
*/
|
|
65
|
+
critRules: WeakMap<DieResult, CritRule> | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* User-supplied variable map for `@name` / `@{name}` references. Always
|
|
68
|
+
* defined — `evaluate()` defaults to an empty object so lookups can be
|
|
69
|
+
* branch-free on presence.
|
|
70
|
+
*/
|
|
71
|
+
readonly context: Readonly<Record<string, number>>;
|
|
72
|
+
/**
|
|
73
|
+
* Behavior when a referenced variable is missing from `context`. Always
|
|
74
|
+
* defined — `evaluate()` defaults to `'throw'`.
|
|
75
|
+
*/
|
|
76
|
+
readonly onMissingVariable: 'throw' | 'zero';
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Reserves `count` dice against the global `maxDice` budget, throwing
|
|
80
|
+
* `DICE_LIMIT_EXCEEDED` when the reservation would overshoot.
|
|
81
|
+
*
|
|
82
|
+
* Every path that consumes RNG draws for dice charges through here — initial
|
|
83
|
+
* pools (`evalDice` / `evalFateDice`), explosion continuations, and reroll
|
|
84
|
+
* replacements — so the limit and its message have one definition.
|
|
85
|
+
*/
|
|
86
|
+
export declare function chargeDice(env: EvalEnv, count: number, nodeType: ASTNode['type']): void;
|
|
87
|
+
/** Single-die shorthand for {@link chargeDice}. */
|
|
88
|
+
export declare function chargeDie(env: EvalEnv, nodeType: ASTNode['type']): void;
|
|
89
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/evaluator/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpE;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,qBAAqB,EAAE,CAAC;IACnD,QAAQ,CAAC,IAAI,EAAE,SAAS,qBAAqB,EAAE,CAAC;CACjD,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,eAAe,EAAE,OAAO,CAAC;IACzB;;;;;OAKG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB;;;;;;;;;OASG;IACH,WAAW,EAAE,OAAO,CAAC;IACrB;;;;;;;;OAQG;IACH,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC;IACpD;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,EAAE,OAAO,GAAG,MAAM,CAAC;CAC9C,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CASvF;AAED,mDAAmD;AACnD,wBAAgB,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAEvE"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EvaluatorError } from '../errors.js';
|
|
2
|
+
export function chargeDice(env, count, nodeType) {
|
|
3
|
+
if (env.totalDiceRolled + count > env.maxDice) {
|
|
4
|
+
throw new EvaluatorError(`Total dice count ${env.totalDiceRolled + count} exceeds limit of ${env.maxDice}`, 'DICE_LIMIT_EXCEEDED', nodeType);
|
|
5
|
+
}
|
|
6
|
+
env.totalDiceRolled += count;
|
|
7
|
+
}
|
|
8
|
+
export function chargeDie(env, nodeType) {
|
|
9
|
+
chargeDice(env, 1, nodeType);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=env.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/evaluator/env.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAgF9C,MAAM,UAAU,UAAU,CAAC,GAAY,EAAE,KAAa,EAAE,QAAyB;IAC/E,IAAI,GAAG,CAAC,eAAe,GAAG,KAAK,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;QAC9C,MAAM,IAAI,cAAc,CACtB,oBAAoB,GAAG,CAAC,eAAe,GAAG,KAAK,qBAAqB,GAAG,CAAC,OAAO,EAAE,EACjF,qBAAqB,EACrB,QAAQ,CACT,CAAC;IACJ,CAAC;IACD,GAAG,CAAC,eAAe,IAAI,KAAK,CAAC;AAC/B,CAAC;AAGD,MAAM,UAAU,SAAS,CAAC,GAAY,EAAE,QAAyB;IAC/D,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -3,71 +3,32 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module evaluator/evaluator
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
import { RollParserError } from '../errors.js';
|
|
6
|
+
import { EvaluatorError } from '../errors.js';
|
|
8
7
|
import type { ASTNode } from '../parser/ast.js';
|
|
9
8
|
import type { RNG } from '../rng/types.js';
|
|
10
9
|
import type { DieResult, EvaluateOptions, RollResult } from '../types.js';
|
|
11
10
|
import { DegreeOfSuccess } from '../types.js';
|
|
12
11
|
import { DEFAULT_MAX_EXPLODE_ITERATIONS } from './modifiers/explode.js';
|
|
13
12
|
import { DEFAULT_MAX_REROLL_ITERATIONS } from './modifiers/reroll.js';
|
|
13
|
+
export { EvaluatorError };
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Default value of `EvaluationOptions.maxDice`: the number of dice a single
|
|
16
|
+
* evaluation may roll before `DICE_LIMIT_EXCEEDED` is thrown.
|
|
17
|
+
*
|
|
18
|
+
* Counted across the whole expression, not per pool, so `6000d6+6000d6`
|
|
19
|
+
* breaches it. Includes dice rolled by explosions, rerolls, and
|
|
20
|
+
* meta-expressions.
|
|
21
|
+
*
|
|
22
|
+
* @category Limits
|
|
16
23
|
*/
|
|
17
|
-
export declare class EvaluatorError extends RollParserError {
|
|
18
|
-
readonly nodeType: string | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Source span of the tightest AST node that was being evaluated when the
|
|
21
|
-
* error was thrown — stamped by `evalNode` on the way up, so the innermost
|
|
22
|
-
* node wins. `undefined` when the AST was built without parser spans.
|
|
23
|
-
*/
|
|
24
|
-
start: number | undefined;
|
|
25
|
-
end: number | undefined;
|
|
26
|
-
constructor(message: string, code: RollParserErrorCode, nodeType?: string);
|
|
27
|
-
}
|
|
28
|
-
/** Default maximum total dice allowed per evaluation. */
|
|
29
24
|
export declare const DEFAULT_MAX_DICE = 10000;
|
|
30
25
|
export { DEFAULT_MAX_EXPLODE_ITERATIONS, DEFAULT_MAX_REROLL_ITERATIONS };
|
|
31
|
-
/**
|
|
32
|
-
* Per-evaluation shared environment (created once, shared across all branches).
|
|
33
|
-
*
|
|
34
|
-
* Exported for use by modifier implementations under `./modifiers/*`. Not part
|
|
35
|
-
* of the public library API.
|
|
36
|
-
*/
|
|
37
|
-
export type EvalEnv = {
|
|
38
|
-
readonly maxDice: number;
|
|
39
|
-
readonly maxExplodeIterations: number;
|
|
40
|
-
readonly maxRerollIterations: number;
|
|
41
|
-
totalDiceRolled: number;
|
|
42
|
-
/**
|
|
43
|
-
* Set to `true` by `evalSuccessCount`. Propagates through the shared env
|
|
44
|
-
* so `evaluate()` can include `successes`/`failures` fields even when no
|
|
45
|
-
* die was tagged (impossible threshold).
|
|
46
|
-
*/
|
|
47
|
-
hasSuccessCount: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* `true` while the evaluator is inside a `VersusNode`'s roll or DC
|
|
50
|
-
* sub-evaluation. `evalVersus` rejects nesting via this flag — catches
|
|
51
|
-
* paren-nested versus (`1d20 vs (5 vs 3)`) that slip past the parser's
|
|
52
|
-
* left-chain check.
|
|
53
|
-
*/
|
|
54
|
-
insideVersus: boolean;
|
|
55
|
-
/**
|
|
56
|
-
* User-supplied variable map for `@name` / `@{name}` references. Always
|
|
57
|
-
* defined — `evaluate()` defaults to an empty object so lookups can be
|
|
58
|
-
* branch-free on presence.
|
|
59
|
-
*/
|
|
60
|
-
readonly context: Readonly<Record<string, number>>;
|
|
61
|
-
/**
|
|
62
|
-
* Behavior when a referenced variable is missing from `context`. Always
|
|
63
|
-
* defined — `evaluate()` defaults to `'throw'`.
|
|
64
|
-
*/
|
|
65
|
-
readonly onMissingVariable: 'throw' | 'zero';
|
|
66
|
-
};
|
|
67
26
|
/**
|
|
68
27
|
* Per-branch mutable accumulator for tracking rolls and output during recursion.
|
|
69
28
|
*
|
|
70
|
-
*
|
|
29
|
+
* Module-level export, deliberately absent from `src/index.ts` — the package
|
|
30
|
+
* surface never mentions it. See {@link mergeMetaRolls} for why the export
|
|
31
|
+
* exists at all.
|
|
71
32
|
*/
|
|
72
33
|
export type EvalContext = {
|
|
73
34
|
rolls: DieResult[];
|
|
@@ -86,36 +47,41 @@ export type EvalContext = {
|
|
|
86
47
|
};
|
|
87
48
|
};
|
|
88
49
|
/**
|
|
89
|
-
*
|
|
90
|
-
* audit trail, tagging them as `'meta'` + `'dropped'`. Meta dice are dice
|
|
91
|
-
* rolled to compute parameters (dice count, sides, threshold, modifier
|
|
92
|
-
* count) — they consume RNG and count against `maxDice`, so they must be
|
|
93
|
-
* inspectable. Tagging them `'dropped'` keeps totals correct via
|
|
94
|
-
* `sumKeptDice`; `'meta'` lets renderers hide them and lets callers
|
|
95
|
-
* distinguish them from ordinary pool dice.
|
|
50
|
+
* Evaluates a parsed AST against an {@link RNG} and returns the roll result.
|
|
96
51
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
export declare function mergeMetaRolls(parent: EvalContext, source: EvalContext): void;
|
|
104
|
-
/**
|
|
105
|
-
* Evaluates a parsed AST and returns the roll result.
|
|
52
|
+
* The second half of the pipeline — {@link roll} is `evaluate(parse(...))`.
|
|
53
|
+
* Call it directly to reuse one AST across many rolls, or to drive a
|
|
54
|
+
* hand-built AST.
|
|
55
|
+
*
|
|
56
|
+
* Unlike `roll`, the RNG is required: `evaluate` never invents a randomness
|
|
57
|
+
* source, so a caller can never accidentally get an unseeded roll.
|
|
106
58
|
*
|
|
107
|
-
* @param ast - The
|
|
108
|
-
* @param rng -
|
|
109
|
-
* @param options -
|
|
110
|
-
*
|
|
59
|
+
* @param ast - The AST to evaluate, from {@link parse} or hand-built
|
|
60
|
+
* @param rng - Randomness source; one `nextInt` call per die
|
|
61
|
+
* @param options - Evaluation limits plus the original `notation` string,
|
|
62
|
+
* which the AST cannot supply
|
|
63
|
+
* @returns Complete {@link RollResult}
|
|
64
|
+
* @throws {EvaluatorError} On a limit breach, division by zero, an undefined
|
|
65
|
+
* variable, or a non-finite total
|
|
66
|
+
* @throws {RollParserError} `INVALID_EVALUATION_LIMIT` when a supplied limit is
|
|
67
|
+
* not an integer in range — raised before any die is rolled
|
|
111
68
|
*
|
|
112
69
|
* @example
|
|
113
70
|
* ```typescript
|
|
71
|
+
* import { evaluate, parse } from 'roll-parser';
|
|
72
|
+
* import { createMockRng } from 'roll-parser/testing';
|
|
73
|
+
*
|
|
114
74
|
* const ast = parse('2d6+3');
|
|
115
|
-
* const
|
|
116
|
-
*
|
|
117
|
-
*
|
|
75
|
+
* const result = evaluate(ast, createMockRng([4, 2]), { notation: '2d6+3' });
|
|
76
|
+
* result.total; // 9
|
|
77
|
+
* result.rendered; // '2d6[4, 2] + 3 = 9'
|
|
118
78
|
* ```
|
|
79
|
+
*
|
|
80
|
+
* Omitting `notation` falls back to the normalized `expression`, which is
|
|
81
|
+
* reconstructed from the AST — so `RollResult.notation` is always a string,
|
|
82
|
+
* just not necessarily the one the user typed.
|
|
83
|
+
*
|
|
84
|
+
* @category Core
|
|
119
85
|
*/
|
|
120
86
|
export declare function evaluate(ast: ASTNode, rng: RNG, options?: EvaluateOptions): RollResult;
|
|
121
87
|
//# sourceMappingURL=evaluator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/evaluator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/evaluator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAiB,cAAc,EAAuC,MAAM,cAAc,CAAC;AAClG,OAAO,KAAK,EACV,OAAO,EAmBR,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAIV,SAAS,EACT,eAAe,EAKf,UAAU,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAK9C,OAAO,EAKL,8BAA8B,EAC/B,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAGL,6BAA6B,EAC9B,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EAAE,cAAc,EAAE,CAAC;AAM1B;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAmCvC,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,CAAC;AAMzE;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB;;;;;OAKG;IACH,cAAc,CAAC,EAAE;QACf,MAAM,EAAE,eAAe,CAAC;QACxB,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;QAC5B,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAogDF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,eAAoB,GAAG,UAAU,CA8D1F"}
|