Skip to content

Commit f36d680

Browse files
committed
parser: update position when reporting lexer errors for unrecognized token
By default we point to the start of the most recent token we parsed. This is used when erroring out on parser issues, to print the line that caused the error, with a pointer to where we were when we got the error. In this particular case, the pointer pointed to the start of the last token we successfully parsed (col), but was not updated if we hit a token we didn't understand at all. Instead use a pointer to the unrecognized token itself. Fixes: #14415
1 parent 2d22385 commit f36d680

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mesonbuild/mparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def lex(self, filename: str) -> T.Generator[Token, None, None]:
221221
yield Token(tid, filename, curline_start, curline, col, bytespan, value)
222222
break
223223
if not matched:
224-
raise ParseException(f'lexer: unrecognized token {self.code[loc]!r}', self.getline(line_start), lineno, col)
224+
raise ParseException(f'lexer: unrecognized token {self.code[loc]!r}', self.getline(line_start), lineno, loc - line_start)
225225

226226
@dataclass
227227
class BaseNode:

0 commit comments

Comments
 (0)