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 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/parser/event_parser/grammar') 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); + } } -- cgit v1.2.3 From 60725def49834bb7dfd46c1a7b84d86f810e1d03 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 14:30:59 +0300 Subject: Simplify --- src/parser/event_parser/grammar/mod.rs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'src/parser/event_parser/grammar') diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index b87f3ca8a..79a4c10d3 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -57,7 +57,7 @@ impl<'p> Parser<'p> { err.complete(self, ERROR); } - pub(crate) fn expect(&mut self, kind: SyntaxKind) -> bool { + fn expect(&mut self, kind: SyntaxKind) -> bool { if self.at(kind) { self.bump(); true @@ -77,40 +77,24 @@ impl<'p> Parser<'p> { trait Lookahead: Copy { fn is_ahead(self, p: &Parser) -> bool; - fn consume(p: &mut Parser); } impl Lookahead for SyntaxKind { fn is_ahead(self, p: &Parser) -> bool { p.current() == self } - - fn consume(p: &mut Parser) { - p.bump(); - } } impl Lookahead for [SyntaxKind; 2] { fn is_ahead(self, p: &Parser) -> bool { p.current() == self[0] && p.raw_lookahead(1) == self[1] } - - fn consume(p: &mut Parser) { - p.bump(); - p.bump(); - } } impl Lookahead for [SyntaxKind; 3] { fn is_ahead(self, p: &Parser) -> bool { p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2] } - - fn consume(p: &mut Parser) { - p.bump(); - p.bump(); - p.bump(); - } } #[derive(Clone, Copy)] @@ -121,8 +105,4 @@ impl<'a> Lookahead for AnyOf<'a> { let curr = p.current(); self.0.iter().any(|&k| k == curr) } - - fn consume(p: &mut Parser) { - p.bump(); - } } -- cgit v1.2.3 From 2141888782a74de4a655fee585c99163a3e75e5c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 14:33:10 +0300 Subject: Rename raw_lookahead -> nth --- src/parser/event_parser/grammar/items.rs | 4 ++-- src/parser/event_parser/grammar/mod.rs | 6 +++--- src/parser/event_parser/grammar/paths.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/parser/event_parser/grammar') diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 812e407d1..7fed5e83b 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs @@ -14,7 +14,7 @@ fn item(p: &mut Parser) { let item = p.start(); attributes::outer_attributes(p); visibility(p); - let la = p.raw_lookahead(1); + let la = p.nth(1); let item_kind = match p.current() { EXTERN_KW if la == CRATE_KW => { extern_crate_item(p); @@ -171,7 +171,7 @@ fn use_item(p: &mut Parser) { p.expect(SEMI); fn use_tree(p: &mut Parser) { - let la = p.raw_lookahead(1); + let la = p.nth(1); let m = p.start(); match (p.current(), la) { (STAR, _) => { diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index 79a4c10d3..931193b5f 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs @@ -20,7 +20,7 @@ fn visibility(p: &mut Parser) { let vis = p.start(); p.bump(); if p.at(L_PAREN) { - match p.raw_lookahead(1) { + match p.nth(1) { CRATE_KW | SELF_KW | SUPER_KW | IN_KW => { p.bump(); if p.bump() == IN_KW { @@ -87,13 +87,13 @@ impl Lookahead for SyntaxKind { impl Lookahead for [SyntaxKind; 2] { fn is_ahead(self, p: &Parser) -> bool { - p.current() == self[0] && p.raw_lookahead(1) == self[1] + p.current() == self[0] && p.nth(1) == self[1] } } impl Lookahead for [SyntaxKind; 3] { fn is_ahead(self, p: &Parser) -> bool { - p.current() == self[0] && p.raw_lookahead(1) == self[1] && p.raw_lookahead(2) == self[2] + p.current() == self[0] && p.nth(1) == self[1] && p.nth(2) == self[2] } } diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index 4e028073a..6c8a89f6c 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs @@ -12,7 +12,7 @@ pub(crate) fn use_path(p: &mut Parser) { path_segment(p, true); let mut qual = path.complete(p, PATH); loop { - if p.at(COLONCOLON) && !items::is_use_tree_start(p.raw_lookahead(1)) { + if p.at(COLONCOLON) && !items::is_use_tree_start(p.nth(1)) { let path = qual.precede(p); p.bump(); path_segment(p, false); -- cgit v1.2.3