From d1d47e62445806a7ecfb747989d2cb34989d5d51 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 20:48:37 +0300 Subject: Skip over balanced parens --- src/parser/event_parser/grammar/items.rs | 5 +++++ src/parser/event_parser/grammar/mod.rs | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 309e4f4de..56e3208ac 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -36,6 +36,11 @@ fn item(p: &mut Parser) { fn_item(p); FN_ITEM } + L_CURLY => { + item.abandon(p); + error_block(p, "expected item"); + return; + } err_token => { item.abandon(p); let message = if err_token == SEMI { diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 92125acd1..e7f1915d2 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -49,6 +49,23 @@ fn alias(p: &mut Parser) -> bool { true //FIXME: return false if three are errors } +fn error_block(p: &mut Parser, message: &str) { + assert!(p.at(L_CURLY)); + let err = p.start(); + p.error().message(message).emit(); + p.bump(); + let mut level: u32 = 1; + while level > 0 && !p.at(EOF) { + match p.current() { + L_CURLY => level += 1, + R_CURLY => level -= 1, + _ => (), + } + p.bump(); + } + err.complete(p, ERROR); +} + impl<'p> Parser<'p> { fn at(&self, l: L) -> bool { l.is_ahead(self) -- cgit v1.2.3