roll-parser 3.0.0-alpha.0 → 3.0.0-beta.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 +91 -0
- package/README.md +166 -30
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/format.d.ts +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli.js +1110 -277
- package/dist/cli.js.map +28 -0
- package/dist/errors.d.ts +7 -4
- package/dist/errors.d.ts.map +1 -1
- package/dist/evaluator/evaluator.d.ts +63 -7
- package/dist/evaluator/evaluator.d.ts.map +1 -1
- package/dist/evaluator/index.d.ts +2 -2
- package/dist/evaluator/index.d.ts.map +1 -1
- package/dist/evaluator/modifiers/compare.d.ts +1 -1
- package/dist/evaluator/modifiers/compare.d.ts.map +1 -1
- package/dist/evaluator/modifiers/crit-threshold.d.ts +28 -0
- package/dist/evaluator/modifiers/crit-threshold.d.ts.map +1 -0
- package/dist/evaluator/modifiers/explode.d.ts +8 -4
- package/dist/evaluator/modifiers/explode.d.ts.map +1 -1
- package/dist/evaluator/modifiers/keep-drop.d.ts +1 -1
- package/dist/evaluator/modifiers/keep-drop.d.ts.map +1 -1
- package/dist/evaluator/modifiers/reroll.d.ts +4 -4
- package/dist/evaluator/modifiers/reroll.d.ts.map +1 -1
- package/dist/evaluator/modifiers/sort.d.ts +23 -0
- package/dist/evaluator/modifiers/sort.d.ts.map +1 -0
- package/dist/evaluator/modifiers/success-count.d.ts +1 -1
- package/dist/evaluator/modifiers/success-count.d.ts.map +1 -1
- package/dist/index.d.ts +13 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1112 -275
- package/dist/index.js.map +26 -0
- package/dist/lexer/lexer.d.ts +18 -3
- package/dist/lexer/lexer.d.ts.map +1 -1
- package/dist/lexer/tokens.d.ts +22 -2
- package/dist/lexer/tokens.d.ts.map +1 -1
- package/dist/parser/ast.d.ts +209 -24
- package/dist/parser/ast.d.ts.map +1 -1
- package/dist/parser/parser.d.ts +48 -5
- package/dist/parser/parser.d.ts.map +1 -1
- package/dist/rng/index.d.ts +2 -2
- package/dist/rng/index.d.ts.map +1 -1
- package/dist/rng/mock.d.ts +1 -1
- package/dist/rng/mock.d.ts.map +1 -1
- package/dist/rng/seeded.d.ts +8 -1
- package/dist/rng/seeded.d.ts.map +1 -1
- package/dist/roll.d.ts +6 -2
- package/dist/roll.d.ts.map +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +3 -0
- package/dist/testing.js.map +11 -0
- package/dist/types.d.ts +143 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -18
- package/src/cli/args.ts +2 -1
- package/src/cli/format.ts +8 -4
- package/src/cli/index.ts +22 -5
- package/src/errors.ts +15 -3
- package/src/evaluator/evaluator.ts +826 -111
- package/src/evaluator/index.ts +2 -2
- package/src/evaluator/modifiers/compare.ts +1 -1
- package/src/evaluator/modifiers/crit-threshold.ts +59 -0
- package/src/evaluator/modifiers/explode.ts +29 -25
- package/src/evaluator/modifiers/keep-drop.ts +1 -1
- package/src/evaluator/modifiers/reroll.ts +18 -25
- package/src/evaluator/modifiers/sort.ts +30 -0
- package/src/evaluator/modifiers/success-count.ts +2 -2
- package/src/index.ts +33 -15
- package/src/lexer/lexer.ts +101 -8
- package/src/lexer/tokens.ts +42 -2
- package/src/parser/ast.ts +397 -30
- package/src/parser/parser.ts +590 -67
- package/src/rng/index.ts +2 -2
- package/src/rng/mock.ts +1 -1
- package/src/rng/seeded.ts +31 -1
- package/src/roll.ts +14 -6
- package/src/testing.ts +1 -1
- package/src/types.ts +127 -2
- package/dist/index.mjs +0 -1724
- package/dist/testing.mjs +0 -39
package/dist/errors.d.ts
CHANGED
|
@@ -10,14 +10,17 @@
|
|
|
10
10
|
*
|
|
11
11
|
* Lexer: `UNEXPECTED_CHARACTER`, `UNEXPECTED_IDENTIFIER`
|
|
12
12
|
* Parser: `UNEXPECTED_TOKEN`, `UNEXPECTED_END`, `EXPECTED_TOKEN`,
|
|
13
|
-
* `
|
|
14
|
-
* `
|
|
13
|
+
* `INVALID_MODIFIER_TARGET`, `INVALID_EXPLODE_TARGET`, `INVALID_REROLL_TARGET`,
|
|
14
|
+
* `INVALID_SUCCESS_COUNT_TARGET`, `INVALID_SORT_TARGET`,
|
|
15
|
+
* `INVALID_CRIT_THRESHOLD_TARGET`, `NESTED_VERSUS`, `INVALID_FUNCTION_ARITY`,
|
|
16
|
+
* `AMBIGUOUS_DICE_CHAIN`, `MAX_DEPTH_EXCEEDED`
|
|
15
17
|
* Evaluator: `INVALID_DICE_COUNT`, `INVALID_DICE_SIDES`, `DICE_LIMIT_EXCEEDED`,
|
|
16
18
|
* `DIVISION_BY_ZERO`, `MODULO_BY_ZERO`, `UNKNOWN_OPERATOR`, `UNKNOWN_NODE_TYPE`,
|
|
17
19
|
* `INVALID_MODIFIER_COUNT`, `EXPLODE_LIMIT_EXCEEDED`, `REROLL_LIMIT_EXCEEDED`,
|
|
18
|
-
* `INVALID_THRESHOLD`, `NESTED_VERSUS`, `UNKNOWN_FUNCTION`
|
|
20
|
+
* `INVALID_THRESHOLD`, `NESTED_VERSUS`, `UNKNOWN_FUNCTION`, `UNDEFINED_VARIABLE`,
|
|
21
|
+
* `INVALID_VARIABLE_VALUE`, `NON_FINITE_RESULT`
|
|
19
22
|
*/
|
|
20
|
-
declare const ROLL_PARSER_ERROR_CODES: readonly ["UNEXPECTED_CHARACTER", "UNEXPECTED_IDENTIFIER", "UNEXPECTED_TOKEN", "UNEXPECTED_END", "EXPECTED_TOKEN", "INVALID_DICE_COUNT", "INVALID_DICE_SIDES", "DICE_LIMIT_EXCEEDED", "DIVISION_BY_ZERO", "MODULO_BY_ZERO", "UNKNOWN_OPERATOR", "UNKNOWN_NODE_TYPE", "INVALID_MODIFIER_COUNT", "EXPLODE_LIMIT_EXCEEDED", "INVALID_EXPLODE_TARGET", "REROLL_LIMIT_EXCEEDED", "INVALID_SUCCESS_COUNT_TARGET", "INVALID_THRESHOLD", "NESTED_VERSUS", "INVALID_FUNCTION_ARITY", "UNKNOWN_FUNCTION"];
|
|
23
|
+
declare const ROLL_PARSER_ERROR_CODES: readonly ["UNEXPECTED_CHARACTER", "UNEXPECTED_IDENTIFIER", "UNEXPECTED_TOKEN", "UNEXPECTED_END", "EXPECTED_TOKEN", "INVALID_DICE_COUNT", "INVALID_DICE_SIDES", "DICE_LIMIT_EXCEEDED", "DIVISION_BY_ZERO", "MODULO_BY_ZERO", "UNKNOWN_OPERATOR", "UNKNOWN_NODE_TYPE", "INVALID_MODIFIER_COUNT", "INVALID_MODIFIER_TARGET", "EXPLODE_LIMIT_EXCEEDED", "INVALID_EXPLODE_TARGET", "REROLL_LIMIT_EXCEEDED", "INVALID_REROLL_TARGET", "INVALID_SUCCESS_COUNT_TARGET", "INVALID_SORT_TARGET", "INVALID_CRIT_THRESHOLD_TARGET", "INVALID_THRESHOLD", "NESTED_VERSUS", "INVALID_FUNCTION_ARITY", "UNKNOWN_FUNCTION", "UNDEFINED_VARIABLE", "INVALID_VARIABLE_VALUE", "AMBIGUOUS_DICE_CHAIN", "MAX_DEPTH_EXCEEDED", "NON_FINITE_RESULT"];
|
|
21
24
|
export type RollParserErrorCode = (typeof ROLL_PARSER_ERROR_CODES)[number];
|
|
22
25
|
/**
|
|
23
26
|
* Base error class for all roll-parser errors.
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;GAgBG;AACH,QAAA,MAAM,uBAAuB,gsBA+BnB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3E;;;;;;GAMG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB;CAKvD;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAQ1E"}
|
|
@@ -3,18 +3,26 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module evaluator/evaluator
|
|
5
5
|
*/
|
|
6
|
-
import type { RollParserErrorCode } from '../errors';
|
|
7
|
-
import { RollParserError } from '../errors';
|
|
8
|
-
import type { ASTNode } from '../parser/ast';
|
|
9
|
-
import type { RNG } from '../rng/types';
|
|
10
|
-
import type { EvaluateOptions, RollResult } from '../types';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
6
|
+
import type { RollParserErrorCode } from '../errors.js';
|
|
7
|
+
import { RollParserError } from '../errors.js';
|
|
8
|
+
import type { ASTNode } from '../parser/ast.js';
|
|
9
|
+
import type { RNG } from '../rng/types.js';
|
|
10
|
+
import type { DieResult, EvaluateOptions, RollResult } from '../types.js';
|
|
11
|
+
import { DegreeOfSuccess } from '../types.js';
|
|
12
|
+
import { DEFAULT_MAX_EXPLODE_ITERATIONS } from './modifiers/explode.js';
|
|
13
|
+
import { DEFAULT_MAX_REROLL_ITERATIONS } from './modifiers/reroll.js';
|
|
13
14
|
/**
|
|
14
15
|
* Error thrown during AST evaluation.
|
|
15
16
|
*/
|
|
16
17
|
export declare class EvaluatorError extends RollParserError {
|
|
17
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;
|
|
18
26
|
constructor(message: string, code: RollParserErrorCode, nodeType?: string);
|
|
19
27
|
}
|
|
20
28
|
/** Default maximum total dice allowed per evaluation. */
|
|
@@ -44,7 +52,55 @@ export type EvalEnv = {
|
|
|
44
52
|
* left-chain check.
|
|
45
53
|
*/
|
|
46
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';
|
|
47
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Per-branch mutable accumulator for tracking rolls and output during recursion.
|
|
69
|
+
*
|
|
70
|
+
* @internal exported for targeted `mergeMetaRolls` tests only; not a public API.
|
|
71
|
+
*/
|
|
72
|
+
export type EvalContext = {
|
|
73
|
+
rolls: DieResult[];
|
|
74
|
+
expressionParts: string[];
|
|
75
|
+
renderedParts: string[];
|
|
76
|
+
/**
|
|
77
|
+
* Populated by `evalVersus` with the resolved degree and natural value.
|
|
78
|
+
* `evaluate()` reads this from the top-level ctx to surface `degree` and
|
|
79
|
+
* `natural` on the final `RollResult`. Only populated when `vs` is the
|
|
80
|
+
* root of the expression.
|
|
81
|
+
*/
|
|
82
|
+
versusMetadata?: {
|
|
83
|
+
degree: DegreeOfSuccess;
|
|
84
|
+
natural: number | undefined;
|
|
85
|
+
dcTotal: number;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Forwards rolls from a throwaway sub-expression context into the parent
|
|
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.
|
|
96
|
+
*
|
|
97
|
+
* `'success'`/`'failure'` tags are stripped here as defense-in-depth against
|
|
98
|
+
* a SuccessCount leaking into a meta sub-expression (parser rejects all such
|
|
99
|
+
* wrappings; this strip ensures a future parse regression cannot leak tags
|
|
100
|
+
* into the top-level `successes`/`failures` scan).
|
|
101
|
+
*/
|
|
102
|
+
/** @internal exported for targeted defense-in-depth tests only. */
|
|
103
|
+
export declare function mergeMetaRolls(parent: EvalContext, source: EvalContext): void;
|
|
48
104
|
/**
|
|
49
105
|
* Evaluates a parsed AST and returns the roll result.
|
|
50
106
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/evaluator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/evaluator/evaluator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EACV,OAAO,EAkBR,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,KAAK,EAEV,SAAS,EACT,eAAe,EAGf,UAAU,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAKL,8BAA8B,EAC/B,MAAM,wBAAwB,CAAC;AAShC,OAAO,EAGL,6BAA6B,EAC9B,MAAM,uBAAuB,CAAC;AAI/B;;GAEG;AACH,qBAAa,cAAe,SAAQ,eAAe;IACjD,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC;;;;OAIG;IACH,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,mBAAmB,EAAE,QAAQ,CAAC,EAAE,MAAM;CAO1E;AAED,yDAAyD;AACzD,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,CAAC;AAEzE;;;;;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;;;;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;;;;GAIG;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;AA+FF;;;;;;;;;;;;;GAaG;AACH,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAa7E;AA8pCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,eAAoB,GAAG,UAAU,CAmF1F"}
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module evaluator
|
|
5
5
|
*/
|
|
6
|
-
export { DEFAULT_MAX_DICE, evaluate, EvaluatorError } from './evaluator';
|
|
7
|
-
export { applyDropHighest, applyDropLowest, applyKeepHighest, applyKeepLowest, sumKeptDice, } from './modifiers/keep-drop';
|
|
6
|
+
export { DEFAULT_MAX_DICE, evaluate, EvaluatorError } from './evaluator.js';
|
|
7
|
+
export { applyDropHighest, applyDropLowest, applyKeepHighest, applyKeepLowest, sumKeptDice, } from './modifiers/keep-drop.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evaluator/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evaluator/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,WAAW,GACZ,MAAM,0BAA0B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/compare.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/compare.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAa5F"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Critical / fumble threshold modifier.
|
|
3
|
+
*
|
|
4
|
+
* Overrides the default `critical`/`fumble` flag logic for a dice pool.
|
|
5
|
+
* `cs` and `cf` are independent (Roll20 semantics): the evaluator passes
|
|
6
|
+
* `['default']` for a side with no explicit thresholds, so overriding one
|
|
7
|
+
* side never wipes the other. An empty threshold array (not produced by the
|
|
8
|
+
* evaluator) would force the corresponding flag to `false` on every die.
|
|
9
|
+
* Meta dice (rolled to compute counts/sides/modifier args) are skipped so
|
|
10
|
+
* their bookkeeping stays untouched.
|
|
11
|
+
*
|
|
12
|
+
* Display-only: does not alter `total`, explosion triggers, success
|
|
13
|
+
* counting, or any other modifier flag. Dropped dice still participate —
|
|
14
|
+
* their `critical`/`fumble` metadata reflects what they rolled, not
|
|
15
|
+
* whether they contributed to the total.
|
|
16
|
+
*
|
|
17
|
+
* @module evaluator/modifiers/crit-threshold
|
|
18
|
+
*/
|
|
19
|
+
import type { DieResult, ResolvedCritThreshold } from '../../types.js';
|
|
20
|
+
export type { ResolvedCritThreshold } from '../../types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Applies success/fail threshold arrays to a dice pool, overriding each
|
|
23
|
+
* die's `critical` and `fumble` flags in place. A die matches `'default'`
|
|
24
|
+
* on the success side when `result === sides && sides > 1`, and on the
|
|
25
|
+
* fail side when `result === 1`. Meta dice are skipped.
|
|
26
|
+
*/
|
|
27
|
+
export declare function applyCritThresholds(dice: DieResult[], successThresholds: ResolvedCritThreshold[], failThresholds: ResolvedCritThreshold[]): void;
|
|
28
|
+
//# sourceMappingURL=crit-threshold.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crit-threshold.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/crit-threshold.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAKvE,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAE5D;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,SAAS,EAAE,EACjB,iBAAiB,EAAE,qBAAqB,EAAE,EAC1C,cAAc,EAAE,qBAAqB,EAAE,GACtC,IAAI,CAON"}
|
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @module evaluator/modifiers/explode
|
|
9
9
|
*/
|
|
10
|
-
import type { RNG } from '../../rng/types';
|
|
11
|
-
import type { CompareOp } from '../../types';
|
|
12
|
-
import type { DieResult } from '../../types';
|
|
13
|
-
import { type EvalEnv } from '../evaluator';
|
|
10
|
+
import type { RNG } from '../../rng/types.js';
|
|
11
|
+
import type { CompareOp } from '../../types.js';
|
|
12
|
+
import type { DieResult } from '../../types.js';
|
|
13
|
+
import { type EvalEnv } from '../evaluator.js';
|
|
14
14
|
/** Default maximum explosion iterations per die. */
|
|
15
15
|
export declare const DEFAULT_MAX_EXPLODE_ITERATIONS = 1000;
|
|
16
16
|
/**
|
|
@@ -33,6 +33,10 @@ export declare function applyStandardExplode(pool: DieResult[], shouldExplode: S
|
|
|
33
33
|
* Compound explode: pool length stays the same. Each original die's `result`
|
|
34
34
|
* accumulates every explosion roll, and gains the `'exploded'` modifier once
|
|
35
35
|
* it actually exploded at least once.
|
|
36
|
+
*
|
|
37
|
+
* Mutates exploded dice in place — the same `DieResult` objects are shared
|
|
38
|
+
* between `RollResult.rolls` and the `RollPart` tree, and both must reflect
|
|
39
|
+
* post-explosion state.
|
|
36
40
|
*/
|
|
37
41
|
export declare function applyCompoundExplode(pool: DieResult[], shouldExplode: ShouldExplode, rng: RNG, env: EvalEnv): DieResult[];
|
|
38
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"explode.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/explode.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"explode.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/explode.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAE/D,oDAAoD;AACpD,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AAEpD;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,SAAS,GAAG,SAAS,EAC/B,cAAc,EAAE,MAAM,GAAG,SAAS,GACjC,aAAa,CAgBf;AAyCD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,EAAE,EACjB,aAAa,EAAE,aAAa,EAC5B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,OAAO,GACX,SAAS,EAAE,CA6Bb;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,EAAE,EACjB,aAAa,EAAE,aAAa,EAC5B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,OAAO,GACX,SAAS,EAAE,CAiCb;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,SAAS,EAAE,EACjB,aAAa,EAAE,aAAa,EAC5B,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,OAAO,GACX,SAAS,EAAE,CA8Bb"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module evaluator/modifiers/keep-drop
|
|
5
5
|
*/
|
|
6
|
-
import type { DieResult } from '../../types';
|
|
6
|
+
import type { DieResult } from '../../types.js';
|
|
7
7
|
/**
|
|
8
8
|
* Marks all eligible dice as `'kept'`. Dice that already carry `'dropped'`
|
|
9
9
|
* (e.g., intermediate rerolls, or the loser of a prior modifier) are left
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keep-drop.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/keep-drop.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"keep-drop.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/keep-drop.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAQ1D;AAmDD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAU9E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAU7E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAU9E;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAU7E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,CAIrD"}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @module evaluator/modifiers/reroll
|
|
10
10
|
*/
|
|
11
|
-
import type { RNG } from '../../rng/types';
|
|
12
|
-
import type { CompareOp, DieResult } from '../../types';
|
|
13
|
-
import { type EvalEnv } from '../evaluator';
|
|
14
|
-
import { matchesCondition } from './compare';
|
|
11
|
+
import type { RNG } from '../../rng/types.js';
|
|
12
|
+
import type { CompareOp, DieResult } from '../../types.js';
|
|
13
|
+
import { type EvalEnv } from '../evaluator.js';
|
|
14
|
+
import { matchesCondition } from './compare.js';
|
|
15
15
|
/** Default maximum reroll iterations per die. */
|
|
16
16
|
export declare const DEFAULT_MAX_REROLL_ITERATIONS = 1000;
|
|
17
17
|
export { matchesCondition };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reroll.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/reroll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"reroll.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/reroll.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAkB,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,iDAAiD;AACjD,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAEnD,OAAO,EAAE,gBAAgB,EAAE,CAAC;AA8D5B;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,SAAS,EAAE,EACjB,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,OAAO,GACX,SAAS,EAAE,CA+Bb;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,EAAE,EACjB,QAAQ,EAAE,SAAS,EACnB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,OAAO,GACX,SAAS,EAAE,CAyBb"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sort modifier implementation.
|
|
3
|
+
*
|
|
4
|
+
* Sort is purely cosmetic — it reorders the dice produced by its target in
|
|
5
|
+
* ascending or descending order of `result` without touching any flag
|
|
6
|
+
* (`kept`, `dropped`, `critical`, `fumble`, `rerolled`, `meta`) or the total.
|
|
7
|
+
* Dropped dice stay in the pool and sort alongside kept dice so readers can
|
|
8
|
+
* see where the dropped value landed in the ordered sequence.
|
|
9
|
+
*
|
|
10
|
+
* @module evaluator/modifiers/sort
|
|
11
|
+
*/
|
|
12
|
+
import type { DieResult } from '../../types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Returns a sorted copy of `dice` in the given order, preserving every die's
|
|
15
|
+
* original flags and metadata. Comparison is on `.result` — the raw face
|
|
16
|
+
* value is what the user sees in rendered output, so ordering by raw value
|
|
17
|
+
* matches the visual intent regardless of any `kept`/`dropped` flagging.
|
|
18
|
+
*
|
|
19
|
+
* Relies on `Array.prototype.sort` being stable — equal-valued dice retain
|
|
20
|
+
* their original insertion order.
|
|
21
|
+
*/
|
|
22
|
+
export declare function sortDice(dice: DieResult[], order: 'ascending' | 'descending'): DieResult[];
|
|
23
|
+
//# sourceMappingURL=sort.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/sort.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,WAAW,GAAG,YAAY,GAAG,SAAS,EAAE,CAM1F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"success-count.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/success-count.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"success-count.d.ts","sourceRoot":"","sources":["../../../src/evaluator/modifiers/success-count.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3D,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,SAAS,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,wBAAgB,cAAc,CAC5B,IAAI,EAAE,SAAS,EAAE,EACjB,SAAS,EAAE,iBAAiB,EAC5B,aAAa,CAAC,EAAE,iBAAiB,GAChC,kBAAkB,CAuBpB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module roll-parser
|
|
5
5
|
*/
|
|
6
|
-
export { RollParserError, isRollParserError } from './errors';
|
|
7
|
-
export type { RollParserErrorCode } from './errors';
|
|
8
|
-
export { LexerError } from './lexer/lexer';
|
|
9
|
-
export { parse, ParseError } from './parser/parser';
|
|
10
|
-
export type { ASTNode, BinaryOpNode, DiceNode, ExplodeNode, FateDiceNode, FunctionCallNode, LiteralNode, ModifierNode, RerollNode, SuccessCountNode, UnaryOpNode, VersusNode, } from './parser/ast';
|
|
11
|
-
export { isBinaryOp, isDice, isExplode, isFateDice, isFunctionCall, isLiteral, isModifier, isReroll, isSuccessCount, isUnaryOp, isVersus, } from './parser/ast';
|
|
12
|
-
export type { RNG } from './rng/types';
|
|
13
|
-
export { SeededRNG } from './rng/seeded';
|
|
14
|
-
export { DEFAULT_MAX_DICE, DEFAULT_MAX_EXPLODE_ITERATIONS, DEFAULT_MAX_REROLL_ITERATIONS, evaluate, EvaluatorError, } from './evaluator/evaluator';
|
|
15
|
-
export type { CompareOp, ComparePoint, DieModifier, DieResult, EvaluateOptions, RollResult, } from './types';
|
|
16
|
-
export { DegreeOfSuccess } from './types';
|
|
17
|
-
export { roll } from './roll';
|
|
18
|
-
export type { RollOptions } from './roll';
|
|
6
|
+
export { RollParserError, isRollParserError } from './errors.js';
|
|
7
|
+
export type { RollParserErrorCode } from './errors.js';
|
|
8
|
+
export { LexerError } from './lexer/lexer.js';
|
|
9
|
+
export { parse, ParseError } from './parser/parser.js';
|
|
10
|
+
export type { ASTNode, BinaryOpNode, DiceNode, NodeSpan, ExplodeNode, FateDiceNode, FunctionCallNode, GroupedNode, LiteralNode, ModifierNode, RerollNode, SuccessCountNode, SortNode, CritThresholdNode, GroupNode, UnaryOpNode, VariableNode, VersusNode, } from './parser/ast.js';
|
|
11
|
+
export { isBinaryOp, isCritThreshold, isDice, isExplode, isFateDice, isFunctionCall, isGroup, isGrouped, isLiteral, isModifier, isReroll, isSort, isSuccessCount, isUnaryOp, isVariable, isVersus, } from './parser/ast.js';
|
|
12
|
+
export type { RNG } from './rng/types.js';
|
|
13
|
+
export { SeededRNG } from './rng/seeded.js';
|
|
14
|
+
export { DEFAULT_MAX_DICE, DEFAULT_MAX_EXPLODE_ITERATIONS, DEFAULT_MAX_REROLL_ITERATIONS, evaluate, EvaluatorError, } from './evaluator/evaluator.js';
|
|
15
|
+
export type { CompareOp, ComparePoint, DieModifier, DieResult, EvaluateOptions, ModifierSpec, ResolvedComparePoint, ResolvedCritThreshold, RollPart, RollPartType, RollResult, } from './types.js';
|
|
16
|
+
export { DegreeOfSuccess } from './types.js';
|
|
17
|
+
export { roll } from './roll.js';
|
|
18
|
+
export type { RollOptions } from './roll.js';
|
|
19
19
|
export declare const VERSION: string;
|
|
20
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EACV,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,QAAQ,EACR,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,YAAY,EACZ,UAAU,GACX,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,UAAU,EACV,eAAe,EACf,MAAM,EACN,SAAS,EACT,UAAU,EACV,cAAc,EACd,OAAO,EACP,SAAS,EACT,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,cAAc,EACd,SAAS,EACT,UAAU,EACV,QAAQ,GACT,MAAM,iBAAiB,CAAC;AAGzB,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9B,6BAA6B,EAC7B,QAAQ,EACR,cAAc,GACf,MAAM,0BAA0B,CAAC;AAClC,YAAY,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,SAAS,EACT,eAAe,EACf,YAAY,EACZ,oBAAoB,EACpB,qBAAqB,EACrB,QAAQ,EACR,YAAY,EACZ,UAAU,GACX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAM7C,eAAO,MAAM,OAAO,EAAE,MAAgB,CAAC"}
|