After consuming EOF, only configurations in a RuleStopState are viable

This commit is contained in:
Sam Harwell 2013-01-02 09:03:14 -06:00
parent b34ad624bc
commit 4040dc0d6d
2 changed files with 25 additions and 5 deletions

View File

@ -947,10 +947,31 @@ public class ParserATNSimulator extends ATNSimulator {
}
}
if ( reach.size()==0 ) return null;
if (t == IntStream.EOF) {
reach = removeNonRuleStopStates(reach);
}
if ( reach.isEmpty() ) return null;
return reach;
}
protected ATNConfigSet removeNonRuleStopStates(ATNConfigSet configs) {
if (PredictionMode.onlyRuleStopStates(configs)) {
return configs;
}
ATNConfigSet result = new ATNConfigSet(configs.fullCtx);
for (ATNConfig config : configs) {
if (!(config.state instanceof RuleStopState)) {
continue;
}
result.add(config, mergeCache);
}
return result;
}
@NotNull
public ATNConfigSet computeStartState(@NotNull ATNState p,
@Nullable RuleContext ctx,

View File

@ -121,7 +121,7 @@ public class TestFullContextParsing extends BaseTest {
this.stderrDuringParse);
}
@Test(timeout = 5000)
@Test
public void testSLLSeesEOFInLLGrammar() {
String grammar =
"grammar T;\n"+
@ -138,10 +138,9 @@ public class TestFullContextParsing extends BaseTest {
String expecting =
"Decision 0:\n" +
"s0-INT->s1\n" +
"s1-ID->s2\n" +
"s2-EOF->s3^\n"; // Must point at accept state
"s1-ID->s2^\n"; // Must point at accept state
assertEquals(expecting, result);
assertEquals("line 1:6 reportAttemptingFullContext d=0, input='34abc'\n" +
assertEquals("line 1:3 reportAttemptingFullContext d=0, input='34abc'\n" +
"line 1:0 reportContextSensitivity d=0, input='34'\n",
this.stderrDuringParse);
}