Congratulations on opening your first change. Thank you for your contribution!
Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.
Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.
During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.
To view, visit change 85435. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Missing space here
To view, visit change 85435. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
File src/go/scanner/scanner.go:
Patch Set #1, Line 511: return c[:j]
Odd number of backquote shoud be an error. So last one is invalid.
To view, visit change 85435. To unsubscribe, or for help writing mail filters, visit settings.
Patch set 1:Code-Review -1
Ryuichi Hayashida has uploaded this change for review.
go/scanner: allow backtick in raw string literal
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:
https://github.com/golang/go/issues/23228
Fixes #23228
Change-Id: I5708cb3538fb49ca8669ad56e22b15a36461925a
---
M doc/go_spec.html
M src/go/scanner/scanner.go
M src/go/scanner/scanner_test.go
M test/string_lit.go
4 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/doc/go_spec.html b/doc/go_spec.html
index ebf1cef..fe36113 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -456,7 +456,12 @@
contain newlines.
Carriage return characters ('\r') inside raw string literals
are discarded from the raw string value.
+To contain back quotes in raw string literals, doubled back quotes '``'
+are available. They means one back quotes in raw string literals.
</p>
+<pre>
+`foo `` bar` // Equivalent to "foo ` bar"
+</pre>
<p>
Interpreted string literals are character sequences between double
quotes, as in <code>"bar"</code>.
diff --git a/src/go/scanner/scanner.go b/src/go/scanner/scanner.go
index a86e4eb..0257b2d 100644
--- a/src/go/scanner/scanner.go
+++ b/src/go/scanner/scanner.go
@@ -492,11 +492,31 @@
return c[:i]
}
+func stripDoubledBackquotes(b []byte) []byte {
+ l := len(b)
+ c := make([]byte, l)
+ i, j := 0, 0
+ for {
+ c[j] = b[i]
+ j++
+ if i == l-1 {
+ break
+ }
+ if b[i] == '`' && b[i+1] == '`' {
+ i += 2
+ } else {
+ i++
+ }
+ }
+ return c[:j]
+}
+
func (s *Scanner) scanRawString() string {
// '`' opening already consumed
offs := s.offset - 1
hasCR := false
+ hasBQ := false
for {
ch := s.ch
if ch < 0 {
@@ -505,7 +525,12 @@
}
s.next()
if ch == '`' {
- break
+ if s.ch == '`' {
+ s.next()
+ hasBQ = true
+ } else {
+ break
+ }
}
if ch == '\r' {
hasCR = true
@@ -516,6 +541,9 @@
if hasCR {
lit = stripCR(lit)
}
+ if hasBQ {
+ lit = stripDoubledBackquotes(lit)
+ }
return string(lit)
}
diff --git a/src/go/scanner/scanner_test.go b/src/go/scanner/scanner_test.go
index ff41c03..564254d 100644
--- a/src/go/scanner/scanner_test.go
+++ b/src/go/scanner/scanner_test.go
@@ -90,6 +90,9 @@
},
{token.STRING, "`\r`", literal},
{token.STRING, "`foo\r\nbar`", literal},
+ {token.STRING, "`foo``bar`", literal},
+ {token.STRING, "````", literal},
+ {token.STRING, "`foo````bar`", literal},
// Operators and delimiters
{token.ADD, "+", operator},
@@ -285,6 +288,7 @@
elit = e.lit
if elit[0] == '`' {
elit = string(stripCR([]byte(elit)))
+ elit = string(stripDoubledBackquotes([]byte(elit)))
}
} else if e.tok.IsKeyword() {
elit = e.lit
diff --git a/test/string_lit.go b/test/string_lit.go
index 4751b82..f92ddad 100644
--- a/test/string_lit.go
+++ b/test/string_lit.go
@@ -93,6 +93,8 @@
`\000\123\x00\312\xFE\u0123\ubabe\U0000babe`,
"backslashes 2 (backquote)")
assert("\\x\\u\\U\\", `\x\u\U\`, "backslash 3 (backquote)")
+ assert(`foo `` bar`, "foo ` bar", "backquote in raw string literal")
+ assert(````, "`", "backquote-only raw string literal")
// test large and surrogate-half runes. perhaps not the most logical place for these tests.
var r int32
To view, visit change 85435. To unsubscribe, or for help writing mail filters, visit settings.
-2 to prevent accidental merge, pending proposal issue's approval.
Patch set 1:Code-Review -2
Andrew Bonventre abandoned this change.
To view, visit change 85435. To unsubscribe, or for help writing mail filters, visit settings.