Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Parser

import { Parser } from "https://raw.githubusercontent.com/wavebeem/bread-n-butter/v0.6.0/src/bread-n-butter.ts";

Represents a parsing action; typically not created directly via new.

class Parser<A> {
constructor(action: (context: Context) => ActionResult<A>);
action: (context: Context) => ActionResult<A>;
 
and<B>(parserB: Parser<B>): Parser<[A, B]>;
chain<B>(fn: (value: A) => Parser<B>): Parser<B>;
desc(expected: string[]): Parser<A>;
map<B>(fn: (value: A) => B): Parser<B>;
next<B>(parserB: Parser<B>): Parser<B>;
node<S extends string>(name: S): Parser<ParseNode<S, A>>;
or<B>(parserB: Parser<B>): Parser<A | B>;
parse(input: string): ParseOK<A> | ParseFail;
repeat(min?, max?): Parser<A[]>;
sepBy<B>(
separator: Parser<B>,
min?,
max?,
): Parser<A[]>;
skip<B>(parserB: Parser<B>): Parser<A>;
thru<B>(fn: (parser: this) => B): B;
trim<B>(beforeAndAfter: Parser<B>): Parser<A>;
tryParse(input: string): A;
wrap<B, C>(before: Parser<B>, after: Parser<C>): Parser<A>;
}

§Type Parameters

§Constructors

§
new Parser(action: (context: Context) => ActionResult<A>)
[src]

Creates a new custom parser that performs the given parsing action.

§Properties

§
action: (context: Context) => ActionResult<A>
[src]

The parsing action. Takes a parsing Context and returns an ActionResult representing success or failure.

§Methods

§
and<B>(parserB: Parser<B>): Parser<[A, B]>
[src]

Combines two parsers one after the other, yielding the results of both in an array.

§
chain<B>(fn: (value: A) => Parser<B>): Parser<B>
[src]

Parse using the current parser. If it succeeds, pass the value to the callback function, which returns the next parser to use.

§
desc(expected: string[]): Parser<A>
[src]

Returns a parser which parses the same value, but discards other error messages, using the ones supplied instead.

§
map<B>(fn: (value: A) => B): Parser<B>
[src]

Yields the value from the parser after being called with the callback.

§
node<S extends string>(name: S): Parser<ParseNode<S, A>>
[src]

Returns a parser that adds name and start/end location metadata.

§
or<B>(parserB: Parser<B>): Parser<A | B>
[src]

Try to parse using the current parser. If that fails, parse using the second parser.

§
parse(input: string): ParseOK<A> | ParseFail
[src]

Returns a parse result with either the value or error information.

§
repeat(min?, max?): Parser<A[]>
[src]

Repeats the current parser between min and max times, yielding the results in an array.

§
sepBy<B>(separator: Parser<B>, min?, max?): Parser<A[]>
[src]

Returns a parser that parses between min and max times, separated by the separator parser supplied.

§
thru<B>(fn: (parser: this) => B): B
[src]

Returns the callback called with the parser.

§
trim<B>(beforeAndAfter: Parser<B>): Parser<A>
[src]

Ignores content before and after the current parser, based on the supplied parser.

§
tryParse(input: string): A
[src]

Returns the parsed result or throws an error.

§
wrap<B, C>(before: Parser<B>, after: Parser<C>): Parser<A>
[src]

Wraps the current parser with before & after parsers.