Package quickparse.grammar.symbol
Class TokenSymbol
java.lang.Object
quickparse.grammar.symbol.Symbol
quickparse.grammar.symbol.TokenSymbol
public class TokenSymbol extends Symbol
Defines the symbol used in grammars to represent a token.
A token is matched against a given pattern, that is expressed as a standard Java Regular Expression.
A token is matched against a given pattern, that is expressed as a standard Java Regular Expression.
-
Nested Class Summary
Nested classes/interfaces inherited from class quickparse.grammar.symbol.Symbol
Symbol.ConstructAction, Symbol.ConstructFunction<R,C>, Symbol.Function<R,C>, Symbol.TokenAction, Symbol.TokenFunction<R,C> -
Method Summary
Modifier and Type Method Description <R, C> Raccept(C context, Symbol.Function<R,C> symbolFunction)Solves the subclass of this symbol (ConstructSymbolorTokenSymboland computes the givenSymbol.Functionbooleanequals(java.lang.Object obj)static TokenSymbolget(java.lang.String name, java.lang.String pattern)Gets a newTokenSymbolinstance for the given name and pattern.
This method uses the Flyweight design pattern by GoF to cache already created instances.java.lang.StringgetName()The name of the symboljava.util.regex.PatterngetPattern()Gets the pattern that matches thisTokenSymbolinthashCode()java.lang.StringtoString()Methods inherited from class quickparse.grammar.symbol.Symbol
ifConstruct, ifConstruct, ifToken, ifToken
-
Method Details
-
get
Gets a newTokenSymbolinstance for the given name and pattern.
This method uses the Flyweight design pattern by GoF to cache already created instances.- Parameters:
name- the name of the tokenpattern- the Java Regular Expression to match the token against.- Returns:
- a
TokenSymbolinstance
-
getName
public java.lang.String getName()Description copied from class:SymbolThe name of the symbol -
getPattern
public java.util.regex.Pattern getPattern()Gets the pattern that matches thisTokenSymbol- Returns:
- a compiled
Pattern
-
accept
Description copied from class:SymbolSolves the subclass of this symbol (ConstructSymbolorTokenSymboland computes the givenSymbol.Function- Specified by:
acceptin classSymbol- Type Parameters:
R- the return type of the functionC- the context type for the function- Parameters:
context- the context used for computationsymbolFunction- the function that must be computed on this symbol- Returns:
- the return value returned by computing the
Symbol.Function
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)- Overrides:
equalsin classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-