Class Tokenizer

The Tokenizer class provides functionality to tokenize code strings into a set of tokens. It supports identifying comments, reserved tokens, loops, and blocks within the code.

Properties

code: string

The original code string.

codeLines: { fromIndex: number; line: string }[] = ...
index: number = 0
tokens: IToken[]

An array of IToken objects representing the tokenized code.

CommentChar: "\"" = '"'

Character that indicates the start and end of a comment.

Reserved: string[] = ...

List of reserved symbols that represent specific token types.

Accessors

Methods

  • Retrieves the line of code corresponding to the specified index.

    Parameters

    • index: number

      The index of the character in the code.

    Returns { fromIndex: number; line: string }

    The line of code and its starting index.

  • Locates the line of code containing the specified token.

    Parameters

    • Optionaltoken: IToken

      The token to locate (defaults to the current token).

    Returns { fromIndex: number; line: string }

    The line of code and its starting index.

  • Retrieves a token by its index.

    Parameters

    • index: number = ...

      The index of the token (defaults to the current token index).

    Returns null | IToken

    The token at the specified index, or null if the index is out of range.

  • Determines if a given token matches a reserved token and returns detailed token information.

    Parameters

    • token: IToken

      The token to check.

    Returns {
        "0": boolean;
        "1": boolean;
        copy: boolean;
        delete: boolean;
        fileHead: boolean;
        log: boolean;
        pointerNext: boolean;
        pointerPrevious: boolean;
        print: boolean;
    }

    An object mapping reserved token types to boolean values indicating a match.

  • Tokenizes a code string into an array of IToken objects.

    Parameters

    • code: string

      The code string to tokenize.

    Returns Tokenizer

    A new instance of the Tokenizer class containing the tokens and the original code.