Skip to content

Latest commit

 

History

History
31 lines (20 loc) · 1.45 KB

prsc.dispatch.md

File metadata and controls

31 lines (20 loc) · 1.45 KB

Home > prsc > dispatch

dispatch() function

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>;

Parameters

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>