public class TerminalSymbol extends Symbol
Terminal symbols match some input token(s) literally.
Modifier and Type | Field and Description |
---|---|
static TerminalSymbol |
EOF |
static TerminalSymbol |
EPSILON |
Constructor and Description |
---|
TerminalSymbol(Token token)
Make a symbol for the specified token.
|
TerminalSymbol(Token token,
java.util.Collection<ParserAttribute> attributes)
Make a symbol for the specified token with the given attributes
|
TerminalSymbol(Token token,
ParserAttribute attribute)
Make a symbol for the specified token with a given ParserAttribute.
|
Modifier and Type | Method and Description |
---|---|
static TerminalSymbol |
ch(char terminal)
Return a token for a string.
|
boolean |
equals(java.lang.Object obj)
Test tokens for equality.
|
Token |
getToken()
Get the token associated with this terminal symbol.
|
int |
hashCode()
Assure that equal tokens return the same hash code.
|
boolean |
matches(Symbol input)
Does this symbol match this other symbol?
|
boolean |
matches(Token input)
Does this symbol match the given token?
|
static TerminalSymbol |
regex(java.lang.String regex)
Return a token for a string.
|
static TerminalSymbol |
s(java.lang.String terminal)
Return a token for a string.
|
java.lang.String |
toString()
Pretty print a token.
|
addAttribute, addAttributes, getAttribute, getAttributes, getAttributesMap, getAttributeValue, hasAttribute
public static final TerminalSymbol EPSILON
public static final TerminalSymbol EOF
public TerminalSymbol(Token token)
token
- the tokenjava.lang.NullPointerException
- if the token is nullpublic TerminalSymbol(Token token, ParserAttribute attribute)
token
- the tokenattribute
- the attributejava.lang.NullPointerException
- if either is nullGrammarException
- if the attribute attempts to make the symbol optionalpublic TerminalSymbol(Token token, java.util.Collection<ParserAttribute> attributes)
token
- the tokenattributes
- a collection of attributesjava.lang.NullPointerException
- if the token is nullGrammarException
- if the attributes attempt to make the symbol optionalpublic static TerminalSymbol s(java.lang.String terminal)
This is just a convenience method for a terminal symbol for a TokenString
.
terminal
- the stringpublic static TerminalSymbol ch(char terminal)
This is just a convenience method for a terminal symbol for a TokenCharacter
.
terminal
- the characterpublic static TerminalSymbol regex(java.lang.String regex)
This is just a convenience method for a terminal symbol for a TokenRegex
.
regex
- the regexpublic Token getToken()
public boolean matches(Token input)
public final boolean matches(Symbol input)
No, it does not. No terminal ever matches another symbol.
public boolean equals(java.lang.Object obj)
Two tokens are equal if they represent the same string and have the same attributes.
equals
in class java.lang.Object
obj
- An object.obj
is equal to this terminal character.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object