The StringReader is the hearth on how the Gobstones Language code is read for translation. The code passes through an instance of this class, and is read one word at a time, maintaining characters that are non word exactly as they are (preserves formatting of the code).

The most important method in this class is probably the isAlpha method, that states what characters should be considered part of a word, and which don't. In order to better support UTF-8 this method should be revised in the future.

Hierarchy

  • StringReader

Constructors

  • Create a new instance of a StringReader for the given string. The reader starts at position 0 (the beginning of the string).

    Parameters

    • str: string

      The string this reader should operate uppon.

    • wordEnders: RegExp = ...

    Returns StringReader

Properties

index: number

The current index where the reader is at.

str: string

The string given to the reader.

wordEnders: RegExp

The regexp used to detect when a word ends

Methods

  • Returns whether or not this reader has reach the end of the file.

    Returns boolean

  • Returns whether or not the given character is an alphanumeric character (or a character that can form part of a Gobstones Language identifier or keyword that requires translation).

    Todo

    There should be a way to provide the suffix to the reader in order to avoid using it as a finishing character.

    Parameters

    • char: string

    Returns boolean

  • Returns whether or not the current element in this reader is a word.

    Returns boolean

  • Consume and return the next character in this reader. If the reader is at the end of the file, undefined is returned.

    Returns string

  • Consume and return the next word (multiple characters) in this reader. If the reader is at the end of the file, undefined is returned.

    Returns string

  • Returns the number of characters that needs to be consumed to end the current word (that is, reach the non alpha character)

    Returns number

  • Peek on the next character in this reader, without consuming it. If the reader is at the end of the file, undefined is returned.

    Returns string

  • Peek on the next word (multiple characters) in this reader, without consuming it. If the reader is at the end of the file, undefined is returned.

    Returns string