Merge pull request #279 from sharwell/fix-270
Support list labels on a set of tokens (fixes #270)
This commit is contained in:
commit
6bf738cabd
|
@ -181,12 +181,16 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
|||
else matchOp = new MatchSet(this, setAST);
|
||||
if ( labelAST!=null ) {
|
||||
String label = labelAST.getText();
|
||||
Decl d = getTokenLabelDecl(label);
|
||||
matchOp.labels.add(d);
|
||||
getCurrentRuleFunction().addContextDecl(setAST.getAltLabel(), d);
|
||||
RuleFunction rf = getCurrentRuleFunction();
|
||||
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
|
||||
defineImplicitLabel(setAST, matchOp);
|
||||
TokenListDecl l = getTokenListLabelDecl(label);
|
||||
getCurrentRuleFunction().addContextDecl(setAST.getAltLabel(), l);
|
||||
rf.addContextDecl(setAST.getAltLabel(), l);
|
||||
}
|
||||
else {
|
||||
Decl d = getTokenLabelDecl(label);
|
||||
matchOp.labels.add(d);
|
||||
rf.addContextDecl(setAST.getAltLabel(), d);
|
||||
}
|
||||
}
|
||||
if ( controller.needsImplicitLabel(setAST, matchOp) ) defineImplicitLabel(setAST, matchOp);
|
||||
|
|
|
@ -82,6 +82,27 @@ public class TestParserExec extends BaseTest {
|
|||
assertEquals(null, stderrDuringParse);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a regression test for #270 "Fix operator += applied to a set of
|
||||
* tokens".
|
||||
* https://github.com/antlr/antlr4/issues/270
|
||||
*/
|
||||
@Test public void testListLabelOnSet() {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
"a : b b* ';' ;\n" +
|
||||
"b : ID val+=(INT | FLOAT)*;\n" +
|
||||
"ID : 'a'..'z'+ ;\n" +
|
||||
"INT : '0'..'9'+;\n" +
|
||||
"FLOAT : [0-9]+ '.' [0-9]+;\n" +
|
||||
"WS : (' '|'\\n') -> skip ;\n";
|
||||
|
||||
String found = execParser("T.g4", grammar, "TParser", "TLexer", "a",
|
||||
"abc 34;", false);
|
||||
assertEquals("", found);
|
||||
assertEquals(null, stderrDuringParse);
|
||||
}
|
||||
|
||||
@Test public void testBasic() throws Exception {
|
||||
String grammar =
|
||||
"grammar T;\n" +
|
||||
|
|
Loading…
Reference in New Issue