diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 43 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 20 |
2 files changed, 51 insertions, 12 deletions
diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index 4d8783735..a6d8f375c 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs | |||
@@ -19,18 +19,36 @@ fn item(p: &mut Parser) { | |||
19 | visibility(p); | 19 | visibility(p); |
20 | let la = p.nth(1); | 20 | let la = p.nth(1); |
21 | let item_kind = match p.current() { | 21 | let item_kind = match p.current() { |
22 | USE_KW => { | ||
23 | use_item(p); | ||
24 | USE_ITEM | ||
25 | } | ||
22 | EXTERN_KW if la == CRATE_KW => { | 26 | EXTERN_KW if la == CRATE_KW => { |
23 | extern_crate_item(p); | 27 | extern_crate_item(p); |
24 | EXTERN_CRATE_ITEM | 28 | EXTERN_CRATE_ITEM |
25 | } | 29 | } |
30 | EXTERN_KW => { | ||
31 | abi(p); | ||
32 | match p.current() { | ||
33 | FN_KW => { | ||
34 | fn_item(p); | ||
35 | FN_ITEM | ||
36 | } | ||
37 | L_CURLY => { | ||
38 | extern_block(p); | ||
39 | EXTERN_BLOCK | ||
40 | } | ||
41 | _ => { | ||
42 | item.abandon(p); | ||
43 | p.error().message("expected `fn` or `{`").emit(); | ||
44 | return; | ||
45 | } | ||
46 | } | ||
47 | } | ||
26 | MOD_KW => { | 48 | MOD_KW => { |
27 | mod_item(p); | 49 | mod_item(p); |
28 | MOD_ITEM | 50 | MOD_ITEM |
29 | } | 51 | } |
30 | USE_KW => { | ||
31 | use_item(p); | ||
32 | USE_ITEM | ||
33 | } | ||
34 | STRUCT_KW => { | 52 | STRUCT_KW => { |
35 | structs::struct_item(p); | 53 | structs::struct_item(p); |
36 | STRUCT_ITEM | 54 | STRUCT_ITEM |
@@ -155,6 +173,12 @@ fn mod_item(p: &mut Parser) { | |||
155 | } | 173 | } |
156 | } | 174 | } |
157 | 175 | ||
176 | fn extern_block(p: &mut Parser) { | ||
177 | assert!(p.at(L_CURLY)); | ||
178 | p.bump(); | ||
179 | p.expect(R_CURLY); | ||
180 | } | ||
181 | |||
158 | pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool { | 182 | pub(super) fn is_use_tree_start(kind: SyntaxKind) -> bool { |
159 | kind == STAR || kind == L_CURLY | 183 | kind == STAR || kind == L_CURLY |
160 | } | 184 | } |
@@ -225,6 +249,17 @@ fn use_item(p: &mut Parser) { | |||
225 | } | 249 | } |
226 | } | 250 | } |
227 | 251 | ||
252 | fn abi(p: &mut Parser) { | ||
253 | assert!(p.at(EXTERN_KW)); | ||
254 | let abi = p.start(); | ||
255 | p.bump(); | ||
256 | match p.current() { | ||
257 | STRING | RAW_STRING => p.bump(), | ||
258 | _ => (), | ||
259 | } | ||
260 | abi.complete(p, ABI); | ||
261 | } | ||
262 | |||
228 | fn fn_item(p: &mut Parser) { | 263 | fn fn_item(p: &mut Parser) { |
229 | assert!(p.at(FN_KW)); | 264 | assert!(p.at(FN_KW)); |
230 | p.bump(); | 265 | p.bump(); |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index cd4c753a9..7577fa037 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -82,15 +82,16 @@ pub enum SyntaxKind { | |||
82 | FILE, | 82 | FILE, |
83 | STRUCT_ITEM, | 83 | STRUCT_ITEM, |
84 | ENUM_ITEM, | 84 | ENUM_ITEM, |
85 | FN_ITEM, | ||
86 | EXTERN_CRATE_ITEM, | ||
87 | MOD_ITEM, | ||
88 | USE_ITEM, | ||
89 | EXTERN_BLOCK, | ||
85 | ENUM_VARIANT, | 90 | ENUM_VARIANT, |
86 | NAMED_FIELD, | 91 | NAMED_FIELD, |
87 | POS_FIELD, | 92 | POS_FIELD, |
88 | FN_ITEM, | ||
89 | EXTERN_CRATE_ITEM, | ||
90 | ATTR, | 93 | ATTR, |
91 | META_ITEM, | 94 | META_ITEM, |
92 | MOD_ITEM, | ||
93 | USE_ITEM, | ||
94 | USE_TREE, | 95 | USE_TREE, |
95 | PATH, | 96 | PATH, |
96 | PATH_SEGMENT, | 97 | PATH_SEGMENT, |
@@ -100,6 +101,7 @@ pub enum SyntaxKind { | |||
100 | TYPE_PARAM_LIST, | 101 | TYPE_PARAM_LIST, |
101 | LIFETIME_PARAM, | 102 | LIFETIME_PARAM, |
102 | TYPE_PARAM, | 103 | TYPE_PARAM, |
104 | ABI, | ||
103 | 105 | ||
104 | // Technical SyntaxKinds: they appear temporally during parsing, | 106 | // Technical SyntaxKinds: they appear temporally during parsing, |
105 | // but never end up in the final tree | 107 | // but never end up in the final tree |
@@ -189,15 +191,16 @@ impl SyntaxKind { | |||
189 | FILE => &SyntaxInfo { name: "FILE" }, | 191 | FILE => &SyntaxInfo { name: "FILE" }, |
190 | STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" }, | 192 | STRUCT_ITEM => &SyntaxInfo { name: "STRUCT_ITEM" }, |
191 | ENUM_ITEM => &SyntaxInfo { name: "ENUM_ITEM" }, | 193 | ENUM_ITEM => &SyntaxInfo { name: "ENUM_ITEM" }, |
194 | FN_ITEM => &SyntaxInfo { name: "FN_ITEM" }, | ||
195 | EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, | ||
196 | MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, | ||
197 | USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, | ||
198 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | ||
192 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 199 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
193 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 200 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
194 | POS_FIELD => &SyntaxInfo { name: "POS_FIELD" }, | 201 | POS_FIELD => &SyntaxInfo { name: "POS_FIELD" }, |
195 | FN_ITEM => &SyntaxInfo { name: "FN_ITEM" }, | ||
196 | EXTERN_CRATE_ITEM => &SyntaxInfo { name: "EXTERN_CRATE_ITEM" }, | ||
197 | ATTR => &SyntaxInfo { name: "ATTR" }, | 202 | ATTR => &SyntaxInfo { name: "ATTR" }, |
198 | META_ITEM => &SyntaxInfo { name: "META_ITEM" }, | 203 | META_ITEM => &SyntaxInfo { name: "META_ITEM" }, |
199 | MOD_ITEM => &SyntaxInfo { name: "MOD_ITEM" }, | ||
200 | USE_ITEM => &SyntaxInfo { name: "USE_ITEM" }, | ||
201 | USE_TREE => &SyntaxInfo { name: "USE_TREE" }, | 204 | USE_TREE => &SyntaxInfo { name: "USE_TREE" }, |
202 | PATH => &SyntaxInfo { name: "PATH" }, | 205 | PATH => &SyntaxInfo { name: "PATH" }, |
203 | PATH_SEGMENT => &SyntaxInfo { name: "PATH_SEGMENT" }, | 206 | PATH_SEGMENT => &SyntaxInfo { name: "PATH_SEGMENT" }, |
@@ -207,6 +210,7 @@ impl SyntaxKind { | |||
207 | TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, | 210 | TYPE_PARAM_LIST => &SyntaxInfo { name: "TYPE_PARAM_LIST" }, |
208 | LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, | 211 | LIFETIME_PARAM => &SyntaxInfo { name: "LIFETIME_PARAM" }, |
209 | TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, | 212 | TYPE_PARAM => &SyntaxInfo { name: "TYPE_PARAM" }, |
213 | ABI => &SyntaxInfo { name: "ABI" }, | ||
210 | 214 | ||
211 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, | 215 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, |
212 | EOF => &SyntaxInfo { name: "EOF" }, | 216 | EOF => &SyntaxInfo { name: "EOF" }, |