diff options
author | Matthew Dempsky <mdempsky@google.com> | 2016-06-06 17:59:05 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2016-08-19 01:10:21 +0000 |
commit | 70544c91ffac19f5ffa66c59e3097f3f1fe900f8 (patch) | |
tree | c08092c66c598727d7ee4354196e64b34ba34cdb /src/cmd/compile/internal/syntax/scanner_test.go | |
parent | 2ff463948c92e71651a31c621826281035a7071a (diff) | |
download | go-70544c91ffac19f5ffa66c59e3097f3f1fe900f8.tar.gz go-70544c91ffac19f5ffa66c59e3097f3f1fe900f8.zip |
cmd/compile/internal/syntax: match old parser errors and line numbers
This makes a bunch of changes to package syntax to tweak line numbers
for AST nodes. For example, short variable declaration statements are
now associated with the location of the ":=" token, and function calls
are associated with the location of the final ")" token. These help
satisfy many unit tests that assume the old parser's behavior.
Because many of these changes are questionable, they're guarded behind
a new "gcCompat" const to make them easy to identify and revisit in
the future.
A handful of remaining tests are too difficult to make behave
identically. These have been updated to execute with -newparser=0 and
comments explaining why they need to be fixed.
all.bash now passes with both the old and new parsers.
Change-Id: Iab834b71ca8698d39269f261eb5c92a0d55a3bf4
Reviewed-on: https://go-review.googlesource.com/27199
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/syntax/scanner_test.go')
-rw-r--r-- | src/cmd/compile/internal/syntax/scanner_test.go | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/cmd/compile/internal/syntax/scanner_test.go b/src/cmd/compile/internal/syntax/scanner_test.go index 69e81aceca..4b582ccfdf 100644 --- a/src/cmd/compile/internal/syntax/scanner_test.go +++ b/src/cmd/compile/internal/syntax/scanner_test.go @@ -269,7 +269,7 @@ func TestScanErrors(t *testing.T) { // token-level errors {"x + ~y", "bitwise complement operator is ^", 4, 1}, - {"foo$bar = 0", "invalid rune '$'", 3, 1}, + {"foo$bar = 0", "illegal character U+0024 '$'", 3, 1}, {"const x = 0xyz", "malformed hex constant", 12, 1}, {"0123456789", "malformed octal constant", 10, 1}, {"0123456789. /* foobar", "comment not terminated", 12, 1}, // valid float constant @@ -277,17 +277,17 @@ func TestScanErrors(t *testing.T) { {"var a, b = 08, 07\n", "malformed octal constant", 13, 1}, {"(x + 1.0e+x)", "malformed floating-point constant exponent", 10, 1}, - {`''`, "empty character literal", 1, 1}, + {`''`, "empty character literal or unescaped ' in character literal", 1, 1}, {"'\n", "newline in character literal", 1, 1}, {`'\`, "missing '", 2, 1}, {`'\'`, "missing '", 3, 1}, {`'\x`, "missing '", 3, 1}, - {`'\x'`, "escape sequence incomplete", 3, 1}, + {`'\x'`, "non-hex character in escape sequence: '", 3, 1}, {`'\y'`, "unknown escape sequence", 2, 1}, - {`'\x0'`, "escape sequence incomplete", 4, 1}, - {`'\00'`, "escape sequence incomplete", 4, 1}, + {`'\x0'`, "non-hex character in escape sequence: '", 4, 1}, + {`'\00'`, "non-octal character in escape sequence: '", 4, 1}, {`'\377' /*`, "comment not terminated", 7, 1}, // valid octal escape - {`'\378`, "illegal character U+0038 '8' in escape sequence", 4, 1}, + {`'\378`, "non-octal character in escape sequence: 8", 4, 1}, {`'\400'`, "octal escape value > 255: 256", 5, 1}, {`'xx`, "missing '", 2, 1}, @@ -302,19 +302,19 @@ func TestScanErrors(t *testing.T) { {`"\`, "string not terminated", 0, 1}, {`"\"`, "string not terminated", 0, 1}, {`"\x`, "string not terminated", 0, 1}, - {`"\x"`, "escape sequence incomplete", 3, 1}, + {`"\x"`, "non-hex character in escape sequence: \"", 3, 1}, {`"\y"`, "unknown escape sequence", 2, 1}, - {`"\x0"`, "escape sequence incomplete", 4, 1}, - {`"\00"`, "escape sequence incomplete", 4, 1}, + {`"\x0"`, "non-hex character in escape sequence: \"", 4, 1}, + {`"\00"`, "non-octal character in escape sequence: \"", 4, 1}, {`"\377" /*`, "comment not terminated", 7, 1}, // valid octal escape - {`"\378"`, "illegal character U+0038 '8' in escape sequence", 4, 1}, + {`"\378"`, "non-octal character in escape sequence: 8", 4, 1}, {`"\400"`, "octal escape value > 255: 256", 5, 1}, {`s := "foo\z"`, "unknown escape sequence", 10, 1}, {`s := "foo\z00\nbar"`, "unknown escape sequence", 10, 1}, {`"\x`, "string not terminated", 0, 1}, - {`"\x"`, "escape sequence incomplete", 3, 1}, - {`var s string = "\x"`, "escape sequence incomplete", 18, 1}, + {`"\x"`, "non-hex character in escape sequence: \"", 3, 1}, + {`var s string = "\x"`, "non-hex character in escape sequence: \"", 18, 1}, {`return "\Uffffffff"`, "escape sequence is invalid Unicode code point", 18, 1}, // former problem cases |