From caba13a2dd1f3514ced3fbc2d4966def644f5ad8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 00:05:31 +0300 Subject: Simplify --- src/parser/event_parser/grammar/items.rs | 24 +++++++++++++----------- src/parser/event_parser/grammar/mod.rs | 9 +++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) (limited to 'src/parser') diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 2e0aa3043..38a4657aa 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -45,7 +45,6 @@ fn item(p: &mut Parser) { } err_token => { item.abandon(p); - let err = p.start(); let message = if err_token == SEMI { //TODO: if the item is incomplete, this message is misleading "expected item, found `;`\n\ @@ -53,11 +52,7 @@ fn item(p: &mut Parser) { } else { "expected item" }; - p.error() - .message(message) - .emit(); - p.bump(); - err.complete(p, ERROR); + p.err_and_bump(message); return; } }; @@ -127,7 +122,7 @@ fn pos_fields(p: &mut Parser) { if !p.expect(L_PAREN) { return; } - while !(p.at(R_PAREN) || p.at(EOF)) { + while !p.at(R_PAREN) && !p.at(EOF) { let pos_field = p.start(); visibility(p); types::type_ref(p); @@ -173,7 +168,7 @@ fn use_item(p: &mut Parser) { use_tree(p); p.expect(SEMI); - fn use_tree(p: &mut Parser) -> bool { + fn use_tree(p: &mut Parser){ let la = p.raw_lookahead(1); let m = p.start(); match (p.current(), la) { @@ -216,16 +211,23 @@ fn use_item(p: &mut Parser) { } _ => { m.abandon(p); - return false + p.err_and_bump("expected one of `*`, `::`, `{`, `self`, `super`, `indent`"); + return; }, } m.complete(p, USE_TREE); - return true; } fn nested_trees(p: &mut Parser) { assert!(p.at(L_CURLY)); - p.curly_block(|p| comma_list(p, EOF, use_tree)); + p.bump(); + while !p.at(EOF) && !p.at(R_CURLY) { + use_tree(p); + if !p.at(R_CURLY) { + p.expect(COMMA); + } + } + p.expect(R_CURLY); } } diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 32e4db698..67773453b 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -84,6 +84,15 @@ impl<'p> Parser<'p> { l.is_ahead(self) } + fn err_and_bump(&mut self, message: &str) { + let err = self.start(); + self.error() + .message(message) + .emit(); + self.bump(); + err.complete(self, ERROR); + } + pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { if self.at(kind) { self.bump(); -- cgit v1.2.3