Creates a parser that looks at a single codepoint to determine which parser to invoke. Can be used as an alternative to large or
parsers if looking ahead can narrow down the options.
Can optionally look ahead further than the current codepoint, which is useful when nesting several dispatch
parsers.
Signature:
export declare function dispatch<T>(mapping: {
[codepoint: number]: Parser<T>;
}, otherwise: Parser<T> | undefined, extraOffset?: number, expected?: string[]): Parser<T>;
Parameter | Type | Description |
---|---|---|
mapping | { [codepoint: number]: Parser<T>; } | Object mapping code points to parsers |
otherwise | Parser<T> | undefined | Parser to use when the code point is not found in the mapping, or undefined to reject in that situation. |
extraOffset | number | (Optional) How far ahead to look for the codepoint, defaults to 0 |
expected | string[] | (Optional) Expected values for parse errors generated when there is no codepoint or when the codepoint is not in the mapping and there is no otherwise parser |
Returns:
Parser<T>