Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ErrorToken<TExpected>

The class for invalid recovery tokens.

Unlike valid tokens, error tokens:

  • Have no value.
  • Contain an extra property, expected with an array of tokens that would have fixed the issue (NOT every possible token that could be there).
  • The start end positions will always be equal. An invalid token has no length.

Type parameters

Hierarchy

  • Token<false, never, never, TExpected[]>
    • ErrorToken

Index

Constructors

Properties

Accessors

Methods

Constructors

  • new ErrorToken<TExpected>(__namedParameters: { end: number; expected: TExpected[]; start: number }): ErrorToken<TExpected>

Properties

end: number
expected: TExpected[]
start: number
type: never
value: never

Accessors

Methods

  • stringify(): string
  • Returns the canonical string version of the token (for valid tokens).

    For example, say the separators are ["-"] and the user inputs key\\-, the canonical version is the same because the - required escaping. But, say they inputted key\\+ thinking the + is a separator that needed to be escaped. This function will correctly return key+ in this situation.

    The main purpose is to provide some definitive string versions of tokens so at the higher node levels, the string versions of shortcuts can be used for normalizing shortcuts to check for equality. See Node.stringify for more.

    So it should also be specified when extending from this class to customize the canonical version of key notes ParserOptions.keyNote since you probably don't want something like key(note) to not be equal to key( note).

    The default implementation only needs to take care of how key and separator tokens are stringified.

    Returns string

Generated using TypeDoc