mirror of
https://github.com/golang/go
synced 2024-11-18 03:24:42 -07:00
cmd/compile/internal/gc: consume at least one token in case of syntax error
Fixes #13248. TBR: iant Change-Id: Ic8b10704f945e6daef04bb38a00e249854b4ef19 Reviewed-on: https://go-review.googlesource.com/16930 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
d8dd9c714b
commit
ac658a83c2
@ -141,17 +141,21 @@ func (p *parser) syntax_error(msg string) {
|
|||||||
Yyerror("syntax error: unexpected " + tok + msg)
|
Yyerror("syntax error: unexpected " + tok + msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance consumes tokens until it finds one in the stoplist.
|
// Advance consumes tokens until it finds a token of the stoplist.
|
||||||
// If the stoplist is empty, the next token is consumed.
|
// If the stoplist is empty or no advance was necessary, the next
|
||||||
|
// token is consumed.
|
||||||
func (p *parser) advance(stoplist ...int32) {
|
func (p *parser) advance(stoplist ...int32) {
|
||||||
if len(stoplist) == 0 {
|
if len(stoplist) == 0 {
|
||||||
p.next()
|
p.next()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for p.tok != EOF {
|
for n := 0; p.tok != EOF; n++ {
|
||||||
for _, stop := range stoplist {
|
for _, stop := range stoplist {
|
||||||
if p.tok == stop {
|
if p.tok == stop {
|
||||||
|
if n == 0 {
|
||||||
|
p.next() // consume at least one token
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1409,8 +1413,8 @@ func (p *parser) operand(keep_parens bool) *Node {
|
|||||||
return nil
|
return nil
|
||||||
|
|
||||||
default:
|
default:
|
||||||
p.syntax_error("in operand")
|
p.syntax_error("expecting expression")
|
||||||
p.advance(';', '}')
|
p.advance()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user