Class VocabularyImpl
- java.lang.Object
-
- org.antlr.v4.runtime.VocabularyImpl
-
- All Implemented Interfaces:
Vocabulary
public class VocabularyImpl extends Object implements Vocabulary
This class provides a default implementation of theVocabularyinterface.- Author:
- Sam Harwell
-
-
Field Summary
Fields Modifier and Type Field Description static VocabularyImplEMPTY_VOCABULARYGets an emptyVocabularyinstance.
-
Constructor Summary
Constructors Constructor Description VocabularyImpl(String[] literalNames, String[] symbolicNames)Constructs a new instance ofVocabularyImplfrom the specified literal and symbolic token names.VocabularyImpl(String[] literalNames, String[] symbolicNames, String[] displayNames)Constructs a new instance ofVocabularyImplfrom the specified literal, symbolic, and display token names.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static VocabularyfromTokenNames(String[] tokenNames)Returns aVocabularyImplinstance from the specified set of token names.StringgetDisplayName(int tokenType)Gets the display name of a token type.String[]getDisplayNames()StringgetLiteralName(int tokenType)Gets the string literal associated with a token type.String[]getLiteralNames()intgetMaxTokenType()Returns the highest token type value.StringgetSymbolicName(int tokenType)Gets the symbolic name associated with a token type.String[]getSymbolicNames()
-
-
-
Field Detail
-
EMPTY_VOCABULARY
public static final VocabularyImpl EMPTY_VOCABULARY
Gets an emptyVocabularyinstance.No literal or symbol names are assigned to token types, so
getDisplayName(int)returns the numeric value for all tokens exceptToken.EOF.
-
-
Constructor Detail
-
VocabularyImpl
public VocabularyImpl(String[] literalNames, String[] symbolicNames)
Constructs a new instance ofVocabularyImplfrom the specified literal and symbolic token names.- Parameters:
literalNames- The literal names assigned to tokens, ornullif no literal names are assigned.symbolicNames- The symbolic names assigned to tokens, ornullif no symbolic names are assigned.- See Also:
getLiteralName(int),getSymbolicName(int)
-
VocabularyImpl
public VocabularyImpl(String[] literalNames, String[] symbolicNames, String[] displayNames)
Constructs a new instance ofVocabularyImplfrom the specified literal, symbolic, and display token names.- Parameters:
literalNames- The literal names assigned to tokens, ornullif no literal names are assigned.symbolicNames- The symbolic names assigned to tokens, ornullif no symbolic names are assigned.displayNames- The display names assigned to tokens, ornullto use the values inliteralNamesandsymbolicNamesas the source of display names, as described ingetDisplayName(int).- See Also:
getLiteralName(int),getSymbolicName(int),getDisplayName(int)
-
-
Method Detail
-
fromTokenNames
public static Vocabulary fromTokenNames(String[] tokenNames)
Returns aVocabularyImplinstance from the specified set of token names. This method acts as a compatibility layer for the singletokenNamesarray generated by previous releases of ANTLR.The resulting vocabulary instance returns
nullforgetLiteralName(int)andgetSymbolicName(int), and the value fromtokenNamesfor the display names.- Parameters:
tokenNames- The token names, ornullif no token names are available.- Returns:
- A
Vocabularyinstance which usestokenNamesfor the display names of tokens.
-
getMaxTokenType
public int getMaxTokenType()
Description copied from interface:VocabularyReturns the highest token type value. It can be used to iterate from zero to that number, inclusively, thus querying all stored entries.- Specified by:
getMaxTokenTypein interfaceVocabulary- Returns:
- the highest token type value
-
getLiteralName
public String getLiteralName(int tokenType)
Description copied from interface:VocabularyGets the string literal associated with a token type. The string returned by this method, when notnull, can be used unaltered in a parser grammar to represent this token type.The following table shows examples of lexer rules and the literal names assigned to the corresponding token types.
Rule Literal Name Java String Literal THIS : 'this';'this'"'this'"SQUOTE : '\'';'\''"'\\''"ID : [A-Z]+;n/a null- Specified by:
getLiteralNamein interfaceVocabulary- Parameters:
tokenType- The token type.- Returns:
- The string literal associated with the specified token type, or
nullif no string literal is associated with the type.
-
getSymbolicName
public String getSymbolicName(int tokenType)
Description copied from interface:VocabularyGets the symbolic name associated with a token type. The string returned by this method, when notnull, can be used unaltered in a parser grammar to represent this token type.This method supports token types defined by any of the following methods:
- Tokens created by lexer rules.
- Tokens defined in a
tokens{}block in a lexer or parser grammar. - The implicitly defined
EOFtoken, which has the token typeToken.EOF.
The following table shows examples of lexer rules and the literal names assigned to the corresponding token types.
Rule Symbolic Name THIS : 'this';THISSQUOTE : '\'';SQUOTEID : [A-Z]+;ID- Specified by:
getSymbolicNamein interfaceVocabulary- Parameters:
tokenType- The token type.- Returns:
- The symbolic name associated with the specified token type, or
nullif no symbolic name is associated with the type.
-
getDisplayName
public String getDisplayName(int tokenType)
Description copied from interface:VocabularyGets the display name of a token type.ANTLR provides a default implementation of this method, but applications are free to override the behavior in any manner which makes sense for the application. The default implementation returns the first result from the following list which produces a non-
nullresult.- The result of
Vocabulary.getLiteralName(int) - The result of
Vocabulary.getSymbolicName(int) - The result of
Integer.toString(int, int)
- Specified by:
getDisplayNamein interfaceVocabulary- Parameters:
tokenType- The token type.- Returns:
- The display name of the token type, for use in error reporting or other user-visible messages which reference specific token types.
- The result of
-
getLiteralNames
public String[] getLiteralNames()
-
getSymbolicNames
public String[] getSymbolicNames()
-
getDisplayNames
public String[] getDisplayNames()
-
-