mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile/internal/parser: removed TODO (cleanup)
- checking for the correct closing token leads to slightly better behavior for some randomly bogus programs - removed `switch` in favor of an `if` statement Follow-up on https://go-review.googlesource.com/c/go/+/71250. Change-Id: I47f6c47b43baf790907f55ed97a947661687a9db Reviewed-on: https://go-review.googlesource.com/71252 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
3be5d55180
commit
4fe43f8146
1 changed files with 3 additions and 9 deletions
|
|
@ -368,17 +368,12 @@ func (p *parser) list(open, sep, close token, f func() bool) src.Pos {
|
|||
var done bool
|
||||
for p.tok != _EOF && p.tok != close && !done {
|
||||
done = f()
|
||||
switch p.tok {
|
||||
case sep:
|
||||
p.next()
|
||||
case _Rparen, _Rbrace:
|
||||
// comma is optional before ) or } - nothing to do
|
||||
// TODO(gri): consider restricting this case
|
||||
// to the expected close token only
|
||||
default:
|
||||
// sep is optional before close
|
||||
if !p.got(sep) && p.tok != close {
|
||||
p.syntax_error(fmt.Sprintf("expecting %s or %s", tokstring(sep), tokstring(close)))
|
||||
p.advance(_Rparen, _Rbrack, _Rbrace)
|
||||
if p.tok != close {
|
||||
// position could be better but we had an error so we don't care
|
||||
return p.pos()
|
||||
}
|
||||
}
|
||||
|
|
@ -386,7 +381,6 @@ func (p *parser) list(open, sep, close token, f func() bool) src.Pos {
|
|||
|
||||
pos := p.pos()
|
||||
p.want(close)
|
||||
|
||||
return pos
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue