diff options
author | Aleksey Kladov <[email protected]> | 2018-01-07 16:50:54 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-07 16:50:54 +0000 |
commit | f194750a2a4d5f034e89b937e1271637b884a503 (patch) | |
tree | 1f6ebe89813801a07e2be445acd6b112627adf9c /src/parser | |
parent | b5034410c8e5aabf809d2665e38017ef79d05601 (diff) |
G: start attributes
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/event_parser/grammar.rs | 26 | ||||
-rw-r--r-- | src/parser/event_parser/parser.rs | 8 |
2 files changed, 29 insertions, 5 deletions
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) { | |||
17 | }) | 17 | }) |
18 | } | 18 | } |
19 | 19 | ||
20 | fn inner_attributes(_: &mut Parser) { | ||
21 | //TODO | ||
22 | } | ||
23 | |||
24 | fn item_first(p: &Parser) -> bool { | 20 | fn item_first(p: &Parser) -> bool { |
25 | let current = match p.current() { | 21 | let current = match p.current() { |
26 | Some(c) => c, | 22 | Some(c) => c, |
@@ -58,6 +54,20 @@ fn fn_item(p: &mut Parser) { | |||
58 | 54 | ||
59 | // Paths, types, attributes, and stuff // | 55 | // Paths, types, attributes, and stuff // |
60 | 56 | ||
57 | fn inner_attributes(p: &mut Parser) { | ||
58 | many(p, inner_attribute) | ||
59 | } | ||
60 | |||
61 | fn inner_attribute(p: &mut Parser) -> bool { | ||
62 | if !(p.lookahead(&[EXCL, POUND])) { | ||
63 | return false; | ||
64 | } | ||
65 | node(p, ATTR, |p| { | ||
66 | p.bump_n(2); | ||
67 | }); | ||
68 | true | ||
69 | } | ||
70 | |||
61 | fn outer_attributes(_: &mut Parser) { | 71 | fn outer_attributes(_: &mut Parser) { |
62 | } | 72 | } |
63 | 73 | ||
@@ -143,9 +153,15 @@ impl<'p> Parser<'p> { | |||
143 | } | 153 | } |
144 | } | 154 | } |
145 | 155 | ||
146 | pub(crate) fn optional(&mut self, kind: SyntaxKind) { | 156 | fn optional(&mut self, kind: SyntaxKind) { |
147 | if self.current_is(kind) { | 157 | if self.current_is(kind) { |
148 | self.bump(); | 158 | self.bump(); |
149 | } | 159 | } |
150 | } | 160 | } |
161 | |||
162 | fn bump_n(&mut self, n: u8) { | ||
163 | for _ in 0..n { | ||
164 | self.bump(); | ||
165 | } | ||
166 | } | ||
151 | } \ No newline at end of file | 167 | } \ 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> { | |||
86 | Some(kind) | 86 | Some(kind) |
87 | } | 87 | } |
88 | 88 | ||
89 | pub(crate) fn lookahead(&self, kinds: &[SyntaxKind]) -> bool { | ||
90 | if self.non_ws_tokens[self.pos..].len() < kinds.len() { | ||
91 | return false | ||
92 | } | ||
93 | kinds.iter().zip(self.non_ws_tokens[self.pos..].iter()) | ||
94 | .all(|(&k1, &(idx, _))| k1 == self.raw_tokens[idx].kind) | ||
95 | } | ||
96 | |||
89 | pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool { | 97 | pub(crate) fn curly_block<F: FnOnce(&mut Parser)>(&mut self, f: F) -> bool { |
90 | let old_level = self.curly_level; | 98 | let old_level = self.curly_level; |
91 | let old_limit = self.curly_limit; | 99 | let old_limit = self.curly_limit; |