Class Token

java.lang.Object
com.iizix.prop.gunit.internal.Token

public final class Token extends Object
One token of a unit formula, carrying its span in the original, untouched source string.

The offsets are the whole point of the class. Nothing is substituted into the source before scanning, so start and end index the exact characters the author typed, and an error can be shown under the right caret position even in a formula containing multi-character units such as dlg.

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The exclusive end offset in the original source string, so that the length is end-start.
    final TokenKind
    The kind of token.
    final int
    The inclusive start offset in the original source string.
    final String
    The exact source text of the token, as written, i.e.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Token(TokenKind kind, int start, int end, String text)
    Creates a token.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Gets the length of the token in characters.
    Returns a string representation of this class instance, for debugging.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • kind

      public final TokenKind kind
      The kind of token.
    • start

      public final int start
      The inclusive start offset in the original source string.
    • end

      public final int end
      The exclusive end offset in the original source string, so that the length is end-start.
    • text

      public final String text
      The exact source text of the token, as written, i.e. NOT case folded. Empty for TokenKind.EOF.
  • Constructor Details

    • Token

      public Token(TokenKind kind, int start, int end, String text)
      Creates a token.
      Parameters:
      kind - The kind of token.
      start - The inclusive start offset in the original source string.
      end - The exclusive end offset in the original source string.
      text - The exact source text of the token.
  • Method Details

    • getLength

      public int getLength()
      Gets the length of the token in characters.
      Returns:
      The length, zero for TokenKind.EOF.
    • toString

      public String toString()
      Returns a string representation of this class instance, for debugging.
      Overrides:
      toString in class Object
      Returns:
      A string representation of this class instance.