Skip to content

Commit 2331f6d

Browse files
committed
Support explicit token assignments in combined grammars (fixes antlr#157)
1 parent c10b287 commit 2331f6d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

tool/src/main/java/org/antlr/tool/AssignTokenTypesBehavior.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,14 @@ protected void aliasTokenIDsAndLiterals(Grammar root) {
271271
String tokenID = entry.getKey();
272272
String literal = entry.getValue();
273273
if ( literal.charAt(0)=='\'' && stringLiterals.get(literal)!=null ) {
274-
stringLiterals.put(literal, tokens.get(tokenID));
275-
// an alias still means you need a lexer rule for it
276274
Integer typeI = tokens.get(tokenID);
275+
if (typeI == null) {
276+
// must have been imported from a tokenVocab
277+
typeI = grammar.composite.tokenIDToTypeMap.get(tokenID);
278+
}
279+
280+
stringLiterals.put(literal, typeI);
281+
// an alias still means you need a lexer rule for it
277282
if ( !tokenRuleDefs.contains(tokenID) ) {
278283
root.defineLexerRuleForAliasedStringLiteral(tokenID, literal, typeI);
279284
}

0 commit comments

Comments
 (0)