From a450142aca947b9364e498897f522f854f19781d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 26 Aug 2018 09:12:18 +0300 Subject: fix stray curly --- crates/libsyntax2/src/grammar/items/mod.rs | 7 ++++++- crates/libsyntax2/src/lib.rs | 4 ++-- crates/libsyntax2/src/parser_api.rs | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) (limited to 'crates/libsyntax2/src') diff --git a/crates/libsyntax2/src/grammar/items/mod.rs b/crates/libsyntax2/src/grammar/items/mod.rs index 32d0778c4..a285892df 100644 --- a/crates/libsyntax2/src/grammar/items/mod.rs +++ b/crates/libsyntax2/src/grammar/items/mod.rs @@ -43,7 +43,12 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF m.abandon(p); if p.at(L_CURLY) { error_block(p, "expected an item"); - } else if !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) { + } else if p.at(R_CURLY) && !stop_on_r_curly { + let e = p.start(); + p.error("unmatched `}`"); + p.bump(); + e.complete(p, ERROR); + } else if !p.at(EOF) && !p.at(R_CURLY) { p.err_and_bump("expected an item"); } else { p.error("expected an item"); diff --git a/crates/libsyntax2/src/lib.rs b/crates/libsyntax2/src/lib.rs index 9ba9970c9..93057dd6a 100644 --- a/crates/libsyntax2/src/lib.rs +++ b/crates/libsyntax2/src/lib.rs @@ -127,12 +127,12 @@ fn validate_block_structure(root: SyntaxNodeRef) { assert_eq!( node.parent(), pair.parent(), - "unpaired curleys:\n{}", + "\nunpaired curleys:\n{}", utils::dump_tree(root), ); assert!( node.next_sibling().is_none() && pair.prev_sibling().is_none(), - "floating curlys at {:?}\nfile:\n{}\nerror:\n{}\n", + "\nfloating curlys at {:?}\nfile:\n{}\nerror:\n{}\n", node, root.text(), node.text(), diff --git a/crates/libsyntax2/src/parser_api.rs b/crates/libsyntax2/src/parser_api.rs index bb34fe973..0a3b29b70 100644 --- a/crates/libsyntax2/src/parser_api.rs +++ b/crates/libsyntax2/src/parser_api.rs @@ -141,7 +141,9 @@ impl<'t> Parser<'t> { pub(crate) fn err_and_bump(&mut self, message: &str) { let m = self.start(); self.error(message); - self.bump(); + if !self.at(SyntaxKind::L_CURLY) && !self.at(SyntaxKind::R_CURLY) { + self.bump(); + } m.complete(self, ERROR); } } -- cgit v1.2.3