import type { Combinator, DispatchMatcherCase } from '../types.ts'; export type DispatchWhen = { readonly kind: 'when'; readonly keys: readonly string[]; readonly parser: Combinator; readonly caseInsensitive: boolean; readonly usesRouted?: boolean; }; export type DispatchWhenMatcher = { readonly kind: 'whenMatcher'; readonly matcher: DispatchStringMatcher; readonly parser: Combinator; readonly caseInsensitive: boolean; readonly usesRouted?: boolean; }; export type DispatchStringMatcher = { readonly kind: 'startsWith'; readonly value: string; } | { readonly kind: 'endsWith'; readonly value: string; } | { readonly kind: 'matches'; readonly value: string; readonly flags: string; }; export type DispatchOtherwise = { readonly kind: 'otherwise'; readonly parser: Combinator; readonly usesRouted?: boolean; }; export type DispatchArm = DispatchWhen | DispatchWhenMatcher | DispatchOtherwise; export type DispatchWhenOptions = { caseInsensitive?: boolean; }; export type DispatchWhenFactory = (key: string | readonly string[], parser: Combinator) => DispatchWhen; export type DispatchWhenKey = string | readonly string[]; export type DispatchWhenSelector = DispatchWhenKey | DispatchStringMatcher; type ArmValue = T extends DispatchWhen ? U : T extends DispatchWhenMatcher ? U : T extends DispatchOtherwise ? U : never; type UnionArms[]> = { [K in keyof T]: ArmValue; }[number]; export declare function parserUsesRouted(parser: Combinator, seen?: Set>): boolean; export declare function branchUsesRouted(branch: { parser: Combinator; usesRouted?: boolean | undefined; }): boolean; export declare function asciiFoldKey(key: string): string; export declare function matchesDispatchMatcher(value: string, matcher: DispatchMatcherCase): boolean; export declare function startsWith(prefix: string): DispatchStringMatcher; export declare function endsWith(suffix: string): DispatchStringMatcher; export declare function matches(pattern: RegExp): DispatchStringMatcher; export declare function when(key: DispatchWhenKey, parser: Combinator, opts?: DispatchWhenOptions): DispatchWhen; export declare function when(matcher: DispatchStringMatcher, parser: Combinator, opts?: DispatchWhenOptions): DispatchWhenMatcher; export declare function makeWhen(opts?: DispatchWhenOptions): DispatchWhenFactory; export declare function otherwise(parser: Combinator): DispatchOtherwise; /** * Reuse the token the enclosing `dispatch()` already consumed to select this branch, * instead of re-recognizing it. * * With no argument this is dispatch-only: outside a dispatch branch (or at a position * other than the selector's) it fails with `expected: ['routed()']`. * * `routed(fallback)` makes the SAME production usable in both contexts: inside a * dispatch branch it reuses the routed token; anywhere else it parses `fallback` in * place. That is what collapses a `Routed` twin production into its original — * `sequence(routed(Name), Prelude, ';')` replaces the pair * `sequence(Name, Prelude, ';')` / `sequence(routed(), Prelude, ';')`, which * otherwise differ by exactly one element and duplicate a whole production (and a * whole compiled emission) for a one-token difference. * * A `routed()` in a dispatch SELECTOR is still an error with or without a fallback: * the selector is what produces the routed token, so reading it there is misuse. */ export declare function routed(fallback?: Combinator): Combinator; export declare function dispatch[]>(selector: Combinator, ...arms: T): Combinator<[S, UnionArms]>; export {}; //# sourceMappingURL=dispatch.d.ts.map