forked from jasder/antlr
v4: Call mark() from match instead of matchATN
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9476]
This commit is contained in:
parent
c0262d569b
commit
fc2b4cad07
|
@ -134,11 +134,17 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
public int match(@NotNull CharStream input, int mode) {
|
public int match(@NotNull CharStream input, int mode) {
|
||||||
match_calls++;
|
match_calls++;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
if ( dfa[mode].s0==null ) {
|
int mark = input.mark();
|
||||||
return matchATN(input);
|
try {
|
||||||
|
if ( dfa[mode].s0==null ) {
|
||||||
|
return matchATN(input);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return exec(input, dfa[mode].s0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
finally {
|
||||||
return exec(input, dfa[mode].s0);
|
input.release(mark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,23 +159,15 @@ public class LexerATNSimulator extends ATNSimulator {
|
||||||
|
|
||||||
// only called from test code from outside
|
// only called from test code from outside
|
||||||
public int matchATN(@NotNull CharStream input) {
|
public int matchATN(@NotNull CharStream input) {
|
||||||
int mark = input.mark();
|
startIndex = input.index();
|
||||||
try {
|
ATNState startState = atn.modeToStartState.get(mode);
|
||||||
startIndex = input.index();
|
if ( debug ) System.out.println("mode "+ mode +" start: "+startState);
|
||||||
ATNState startState = atn.modeToStartState.get(mode);
|
OrderedHashSet<ATNConfig> s0_closure = computeStartState(input, startState);
|
||||||
if ( debug ) System.out.println("mode "+ mode +" start: "+startState);
|
int old_mode = mode;
|
||||||
OrderedHashSet<ATNConfig> s0_closure = computeStartState(input, startState);
|
dfa[mode].s0 = addDFAState(s0_closure);
|
||||||
int old_mode = mode;
|
int predict = exec(input, s0_closure);
|
||||||
dfa[mode].s0 = addDFAState(s0_closure);
|
if ( debug ) System.out.println("DFA after matchATN: "+dfa[old_mode].toLexerString());
|
||||||
int predict = exec(input, s0_closure);
|
return predict;
|
||||||
if ( debug ) System.out.println("DFA after matchATN: "+dfa[old_mode].toLexerString());
|
|
||||||
return predict;
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
if (mark >= 0) {
|
|
||||||
input.release(mark);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int exec(@NotNull CharStream input, @NotNull DFAState s0) {
|
protected int exec(@NotNull CharStream input, @NotNull DFAState s0) {
|
||||||
|
|
Loading…
Reference in New Issue