diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-07-22 18:15:38 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-07-22 18:15:38 +0000 |
commit | 22b955cca564a9a3a5b8c9d9dd1e295b7943c128 (patch) | |
tree | abdbd898676e1f853fca2d7e031d105d7ebcf676 /libgo/go/text/scanner | |
parent | 9d04a3af4c6491536badf6bde9707c907e4d196b (diff) | |
download | gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.zip gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.tar.gz gcc-22b955cca564a9a3a5b8c9d9dd1e295b7943c128.tar.bz2 |
libgo: update to go1.7rc3
Reviewed-on: https://go-review.googlesource.com/25150
From-SVN: r238662
Diffstat (limited to 'libgo/go/text/scanner')
-rw-r--r-- | libgo/go/text/scanner/example_test.go | 21 | ||||
-rw-r--r-- | libgo/go/text/scanner/scanner.go | 15 | ||||
-rw-r--r-- | libgo/go/text/scanner/scanner_test.go | 62 |
3 files changed, 48 insertions, 50 deletions
diff --git a/libgo/go/text/scanner/example_test.go b/libgo/go/text/scanner/example_test.go index f8b51b7..f48c31d 100644 --- a/libgo/go/text/scanner/example_test.go +++ b/libgo/go/text/scanner/example_test.go @@ -19,6 +19,7 @@ func Example() { someParsable = text }` var s scanner.Scanner + s.Filename = "example" s.Init(strings.NewReader(src)) var tok rune for tok != scanner.EOF { @@ -27,14 +28,14 @@ func Example() { } // Output: - // At position 3:4 : if - // At position 3:6 : a - // At position 3:8 : > - // At position 3:11 : 10 - // At position 3:13 : { - // At position 4:15 : someParsable - // At position 4:17 : = - // At position 4:22 : text - // At position 5:3 : } - // At position 5:3 : + // At position example:3:4 : if + // At position example:3:6 : a + // At position example:3:8 : > + // At position example:3:11 : 10 + // At position example:3:13 : { + // At position example:4:15 : someParsable + // At position example:4:17 : = + // At position example:4:22 : text + // At position example:5:3 : } + // At position example:5:3 : } diff --git a/libgo/go/text/scanner/scanner.go b/libgo/go/text/scanner/scanner.go index 0155800..e085f8a 100644 --- a/libgo/go/text/scanner/scanner.go +++ b/libgo/go/text/scanner/scanner.go @@ -4,12 +4,12 @@ // Package scanner provides a scanner and tokenizer for UTF-8-encoded text. // It takes an io.Reader providing the source, which then can be tokenized -// through repeated calls to the Scan function. For compatibility with +// through repeated calls to the Scan function. For compatibility with // existing tools, the NUL character is not allowed. If the first character // in the source is a UTF-8 encoded byte order mark (BOM), it is discarded. // // By default, a Scanner skips white space and Go comments and recognizes all -// literals as defined by the Go language specification. It may be +// literals as defined by the Go language specification. It may be // customized to recognize only a subset of those literals and to recognize // different identifier and white space characters. package scanner @@ -37,14 +37,11 @@ func (pos *Position) IsValid() bool { return pos.Line > 0 } func (pos Position) String() string { s := pos.Filename - if pos.IsValid() { - if s != "" { - s += ":" - } - s += fmt.Sprintf("%d:%d", pos.Line, pos.Column) - } if s == "" { - s = "???" + s = "<input>" + } + if pos.IsValid() { + s += fmt.Sprintf(":%d:%d", pos.Line, pos.Column) } return s } diff --git a/libgo/go/text/scanner/scanner_test.go b/libgo/go/text/scanner/scanner_test.go index 798bed7..3e92d65 100644 --- a/libgo/go/text/scanner/scanner_test.go +++ b/libgo/go/text/scanner/scanner_test.go @@ -451,37 +451,37 @@ func testError(t *testing.T, src, pos, msg string, tok rune) { } func TestError(t *testing.T) { - testError(t, "\x00", "1:1", "illegal character NUL", 0) - testError(t, "\x80", "1:1", "illegal UTF-8 encoding", utf8.RuneError) - testError(t, "\xff", "1:1", "illegal UTF-8 encoding", utf8.RuneError) - - testError(t, "a\x00", "1:2", "illegal character NUL", Ident) - testError(t, "ab\x80", "1:3", "illegal UTF-8 encoding", Ident) - testError(t, "abc\xff", "1:4", "illegal UTF-8 encoding", Ident) - - testError(t, `"a`+"\x00", "1:3", "illegal character NUL", String) - testError(t, `"ab`+"\x80", "1:4", "illegal UTF-8 encoding", String) - testError(t, `"abc`+"\xff", "1:5", "illegal UTF-8 encoding", String) - - testError(t, "`a"+"\x00", "1:3", "illegal character NUL", String) - testError(t, "`ab"+"\x80", "1:4", "illegal UTF-8 encoding", String) - testError(t, "`abc"+"\xff", "1:5", "illegal UTF-8 encoding", String) - - testError(t, `'\"'`, "1:3", "illegal char escape", Char) - testError(t, `"\'"`, "1:3", "illegal char escape", String) - - testError(t, `01238`, "1:6", "illegal octal number", Int) - testError(t, `01238123`, "1:9", "illegal octal number", Int) - testError(t, `0x`, "1:3", "illegal hexadecimal number", Int) - testError(t, `0xg`, "1:3", "illegal hexadecimal number", Int) - testError(t, `'aa'`, "1:4", "illegal char literal", Char) - - testError(t, `'`, "1:2", "literal not terminated", Char) - testError(t, `'`+"\n", "1:2", "literal not terminated", Char) - testError(t, `"abc`, "1:5", "literal not terminated", String) - testError(t, `"abc`+"\n", "1:5", "literal not terminated", String) - testError(t, "`abc\n", "2:1", "literal not terminated", String) - testError(t, `/*/`, "1:4", "comment not terminated", EOF) + testError(t, "\x00", "<input>:1:1", "illegal character NUL", 0) + testError(t, "\x80", "<input>:1:1", "illegal UTF-8 encoding", utf8.RuneError) + testError(t, "\xff", "<input>:1:1", "illegal UTF-8 encoding", utf8.RuneError) + + testError(t, "a\x00", "<input>:1:2", "illegal character NUL", Ident) + testError(t, "ab\x80", "<input>:1:3", "illegal UTF-8 encoding", Ident) + testError(t, "abc\xff", "<input>:1:4", "illegal UTF-8 encoding", Ident) + + 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", 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, `'\"'`, "<input>:1:3", "illegal char escape", Char) + testError(t, `"\'"`, "<input>:1:3", "illegal char escape", String) + + testError(t, `01238`, "<input>:1:6", "illegal octal number", Int) + testError(t, `01238123`, "<input>:1:9", "illegal octal number", Int) + testError(t, `0x`, "<input>:1:3", "illegal hexadecimal number", Int) + testError(t, `0xg`, "<input>:1:3", "illegal hexadecimal number", Int) + testError(t, `'aa'`, "<input>:1:4", "illegal char literal", Char) + + testError(t, `'`, "<input>:1:2", "literal not terminated", Char) + 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, `/*/`, "<input>:1:4", "comment not terminated", EOF) } // An errReader returns (0, err) where err is not io.EOF. |