lark-parser / lark

Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
MIT License
4.64k stars 397 forks source link

Fixes to the python grammar #1351

Open MegaIng opened 9 months ago

MegaIng commented 9 months ago

This PR updates the Python grammar to be a bit more up-to-date and correct, and it suggests a set of tests that could be run, although I am not sure if it's a good idea to include those in the repo.

As I wrote @erezsh on gitter, a big problem is that the with statement can't be done correctly, which is why those tests currently get commented out during downloading of the files from the Cpython github. Not sure if there is a good solution for us. This syntax change is part of the reason CPython switched over the PEG parser away from something in the LR family. The changes to the python grammar are very fine grained since I have had bad experiences with trying to do a monolithic change to that grammar, but this could be squished later.

This is a draft since the grammar changes are incomplete, and the tests definitely aren't ready to be uploaded (if they should exists at all).

Note that the grammar changes are in some sense backwards incompatible. Unsure if we care about that.