Class TokenBuilder

java.lang.Object
com.maroontress.clione.impl.TokenBuilder

public final class TokenBuilder extends Object
The builder of Token objects that has a mutable sequence of characters.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Appends the specified character to this builder.
    Returns the last character in this builder.
    Removes the last character in this builder and returns the character.
    void
    Replace the two characters in this builder with the new character representing the specified char value.
    void
    replaceDigraph(char c1, char c2)
    Replace the four characters in this builder with the new two characters representing the specified char values.
    int
    Returns the number of characters in this builder.
    Returns a new token that represents the characters in this builder with the specified token type.
    Returns a new string that represents the characters in this builder.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TokenBuilder

      public TokenBuilder()
      Creates a new instance.
  • Method Details

    • size

      public int size()
      Returns the number of characters in this builder.

      Note that this method does not change this builder.

      Returns:
      The number of characters in this builder.
    • append

      public void append(SourceChar c)
      Appends the specified character to this builder.
      Parameters:
      c - The character to append.
    • removeLast

      public SourceChar removeLast()
      Removes the last character in this builder and returns the character.
      Returns:
      The character that was the last one in this builder.
    • getLast

      public SourceChar getLast()
      Returns the last character in this builder.

      Note that this method does not change this builder.

      Returns:
      The last character in this builder.
    • replaceDigraph

      public void replaceDigraph(char c)
      Replace the two characters in this builder with the new character representing the specified char value.

      Note that this builder must have just two characters to be replaced. They are assumed to represent any digraph.

      The new substituted character has two child characters. They correspond with the characters that were in this builder in the same order.

      Parameters:
      c - The character that is substituted for the two characters in this builder.
      Throws:
      IllegalStateException - If the number of characters in this builder is not two.
    • replaceDigraph

      public void replaceDigraph(char c1, char c2)
      Replace the four characters in this builder with the new two characters representing the specified char values.

      Note that this builder must have just four characters to be replaced. They are assumed to represent the digraph '%:%:'.

      Each character that is substituted has two child characters. The child characters of the first substituted character correspond with the first two characters that were in this builder in the same order. Likewise, the child characters of the second substituted character correspond with the second two characters that were in this builder in the same order.

      Parameters:
      c1 - The first character that is substituted for the first two characters in this builder.
      c2 - The second character that is substituted for the second two characters in this builder.
      Throws:
      IllegalStateException - If the number of characters in this builder is not four.
    • toToken

      public Token toToken(TokenType type)
      Returns a new token that represents the characters in this builder with the specified token type.

      Note that this method does not change this builder.

      Parameters:
      type - The token type.
      Returns:
      The new token.
      Throws:
      IllegalStateException - If this builder is empty.
    • toTokenString

      public String toTokenString()
      Returns a new string that represents the characters in this builder.

      Note that this method does not change this builder.

      Returns:
      The new string.
      Throws:
      IllegalStateException - If this builder is empty.