mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
72ba117bda
commit
9df1a289ac
1 changed files with 21 additions and 22 deletions
|
|
@ -345,30 +345,29 @@ 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 '}'
|
switch p.tok {
|
||||||
if p.tok != token.RPAREN && p.tok != token.RBRACE {
|
case token.RPAREN, token.RBRACE:
|
||||||
switch p.tok {
|
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, "';'")
|
||||||
fallthrough
|
fallthrough
|
||||||
case token.SEMICOLON:
|
case token.SEMICOLON:
|
||||||
if p.lit == ";" {
|
if p.lit == ";" {
|
||||||
// explicit semicolon
|
// explicit semicolon
|
||||||
p.next()
|
p.next()
|
||||||
comment = p.lineComment // use following comments
|
comment = p.lineComment // use following comments
|
||||||
} else {
|
} else {
|
||||||
// artificial semicolon
|
// artificial semicolon
|
||||||
comment = p.lineComment // use preceding comments
|
comment = p.lineComment // use preceding comments
|
||||||
p.next()
|
p.next()
|
||||||
}
|
|
||||||
return comment
|
|
||||||
default:
|
|
||||||
p.errorExpected(p.pos, "';'")
|
|
||||||
p.advance(stmtStart)
|
|
||||||
}
|
}
|
||||||
|
return comment
|
||||||
|
default:
|
||||||
|
p.errorExpected(p.pos, "';'")
|
||||||
|
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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue