Skip to content

Commit c652a8c

Browse files
committed
fix parser syntax error message bounds computation
1 parent 2aaf9b9 commit c652a8c

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonErrorStrategy.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static String getTokeLineText(Parser recognizer, Token token) {
6060
TokenStream tokenStream = recognizer.getTokenStream();
6161
int index = token.getTokenIndex();
6262
// search for line start
63-
int tokenIndex = index - 1;
63+
int tokenIndex = index;
6464
int start = -1;
6565
while (tokenIndex >= 0) {
6666
Token t = tokenStream.get(tokenIndex);
@@ -72,7 +72,7 @@ private static String getTokeLineText(Parser recognizer, Token token) {
7272
}
7373

7474
// search for line stop
75-
tokenIndex = index + 1;
75+
tokenIndex = index;
7676
int stop = -1;
7777
while (tokenIndex < tokenStream.size()) {
7878
Token t = tokenStream.get(tokenIndex);
@@ -82,14 +82,13 @@ private static String getTokeLineText(Parser recognizer, Token token) {
8282
}
8383
tokenIndex++;
8484
}
85-
8685
return token.getInputStream().getText(Interval.of(start, stop));
8786
}
8887

8988
private static void handlePythonSyntaxError(Parser recognizer, RecognitionException e) {
9089
Token offendingToken = e.getOffendingToken();
9190
String lineText = getTokeLineText(recognizer, offendingToken);
92-
String errorMarker = new String(new char[offendingToken.getCharPositionInLine() + 1]).replace('\0', ' ') + "^";
91+
String errorMarker = new String(new char[offendingToken.getCharPositionInLine()]).replace('\0', ' ') + "^";
9392
String pythonSyntaxErrorMessage = "\n" + LINE_PADDING + lineText + "\n" + LINE_PADDING + errorMarker;
9493

9594
RecognitionException re = e;

0 commit comments

Comments
 (0)