zclsyntax: fix parser infinite loops on certain EOF cases
The recovery functions in particular were not all properly handling EOF, so they would spin forever looking for the right place to stop.
This commit is contained in:
parent
db5167e3d8
commit
284eb635b9
@ -71,6 +71,7 @@ Token:
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
bad := p.Read()
|
bad := p.Read()
|
||||||
|
if !p.recovery {
|
||||||
if bad.Type == TokenOQuote {
|
if bad.Type == TokenOQuote {
|
||||||
diags = append(diags, &zcl.Diagnostic{
|
diags = append(diags, &zcl.Diagnostic{
|
||||||
Severity: zcl.DiagError,
|
Severity: zcl.DiagError,
|
||||||
@ -86,6 +87,7 @@ Token:
|
|||||||
Subject: &bad.Range,
|
Subject: &bad.Range,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
endRange = p.PrevRange() // arbitrary, but somewhere inside the body means better diagnostics
|
endRange = p.PrevRange() // arbitrary, but somewhere inside the body means better diagnostics
|
||||||
|
|
||||||
p.recover(end) // attempt to recover to the token after the end of this body
|
p.recover(end) // attempt to recover to the token after the end of this body
|
||||||
@ -169,6 +171,19 @@ Token:
|
|||||||
diags = append(diags, labelDiags...)
|
diags = append(diags, labelDiags...)
|
||||||
labels = append(labels, label)
|
labels = append(labels, label)
|
||||||
labelRanges = append(labelRanges, labelRange)
|
labelRanges = append(labelRanges, labelRange)
|
||||||
|
if labelDiags.HasErrors() {
|
||||||
|
p.recoverAfterBodyItem()
|
||||||
|
return &Block{
|
||||||
|
Type: blockType,
|
||||||
|
Labels: labels,
|
||||||
|
Body: nil,
|
||||||
|
|
||||||
|
TypeRange: ident.Range,
|
||||||
|
LabelRanges: labelRanges,
|
||||||
|
OpenBraceRange: ident.Range, // placeholder
|
||||||
|
CloseBraceRange: ident.Range, // placeholder
|
||||||
|
}, diags
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
switch tok.Type {
|
switch tok.Type {
|
||||||
@ -346,6 +361,8 @@ func (p *parser) recover(end TokenType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nest--
|
nest--
|
||||||
|
case TokenEOF:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -366,7 +383,7 @@ Token:
|
|||||||
for {
|
for {
|
||||||
tok := p.Read()
|
tok := p.Read()
|
||||||
switch tok.Type {
|
switch tok.Type {
|
||||||
case start:
|
case start, TokenEOF:
|
||||||
break Token
|
break Token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user