Grammar.java: add getTokenName(String literal) method

This commit is contained in:
Ivan Kochurkin 2018-09-09 11:51:15 +03:00
parent d714d7ba9c
commit 0a6dbc37b7
1 changed files with 10 additions and 0 deletions

View File

@ -631,6 +631,16 @@ public class Grammar implements AttributeResolver {
return i;
}
public String getTokenName(String literal) {
Grammar grammar = this;
while (grammar != null) {
if (grammar.stringLiteralToTypeMap.containsKey(literal))
return grammar.getTokenName(grammar.stringLiteralToTypeMap.get(literal));
grammar = grammar.parent;
}
return null;
}
/** Given a token type, get a meaningful name for it such as the ID
* or string literal. If this is a lexer and the ttype is in the
* char vocabulary, compute an ANTLR-valid (possibly escaped) char literal.