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

Paul Moore p.f.moore at gmail.com
Fri Nov 4 05:36:20 EDT 2016

On 4 November 2016 at 08:36, Simon Cross <hodgestar+pythondev at gmail.com> wrote:
> On Fri, Nov 4, 2016 at 9:56 AM, Eric V. Smith <eric at trueblade.com> wrote:
>> 2. The parser sees that it's an f-string, and breaks it into expression and
>> text parts.
> I'm with Fabio here. It would be really nice to have a grammar
> specified and documented for this step, even if it's not implemented
> that way. Otherwise it's going to be very hard for, e.g., syntax
> highlighters to know what is intended to be allowed.

I think that if the docs explain the process, essentially as noted by
Eric above:

> Step 2 is the part that limits what types of expressions are allowed.
> While scanning for the end of an expression, it stops at the first '!', ':', or '}' that
> isn't inside of a string and isn't nested inside of parens, braces, and brackets.
> Also, backslashes are not allowed anywhere inside of the expression.

then that would be fine. Possibly a bit more detail would be helpful,
but I'm pretty sure I could reimplement the behaviour (for a syntax
highlighter, for example) based on the above.

I assume that the open item Eric mentions to fix the PEP and docs is
sufficient to cover this, so it'll be documented in due course.


More information about the Python-Dev mailing list