aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent7f8ca07d864b5ec8e668c48c4c029dd0584eae4a (diff)
G: mod item
Diffstat (limited to 'src')
-rw-r--r--src/parser/event_parser/grammar/items.rs21
-rw-r--r--src/parser/event_parser/grammar/mod.rs3
-rw-r--r--src/syntax_kinds.rs127
3 files changed, 83 insertions, 68 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
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs
index 6db82051e..26838d2d8 100644
--- a/src/syntax_kinds.rs
+++ b/src/syntax_kinds.rs
@@ -12,68 +12,70 @@ pub const FALSE_KW: SyntaxKind = SyntaxKind(7);
12pub const AS_KW: SyntaxKind = SyntaxKind(8); 12pub const AS_KW: SyntaxKind = SyntaxKind(8);
13pub const EXTERN_KW: SyntaxKind = SyntaxKind(9); 13pub const EXTERN_KW: SyntaxKind = SyntaxKind(9);
14pub const CRATE_KW: SyntaxKind = SyntaxKind(10); 14pub const CRATE_KW: SyntaxKind = SyntaxKind(10);
15pub const ERROR: SyntaxKind = SyntaxKind(11); 15pub const MOD_KW: SyntaxKind = SyntaxKind(11);
16pub const IDENT: SyntaxKind = SyntaxKind(12); 16pub const ERROR: SyntaxKind = SyntaxKind(12);
17pub const UNDERSCORE: SyntaxKind = SyntaxKind(13); 17pub const IDENT: SyntaxKind = SyntaxKind(13);
18pub const WHITESPACE: SyntaxKind = SyntaxKind(14); 18pub const UNDERSCORE: SyntaxKind = SyntaxKind(14);
19pub const INT_NUMBER: SyntaxKind = SyntaxKind(15); 19pub const WHITESPACE: SyntaxKind = SyntaxKind(15);
20pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(16); 20pub const INT_NUMBER: SyntaxKind = SyntaxKind(16);
21pub const SEMI: SyntaxKind = SyntaxKind(17); 21pub const FLOAT_NUMBER: SyntaxKind = SyntaxKind(17);
22pub const COMMA: SyntaxKind = SyntaxKind(18); 22pub const SEMI: SyntaxKind = SyntaxKind(18);
23pub const DOT: SyntaxKind = SyntaxKind(19); 23pub const COMMA: SyntaxKind = SyntaxKind(19);
24pub const DOTDOT: SyntaxKind = SyntaxKind(20); 24pub const DOT: SyntaxKind = SyntaxKind(20);
25pub const DOTDOTDOT: SyntaxKind = SyntaxKind(21); 25pub const DOTDOT: SyntaxKind = SyntaxKind(21);
26pub const DOTDOTEQ: SyntaxKind = SyntaxKind(22); 26pub const DOTDOTDOT: SyntaxKind = SyntaxKind(22);
27pub const L_PAREN: SyntaxKind = SyntaxKind(23); 27pub const DOTDOTEQ: SyntaxKind = SyntaxKind(23);
28pub const R_PAREN: SyntaxKind = SyntaxKind(24); 28pub const L_PAREN: SyntaxKind = SyntaxKind(24);
29pub const L_CURLY: SyntaxKind = SyntaxKind(25); 29pub const R_PAREN: SyntaxKind = SyntaxKind(25);
30pub const R_CURLY: SyntaxKind = SyntaxKind(26); 30pub const L_CURLY: SyntaxKind = SyntaxKind(26);
31pub const L_BRACK: SyntaxKind = SyntaxKind(27); 31pub const R_CURLY: SyntaxKind = SyntaxKind(27);
32pub const R_BRACK: SyntaxKind = SyntaxKind(28); 32pub const L_BRACK: SyntaxKind = SyntaxKind(28);
33pub const L_ANGLE: SyntaxKind = SyntaxKind(29); 33pub const R_BRACK: SyntaxKind = SyntaxKind(29);
34pub const R_ANGLE: SyntaxKind = SyntaxKind(30); 34pub const L_ANGLE: SyntaxKind = SyntaxKind(30);
35pub const AT: SyntaxKind = SyntaxKind(31); 35pub const R_ANGLE: SyntaxKind = SyntaxKind(31);
36pub const POUND: SyntaxKind = SyntaxKind(32); 36pub const AT: SyntaxKind = SyntaxKind(32);
37pub const TILDE: SyntaxKind = SyntaxKind(33); 37pub const POUND: SyntaxKind = SyntaxKind(33);
38pub const QUESTION: SyntaxKind = SyntaxKind(34); 38pub const TILDE: SyntaxKind = SyntaxKind(34);
39pub const COLON: SyntaxKind = SyntaxKind(35); 39pub const QUESTION: SyntaxKind = SyntaxKind(35);
40pub const COLONCOLON: SyntaxKind = SyntaxKind(36); 40pub const COLON: SyntaxKind = SyntaxKind(36);
41pub const DOLLAR: SyntaxKind = SyntaxKind(37); 41pub const COLONCOLON: SyntaxKind = SyntaxKind(37);
42pub const EQ: SyntaxKind = SyntaxKind(38); 42pub const DOLLAR: SyntaxKind = SyntaxKind(38);
43pub const EQEQ: SyntaxKind = SyntaxKind(39); 43pub const EQ: SyntaxKind = SyntaxKind(39);
44pub const FAT_ARROW: SyntaxKind = SyntaxKind(40); 44pub const EQEQ: SyntaxKind = SyntaxKind(40);
45pub const NEQ: SyntaxKind = SyntaxKind(41); 45pub const FAT_ARROW: SyntaxKind = SyntaxKind(41);
46pub const EXCL: SyntaxKind = SyntaxKind(42); 46pub const NEQ: SyntaxKind = SyntaxKind(42);
47pub const LIFETIME: SyntaxKind = SyntaxKind(43); 47pub const EXCL: SyntaxKind = SyntaxKind(43);
48pub const CHAR: SyntaxKind = SyntaxKind(44); 48pub const LIFETIME: SyntaxKind = SyntaxKind(44);
49pub const BYTE: SyntaxKind = SyntaxKind(45); 49pub const CHAR: SyntaxKind = SyntaxKind(45);
50pub const STRING: SyntaxKind = SyntaxKind(46); 50pub const BYTE: SyntaxKind = SyntaxKind(46);
51pub const RAW_STRING: SyntaxKind = SyntaxKind(47); 51pub const STRING: SyntaxKind = SyntaxKind(47);
52pub const BYTE_STRING: SyntaxKind = SyntaxKind(48); 52pub const RAW_STRING: SyntaxKind = SyntaxKind(48);
53pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(49); 53pub const BYTE_STRING: SyntaxKind = SyntaxKind(49);
54pub const PLUS: SyntaxKind = SyntaxKind(50); 54pub const RAW_BYTE_STRING: SyntaxKind = SyntaxKind(50);
55pub const MINUS: SyntaxKind = SyntaxKind(51); 55pub const PLUS: SyntaxKind = SyntaxKind(51);
56pub const STAR: SyntaxKind = SyntaxKind(52); 56pub const MINUS: SyntaxKind = SyntaxKind(52);
57pub const SLASH: SyntaxKind = SyntaxKind(53); 57pub const STAR: SyntaxKind = SyntaxKind(53);
58pub const CARET: SyntaxKind = SyntaxKind(54); 58pub const SLASH: SyntaxKind = SyntaxKind(54);
59pub const PERCENT: SyntaxKind = SyntaxKind(55); 59pub const CARET: SyntaxKind = SyntaxKind(55);
60pub const AMPERSAND: SyntaxKind = SyntaxKind(56); 60pub const PERCENT: SyntaxKind = SyntaxKind(56);
61pub const PIPE: SyntaxKind = SyntaxKind(57); 61pub const AMPERSAND: SyntaxKind = SyntaxKind(57);
62pub const THIN_ARROW: SyntaxKind = SyntaxKind(58); 62pub const PIPE: SyntaxKind = SyntaxKind(58);
63pub const COMMENT: SyntaxKind = SyntaxKind(59); 63pub const THIN_ARROW: SyntaxKind = SyntaxKind(59);
64pub const DOC_COMMENT: SyntaxKind = SyntaxKind(60); 64pub const COMMENT: SyntaxKind = SyntaxKind(60);
65pub const SHEBANG: SyntaxKind = SyntaxKind(61); 65pub const DOC_COMMENT: SyntaxKind = SyntaxKind(61);
66pub const FILE: SyntaxKind = SyntaxKind(62); 66pub const SHEBANG: SyntaxKind = SyntaxKind(62);
67pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(63); 67pub const FILE: SyntaxKind = SyntaxKind(63);
68pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(64); 68pub const STRUCT_ITEM: SyntaxKind = SyntaxKind(64);
69pub const FN_ITEM: SyntaxKind = SyntaxKind(65); 69pub const STRUCT_FIELD: SyntaxKind = SyntaxKind(65);
70pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(66); 70pub const FN_ITEM: SyntaxKind = SyntaxKind(66);
71pub const ATTR: SyntaxKind = SyntaxKind(67); 71pub const EXTERN_CRATE_ITEM: SyntaxKind = SyntaxKind(67);
72pub const META_ITEM: SyntaxKind = SyntaxKind(68); 72pub const ATTR: SyntaxKind = SyntaxKind(68);
73pub const LITERAL: SyntaxKind = SyntaxKind(69); 73pub const META_ITEM: SyntaxKind = SyntaxKind(69);
74pub const ALIAS: SyntaxKind = SyntaxKind(70); 74pub const MOD_ITEM: SyntaxKind = SyntaxKind(70);
75pub const LITERAL: SyntaxKind = SyntaxKind(71);
76pub const ALIAS: SyntaxKind = SyntaxKind(72);
75 77
76static INFOS: [SyntaxInfo; 71] = [ 78static INFOS: [SyntaxInfo; 73] = [
77 SyntaxInfo { name: "USE_KW" }, 79 SyntaxInfo { name: "USE_KW" },
78 SyntaxInfo { name: "FN_KW" }, 80 SyntaxInfo { name: "FN_KW" },
79 SyntaxInfo { name: "STRUCT_KW" }, 81 SyntaxInfo { name: "STRUCT_KW" },
@@ -85,6 +87,7 @@ static INFOS: [SyntaxInfo; 71] = [
85 SyntaxInfo { name: "AS_KW" }, 87 SyntaxInfo { name: "AS_KW" },
86 SyntaxInfo { name: "EXTERN_KW" }, 88 SyntaxInfo { name: "EXTERN_KW" },
87 SyntaxInfo { name: "CRATE_KW" }, 89 SyntaxInfo { name: "CRATE_KW" },
90 SyntaxInfo { name: "MOD_KW" },
88 SyntaxInfo { name: "ERROR" }, 91 SyntaxInfo { name: "ERROR" },
89 SyntaxInfo { name: "IDENT" }, 92 SyntaxInfo { name: "IDENT" },
90 SyntaxInfo { name: "UNDERSCORE" }, 93 SyntaxInfo { name: "UNDERSCORE" },
@@ -143,6 +146,7 @@ static INFOS: [SyntaxInfo; 71] = [
143 SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, 146 SyntaxInfo { name: "EXTERN_CRATE_ITEM" },
144 SyntaxInfo { name: "ATTR" }, 147 SyntaxInfo { name: "ATTR" },
145 SyntaxInfo { name: "META_ITEM" }, 148 SyntaxInfo { name: "META_ITEM" },
149 SyntaxInfo { name: "MOD_ITEM" },
146 SyntaxInfo { name: "LITERAL" }, 150 SyntaxInfo { name: "LITERAL" },
147 SyntaxInfo { name: "ALIAS" }, 151 SyntaxInfo { name: "ALIAS" },
148]; 152];
@@ -164,6 +168,7 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option<SyntaxKind> {
164 "as" => Some(AS_KW), 168 "as" => Some(AS_KW),
165 "extern" => Some(EXTERN_KW), 169 "extern" => Some(EXTERN_KW),
166 "crate" => Some(CRATE_KW), 170 "crate" => Some(CRATE_KW),
171 "mod" => Some(MOD_KW),
167 _ => None, 172 _ => None,
168 } 173 }
169} 174}