diff options
author | Aleksey Kladov <[email protected]> | 2018-01-09 19:35:55 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-01-09 19:35:55 +0000 |
commit | 1544e89c49c67df00fc72d841f3e39be792cbe2b (patch) | |
tree | 1c8354cd22a77cfc32a2026fa1535cc2986007f8 /src/parser/event_parser | |
parent | 7f8ca07d864b5ec8e668c48c4c029dd0584eae4a (diff) |
G: mod item
Diffstat (limited to 'src/parser/event_parser')
-rw-r--r-- | src/parser/event_parser/grammar/items.rs | 21 | ||||
-rw-r--r-- | src/parser/event_parser/grammar/mod.rs | 3 |
2 files changed, 17 insertions, 7 deletions
diff --git a/src/parser/event_parser/grammar/items.rs b/src/parser/event_parser/grammar/items.rs index 9b174679c..e775db14b 100644 --- a/src/parser/event_parser/grammar/items.rs +++ b/src/parser/event_parser/grammar/items.rs | |||
@@ -1,9 +1,10 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | pub(super) fn mod_items(p: &mut Parser) { | 3 | pub(super) fn mod_contents(p: &mut Parser) { |
4 | attributes::inner_attributes(p); | ||
4 | many(p, |p| { | 5 | many(p, |p| { |
5 | skip_to_first( | 6 | skip_to_first( |
6 | p, item_first, mod_item, | 7 | p, item_first, mod_contents_item, |
7 | "expected item", | 8 | "expected item", |
8 | ) | 9 | ) |
9 | }); | 10 | }); |
@@ -11,12 +12,12 @@ pub(super) fn mod_items(p: &mut Parser) { | |||
11 | 12 | ||
12 | fn item_first(p: &Parser) -> bool { | 13 | fn item_first(p: &Parser) -> bool { |
13 | match p.current() { | 14 | match p.current() { |
14 | STRUCT_KW | FN_KW | EXTERN_KW => true, | 15 | STRUCT_KW | FN_KW | EXTERN_KW | MOD_KW => true, |
15 | _ => false, | 16 | _ => false, |
16 | } | 17 | } |
17 | } | 18 | } |
18 | 19 | ||
19 | fn mod_item(p: &mut Parser) { | 20 | fn mod_contents_item(p: &mut Parser) { |
20 | if item(p) { | 21 | if item(p) { |
21 | if p.current() == SEMI { | 22 | if p.current() == SEMI { |
22 | node(p, ERROR, |p| { | 23 | node(p, ERROR, |p| { |
@@ -39,9 +40,9 @@ fn item(p: &mut Parser) -> bool { | |||
39 | // || node_if(p, CONST_KW, CONST_ITEM, const_item) or const FN! | 40 | // || node_if(p, CONST_KW, CONST_ITEM, const_item) or const FN! |
40 | // || unsafe trait, impl | 41 | // || unsafe trait, impl |
41 | // || node_if(p, FN_KW, FN_ITEM, fn_item) | 42 | // || node_if(p, FN_KW, FN_ITEM, fn_item) |
42 | // || node_if(p, MOD_KW, MOD_ITEM, mod_item) | ||
43 | // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) | 43 | // || node_if(p, TYPE_KW, TYPE_ITEM, type_item) |
44 | node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item) | 44 | node_if(p, [EXTERN_KW, CRATE_KW], EXTERN_CRATE_ITEM, extern_crate_item) |
45 | || node_if(p, MOD_KW, MOD_ITEM, mod_item) | ||
45 | || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) | 46 | || node_if(p, STRUCT_KW, STRUCT_ITEM, struct_item) |
46 | || node_if(p, FN_KW, FN_ITEM, fn_item) | 47 | || node_if(p, FN_KW, FN_ITEM, fn_item) |
47 | } | 48 | } |
@@ -55,6 +56,16 @@ fn extern_crate_item(p: &mut Parser) { | |||
55 | p.expect(IDENT) && alias(p) && p.expect(SEMI); | 56 | p.expect(IDENT) && alias(p) && p.expect(SEMI); |
56 | } | 57 | } |
57 | 58 | ||
59 | fn mod_item(p: &mut Parser) { | ||
60 | if !p.expect(IDENT) { | ||
61 | return; | ||
62 | } | ||
63 | if p.eat(SEMI) { | ||
64 | return; | ||
65 | } | ||
66 | p.curly_block(mod_contents); | ||
67 | } | ||
68 | |||
58 | fn struct_field(p: &mut Parser) -> bool { | 69 | fn struct_field(p: &mut Parser) -> bool { |
59 | node_if(p, IDENT, STRUCT_FIELD, |p| { | 70 | node_if(p, IDENT, STRUCT_FIELD, |p| { |
60 | p.expect(COLON) && p.expect(IDENT); | 71 | p.expect(COLON) && p.expect(IDENT); |
diff --git a/src/parser/event_parser/grammar/mod.rs b/src/parser/event_parser/grammar/mod.rs index dd1270eae..6d1cd7ec3 100644 --- a/src/parser/event_parser/grammar/mod.rs +++ b/src/parser/event_parser/grammar/mod.rs | |||
@@ -10,8 +10,7 @@ mod expressions; | |||
10 | pub(crate) fn file(p: &mut Parser) { | 10 | pub(crate) fn file(p: &mut Parser) { |
11 | node(p, FILE, |p| { | 11 | node(p, FILE, |p| { |
12 | p.optional(SHEBANG); | 12 | p.optional(SHEBANG); |
13 | attributes::inner_attributes(p); | 13 | items::mod_contents(p); |
14 | items::mod_items(p); | ||
15 | }) | 14 | }) |
16 | } | 15 | } |
17 | 16 | ||