Just say "NO" Re: raw string tail escape revisited

Bengt Richter bokr at oz.net
Sat Aug 9 14:17:12 EDT 2003


On Sat, 9 Aug 2003 11:51:16 -0500, Jeff Epler <jepler at unpythonic.net> wrote:

>Well, one problem is that this is incompatible with all existing
>R-strings, which have been in Python for comparative ages.  So we'd be
>forced to implement then as B'' strings (For Bengt).  16 ways to declare
>string literals (single and triple, ' and ", standard, r, u, and ur)
>are bad enough, I don't want to add another 8 (single and triple, ' and
>", b and ub) to the mix.
>	 $ python -c 'import this' | grep "only one"
>
>Secondly, the price in the tokenizer for an R-string vs a regular string is
>essentially zero, since after the leading r, u or ur is parsed, the
>regular rule for parsing any string is used.  Your rule will require
>near-duplication of a 60-line segment of Parser/tokenizer.c and a new
>function similar to PyString_DecodeEscape, probably another 60 lines of
>C.
>
>Finally, I'm not convinced that your description that triple-quotes and
>quote-stuffing work well together.  RIght now, if the parser sees
>	R''''  # dumb way to do "'"
>it'll still be in the midst of parsing a triple-quoted raw string.  How
Right. That was a goof. See prev post (I didn't see this one, or I would have
made it a reply to this).

>will you be able to write a B''' string that begins with a ' if this
>rule is followed?  So there must be strings that you can't write with
>B-quoting, just like there are strings you can't write with R-quoting
>(but this time the problem is with strings that start with quotes
>instead of ending with backslashes).
No, I think you can quote anything. The question is if there are any
reasonable use cases that become obnoxious. The fall-back can always
be if the data starts with a quote, use a single quote of the opposite kind
and double the quoting quote if it appears in the data. With a triple quote,
I think you look at the data's last character. If it's a quote, you use the
opposite triple quote and then if a triple quote of the now quoting kind
occurs in the data, add an extra quote (like doubling, only 33% increase instead of 100%).

Can you think of a case that can't be done as a single string?

Anyhow, it was just the thought that there didn't have to be any impossible cases
that I liked. The current raw string makes lots of impossible cases ending in
quotes that you don't want a literal \ in front of. They would become possible, I think.

Not that there aren't work-arounds ;-)

Regards,
Bengt Richter




More information about the Python-list mailing list