diff --git a/tool/playground/T-input b/tool/playground/T-input index 8baef1b4a..e9d71476f 100644 --- a/tool/playground/T-input +++ b/tool/playground/T-input @@ -1 +1 @@ -abc +34 abc diff --git a/tool/playground/T.g b/tool/playground/T.g index 461286be5..797ea63be 100644 --- a/tool/playground/T.g +++ b/tool/playground/T.g @@ -1,5 +1,11 @@ grammar T; -s : ID ; - +s : a | b ; +a : c ID ; +b : c INT ID ; +c : INT + | + ; +INT : [0-9]+ ; ID : [a-z]+ ; +WS : [ \r\t\n]+ -> skip ; diff --git a/tool/test/org/antlr/v4/test/TestFullContextParsing.java b/tool/test/org/antlr/v4/test/TestFullContextParsing.java index ed7ea745b..275ccd4b5 100644 --- a/tool/test/org/antlr/v4/test/TestFullContextParsing.java +++ b/tool/test/org/antlr/v4/test/TestFullContextParsing.java @@ -32,7 +32,7 @@ package org.antlr.v4.test; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /* cover these cases: @@ -121,6 +121,30 @@ public class TestFullContextParsing extends BaseTest { this.stderrDuringParse); } + @Test public void testSLLSeesEOFInLLGrammar() { + String grammar = + "grammar T;\n"+ + "s @after {dumpDFA();}\n" + + " : a ;\n" + + "a : e ID ;\n" + + "b : e INT ID ;\n" + + "e : INT | ;\n" + + "ID : 'a'..'z'+ ;\n"+ + "INT : '0'..'9'+ ;\n"+ + "WS : (' '|'\\t'|'\\n')+ {skip();} ;\n"; + String result = execParser("T.g4", grammar, "TParser", "TLexer", "s", + "34 abc", true); + String expecting = + "Decision 0:\n" + + "s0-INT->s1\n" + + "s1-ID->s2\n" + + "s2-EOF->s3^\n"; // Must point at accept state + assertEquals(expecting, result); + assertEquals("line 1:6 reportAttemptingFullContext d=0, input='34abc'\n" + + "line 1:0 reportContextSensitivity d=0, input='34'\n", + this.stderrDuringParse); + } + @Test public void testFullContextIF_THEN_ELSEParse() { String grammar = "grammar T;\n"+