zclsyntax: track whether parser is in recovery mode
The parser has some recovery heuristics but they will not always achieve the best result. To prevent unsuccessful recovery from causing a cascade of confusing follow-on errors, we'll track in the parser whether recovery has been attempted and then the specific sub-parsers can use this to skip certain "unexpected token type" errors in recovery situations, assuming instead that an earlier error will cover the problem and that we just want to bail out quickly.
This commit is contained in:
parent
49aa35133f
commit
2c90adb9e1
@ -9,6 +9,12 @@ import (
|
||||
|
||||
type parser struct {
|
||||
*peeker
|
||||
|
||||
// set to true if any recovery is attempted. The parser can use this
|
||||
// to attempt to reduce error noise by suppressing "bad token" errors
|
||||
// in recovery mode, assuming that the recovery heuristics have failed
|
||||
// in this case and left the peeker in a wrong place.
|
||||
recovery bool
|
||||
}
|
||||
|
||||
func (p *parser) ParseBody(end TokenType) (*Body, zcl.Diagnostics) {
|
||||
@ -194,6 +200,7 @@ Token:
|
||||
// unpredictable results on input with bad bracketer nesting.
|
||||
func (p *parser) recover(end TokenType) {
|
||||
start := p.oppositeBracket(end)
|
||||
p.recovery = true
|
||||
|
||||
nest := 0
|
||||
for {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
func ParseConfig(src []byte, filename string, start zcl.Pos) (*Body, zcl.Diagnostics) {
|
||||
tokens := LexConfig(src, filename, start)
|
||||
peeker := newPeeker(tokens, false)
|
||||
parser := &parser{peeker}
|
||||
parser := &parser{peeker: peeker}
|
||||
return parser.ParseBody(TokenEOF)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user