aboutsummaryrefslogtreecommitdiff
path: root/src/parser/event_parser/grammar/attributes.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-07 18:46:10 +0000
committerAleksey Kladov <[email protected]>2018-01-07 18:46:10 +0000
commit55027bed0867356a7c84ab2df3d6dcecc45e455d (patch)
treed9188e801d202b76cdb8a242f693cba310bb8fe1 /src/parser/event_parser/grammar/attributes.rs
parent0aef78e512bfa271e8ff411359072dc1132e2c65 (diff)
Split into modules
Diffstat (limited to 'src/parser/event_parser/grammar/attributes.rs')
-rw-r--r--src/parser/event_parser/grammar/attributes.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/parser/event_parser/grammar/attributes.rs b/src/parser/event_parser/grammar/attributes.rs
new file mode 100644
index 000000000..c80f782ab
--- /dev/null
+++ b/src/parser/event_parser/grammar/attributes.rs
@@ -0,0 +1,42 @@
1use super::*;
2
3pub(super) fn inner_attributes(p: &mut Parser) {
4 many(p, |p| attribute(p, true))
5}
6
7pub(super) fn outer_attributes(_: &mut Parser) {
8}
9
10
11fn attribute(p: &mut Parser, inner: bool) -> bool {
12 let attr_start = inner && p.lookahead(&[POUND, EXCL, L_BRACK])
13 || !inner && p.lookahead(&[POUND, L_BRACK]);
14 if !attr_start {
15 return false;
16 }
17 node(p, ATTR, |p| {
18 p.bump_n(if inner { 3 } else { 2 });
19 meta_item(p) && p.expect(R_BRACK);
20 });
21 true
22}
23
24fn meta_item(p: &mut Parser) -> bool {
25 node_if(p, IDENT, META_ITEM, |p| {
26 if p.eat(EQ) {
27 if !expressions::literal(p) {
28 p.error()
29 .message("expected literal")
30 .emit();
31 }
32 } else if p.eat(L_PAREN) {
33 comma_list(p, R_PAREN, meta_item_inner);
34 p.expect(R_PAREN);
35 }
36 })
37}
38
39fn meta_item_inner(p: &mut Parser) -> bool {
40 meta_item(p) || expressions::literal(p)
41}
42