mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Recover from missing slots in delimited parsing
This commit is contained in:
parent
e865d45904
commit
974e69b0c5
16 changed files with 261 additions and 55 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue