]> Cypherpunks repositories - gostls13.git/commit
go/parser: avoid endless loop in case of internal error
authorRobert Griesemer <gri@golang.org>
Thu, 8 Mar 2012 05:28:50 +0000 (21:28 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 8 Mar 2012 05:28:50 +0000 (21:28 -0800)
commitf3c39d8f2bff2c1c5dde404dc533ac0b38326645
tree4eb367b4bf0a8cd36b7741f8e3c4b1222245c964
parentc9836be112d4c9f7836c2adcfa2f7e941c8a1ecd
go/parser: avoid endless loop in case of internal error

Factored the error synchronization code into two functions
syncStmt and syncDecl. Because they may return w/o advancing
the scanner, there is potential for endless loops across
multiple parse functions; typically caused by an incorrect
token list in these functions (e.g., adding token.ELSE to
syncStmt will cause the parser to go into an endless loop
for test/syntax/semi7.go without this mechanism). This would
indicate a compiler bug, exposed only in an error situation
for very specific source files. Added a mechanism to force
scanner advance if an endless loop is detected. As a result,
error recovery will be less good in those cases, but the parser
reported a source error already and at least doesn't get stuck.

R=rsc, rsc
CC=golang-dev
https://golang.org/cl/5784046
src/pkg/go/parser/parser.go