[Python-Dev] Parsing f-strings from PEP 498 -- Literal String Interpolation

Fabio Zadrozny fabiofz at gmail.com
Thu Nov 3 15:06:21 EDT 2016

Hi Python-Dev,

I'm trying to get my head around on what's accepted in f-strings --
https://www.python.org/dev/peps/pep-0498/ seems very light on the details
on what it does accept as an expression and how things should actually be
parsed (and the current implementation still doesn't seem to be in a state
for a final release, so, I thought asking on python-dev would be a
reasonable option).

I was thinking there'd be some grammar for it (something as
https://docs.python.org/3.6/reference/grammar.html), but all I could find
related to this is a quote saying that f-strings should be something as:

f ' <text> { <expression> <optional !s, !r, or !a> <optional : format
specifier> } <text>

So, given that, is it safe to assume that <expression> would be equal to
the "test" node from the official grammar?

I initially thought it would obviously be, but the PEP says that using a
lamda inside the expression would conflict because of the colon (which
wouldn't happen if a proper grammar was actually used for this parsing as
there'd be no conflict as the lamda would properly consume the colon), so,
I guess some pre-parser steps takes place to separate the expression to
then be parsed, so, I'm interested on knowing how exactly that should work
when the implementation is finished -- lots of plus points if there's
actually a grammar to back it up :)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20161103/ce7b132d/attachment.html>

More information about the Python-Dev mailing list