mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/syntax: differentiate between ';' and '\n' in syntax errors
Towards better syntax error messages: With this change, the parser knows whether a semicolon was an actual ';' in the source, or whether it was an automatically inserted semicolon as result of a '\n' or EOF. Using this information in error messages makes them more understandable. For #17328. Change-Id: I8cd9accee8681b62569d0ecef922d38682b401eb Reviewed-on: https://go-review.googlesource.com/36636 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
4f6d4bb3f4
commit
9799622f09
5 changed files with 19 additions and 7 deletions
|
|
@ -144,7 +144,7 @@ func (p *parser) syntax_error_at(pos src.Pos, msg string) {
|
|||
// determine token string
|
||||
var tok string
|
||||
switch p.tok {
|
||||
case _Name:
|
||||
case _Name, _Semi:
|
||||
tok = p.lit
|
||||
case _Literal:
|
||||
tok = "literal " + p.lit
|
||||
|
|
@ -215,7 +215,7 @@ func tokstring(tok token) string {
|
|||
case _Comma:
|
||||
return "comma"
|
||||
case _Semi:
|
||||
return "semicolon or newline"
|
||||
return "semicolon"
|
||||
}
|
||||
return tok.String()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue