import type { Combinator, ParseError } from '../types.ts'; export type { ParseError }; export { assertionFailureExpected, directTerminalFailureExpected } from './expected.ts'; /** * Statically derive the "expected" token set from a combinator's structure, * so a failure can name what it wanted without running anything: * * literal('}') -> ['"}"'] * keywords(['a','b']) -> ['"a"', '"b"'] * choice(x, y) -> expected(x) ++ expected(y) (all alternatives) * sequence(a, b, …) -> expected(a) ++ … through the NULLABLE prefix * label('s', x) -> ['s'] (an explicit name wins) * * This is what lets expect() report a meaningful, IDENTICAL expectation in both * the interpreter and the compiled output (the compiled path does not rebuild the * runtime `expected` array, so it reads this precomputed set instead). * * The result is DEDUPLICATED. Deriving through a nullable prefix re-reaches the * same token from several terms — a value grammar whose leading terms are all * optional names its value-start set once per term — and an expectation list that * offers `"@{"` five times is wrong for a reader and expensive for a parser: a * choice that loses every arm materializes `[...arm0, ...arm1, …]` at runtime, and * those arrays feed the enclosing choice's concat in turn, so duplicates compound * multiplicatively up the nesting. On jess's Less grammar the un-deduped sets cost * 32% of parse time on `benchmark.less` (medians 20.7 → 14.2 ms over 100 * interleaved pairs, 99/100 wins, min 19.1 → 13.0), which is the whole of the Less * regression 0.35.0 shipped. Dedup is not an optimisation bolted onto the * derivation — a SET is what the derivation always meant. */ export declare function deriveExpected(c: Combinator): string[]; /** * Required-token combinator. Tries `combinator`; on success returns it verbatim. * On failure it does NOT fail — it records a {@link ParseError} (the statically * derived expected set, or `label` when given) into `ctx._errors` and RECOVERS IN * PLACE, returning a zero-width success so the enclosing sequence continues as if * the token were present. * * Use it to mark required delimiters/terminators (`}` `)` `;`, a selector before a * block) so a missing one is reported with position + expectation rather than * aborting the whole parse or being silently swallowed by a catch-all. * * sequence(literal('{'), declList, expect(literal('}'))) * * Errors are only collected when the parse runs with `{ recover: true }`; without * it, expect() still recovers in place but records nothing (zero overhead beyond * the inner attempt). */ export declare function expect(combinator: Combinator, label?: string): Combinator; /** True when `value` is a recovery {@link ParseError} node. */ export declare function isParseError(value: unknown): value is ParseError; //# sourceMappingURL=expect.d.ts.map