we-like-parsers / pegen

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

`data/python.gram` produces wrong results when parsing fstring with `=` in `{}` #101

Open zhenkuny opened 2 months ago

zhenkuny commented 2 months ago

python -m pegen data/python.gram -o python_parser.py

import ast
import python_parser as pp

print(ast.dump(pp.parse_string('f"{x=}"', 'eval')))
print(ast.dump(ast.parse('f"{x=}"', mode='eval')))

outputs this:

Expression(body=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=114)]))
Expression(body=JoinedStr(values=[Constant(value='x='), FormattedValue(value=Name(id='x', ctx=Load()), conversion=114)]))

We can see that "=" is not considered in the python.gram.