Avoid ; -> , recovery and unclosed } recovery from being too verbose

Those two recovery attempts have a very bad interaction that causes too
unnecessary output. Add a simple gate to avoid interpreting a `;` as a
`,` when there are unclosed braces.
This commit is contained in:
Esteban Küber 2021-04-08 19:12:00 -07:00
parent 8e8159681f
commit 0d7167698f
4 changed files with 21 additions and 145 deletions

View file

@ -703,6 +703,8 @@ impl<'a> Parser<'a> {
let mut recovered = false;
let mut trailing = false;
let mut v = vec![];
let unclosed_delims = !self.unclosed_delims.is_empty();
while !self.expect_any_with_type(kets, expect) {
if let token::CloseDelim(..) | token::Eof = self.token.kind {
break;
@ -723,7 +725,7 @@ impl<'a> Parser<'a> {
// Attempt to keep parsing if it was a similar separator.
if let Some(ref tokens) = t.similar_tokens() {
if tokens.contains(&self.token.kind) {
if tokens.contains(&self.token.kind) && !unclosed_delims {
self.bump();
}
}