Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace Primitives

Index

Type aliases

Outcome

Outcome<T>: Success<T> | Failure

Union type representing a successful or failed parse.

Type parameters

  • T

Variables

Const EOF

EOF: EOFMark = ...

Let PAD

PAD: number = 10

Const lower_chars

lower_chars: string[] = ...

Const upper_chars

upper_chars: string[] = ...

Functions

appfun

  • appfun allows the user to apply a function f to the result of a parser p, assuming that p is successful. This is the same as the |>> function from FParsec and is an alias for pipe.

    Type parameters

    • T

    • U

    Parameters

    Returns (f: (t: T) => U) => (istream: CharStream) => Generator<any, Failure | Success<U>, undefined>

between

bind

char

  • char takes a character and yields a parser that consume that character. The returned parser succeeds if the next character in the input stream is c, otherwise it fails.

    Parameters

    • c: string

    Returns IParser<CharStream>

choice

  • choice specifies an ordered choice between two parsers, p1 and p2. The returned parser will first apply parser p1. If p1 succeeds, p1's Outcome is returned. If p1 fails, p2 is applied and the Outcome of p2 is returned.

    An exception is when an outcome is a critical failure, that outcome is immediately returned.

    Type parameters

    • T

    Parameters

    Returns (p2: IParser<T>) => IParser<T>

choices

  • Like choice, but chooses from multiple possible parsers The parser will be tried in the order of the input, and the result of the first parser to succeed is returned Example usage: choices(p1, p2, p3)

    Type parameters

    • T

    Parameters

    • Rest ...parsers: IParser<T>[]

      An array of parsers to try

    Returns IParser<T>

debug

  • The debug parser takes a parser p and a debug string, printing the debug string as a side-effect before applying p to the input.

    Type parameters

    • T

    Parameters

    Returns (label: string) => (istream: CharStream) => Generator<any, Outcome<T>, undefined>

delay

diagnosticMessage

  • diagnosticMessage(fail: Failure, windowSz: number): string
  • Produce a diagnostic message for a parser failure.

    Parameters

    • fail: Failure

      The Failure object.

    • windowSz: number

      The amount of context (in chars) to show to the left and right of the failure position.

    Returns string

Const digit

  • digit returns a parser that consumes a single numeric character, from 0-9. Note that the type of the result is a string, not a number.

    Parameters

    Returns Generator<any, Outcome<CharStream>, undefined>

Const eof

expect

  • expect tries to apply the given parser and returns the result of that parser if it succeeds, otherwise it returns a critical Failure If the parser results in a critical Failure, expect simply returns it, otherwise expect creates a critical Failure with the given error message and the start pos of the istream as the error pos.

    Type parameters

    • T

    Parameters

    • parser: IParser<T>

      The parser to try

    Returns (error_msg: string) => (istream: CharStream) => Generator<any, Failure | Success<T>, undefined>

fail

  • fail fails if the given parser p succeeds. On failure, fail returns the given error message. For either outcome, success or failure, fail never consumes input.

    Type parameters

    • T

    Parameters

    Returns (msg: string) => IParser<undefined>

      • (msg: string): IParser<undefined>
      • Parameters

        • msg: string

          An error message

        Returns IParser<undefined>

Const float

fresult

Const integer

Const item

  • item successfully consumes the first character if the input string is non-empty, otherwise it fails.

    Parameters

    Returns Generator<any, Outcome<CharStream>, undefined>

left

Const letter

Const lower

many

  • many repeatedly applies the parser p until p fails. many always succeeds, even if it matches nothing or if an outcome is critical. many tries to guard against an infinite loop by raising an exception if p succeeds without changing the parser state.

    Type parameters

    • T

    Parameters

    Returns IParser<T[]>

many1

  • many1 repeatedly applies the parser p until p fails. many1 must succeed at least once. many1 tries to guard against an infinite loop by raising an exception if p succeeds without changing the parser state.

    Type parameters

    • T

    Parameters

    Returns (istream: CharStream) => Generator<any, Failure | Success<T[]>, undefined>

matchWhile

  • An optimized parser that seeks the input until the given predicate does not return true. On success, it returns the matching CharStream.

    Parameters

    • pred: (char: string) => boolean

      A function that returns true if the given character should be accepted.

        • (char: string): boolean
        • Parameters

          • char: string

          Returns boolean

    Returns IParser<CharStream>

matchWhileCharCode

  • An optimized parser that seeks the input until the given predicate does not return true. On success, it returns the matching CharStream.

    Parameters

    • pred: (char: number) => boolean

      A function that returns true if the given character code should be accepted.

        • (char: number): boolean
        • Parameters

          • char: number

          Returns boolean

    Returns IParser<CharStream>

Const nl

ok

  • ok succeeds without consuming any input, returning whatever is given here.

    Type parameters

    • T

    Parameters

    • res: T

      A result object.

    Returns IParser<T>

Const pipe

  • pipe allows the user to apply a function f to the result of a parser p, assuming that p is successful. This is the same as the |>> function from FParsec and is an alias for appfun

    Type parameters

    • T

    • U

    Parameters

    Returns (f: (t: T) => U) => (istream: CharStream) => Generator<any, Failure | Success<U>, undefined>

pipe2

  • pipe2(p1)(p2)(f) applies the parsers p1 and p2 in sequence. It returns the result of the function application f(t,u), where t and u are the results returned by p1 and p2.

    Type parameters

    • T

    • U

    • V

    Parameters

    Returns (q: IParser<U>) => (f: (t: T, u: U) => V) => (istream: CharStream) => Generator<any, Failure | Success<V>, undefined>

pipe3

  • pipe3(p1)(p2)(p3)(f) applies the parsers p1, p2, and p3 in sequence. It returns the result of the function application f(a,b,c), where a, b, and c are the results returned by p1, p2, and p3, respectively.

    Type parameters

    • A

    • B

    • C

    • D

    Parameters

    Returns (p2: IParser<B>) => (p3: IParser<C>) => (f: (a: A, b: B, c: C) => D) => (istream: CharStream) => Generator<any, Failure | Success<D>, undefined>

prefix

  • prefix is a prefix-optimized choice combinator. If pre succeeds, p is called, and prefix's and p's results are returned by calling the reducer f. If p fails, just p's result is returned. Use this whereever you would write choice(p)(pipe2(p)(q)(f)).

    Type parameters

    • T

    • U

    Parameters

    • pre: IParser<T>

      A prefix parser that should always succeed.

    Returns (p: IParser<U>) => (f: (t: T, u: U) => T) => (istream: CharStream) => Generator<any, Failure | Success<T>, undefined>

rec1ArgParser

  • rec1ArgParser is a forward declaration for a recursive parser that takes one argument. It is effectively a form of deferred evaluation to prevent Javascript from eagerly expanding recursive grammar productions.

    Type parameters

    • A

    • T

    Returns [(arg: A) => IParser<T>, Arg1RefCell<A, T>]

    A pair, [decl,impl] where decl is a parser declaration and impl is an implementation for p

recParser

  • recParser is a forward declaration for a recursive parser. It is effectively a form of deferred evaluation to prevent Javascript from eagerly expanding recursive grammar productions.

    Type parameters

    • T

    Returns [IParser<T>, RefCell<T>]

    A pair, [decl,impl] where decl is a parser declaration and impl is an implementation for p

result

  • result succeeds without consuming any input, and returns v.

    Type parameters

    • T

    Parameters

    • v: T

      The result of the parse.

    Returns IParser<T>

right

sat

  • sat takes a predicate and yields a parser that consumes a single character if the character satisfies the predicate, otherwise it fails.

    Parameters

    • p: (ch: string) => boolean
        • (ch: string): boolean
        • Parameters

          • ch: string

          Returns boolean

    Returns IParser<CharStream>

satClass

  • satClass takes an array of satisfactory characters and yields a parser that consumes a single character if the character is in the array, otherwise it fails.

    Parameters

    • char_class: string[]

    Returns IParser<CharStream>

seq

str

strSat

  • Match any of given alternatives in the given array of strings. Matches longest-first and, where length is the same, lexicographically first.

    Parameters

    • strs: string[]

      An array of acceptable strings.

    Returns IParser<CharStream>

Const upper

Const ws

  • ws matches zero or more of the following whitespace characters: ' ', '\t', '\n', or '\r\n' ws returns matched whitespace in a single CharStream result. Note: ws NEVER fails

    Parameters

    Returns Generator<any, Outcome<CharStream>, undefined>

Const ws1

  • ws1 matches one or more of the following whitespace characters: ' ', '\t', '\n', or '\r\n' ws1 returns matched whitespace in a single CharStream result.

    Parameters

    Returns Generator<any, Outcome<CharStream>, undefined>

zero

  • zero fails without consuming any input.

    Type parameters

    • T

    Parameters

    • msg: string

      the error message.

    Returns IParser<T>

Generated using TypeDoc