mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
2ff463948c
commit
70544c91ff
9 changed files with 172 additions and 90 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue