On 8/14/2019 11:02 AM, Random832 wrote:
On Mon, Aug 12, 2019, at 15:15, Terry Reedy wrote:
Please no more combinations. The presence of both legal and illegal
combinations is already a mild nightmare for processing and testing.
idlelib.colorizer has the following re to detest legal combinations

      stringprefix = r"(?i:r|u|f|fr|rf|b|br|rb)?"

More advanced syntax highlighting editors have to handle each string type separately 
anyway, because they highlight (valid) backslash-escapes and f-string formatters. 
The proposed 'v-string' type would need separate handling even in a simplistic 
editor like IDLE, because it's different at the basic level of \" not ending 
the string (whereas, for better or worse, all current string types have exactly the 
same rules for how to find the end delimiter)

The reason I defined f-strings as I did is so that lexer/parsers (editors, syntax highlighters, other implementations, etc.) could easily ignore them, at least as a first pass. They're literally like all other strings to the lexer. Python's lexer/parser says that a string is:

- some optional letters, making the string prefix
- an opening quote or triple quote
- some optional chars, with \ escaping
- a matching closing quote or triple quote

The parser then validates the string prefix ('f' is okay, 'b' is okay, 'fb' isn't okay, 'x' isn't okay, etc.) It then operates on the contents of the string, based on what the string prefix tell it to do.

So all an alternate lexer/parser has to do is add 'f' to the valid string prefixes, and it could then at least skip over f-strings. Somewhere in my notes I have 3 or 4 examples of projects that did this, and voila: they "supported" f-strings. Imagine a syntax highlighter that didn't want to highlight the inside of an f-string.

The proposed v-strings would indeed break this. I'm opposed to them for this reason, among others.

That all said, I am considering moving f-string parsing into the CPython parser. That would let you say things like:

f'some text {ord('a')}'

I'm not sure that's a great idea, but I've discussed it with several alternate implementations, and with authors of several editors, and they seem okay with it. I'm following Guido's parser experiment with some interest, to see how it might interact with this proposal. Might they also be okay with v-strings? Maybe. But it seems like a lot of hassle for a very minor feature.

Eric
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/BDZCXGRW5KTUOGMRT6OHH6S3UD4BV5ZV/

Reply via email to