diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-02 19:09:12 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-02-02 19:09:12 +0000 |
commit | a1fcead680b0f52036dd48dd1781606e7a7339db (patch) | |
tree | 210819a7f29195b3c50101f87adf67bffe78413b /src/parser/event_parser/grammar | |
parent | 3c6ccfe6474cf15e7c59c8b6c01d8a1b3604ba02 (diff) | |
parent | c9318e046c44fd3c161ff1253eb41c108e4733e3 (diff) |
Merge #33
33: G: extern functions r=matklad a=matklad
Diffstat (limited to 'src/parser/event_parser/grammar')
-rw-r--r-- | src/parser/event_parser/grammar/items/mod.rs | 43 |
1 files changed, 39 insertions, 4 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(); |