diff --git a/zcl/zclsyntax/parser.go b/zcl/zclsyntax/parser.go index 1de5615..8cf0c6e 100644 --- a/zcl/zclsyntax/parser.go +++ b/zcl/zclsyntax/parser.go @@ -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 { diff --git a/zcl/zclsyntax/public.go b/zcl/zclsyntax/public.go index 362337f..7c513bf 100644 --- a/zcl/zclsyntax/public.go +++ b/zcl/zclsyntax/public.go @@ -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) }