]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: consume at least one token in case of syntax error
authorRobert Griesemer <gri@golang.org>
Sat, 14 Nov 2015 05:21:39 +0000 (21:21 -0800)
committerRobert Griesemer <gri@golang.org>
Sat, 14 Nov 2015 05:40:52 +0000 (05:40 +0000)
Fixes #13248.

TBR: iant

Change-Id: Ic8b10704f945e6daef04bb38a00e249854b4ef19
Reviewed-on: https://go-review.googlesource.com/16930
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/parser.go

index d5084fcd4784cd5bb66af6b476ae203c47a2839c..c8a682680d65bc70e1bf88553919e1a832b8a497 100644 (file)
@@ -141,17 +141,21 @@ func (p *parser) syntax_error(msg string) {
        Yyerror("syntax error: unexpected " + tok + msg)
 }
 
-// Advance consumes tokens until it finds one in the stoplist.
-// If the stoplist is empty, the next token is consumed.
+// Advance consumes tokens until it finds a token of the stoplist.
+// If the stoplist is empty or no advance was necessary, the next
+// token is consumed.
 func (p *parser) advance(stoplist ...int32) {
        if len(stoplist) == 0 {
                p.next()
                return
        }
 
-       for p.tok != EOF {
+       for n := 0; p.tok != EOF; n++ {
                for _, stop := range stoplist {
                        if p.tok == stop {
+                               if n == 0 {
+                                       p.next() // consume at least one token
+                               }
                                return
                        }
                }
@@ -1409,8 +1413,8 @@ func (p *parser) operand(keep_parens bool) *Node {
                return nil
 
        default:
-               p.syntax_error("in operand")
-               p.advance(';', '}')
+               p.syntax_error("expecting expression")
+               p.advance()
                return nil
        }
 }