Package org.nineml.coffeegrinder.parser
Class TerminalSymbol
- java.lang.Object
-
- org.nineml.coffeegrinder.util.Decoratable
-
- org.nineml.coffeegrinder.parser.Symbol
-
- org.nineml.coffeegrinder.parser.TerminalSymbol
-
public class TerminalSymbol extends Symbol
A terminal symbol.Terminal symbols match some input token(s) literally.
-
-
Field Summary
Fields Modifier and Type Field Description static TerminalSymbolEOFstatic TerminalSymbolEPSILONstatic TerminalSymbolUNDEFINED
-
Constructor Summary
Constructors Constructor 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 attributesTerminalSymbol(Token token, ParserAttribute attribute)Make a symbol for the specified token with a given ParserAttribute.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TerminalSymbolch(char terminal)Return a token for a string.booleanequals(java.lang.Object obj)Test tokens for equality.TokengetToken()Get the token associated with this terminal symbol.inthashCode()Assure that equal tokens return the same hash code.booleanmatches(Symbol input)Does this symbol match this other symbol?booleanmatches(Token input)Does this symbol match the given token?static TerminalSymbolregex(java.lang.String regex)Return a token for a string.static TerminalSymbols(java.lang.String terminal)Return a token for a string.java.lang.StringtoString()Pretty print a token.-
Methods inherited from class org.nineml.coffeegrinder.util.Decoratable
addAttribute, addAttributes, getAttribute, getAttributes, getAttributesMap, getAttributeValue, hasAttribute
-
-
-
-
Field Detail
-
EPSILON
public static final TerminalSymbol EPSILON
-
EOF
public static final TerminalSymbol EOF
-
UNDEFINED
public static final TerminalSymbol UNDEFINED
-
-
Constructor Detail
-
TerminalSymbol
public TerminalSymbol(Token token)
Make a symbol for the specified token.- Parameters:
token- the token- Throws:
java.lang.NullPointerException- if the token is null
-
TerminalSymbol
public TerminalSymbol(Token token, ParserAttribute attribute)
Make a symbol for the specified token with a given ParserAttribute.- Parameters:
token- the tokenattribute- the attribute- Throws:
java.lang.NullPointerException- if either is nullGrammarException- if the attribute attempts to make the symbol optional
-
TerminalSymbol
public TerminalSymbol(Token token, java.util.Collection<ParserAttribute> attributes)
Make a symbol for the specified token with the given attributes- Parameters:
token- the tokenattributes- a collection of attributes- Throws:
java.lang.NullPointerException- if the token is nullGrammarException- if the attributes attempt to make the symbol optional
-
-
Method Detail
-
s
public static TerminalSymbol s(java.lang.String terminal)
Return a token for a string.This is just a convenience method for a terminal symbol for a
TokenString.- Parameters:
terminal- the string- Returns:
- the terminal symbol
-
ch
public static TerminalSymbol ch(char terminal)
Return a token for a string.This is just a convenience method for a terminal symbol for a
TokenCharacter.- Parameters:
terminal- the character- Returns:
- the terminal symbol
-
regex
public static TerminalSymbol regex(java.lang.String regex)
Return a token for a string.This is just a convenience method for a terminal symbol for a
TokenRegex.- Parameters:
regex- the regex- Returns:
- the terminal symbol
-
getToken
public Token getToken()
Get the token associated with this terminal symbol.- Returns:
- the token
-
matches
public boolean matches(Token input)
Does this symbol match the given token?
-
matches
public final boolean matches(Symbol input)
Does this symbol match this other symbol?No, it does not. No terminal ever matches another symbol.
-
equals
public boolean equals(java.lang.Object obj)
Test tokens for equality.Two tokens are equal if they represent the same string and have the same attributes.
- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- An object.- Returns:
- true if
objis equal to this terminal character.
-
hashCode
public int hashCode()
Assure that equal tokens return the same hash code.- Overrides:
hashCodein classjava.lang.Object- Returns:
- the hash code.
-
toString
public java.lang.String toString()
Pretty print a token.- Overrides:
toStringin classjava.lang.Object- Returns:
- a string representation of the object.
-
-