Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Token<TValid, TType, TValue, TExpected>

The base class from which ValidToken and ErrorToken extend.

Mostly for internal use or for checking something is any type of token.

if (token instanceof Token) {
//...
}

Only really takes care of setting the start/end position.

Type parameters

  • TValid: boolean = boolean

  • TType: TValid extends true ? TOKEN_TYPE : never = TValid extends true ? TOKEN_TYPE : never

  • TValue: TValid extends true ? string : never = TValid extends true ? string : never

  • TExpected: TValid extends false ? any[] : never = TValid extends false ? TOKEN_TYPE[] : never

Hierarchy

Index

Constructors

Properties

Accessors

Methods

Constructors

  • new Token<TValid, TType, TValue, TExpected>(start: number, end: number): Token<TValid, TType, TValue, TExpected>
  • Type parameters

    • TValid: boolean = boolean

    • TType: TOKEN_TYPE = TValid extends true ? TOKEN_TYPE : never

    • TValue: string = TValid extends true ? string : never

    • TExpected: any[] = TValid extends false ? TOKEN_TYPE[] : never

    Parameters

    • start: number
    • end: number

    Returns Token<TValid, TType, TValue, TExpected>

Properties

end: number
expected: TExpected
start: number
type: TType
value: TValue

Accessors

Methods

  • stringify(_opts: Pick<FullParserOptions<any, any>, "separators" | "keyNote">): 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.

    Parameters

    Returns string

Generated using TypeDoc