Token
objects that has a mutable sequence of
characters.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
append
(SourceChar c) Appends the specified character to this builder.getLast()
Returns the last character in this builder.Removes the last character in this builder and returns the character.void
replaceDigraph
(char c) Replace the two characters in this builder with the new character representing the specifiedchar
value.void
replaceDigraph
(char c1, char c2) Replace the four characters in this builder with the new two characters representing the specifiedchar
values.int
size()
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.
-
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
Appends the specified character to this builder.- Parameters:
c
- The character to append.
-
removeLast
Removes the last character in this builder and returns the character.- Returns:
- The character that was the last one in this builder.
-
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 specifiedchar
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 specifiedchar
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
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
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.
-