[issue39564] Parsed expression has wrong col_offset when concatenating f-strings

Lysandros Nikolaou report at bugs.python.org
Thu Feb 6 22:32:04 EST 2020


Lysandros Nikolaou <lisandrosnik at gmail.com> added the comment:

> Can I ask how pegen solved this problem? Did you move parsing of f-strings into the grammar?

No, we actually do a very similar thing to what ast.c does.

I think there is only one major difference between what pegen does and what ast.c does. If I understand correctly, fstring_compile_expr calls fstring_fix_node_location with parent set to the whole STRING+ node. We OTOH only pass as parent the current STRING token (we work with tokens returned by the tokenizer) and then walk the AST tree and adjust the line/col_offset based on that. I'm not sure that this is bug-free, but after some testing, I could find any obvious errors.

If you want, you can take a loot at the code on https://github.com/gvanrossum/pegen/pull/183.

----------

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


More information about the Python-bugs-list mailing list