parserlib
    Preparing search index...

    Function compile

    • Compile a Parser from a grammar represented as a string.

      Type Parameters

      • NT

        a Typescript Enum with one symbol for each nonterminal used in the grammar, matching the nonterminals when compared case-insensitively (so ROOT and Root and root are the same).

      Parameters

      • grammar: string

        the grammar to use

      • nonterminals: NonterminalEnum

        the runtime object of the nonterminals enum. For example, if enum Nonterminals { root, a, b, c }; then Nonterminals must be explicitly passed as this runtime parameter compile(grammar, Nonterminals, Nonterminals.root); (in addition to being implicitly used for the type parameter NT)

      • rootNonterminal: NT

        the desired root nonterminal in the grammar

      Returns Parser<NT>

      a parser for the given grammar that will start parsing at rootNonterminal.

      ParseError if the grammar has a syntax error