Class Parser

Converts JS RegExp to refa's RE AST format.

Hierarchy

  • Parser

Properties

The parsed AST of the literal this parser works on.

While not explicitly typed that way, the parser will assume that the AST is readonly and makes optimizations based on that assumption. It is not safe to change the AST in any way.

flags: Required<Flags>

This contains the same flags as ast.flags but with a better type.

literal: Literal

The literal of the parser instance.

maxCharacter: Char

The maximum character of all character sets in the parsed AST.

This value will also be returned as part of the ParseResult.

Methods

  • Creates a new parser from the given regexpp AST.

    When the JS RegExp has already been parsed using regexpp, this method can be used to avoid parsing the regex again.

    The given AST is not allowed to be changed during the lifetime of the returned parser.

    Parameters

    Returns Parser

  • Creates a new parser from the given literal.

    This function will throw a SyntaxError if the given literal is not a valid RegExp literal according to the given RegExp parser options.

    If a string is given as the literal, it must be of the form /pattern/flags. If possible, use the object form with Literal instead.

    Parameters

    • literal: string | Literal
    • Optional parserOptions: Options

    Returns Parser