forked from jasder/antlr
fix bug where X : 'x' {pred}? ; wasn't seen as alias from X to 'x'.
This commit is contained in:
parent
7192cc9a68
commit
5a2197a74d
|
@ -767,6 +767,16 @@ public class Grammar implements AttributeResolver {
|
||||||
// try with action in there
|
// try with action in there
|
||||||
isLitRule =
|
isLitRule =
|
||||||
wiz.parse(r, "(RULE %name:TOKEN_REF (BLOCK (ALT %lit:STRING_LITERAL ACTION)))", nodes);
|
wiz.parse(r, "(RULE %name:TOKEN_REF (BLOCK (ALT %lit:STRING_LITERAL ACTION)))", nodes);
|
||||||
|
if ( isLitRule ) {
|
||||||
|
GrammarAST litNode = (GrammarAST)nodes.get("lit");
|
||||||
|
GrammarAST nameNode = (GrammarAST)nodes.get("name");
|
||||||
|
lexerRuleToStringLiteral.put(litNode.getText(), nameNode.getText());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
nodes = new HashMap();
|
||||||
|
// try with pred in there
|
||||||
|
isLitRule =
|
||||||
|
wiz.parse(r, "(RULE %name:TOKEN_REF (BLOCK (ALT %lit:STRING_LITERAL SEMPRED)))", nodes);
|
||||||
if ( isLitRule ) {
|
if ( isLitRule ) {
|
||||||
GrammarAST litNode = (GrammarAST)nodes.get("lit");
|
GrammarAST litNode = (GrammarAST)nodes.get("lit");
|
||||||
GrammarAST nameNode = (GrammarAST)nodes.get("name");
|
GrammarAST nameNode = (GrammarAST)nodes.get("name");
|
||||||
|
|
|
@ -98,6 +98,21 @@ public class TestTokenTypeAssignment extends BaseTest {
|
||||||
assertEquals("[E, 'x']", tokens.toString());
|
assertEquals("[E, 'x']", tokens.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test public void testPredDoesNotHideNameToLiteralMapInLexer() throws Exception {
|
||||||
|
// 'x' is token and char in lexer rule
|
||||||
|
Grammar g = new Grammar(
|
||||||
|
"grammar t;\n" +
|
||||||
|
"a : 'x' X ; \n" +
|
||||||
|
"X: 'x' {true}?;\n"); // must match as alias even with pred
|
||||||
|
|
||||||
|
assertEquals("{'x'=1}", g.stringLiteralToTypeMap.toString());
|
||||||
|
assertEquals("{EOF=-1, X=1}", g.tokenNameToTypeMap.toString());
|
||||||
|
|
||||||
|
// pushed in lexer from parser
|
||||||
|
assertEquals("{'x'=1}", g.implicitLexer.stringLiteralToTypeMap.toString());
|
||||||
|
assertEquals("{EOF=-1, X=1}", g.implicitLexer.tokenNameToTypeMap.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test public void testCombinedGrammarWithRefToLiteralButNoTokenIDRef() throws Exception {
|
@Test public void testCombinedGrammarWithRefToLiteralButNoTokenIDRef() throws Exception {
|
||||||
Grammar g = new Grammar(
|
Grammar g = new Grammar(
|
||||||
"grammar t;\n"+
|
"grammar t;\n"+
|
||||||
|
|
Loading…
Reference in New Issue