]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: simplify expectSemi
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Mon, 15 Sep 2025 17:37:04 +0000 (19:37 +0200)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Wed, 17 Sep 2025 05:22:30 +0000 (22:22 -0700)
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>

src/go/parser/parser.go

index 9ee1576a99e85dd3ab49c70ccde8611e745b0f3d..e725371e76825e2f525a77bffb832a0892bb79dd 100644 (file)
@@ -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.
 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 {
-               case token.COMMA:
-                       // permit a ',' instead of a ';' but complain
-                       p.errorExpected(p.pos, "';'")
-                       fallthrough
-               case token.SEMICOLON:
-                       if p.lit == ";" {
-                               // explicit semicolon
-                               p.next()
-                               comment = p.lineComment // use following comments
-                       } else {
-                               // artificial semicolon
-                               comment = p.lineComment // use preceding comments
-                               p.next()
-                       }
-                       return comment
-               default:
-                       p.errorExpected(p.pos, "';'")
-                       p.advance(stmtStart)
+       switch p.tok {
+       case token.RPAREN, token.RBRACE:
+               return nil // semicolon is optional before a closing ')' or '}'
+       case token.COMMA:
+               // permit a ',' instead of a ';' but complain
+               p.errorExpected(p.pos, "';'")
+               fallthrough
+       case token.SEMICOLON:
+               if p.lit == ";" {
+                       // explicit semicolon
+                       p.next()
+                       comment = p.lineComment // use following comments
+               } else {
+                       // artificial semicolon
+                       comment = p.lineComment // use preceding comments
+                       p.next()
                }
+               return comment
+       default:
+               p.errorExpected(p.pos, "';'")
+               p.advance(stmtStart)
+               return nil
        }
-       return nil
 }
 
 func (p *parser) atComma(context string, follow token.Token) bool {