[issue44324] add a "expected expression" syntax error

Pablo Galindo Salgado report at bugs.python.org
Sun Jun 6 19:52:11 EDT 2021


Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:

>> Well, I was thinking we could just do a simple check in _PyPegen_check_tokenizer_errors or _PyPegen_run_parser functions. If the last three tokens in the Parser object's tokens array are NAME, EQUAL/MINEQUAL/etc and NEWLINE, we raise the special error. Is this the right way to do it? I saw that unclosed parentheses' special error are checked in the same place. 

I find that quite inelegant and error prone. A PEG parser is not assured to finish when you think it will finish as it can backtrack and expand to parse left recursive rules. Incorrect syntax must be handled by the parser itself using the parser process, not after the fact. Once the parser has finished, the semantic information is gone and you are left with unstructured tokens.


> Yea, I realized that the "expected an expression" error can be used in multiple places. Could be added one by one?

Not sure what you mean here, but this should be added in a single place related to the assignment rule, otherwise is going to be quite difficult to maintain.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44324>
_______________________________________


More information about the Python-bugs-list mailing list