aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/grammar/items/mod.rs17
-rw-r--r--src/parser/grammar/mod.rs24
-rw-r--r--src/parser/grammar/types.rs26
3 files changed, 50 insertions, 17 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs
index b1edf2f22..18ee8af86 100644
--- a/src/parser/grammar/items/mod.rs
+++ b/src/parser/grammar/items/mod.rs
@@ -222,12 +222,6 @@ fn fn_item(p: &mut Parser) {
222 p.expect(L_CURLY); 222 p.expect(L_CURLY);
223 p.expect(R_CURLY); 223 p.expect(R_CURLY);
224 } 224 }
225
226 fn fn_value_parameters(p: &mut Parser) {
227 assert!(p.at(L_PAREN));
228 p.bump();
229 p.expect(R_PAREN);
230 }
231} 225}
232 226
233// test type_item 227// test type_item
@@ -263,14 +257,3 @@ fn mod_item(p: &mut Parser) {
263 } 257 }
264 } 258 }
265} 259}
266
267fn abi(p: &mut Parser) {
268 assert!(p.at(EXTERN_KW));
269 let abi = p.start();
270 p.bump();
271 match p.current() {
272 STRING | RAW_STRING => p.bump(),
273 _ => (),
274 }
275 abi.complete(p, ABI);
276}
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs
index abf9fe86c..5266354c1 100644
--- a/src/parser/grammar/mod.rs
+++ b/src/parser/grammar/mod.rs
@@ -50,6 +50,30 @@ fn alias(p: &mut Parser) -> bool {
50 true //FIXME: return false if three are errors 50 true //FIXME: return false if three are errors
51} 51}
52 52
53fn abi(p: &mut Parser) {
54 assert!(p.at(EXTERN_KW));
55 let abi = p.start();
56 p.bump();
57 match p.current() {
58 STRING | RAW_STRING => p.bump(),
59 _ => (),
60 }
61 abi.complete(p, ABI);
62}
63
64fn fn_value_parameters(p: &mut Parser) {
65 assert!(p.at(L_PAREN));
66 p.bump();
67 p.expect(R_PAREN);
68}
69
70fn fn_ret_type(p: &mut Parser) {
71 if p.at(THIN_ARROW) {
72 p.bump();
73 types::type_(p);
74 }
75}
76
53fn name(p: &mut Parser) { 77fn name(p: &mut Parser) {
54 if p.at(IDENT) { 78 if p.at(IDENT) {
55 let m = p.start(); 79 let m = p.start();
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs
index 37b74bfe7..ea4df8639 100644
--- a/src/parser/grammar/types.rs
+++ b/src/parser/grammar/types.rs
@@ -8,6 +8,7 @@ pub(super) fn type_(p: &mut Parser) {
8 L_BRACK => array_or_slice_type(p), 8 L_BRACK => array_or_slice_type(p),
9 AMPERSAND => reference_type(p), 9 AMPERSAND => reference_type(p),
10 UNDERSCORE => placeholder_type(p), 10 UNDERSCORE => placeholder_type(p),
11 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
11 IDENT => path_type(p), 12 IDENT => path_type(p),
12 _ => { 13 _ => {
13 p.error("expected type"); 14 p.error("expected type");
@@ -140,6 +141,31 @@ fn placeholder_type(p: &mut Parser) {
140 m.complete(p, PLACEHOLDER_TYPE); 141 m.complete(p, PLACEHOLDER_TYPE);
141} 142}
142 143
144// test fn_pointer_type
145// type A = fn();
146// type B = unsafe fn();
147// type C = unsafe extern "C" fn();
148fn fn_pointer_type(p: &mut Parser) {
149 let m = p.start();
150 p.eat(UNSAFE_KW);
151 if p.at(EXTERN_KW) {
152 abi(p);
153 }
154 // test fn_pointer_type_missing_fn
155 // type F = unsafe ();
156 if !p.eat(FN_KW) {
157 m.abandon(p);
158 p.error("expected `fn`");
159 return;
160 }
161
162 fn_value_parameters(p);
163 // test fn_pointer_type_with_ret
164 // type F = fn() -> ();
165 fn_ret_type(p);
166 m.complete(p, FN_POINTER_TYPE);
167}
168
143fn path_type(p: &mut Parser) { 169fn path_type(p: &mut Parser) {
144 assert!(p.at(IDENT)); 170 assert!(p.at(IDENT));
145 let m = p.start(); 171 let m = p.start();