add unit test for case when SLL needs to see EOF

This commit is contained in:
Terence Parr 2012-12-23 15:31:35 -08:00
parent dc3279cf23
commit 36c3b2341c
3 changed files with 34 additions and 4 deletions

View File

@ -1 +1 @@
abc
34 abc

View File

@ -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 ;

View File

@ -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"+