forked from jasder/antlr
Fix lexer error recovery could try to consume EOF
This commit is contained in:
parent
0903370117
commit
b917c01bba
|
@ -134,17 +134,17 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
|
||||||
throw new IllegalStateException("nextToken requires a non-null input stream.");
|
throw new IllegalStateException("nextToken requires a non-null input stream.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_hitEOF) {
|
|
||||||
emitEOF();
|
|
||||||
return _token;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark start location in char stream so unbuffered streams are
|
// Mark start location in char stream so unbuffered streams are
|
||||||
// guaranteed at least have text of current token
|
// guaranteed at least have text of current token
|
||||||
int tokenStartMarker = _input.mark();
|
int tokenStartMarker = _input.mark();
|
||||||
try{
|
try{
|
||||||
outer:
|
outer:
|
||||||
while (true) {
|
while (true) {
|
||||||
|
if (_hitEOF) {
|
||||||
|
emitEOF();
|
||||||
|
return _token;
|
||||||
|
}
|
||||||
|
|
||||||
_token = null;
|
_token = null;
|
||||||
_channel = Token.DEFAULT_CHANNEL;
|
_channel = Token.DEFAULT_CHANNEL;
|
||||||
_tokenStartCharIndex = _input.index();
|
_tokenStartCharIndex = _input.index();
|
||||||
|
@ -369,7 +369,10 @@ public abstract class Lexer extends Recognizer<Integer, LexerATNSimulator>
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recover(LexerNoViableAltException e) {
|
public void recover(LexerNoViableAltException e) {
|
||||||
getInterpreter().consume(_input); // skip a char and try again
|
if (_input.LA(1) != IntStream.EOF) {
|
||||||
|
// skip a char and try again
|
||||||
|
getInterpreter().consume(_input);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyListeners(LexerNoViableAltException e) {
|
public void notifyListeners(LexerNoViableAltException e) {
|
||||||
|
|
Loading…
Reference in New Issue