Skip to content
Snippets Groups Projects
Commit 84398bd0 authored by Mick Jordan's avatar Mick Jordan
Browse files

fix string index error on parse error

parent b00f7f88
Branches
No related tags found
No related merge requests found
...@@ -289,7 +289,7 @@ final class REngine implements Engine, Engine.Timings { ...@@ -289,7 +289,7 @@ final class REngine implements Engine, Engine.Timings {
} catch (RecognitionException e) { } catch (RecognitionException e) {
String line = e.line <= source.getLineCount() ? source.getCode(e.line) : ""; String line = e.line <= source.getLineCount() ? source.getCode(e.line) : "";
String substring = line.substring(0, Math.min(line.length(), e.charPositionInLine + 1)); String substring = line.substring(0, Math.min(line.length(), e.charPositionInLine + 1));
String token = e.token == null ? substring.substring(substring.length() - 1) : e.token.getText(); String token = e.token == null ? (substring.length() == 0 ? "" : substring.substring(substring.length() - 1)) : e.token.getText();
if (e.token != null && e.token.getType() == Token.EOF && (e instanceof NoViableAltException || e instanceof MismatchedTokenException)) { if (e.token != null && e.token.getType() == Token.EOF && (e instanceof NoViableAltException || e instanceof MismatchedTokenException)) {
// the parser got stuck at the eof, request another line // the parser got stuck at the eof, request another line
throw new IncompleteSourceException(e, source, token, substring, e.line); throw new IncompleteSourceException(e, source, token, substring, e.line);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment