aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-01-09 19:35:55 +0000
committerAleksey Kladov <[email protected]>2018-01-09 19:35:55 +0000
commit1544e89c49c67df00fc72d841f3e39be792cbe2b (patch)
tree1c8354cd22a77cfc32a2026fa1535cc2986007f8 /src/parser
parent7f8ca07d864b5ec8e668c48c4c029dd0584eae4a (diff)
G: mod item
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/event_parser/grammar/items.rs21
-rw-r--r--src/parser/event_parser/grammar/mod.rs3
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 @@
1use super::*; 1use super::*;
2 2
3pub(super) fn mod_items(p: &mut Parser) { 3pub(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
12fn item_first(p: &Parser) -> bool { 13fn 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
19fn mod_item(p: &mut Parser) { 20fn 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
59fn 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
58fn struct_field(p: &mut Parser) -> bool { 69fn 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;
10pub(crate) fn file(p: &mut Parser) { 10pub(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