All exports are re-exported from the barrel src/parse/index.ts. Core types live in
parser.ts, leaf parsers in leaf.ts, span variants in span.ts, and domain parsers
under parsers/.
The main class used for building parsers. It takes a ParserFunction and an optional ParserContext as constructor arguments.
Applies the parser to a string and returns the result.
Applies the current parser, then applies the next parser if the first one succeeds. Returns a new parser that will output an array of the results of both parsers.
Applies the current parser, if it fails, applies the other parser. Returns a new parser that will output the result of the first parser that succeeds.
Applies the current parser, then applies the parser returned by the fn function using the result of the previous parser as input. Returns a new parser that will output the result of the last parser that succeeded.
Applies the current parser, then applies the fn function to the output of the first parser. Returns a new parser that will output the result of the fn function.
Applies the current parser, then applies the parser but returns the output of the first parser. Returns a new parser that will output the result of the first parser.
Applies the current parser, then applies the parser but returns the output of the second parser. Returns a new parser that will output the result of the second parser.
Applies the current parser, if it fails, returns an undefined value. Returns a new parser that will output the result of the first parser or undefined.
Applies the current parser, if it succeeds, applies the parser and fails if it succeeds, or returns the result of the first parser. If no parser is provided, it negates the output of the first parser. Returns a new parser that will output the result of the first parser if the second parser fails or nothing if it succeeds.
Applies the start parser, then applies the current parser, then applies the end parser. Returns a new parser that will output the result of the first parser.
Applies the current parser with the given parser (default is whitespace) on both sides. Returns a new parser that will output the result of the first parser.
Applies the current parser repeatedly, from min to max times. Returns a new parser that will output an array of the results of all successful applications of the first parser.
Applies the current parser, followed by the sep parser and the first parser repeatedly, from min to max times. Returns a new parser that will output an array of the results of all successful applications of the first and second parsers.
Wraps the parser with debug tracing. Logs a rich status line to stderr on each
invocation: badge (Ok/Err/Done), name, offset, and surrounding source lines
with a cursor at the active column. Nested debug calls indent automatically.
When diagnostics are enabled, the output includes expected sets, suggestions, and secondary spans.
Returns a string representation of the current parser with an optional indent value (default is 0).
A class representing the state of a parser after it has been applied to a string.
Returns a new parser state with the offset incremented by len.
Returns a new parser state with the value and isError set to false.
Returns a new parser state with the value and isError set to true.
Returns a new string with a cursor added at the current offset. Pretty prints the state of the currently parsed string.
Returns a new parser that succeeds if the end of the input has been reached, otherwise fails.
Returns a new parser that succeeds if the input string starts with the provided str, otherwise fails.
Returns a new parser that succeeds if the input string matches the provided r regular expression, otherwise fails.
Returns a new parser that applies all parsers in the input list until one succeeds, then returns its output.
Returns a new parser that applies all parsers in the input list in order and returns an array of their outputs.
O(1) first-character dispatch. Branches on the first byte of input to select a parser from the lookup table. Falls back to the fallback parser if no match.
A pre-defined regular expression parser that matches any whitespace character.
Static method. Wraps a parser factory in a lazy thunk — the inner parser is created on first use. Required for recursive grammars.
Decorator form. Lazily initializes a parser returned by a method.
Zero-copy parsers that return Span (start/end offsets) instead of materialized strings.
Like regex(), but returns a Span instead of the matched string.
Like .many(), but merges consecutive spans into one.
Like .sepBy(), but merges consecutive spans into one.
Like .wrap(), but returns a merged span covering start through end.
Combinator-based JSON parser. Returns a JsonValue discriminated union:
null | boolean | number | string | JsonValue[] | Record<string, JsonValue>.
Monolithic hand-rolled JSON parser. charCode dispatch, no combinator overhead. Fastest TypeScript path.
RFC 4180 CSV parser. Handles quoted fields with escaped double-quotes.
Parses backslash-escaped characters (\n, \t, \", \uXXXX, etc.).
Parses a quoted string with escape handling. Defaults to double quotes.
Parses a JSON-style number (integer or decimal with optional exponent).
Structured error diagnostics — opt-in, zero overhead when off.
Activates diagnostic accumulation. Leaf parsers begin recording expected labels at the
furthest offset; wrap() and EOF checks emit suggestions and secondary spans.
Deactivates diagnostics and clears accumulated state.
interface Suggestion {
kind: "unclosed-delimiter" | "trailing-content";
message: string;
openOffset?: number;
}Structured hint emitted by wrap() (unclosed delimiters) and EOF checks (trailing
content).
interface SecondarySpan {
offset: number;
label: string;
}Points to a related source location — e.g., where an unclosed delimiter was opened.
Formats an expected set with Oxford comma: expected X, Y, or Z.
Renders ±4 lines of source context around the current offset with gutter line numbers, a cursor at the active column, and ANSI coloring (red for errors, green for success).