Skip to content

Commit 9df1a28

Browse files
mateusz834odeke-em
authored andcommitted
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 <[email protected]> Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 72ba117 commit 9df1a28

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

src/go/parser/parser.go

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -345,30 +345,29 @@ func (p *parser) expectClosing(tok token.Token, context string) token.Pos {
345345

346346
// expectSemi consumes a semicolon and returns the applicable line comment.
347347
func (p *parser) expectSemi() (comment *ast.CommentGroup) {
348-
// semicolon is optional before a closing ')' or '}'
349-
if p.tok != token.RPAREN && p.tok != token.RBRACE {
350-
switch p.tok {
351-
case token.COMMA:
352-
// permit a ',' instead of a ';' but complain
353-
p.errorExpected(p.pos, "';'")
354-
fallthrough
355-
case token.SEMICOLON:
356-
if p.lit == ";" {
357-
// explicit semicolon
358-
p.next()
359-
comment = p.lineComment // use following comments
360-
} else {
361-
// artificial semicolon
362-
comment = p.lineComment // use preceding comments
363-
p.next()
364-
}
365-
return comment
366-
default:
367-
p.errorExpected(p.pos, "';'")
368-
p.advance(stmtStart)
348+
switch p.tok {
349+
case token.RPAREN, token.RBRACE:
350+
return nil // semicolon is optional before a closing ')' or '}'
351+
case token.COMMA:
352+
// permit a ',' instead of a ';' but complain
353+
p.errorExpected(p.pos, "';'")
354+
fallthrough
355+
case token.SEMICOLON:
356+
if p.lit == ";" {
357+
// explicit semicolon
358+
p.next()
359+
comment = p.lineComment // use following comments
360+
} else {
361+
// artificial semicolon
362+
comment = p.lineComment // use preceding comments
363+
p.next()
369364
}
365+
return comment
366+
default:
367+
p.errorExpected(p.pos, "';'")
368+
p.advance(stmtStart)
369+
return nil
370370
}
371-
return nil
372371
}
373372

374373
func (p *parser) atComma(context string, follow token.Token) bool {

0 commit comments

Comments
 (0)