go/parser: simplify expectSemi

Move the outer if statement, directly into the switch.

Change-Id: I6a6a6964ff15dbcda4f4c9ae1c15423adbfb0ae5
Reviewed-on: https://go-review.googlesource.com/c/go/+/703835
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Mateusz Poliwczak 2025-09-15 19:37:04 +02:00 committed by Emmanuel Odeke
parent 72ba117bda
commit 9df1a289ac

View file

@ -345,9 +345,9 @@ func (p *parser) expectClosing(tok token.Token, context string) token.Pos {
// expectSemi consumes a semicolon and returns the applicable line comment. // expectSemi consumes a semicolon and returns the applicable line comment.
func (p *parser) expectSemi() (comment *ast.CommentGroup) { func (p *parser) expectSemi() (comment *ast.CommentGroup) {
// semicolon is optional before a closing ')' or '}'
if p.tok != token.RPAREN && p.tok != token.RBRACE {
switch p.tok { switch p.tok {
case token.RPAREN, token.RBRACE:
return nil // semicolon is optional before a closing ')' or '}'
case token.COMMA: case token.COMMA:
// permit a ',' instead of a ';' but complain // permit a ',' instead of a ';' but complain
p.errorExpected(p.pos, "';'") p.errorExpected(p.pos, "';'")
@ -366,10 +366,9 @@ func (p *parser) expectSemi() (comment *ast.CommentGroup) {
default: default:
p.errorExpected(p.pos, "';'") p.errorExpected(p.pos, "';'")
p.advance(stmtStart) p.advance(stmtStart)
}
}
return nil return nil
} }
}
func (p *parser) atComma(context string, follow token.Token) bool { func (p *parser) atComma(context string, follow token.Token) bool {
if p.tok == token.COMMA { if p.tok == token.COMMA {