forked from jasder/antlr
addDFAEdge needs to return the true target state of the added edge
This commit is contained in:
parent
74f4938033
commit
2410b97aab
|
@ -700,7 +700,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
input.seek(startIndex);
|
input.seek(startIndex);
|
||||||
BitSet alts = evalSemanticContext(D.predicates, outerContext, true);
|
BitSet alts = evalSemanticContext(D.predicates, outerContext, true);
|
||||||
D.prediction = ATN.INVALID_ALT_NUMBER; // indicate we have preds
|
D.prediction = ATN.INVALID_ALT_NUMBER; // indicate we have preds
|
||||||
addDFAEdge(dfa, previousD, t, D);
|
D = addDFAEdge(dfa, previousD, t, D);
|
||||||
switch (alts.cardinality()) {
|
switch (alts.cardinality()) {
|
||||||
case 0:
|
case 0:
|
||||||
throw noViableAlt(input, outerContext, D.configs, startIndex);
|
throw noViableAlt(input, outerContext, D.configs, startIndex);
|
||||||
|
@ -718,7 +718,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// all adds to dfa are done after we've created full D state
|
// all adds to dfa are done after we've created full D state
|
||||||
addDFAEdge(dfa, previousD, t, D);
|
D = addDFAEdge(dfa, previousD, t, D);
|
||||||
if ( D.isAcceptState ) return predictedAlt;
|
if ( D.isAcceptState ) return predictedAlt;
|
||||||
|
|
||||||
previous = reach;
|
previous = reach;
|
||||||
|
@ -1547,13 +1547,13 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
return alt;
|
return alt;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void addDFAEdge(@NotNull DFA dfa,
|
protected DFAState addDFAEdge(@NotNull DFA dfa,
|
||||||
@Nullable DFAState from,
|
@Nullable DFAState from,
|
||||||
int t,
|
int t,
|
||||||
@Nullable DFAState to)
|
@Nullable DFAState to)
|
||||||
{
|
{
|
||||||
if ( debug ) System.out.println("EDGE "+from+" -> "+to+" upon "+getTokenName(t));
|
if ( debug ) System.out.println("EDGE "+from+" -> "+to+" upon "+getTokenName(t));
|
||||||
if ( from==null || t < -1 || to == null ) return;
|
if ( from==null || t < -1 || to == null ) return to;
|
||||||
to = addDFAState(dfa, to); // used existing if possible not incoming
|
to = addDFAState(dfa, to); // used existing if possible not incoming
|
||||||
synchronized (from) {
|
synchronized (from) {
|
||||||
if ( from.edges==null ) {
|
if ( from.edges==null ) {
|
||||||
|
@ -1562,6 +1562,7 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
from.edges[t+1] = to; // connect
|
from.edges[t+1] = to; // connect
|
||||||
}
|
}
|
||||||
if ( debug ) System.out.println("DFA=\n"+dfa.toString(parser!=null?parser.getTokenNames():null));
|
if ( debug ) System.out.println("DFA=\n"+dfa.toString(parser!=null?parser.getTokenNames():null));
|
||||||
|
return to;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add D if not there and return D. Return previous if already present. */
|
/** Add D if not there and return D. Return previous if already present. */
|
||||||
|
|
Loading…
Reference in New Issue