diff options
| author | bors <bors@rust-lang.org> | 2013-10-08 09:11:35 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-10-08 09:11:35 -0700 |
| commit | 8db52a5c0eff35a87007533d57127e7afd91fb24 (patch) | |
| tree | 17e997cd72222a081b30260d2c6581ec949f3f35 /src/libsyntax/parse | |
| parent | e293026e9c41a5322d95098c30e193fdb815c1bb (diff) | |
| parent | 77d9ac37fc866743b91c0da2951d42c459bb74c5 (diff) | |
| download | rust-8db52a5c0eff35a87007533d57127e7afd91fb24.tar.gz rust-8db52a5c0eff35a87007533d57127e7afd91fb24.zip | |
auto merge of #9756 : catamorphism/rust/issue-2354, r=alexcrichton
r? anybody It's more helpful to list the span of each open delimiter seen so far than to print out an error with the span of the last position in the file. Closes #2354
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ffebe7980bf..da2d4504a2a 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -309,6 +309,7 @@ pub fn Parser(sess: @mut ParseSess, quote_depth: @mut 0, obsolete_set: @mut HashSet::new(), mod_path_stack: @mut ~[], + open_braces: @mut ~[] } } @@ -337,6 +338,8 @@ pub struct Parser { obsolete_set: @mut HashSet<ObsoleteSyntax>, /// Used to determine the path to externally loaded source files mod_path_stack: @mut ~[@str], + /// Stack of spans of open delimiters. Used for error message. + open_braces: @mut ~[Span] } #[unsafe_destructor] @@ -2024,12 +2027,18 @@ impl Parser { match *self.token { token::EOF => { - self.fatal("file ended with unbalanced delimiters"); + for sp in self.open_braces.iter() { + self.span_note(*sp, "Did you mean to close this delimiter?"); + } + // There shouldn't really be a span, but it's easier for the test runner + // if we give it one + self.fatal("This file contains an un-closed delimiter "); } token::LPAREN | token::LBRACE | token::LBRACKET => { let close_delim = token::flip_delimiter(&*self.token); // Parse the open delimiter. + (*self.open_braces).push(*self.span); let mut result = ~[parse_any_tt_tok(self)]; let trees = @@ -2040,6 +2049,7 @@ impl Parser { // Parse the close delimiter. result.push(parse_any_tt_tok(self)); + self.open_braces.pop(); tt_delim(@mut result) } |
