I need EOF edges on rule stop states for start rules.

This commit is contained in:
Terence Parr 2012-10-11 18:55:13 -07:00
parent 27a8e5e521
commit f20cd82920
1 changed files with 12 additions and 0 deletions

View File

@ -29,6 +29,7 @@
package org.antlr.v4.runtime.atn;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.dfa.DFAState;
import org.antlr.v4.runtime.misc.IntervalSet;
import org.antlr.v4.runtime.misc.NotNull;
@ -98,6 +99,9 @@ public abstract class ATNSimulator {
atn.grammarType = toInt(data[p++]);
atn.maxTokenType = toInt(data[p++]);
// Set up target of all EOF edges emanating from rule stop states
ATNState eofTarget = new ATNState();
//
// STATES
//
@ -223,6 +227,14 @@ public abstract class ATNSimulator {
}
}
// If no edges out of stop state, add EOF transition
for (RuleStopState ruleStopState : atn.ruleToStopState) {
if ( ruleStopState.getNumberOfTransitions()==0 ) {
Transition t = new AtomTransition(eofTarget, Token.EOF);
ruleStopState.addTransition(t);
}
}
for (ATNState state : atn.states) {
if (state instanceof PlusLoopbackState) {
PlusLoopbackState loopbackState = (PlusLoopbackState)state;