Class StringTokenizer<R>Abstract

Type Parameters

  • R

Hierarchy (view full)

Constructors

Properties

length: number

Set to the length of the input values (vals) upon instantiation.

path: string
raw: string
tokens: R[] = ...

An array of tokens productd by tokenize().

Tokens are not pushed automatically into tokens within the body of tokenize(). You must do that manually.

vals: string[]

The input values to be tokenized. This array is iterated over in onNextToken to generate tokens.

Accessors

  • get position(): number
  • Returns number

    the zero-based position of the token at the top of vals.

Methods

  • Consumes a sequence of values from vals.

    Parameters

    • Optionalval: string

    Returns {
        until: ((predicate: ((val: string) => boolean)) => string[]);
        while: ((predicate: ((val: string) => boolean)) => string[]);
    }

    An object that allows for the consumption of values, providing methods until and while. These methods determine when to stop or continue the consumption of the sequence.

    • until: ((predicate: ((val: string) => boolean)) => string[])
        • (predicate): string[]
        • Parameters

          • predicate: ((val: string) => boolean)
              • (val): boolean
              • Parameters

                • val: string

                Returns boolean

          Returns string[]

    • while: ((predicate: ((val: string) => boolean)) => string[])
        • (predicate): string[]
        • Parameters

          • predicate: ((val: string) => boolean)
              • (val): boolean
              • Parameters

                • val: string

                Returns boolean

          Returns string[]

  • Consumes chars until a non-numeric-character is encountered. If your use-case requires numbers to have non-numeric characters, you can register a new number regex with registerNumberRegex.

    Parameters

    • firstChar: string

    Returns string

  • Consumes vars until a non-whitespace token is shifted from vals, returning the unshifted non-whitespace char.

    Returns string

  • Consumes chars until a non-word-character is encountered. If your use-case requires words to have non-alphabetical characters, you can register a new word regex with registerWordRegex.

    Parameters

    • firstChar: string

    Returns string[]

  • Abstract method to process the next token.

    This method must be implemented by subclasses of Tokenizer. It defines how each value in vals should be converted into a token.

    Parameters

    • val: string

      The next value to process into a token.

    Returns void

  • This method returns the next value in the sequence to be processed. If no more values are available, will throw an error.

    Parameters

    • lookahead: number = 0

    Returns undefined | string

    The next value from the input sequence

    If the sequence is empty and an errMsg is provided, the method will throw an error with the given message; otherwise, t will throw Unexpected end of input.

  • Change the default number RegEx (/\d/i)

    Parameters

    • numberRegEx: RegExp

    Returns void

  • Change the default whitespace RegEx (/\s|\n|\t/).

    Parameters

    • whitespaceRegEx: RegExp

    Returns void

  • Change the default word RegEx (/[a-z]/i)

    Parameters

    • wordRegEx: RegExp

    Returns void

  • This method unshifts and returns the next value from vals If no more values are available, will throw an error.

    Parameters

    • OptionalerrMsg: string

      An optional error message

    Returns string

    The next value from the input sequence

    If the sequence is empty and an errMsg is provided, the method will throw an error with the given message; otherwise, t will throw Unexpected end of input.