we-like-parsers / pegen

PEG parser generator for Python
https://we-like-parsers.github.io/pegen/
MIT License
150 stars 32 forks source link

Support Python 3.12 f-strings in grammar actions #94

Closed dfremont closed 10 months ago

dfremont commented 10 months ago

As pointed out in #93, in Python 3.12 the PEP 701 changes to f-string tokenization cause Pegen to fail on grammars which contain f-strings in their actions (such as the Python grammar). This PR adds support for the new tokens to Pegen and changes the metagrammar to restore f-string support under 3.12 (while preserving support under older versions of Python).

Two things this PR does not currently do:

dfremont commented 10 months ago

Ah, that explains why it looked funny after I regenerated it!

dfremont commented 10 months ago

Thanks for looking this over, Pablo. I'll mark this ready for review in case you and Matthieu want to merge it without fixing the 3.12 test failures.

MatthieuDartiailh commented 10 months ago

The linting failures should be fixed before merging.

dfremont commented 10 months ago

Fixed!

MatthieuDartiailh commented 10 months ago

Thanks. The regeneration test still seems unhappy though.

dfremont commented 10 months ago

Whoops, I should have run tox. The problem is that the PythonParserGenerator gets its list of tokens from the token package, which prior to 3.12 doesn't include FSTRING_START etc. I've added them manually.

pablogsal commented 10 months ago

Thanks for the PR @dfremont !