Just signed up, "long time listener, first time caller". I only considered my own post after seeing the one from a few days ago suggesting raw"string"
. I though the rust syntax like r"string"
had been decidedly turned down, so going back in that direction with only slightly more verbosity looked like a dead end. But that post's observation seems totally correct to me, that using a poundsign #
in the keyword and also immediately after as a disambiguation character is ugly and confusing. Using other characters as the common disambiguator has been an avenue of discussion, but parsing issues have been mentioned with some of those choices. The idea that only multiline string can be raw also seems like a dead end, both of these seem like symptoms of this thread running out of ideas.
My thought was to go back to the basics and try to find a different way forward. One of the acknowledged options we've been discussing is to use a poundsign keyword, with #raw
being the popular choice. A typical form for other poundsign keywords like this uses parentheses and it seems most here think it to be too verbose, but I don't think anyone has suggested using this canonical form for the edge cases and then allowing terse alternates when there are no ambiguities.
It seems that parentheses around the quote can themselves be a form of disambiguation.
#raw("some\raw\string")
#raw("raw string with a "quoted" part")
Balanced disambiguation characters could be used as need, like earlier suggestions. Using a poundsign for this leads to the same problem mentioned by the earlier post, but perhaps it's somewhat mitigated by being inside parentheses. I think a set of other characters could be selected, maybe ones that would be unavailable except in the recognizable special case within a #raw(..)
, possibly matching left/right pairs even repeated parentheses.
#raw(#"raw string with a "quoted" part"#)
#raw(|"raw string with a "quoted" part"|)
#raw(<"raw string with a "quoted" part">)
#raw(("raw string with a "quoted" part"))
I wouldn't personally like to use backtick as such a character, it's usually used as its own quote character and having it used in conjunction with a double quote looks weird to me. I'd instead favor using backticks fully instead of double quotes.
#raw(`raw string with a "quoted" part`)
Ok, nothing too new yet, here's my slightly new idea: allow a special form of #raw(..)
that leaves out the parentheses and allows #raw
to apply to the string that follows, possibly with whitespace inbetween. There's precedence for a poundsign keyword that looks like this: #if
.
Without whitespace it looks just like what's been suggested previously, however we wouldn't have to shoehorn the disambiguators into this simplified syntax and instead rely parenthesized form for the edge cases.
#raw "some\raw\string"
#raw"some\raw\string"
It seems that most have regarded this to be nice for multiline strings, I don't think allowing whitespace between the keyword and doublequotes would change that.
#raw """
Banana
"""
I'm not sure if parsers would be happy if disambiguation characters or alternate quotes would permitted in this form too, but with some separation between the keyword and the string I think it looks slightly nicer than earlier suggestions.
#raw #"raw string with a "quoted" part"#
#raw |"raw string with a "quoted" part"|
#raw `raw string with a "quoted" part`
That's all I got. First post complete, do I get a badge? (oh, there are badges?)