Interface ParseOptions

Hierarchy

  • ParseOptions

Properties

assertions?: "unknown" | "disable" | "ignore" | "throw" | "parse"

How the parser will handle assertions.

  • "parse"

    The parser will translate every assertion literally to an equivalent RE AST representation. Builtin assertions (e.g. \b, $) will be transformed into equivalent assertions.

  • "disable"

    The parser will disable all assertion by replacing them with an empty character class. This will cause all paths containing an assertion to be (effectively) removed.

  • "ignore"

    The parser will ignore all assertion by replacing them with an empty group.

  • "throw"

    The parser will throw an error when encountering a assertion that cannot be removed.

    E.g. a\B will throw but a([]\b)(\b){0} will not because none of the \bs can be reached.

  • "unknown"

    The parser will create a Unknown node for each assertion. The id of the node will be raw string of the assertion.

Default

"parse"
backreferences?: "unknown" | "disable" | "throw"

How to the parser will handle unresolved backreferences.

  • "disable"

    The parser will replace all backreferences with an empty character class. This will cause all paths containing a backreference to be (effectively) removed.

    E.g. (a*)(\1|b) will be parsed as (a*)(([])|b) which is equivalent to a*b.

  • "throw"

    The parser will throw an error when encountering a backreference that cannot be removed.

    E.g. (a*)b\1 will throw but (a*)[^\s\S]\1 will not because the backreference will be removed anyway because of the empty character class.

  • "unknown"

    The parser will create a Unknown node for each backreference that cannot be removed. The id of the node will be raw string of the backreference.

Backreferences that have been resolved are not affected by this option.

Default

"throw"
getUnknownId?: ((element: Backreference | Assertion) => string)

Type declaration

    • (element: Backreference | Assertion): string
    • Unknown nodes have an id property that can be used to identify the element that created the unknown. This function can be used to control the id value.

      By default, the raw of the element will be used as its id.

      Parameters

      • element: Backreference | Assertion

      Returns string

maxBackreferenceWords?: number

The maximum number of words a backreference can be replaced by.

Set this to 0 to disable resolving backreferences.

Default

100
maxNodes?: number

The maximum number of nodes the parser is allowed to create.

If the regexes requires more nodes, a TooManyNodesError will be thrown.

Default

10000
simplify?: boolean

By default, the parser will try to simplify the generated RE as much as possible.

If set to false, all trivial simplifications will be disabled. This includes:

  • Removing alternatives where all paths go through an empty character class, an alternation with 0 alternatives, or a disabled backreference/assertion.
  • Removing constant 0 and constant 1 quantifiers.
  • Inlining single-alternative groups.

These simplifications might prevent certain backreferences or assertions from throwing an error. It's usually good to have them enabled since parsing is usually faster and the produced RE AST is smaller.

If the produced RE AST is supposed to be a literal translation, then simplifications have to be disabled.

Default

true