-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation of RAISE_SYNTAX_ERROR_NO_COL_OFFSET seems incorrect #126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well, what do you expect given the name of the macro? :-) Maybe the value -1 can be used to indicate the offset is unknown? |
I expected that when the macro is used, no column offset was displayed (so there is no error caret on the final error message).
Exactly! That is what I was thinking about. It sounds odd to me somehow to point always to the beginning of the line. |
The macro itself looks innocent. If anything's the matter, it's in
The C equivalent is similar (you still end up having to construct a 4-tuple). |
FWIW while we're at it, we might want to fix all the inconsistencies between the traceback module and the code in pythonrun.c for various out-of-bound values of the offset (both 0 and below and len(text) and above). |
We have a code path that does this, but currently is not activated if https://github.com/python/cpython/blob/master/Parser/pegen/pegen.c#L417-L418 |
No, ‘loc’ here is confusingly named — it’s the text of the line. |
Indeed, that is confusingly named! We could then pass the None changing the |
Or just two different calls to |
The |
Yeah, but that works only for that particular case. If you make it a bit different it fails. For example: Old parser:
New Parser:
That's why I am saying that always pointing to the beginning of the line is not correct. |
Oh you're right, this is not correct. It seems that |
This PR fixes SyntaxError locations, when the caret is not displayed, by doing the following: - `col_number` always gets set to the location of the offending node/expr. When no caret is to be displayed, this gets achieved by setting the object holding the error line to None. - Introduce a new function `_PyPegen_raise_error_known_location`, which can be called, when an arbitrary `lineno`/`col_offset` needs to be passed. This function then gets used in the grammar (through some new macros and inline functions) so that SyntaxError locations of the new parser match that of the old. Closes we-like-parsers#126.
From python#20020 (comment), it seems that the way
RAISE_SYNTAX_ERROR_NO_COL_OFFSET
works in not correct as is always assigning the caret to the beginning of the line instead of where the error should be.The text was updated successfully, but these errors were encountered: