Provide more context for unenclosed delimiters

* When encountering EOF, point at the last opening brace that does not
   have the same indentation level as its close delimiter.
 * When encountering the wrong type of close delimiter, point at the
   likely correct open delimiter to give a better idea of what went
   wrong.
This commit is contained in:
Esteban Küber
2018-09-04 08:09:49 -07:00
parent 5238b523c3
commit 008aa5a24e
9 changed files with 124 additions and 13 deletions

View File

@@ -66,6 +66,10 @@ pub struct StringReader<'a> {
/// The raw source span which *does not* take `override_span` into account
span_src_raw: Span,
open_braces: Vec<(token::DelimToken, Span)>,
/// The type and spans for all braces that have different indentation.
///
/// Used only for error recovery when arriving to EOF with mismatched braces.
suspicious_open_spans: Vec<(token::DelimToken, Span, Span)>,
crate override_span: Option<Span>,
last_unclosed_found_span: Option<Span>,
}
@@ -216,6 +220,7 @@ impl<'a> StringReader<'a> {
span: syntax_pos::DUMMY_SP,
span_src_raw: syntax_pos::DUMMY_SP,
open_braces: Vec::new(),
suspicious_open_spans: Vec::new(),
override_span,
last_unclosed_found_span: None,
}