Recover from missing slots in delimited parsing

This commit is contained in:
Lukas Wirth 2024-02-08 11:14:33 +01:00
parent e865d45904
commit 974e69b0c5
16 changed files with 261 additions and 55 deletions

View file

@ -393,11 +393,26 @@ fn delimited(
bra: SyntaxKind,
ket: SyntaxKind,
delim: SyntaxKind,
unexpected_delim_message: impl Fn() -> String,
first_set: TokenSet,
mut parser: impl FnMut(&mut Parser<'_>) -> bool,
) {
p.bump(bra);
while !p.at(ket) && !p.at(EOF) {
if p.at(delim) {
// Recover if an argument is missing and only got a delimiter,
// e.g. `(a, , b)`.
// Wrap the erroneous delimiter in an error node so that fixup logic gets rid of it.
// FIXME: Ideally this should be handled in fixup in a structured way, but our list
// nodes currently have no concept of a missing node between two delimiters.
// So doing it this way is easier.
let m = p.start();
p.error(unexpected_delim_message());
p.bump(delim);
m.complete(p, ERROR);
continue;
}
if !parser(p) {
break;
}