New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: Go 2: spec: turn double backquote into single backquote in raw string literals #23228
Comments
Change https://golang.org/cl/85435 mentions this issue: |
This commit enables to embed ` in raw string literal. Doubled backtick `` now means one ` in raw string literal as following. // Outputs 'foo `bar' fmt.Println(`foo `` bar`) // Outputs '`' fmt.Println(````) // Outputs '``' fmt.Println(``````) GitHub issue for proposal of this feature: golang#23228 Fixes golang#23228 Change-Id: I5708cb3538fb49ca8669ad56e22b15a36461925a
@ianlancetaylor Could you tell me why this issue got Go2 label? If my understanding is correct, this change does not any breaking change. |
It breaks all existing 3rd party lexers/parsers and any tool using them. It also breaks every tool that assumes a back tick cannot appear in the value of a raw string literal, etc. |
It's also a language change. Pretty much all language changes are reserved for Go 2, simply because Go 1 is considered "done". This even applies to changes that are backwards compatible. |
This breaks the very nice property that raw strings are completely uninterpreted, and would have to set a new precedent in Go in which doubling a special character is the way to escape it. Some other languages have fulfilled your need with, e.g. triple quoted strings, which may be more consistent with the rest of Go than the proposed form of escaping. |
Raw strings right now are very simple. This would make them more complicated. As you note, you can always use |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What did you expect to see?
I wanted to embed some markdown documents easily as string literals in Go source code such as:
What did you see instead?
Current raw string literal cannot contain back quotes. So I needed to split the string literal into some parts; which does not contain back quotes and which contains back quotes as following:
It was so hard to write/read many back quotes with switching cotexts ("" and ``). But I needed to use raw string here because I also wanted to contain newlines.
Thus, embedding backs quotes in multi-line string literals is hard in Go source code. But it's not so rare case to use back quotes in multi-line string in real world (i.e. markdown documents, shell scripts, help documents, ...).
My proposal
To solve above problem, I want to add a non-breaking change to spec of raw string literal.
To enable raw string literals to contain backquotes, I want to propose that doubled back quotes '``' means one back quote as following:
By this change, my previous problem would be solved as following:
This change should not cause any breaking change because any raw string literals which contain doubled back quotes currently cause a compilation error.
I've already created a patch to implement this proposal to check my proposal is useful. So I'll submit it to Gerrit soon. As long as from my point of view, it is useful 👍
The text was updated successfully, but these errors were encountered: