From f194750a2a4d5f034e89b937e1271637b884a503 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 7 Jan 2018 19:50:54 +0300 Subject: G: start attributes --- src/parser/event_parser/grammar.rs | 26 +++++++++++++++++++++----- src/parser/event_parser/parser.rs | 8 ++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'src/parser/event_parser') diff --git a/src/parser/event_parser/grammar.rs b/src/parser/event_parser/grammar.rs index 09b2f02b2..d657ee1cd 100644 --- a/src/parser/event_parser/grammar.rs +++ b/src/parser/event_parser/grammar.rs @@ -17,10 +17,6 @@ pub fn file(p: &mut Parser) { }) } -fn inner_attributes(_: &mut Parser) { - //TODO -} - fn item_first(p: &Parser) -> bool { let current = match p.current() { Some(c) => c, @@ -58,6 +54,20 @@ fn fn_item(p: &mut Parser) { // Paths, types, attributes, and stuff // +fn inner_attributes(p: &mut Parser) { + many(p, inner_attribute) +} + +fn inner_attribute(p: &mut Parser) -> bool { + if !(p.lookahead(&[EXCL, POUND])) { + return false; + } + node(p, ATTR, |p| { + p.bump_n(2); + }); + true +} + fn outer_attributes(_: &mut Parser) { } @@ -143,9 +153,15 @@ impl<'p> Parser<'p> { } } - pub(crate) fn optional(&mut self, kind: SyntaxKind) { + fn optional(&mut self, kind: SyntaxKind) { if self.current_is(kind) { self.bump(); } } + + fn bump_n(&mut self, n: u8) { + for _ in 0..n { + self.bump(); + } + } } \ No newline at end of file diff --git a/src/parser/event_parser/parser.rs b/src/parser/event_parser/parser.rs index eafa03521..f8330af4e 100644 --- a/src/parser/event_parser/parser.rs +++ b/src/parser/event_parser/parser.rs @@ -86,6 +86,14 @@ impl<'t> Parser<'t> { Some(kind) } + pub(crate) fn lookahead(&self, kinds: &[SyntaxKind]) -> bool { + if self.non_ws_tokens[self.pos..].len() < kinds.len() { + return false + } + kinds.iter().zip(self.non_ws_tokens[self.pos..].iter()) + .all(|(&k1, &(idx, _))| k1 == self.raw_tokens[idx].kind) + } + pub(crate) fn curly_block(&mut self, f: F) -> bool { let old_level = self.curly_level; let old_limit = self.curly_limit; -- cgit v1.2.3