getSymbolicName method
Gets the symbolic name associated with a token type. The string returned by this method, when not null, 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 [EOF] token, which has the token type {@link Token#EOF}.
The following table shows examples of lexer rules and the literal names assigned to the corresponding token types.
Rule | Symbolic Name |
---|---|
{@code THIS : 'this';} | [THIS] |
{@code SQUOTE : '\'';} | [SQUOTE] |
{@code ID : [A-Z]+;} | [ID] |
@param tokenType The token type.
@return The symbolic name associated with the specified token type, or null if no symbolic name is associated with the type.
Implementation
@override
String? getSymbolicName(int tokenType) {
if (tokenType >= 0 && tokenType < symbolicNames.length) {
return symbolicNames[tokenType];
}
if (tokenType == Token.EOF) {
return 'EOF';
}
return null;
}