diff options
author | Aleksey Kladov <[email protected]> | 2018-01-28 17:48:37 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-28 17:53:01 +0000 |
commit | d1d47e62445806a7ecfb747989d2cb34989d5d51 (patch) | |
tree | c47d0cef58945190e9e5dcf40317450cfe0db797 /src/parser | |
parent | 4adf0c20b71f8eb6365893cb1739b1cd33b081cc (diff) |
Skip over balanced parens
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 5 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 17 |
2 files changed, 22 insertions, 0 deletions
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) { | |||
36 | fn_item(p); | 36 | fn_item(p); |
37 | FN_ITEM | 37 | FN_ITEM |
38 | } | 38 | } |
39 | L_CURLY => { | ||
40 | item.abandon(p); | ||
41 | error_block(p, "expected item"); | ||
42 | return; | ||
43 | } | ||
39 | err_token => { | 44 | err_token => { |
40 | item.abandon(p); | 45 | item.abandon(p); |
41 | let message = if err_token == SEMI { | 46 | 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 { | |||
49 | true //FIXME: return false if three are errors | 49 | true //FIXME: return false if three are errors |
50 | } | 50 | } |
51 | 51 | ||
52 | fn error_block(p: &mut Parser, message: &str) { | ||
53 | assert!(p.at(L_CURLY)); | ||
54 | let err = p.start(); | ||
55 | p.error().message(message).emit(); | ||
56 | p.bump(); | ||
57 | let mut level: u32 = 1; | ||
58 | while level > 0 && !p.at(EOF) { | ||
59 | match p.current() { | ||
60 | L_CURLY => level += 1, | ||
61 | R_CURLY => level -= 1, | ||
62 | _ => (), | ||
63 | } | ||
64 | p.bump(); | ||
65 | } | ||
66 | err.complete(p, ERROR); | ||
67 | } | ||
68 | |||
52 | impl<'p> Parser<'p> { | 69 | impl<'p> Parser<'p> { |
53 | fn at<L: Lookahead>(&self, l: L) -> bool { | 70 | fn at<L: Lookahead>(&self, l: L) -> bool { |
54 | l.is_ahead(self) | 71 | l.is_ahead(self) |