From 3cd2b2473b034f290d65e3dc839c0530e55de75b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 14:26:24 +0300 Subject: Drop curly_block closes #13 --- src/parser/event_parser/grammar/items.rs | 18 ++++++++++++- src/parser/event_parser/parser.rs | 45 +++----------------------------- 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 0638e3093..812e407d1 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -235,5 +235,21 @@ fn fn_item(p: &mut Parser) { assert!(p.at(FN_KW)); p.bump(); - p.expect(IDENT) && p.expect(L_PAREN) && p.expect(R_PAREN) && p.curly_block(|_| ()); + p.expect(IDENT); + if p.at(L_PAREN) { + fn_value_parameters(p); + } else { + p.error().message("expected function arguments").emit(); + } + + if p.at(L_CURLY) { + p.expect(L_CURLY); + p.expect(R_CURLY); + } + + fn fn_value_parameters(p: &mut Parser) { + assert!(p.at(L_PAREN)); + p.bump(); + p.expect(R_PAREN); + } } diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs index 573e3d73a..d19663865 100644 --- a/src/parser/event_parser/parser.rs +++ b/src/parser/event_parser/parser.rs @@ -1,7 +1,7 @@ use {SyntaxKind, TextUnit, Token}; use super::Event; use super::super::is_insignificant; -use SyntaxKind::{EOF, ERROR, L_CURLY, R_CURLY, TOMBSTONE}; +use SyntaxKind::{EOF, TOMBSTONE}; pub(crate) struct Marker { pos: u32, @@ -106,9 +106,6 @@ pub(crate) struct Parser<'t> { pos: usize, events: Vec, - - curly_level: i32, - curly_limit: Option, } impl<'t> Parser<'t> { @@ -131,13 +128,10 @@ impl<'t> Parser<'t> { pos: 0, events: Vec::new(), - curly_level: 0, - curly_limit: None, } } pub(crate) fn into_events(self) -> Vec { - assert!(self.curly_limit.is_none()); assert_eq!(self.current(), EOF); self.events } @@ -146,13 +140,7 @@ impl<'t> Parser<'t> { if self.pos == self.tokens.len() { return EOF; } - let token = self.tokens[self.pos]; - if let Some(limit) = self.curly_limit { - if limit == self.curly_level && token.kind == R_CURLY { - return EOF; - } - } - token.kind + self.tokens[self.pos].kind } pub(crate) fn start(&mut self) -> Marker { @@ -172,11 +160,8 @@ impl<'t> Parser<'t> { pub(crate) fn bump(&mut self) -> SyntaxKind { let kind = self.current(); - match kind { - L_CURLY => self.curly_level += 1, - R_CURLY => self.curly_level -= 1, - EOF => return EOF, - _ => (), + if kind == EOF { + return EOF; } self.pos += 1; self.event(Event::Token { @@ -190,28 +175,6 @@ impl<'t> Parser<'t> { self.tokens.get(self.pos + n).map(|t| t.kind).unwrap_or(EOF) } - pub(crate) fn curly_block(&mut self, f: F) -> bool { - let old_level = self.curly_level; - let old_limit = self.curly_limit; - if !self.expect(L_CURLY) { - return false; - } - self.curly_limit = Some(self.curly_level); - f(self); - assert!(self.curly_level > old_level); - self.curly_limit = old_limit; - if !self.expect(R_CURLY) { - let err = self.start(); - while self.curly_level > old_level { - if self.bump() == EOF { - break; - } - } - err.complete(self, ERROR); - } - true - } - fn event(&mut self, event: Event) { self.events.push(event) } -- cgit v1.2.3