On Thu, Aug 18, 2016, at 15:15, Terry Reedy wrote:
> This is the crux of this thread. Is an f-string a single string that
> contains magically handled code, or interleaved strings using { and } as
> closing and opening quotes (which is backwards from their normal
> function of being opener and closer)
I'd rather conceptualize it as a sequence of two* kinds of thing:
literal character sequences [as sequences of characters other than {]
and expressions [started with {, and ended with a } that is not
otherwise part of the expression] rather than treating { as a closing
quote.
In particular, treating } as an opening quote doesn't really work, since
expressions can contain both strings (which may contain an unbalanced })
and dictionary/set literals (which contain balanced }'s which are not in
quotes) - what ends the expression is a } at the top level.
*or three, considering that escapes are used in the non-expression
parts.
> and expressions? The latter view
> makes the grammar context sensitive, I believe, as } could only open a
> string if there is a previous f-tagged string an indefinite number of
> alternations back.
} at the top level is otherwise a syntax error. I don't know enough
about the theoretical constructs involved to know if this makes it
formally 'context sensitive' or not - I don't know that it's any more
context sensitive than ) being valid if there is a matching (. Honestly,
I'd be more worried about : than }.
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/