]> Cypherpunks repositories - gostls13.git/commitdiff
text/scanner: return RawString token rather than String for raw string literals
authorShengyu Zhang <shengyu.zhang@chaitin.com>
Tue, 8 May 2018 03:47:50 +0000 (03:47 +0000)
committerRobert Griesemer <gri@golang.org>
Tue, 8 May 2018 04:59:41 +0000 (04:59 +0000)
Fixes #23675

Change-Id: I78e13d1ca90400e4dd48674b93bb6e2e30718d97
GitHub-Last-Rev: f2b3a59d2bd92f28fc06360e7920c37b9da0af01
GitHub-Pull-Request: golang/go#25287
Reviewed-on: https://go-review.googlesource.com/112037
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/text/scanner/scanner.go
src/text/scanner/scanner_test.go

index 6fb0422fe5e9d84894dd0acc35af522915e34dfa..4e76664dc0c81d223c29cd76333eaef62c6110fb 100644 (file)
@@ -621,7 +621,7 @@ redo:
                case '`':
                        if s.Mode&ScanRawStrings != 0 {
                                s.scanRawString()
-                               tok = String
+                               tok = RawString
                        }
                        ch = s.next()
                default:
index 3e92d659ca029e3d56c0236a589e8d82b52c2507..9a6b72ef673b0eca61b06c0da25ee4d6113237c1 100644 (file)
@@ -209,10 +209,10 @@ var tokenList = []token{
        {String, `"` + f100 + `"`},
 
        {Comment, "// raw strings"},
-       {String, "``"},
-       {String, "`\\`"},
-       {String, "`" + "\n\n/* foobar */\n\n" + "`"},
-       {String, "`" + f100 + "`"},
+       {RawString, "``"},
+       {RawString, "`\\`"},
+       {RawString, "`" + "\n\n/* foobar */\n\n" + "`"},
+       {RawString, "`" + f100 + "`"},
 
        {Comment, "// individual characters"},
        // NUL character is not allowed
@@ -463,9 +463,9 @@ func TestError(t *testing.T) {
        testError(t, `"ab`+"\x80", "<input>:1:4", "illegal UTF-8 encoding", String)
        testError(t, `"abc`+"\xff", "<input>:1:5", "illegal UTF-8 encoding", String)
 
-       testError(t, "`a"+"\x00", "<input>:1:3", "illegal character NUL", String)
-       testError(t, "`ab"+"\x80", "<input>:1:4", "illegal UTF-8 encoding", String)
-       testError(t, "`abc"+"\xff", "<input>:1:5", "illegal UTF-8 encoding", String)
+       testError(t, "`a"+"\x00", "<input>:1:3", "illegal character NUL", RawString)
+       testError(t, "`ab"+"\x80", "<input>:1:4", "illegal UTF-8 encoding", RawString)
+       testError(t, "`abc"+"\xff", "<input>:1:5", "illegal UTF-8 encoding", RawString)
 
        testError(t, `'\"'`, "<input>:1:3", "illegal char escape", Char)
        testError(t, `"\'"`, "<input>:1:3", "illegal char escape", String)
@@ -480,7 +480,7 @@ func TestError(t *testing.T) {
        testError(t, `'`+"\n", "<input>:1:2", "literal not terminated", Char)
        testError(t, `"abc`, "<input>:1:5", "literal not terminated", String)
        testError(t, `"abc`+"\n", "<input>:1:5", "literal not terminated", String)
-       testError(t, "`abc\n", "<input>:2:1", "literal not terminated", String)
+       testError(t, "`abc\n", "<input>:2:1", "literal not terminated", RawString)
        testError(t, `/*/`, "<input>:1:4", "comment not terminated", EOF)
 }