public class VocabularyImpl extends java.lang.Object implements Vocabulary
Vocabulary
interface.| Modifier and Type | Field and Description |
|---|---|
static VocabularyImpl |
EMPTY_VOCABULARY
Gets an empty
Vocabulary instance. |
| Constructor and Description |
|---|
VocabularyImpl(java.lang.String[] literalNames,
java.lang.String[] symbolicNames)
Constructs a new instance of
VocabularyImpl from the specified
literal and symbolic token names. |
VocabularyImpl(java.lang.String[] literalNames,
java.lang.String[] symbolicNames,
java.lang.String[] displayNames)
Constructs a new instance of
VocabularyImpl from the specified
literal, symbolic, and display token names. |
| Modifier and Type | Method and Description |
|---|---|
static Vocabulary |
fromTokenNames(java.lang.String[] tokenNames)
Returns a
VocabularyImpl instance from the specified set of token
names. |
java.lang.String |
getDisplayName(int tokenType)
Gets the display name of a token type.
|
java.lang.String |
getLiteralName(int tokenType)
Gets the string literal associated with a token type.
|
java.lang.String |
getSymbolicName(int tokenType)
Gets the symbolic name associated with a token type.
|
public static final VocabularyImpl EMPTY_VOCABULARY
Vocabulary instance.
No literal or symbol names are assigned to token types, so
getDisplayName(int) returns the numeric value for all tokens
except Token.EOF.
public VocabularyImpl(java.lang.String[] literalNames,
java.lang.String[] symbolicNames)
VocabularyImpl from the specified
literal and symbolic token names.literalNames - The literal names assigned to tokens, or null
if no literal names are assigned.symbolicNames - The symbolic names assigned to tokens, or
null if no symbolic names are assigned.getLiteralName(int),
getSymbolicName(int)public VocabularyImpl(java.lang.String[] literalNames,
java.lang.String[] symbolicNames,
java.lang.String[] displayNames)
VocabularyImpl from the specified
literal, symbolic, and display token names.literalNames - The literal names assigned to tokens, or null
if no literal names are assigned.symbolicNames - The symbolic names assigned to tokens, or
null if no symbolic names are assigned.displayNames - The display names assigned to tokens, or null
to use the values in literalNames and symbolicNames as
the source of display names, as described in
getDisplayName(int).getLiteralName(int),
getSymbolicName(int),
getDisplayName(int)public static Vocabulary fromTokenNames(java.lang.String[] tokenNames)
VocabularyImpl instance from the specified set of token
names. This method acts as a compatibility layer for the single
tokenNames array generated by previous releases of ANTLR.
The resulting vocabulary instance returns null for
getLiteralName(int) and getSymbolicName(int), and the
value from tokenNames for the display names.
tokenNames - The token names, or null if no token names are
available.Vocabulary instance which uses tokenNames for
the display names of tokens.public java.lang.String getLiteralName(int tokenType)
Vocabularynull, 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 |
getLiteralName in interface VocabularytokenType - The token type.null if no string literal is associated with the type.public java.lang.String getSymbolicName(int tokenType)
Vocabularynull, 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{} block in a lexer or parser
grammar.EOF token, which has the token type
Token.EOF.The following table shows examples of lexer rules and the literal names assigned to the corresponding token types.
| Rule | Symbolic Name |
|---|---|
THIS : 'this'; |
THIS |
SQUOTE : '\''; |
SQUOTE |
ID : [A-Z]+; |
ID |
getSymbolicName in interface VocabularytokenType - The token type.null if no symbolic name is associated with the type.public java.lang.String getDisplayName(int tokenType)
VocabularyANTLR 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-null
result.
Vocabulary.getLiteralName(int)Vocabulary.getSymbolicName(int)Integer.toString(int, int)getDisplayName in interface VocabularytokenType - The token type.