aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src
diff options
context:
space:
mode:
authorToby Dimmick <[email protected]>2020-02-07 12:36:33 +0000
committerToby Dimmick <[email protected]>2020-02-07 12:36:33 +0000
commit90ff2be4e820601a1d16ba5716916f7424dfa10d (patch)
tree2267d5456f9f16ced879da399586d7802e933d64 /crates/ra_parser/src
parent0183952d2e1252a030aca3dafd8d7abe093be3a2 (diff)
PR tweaks
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r--crates/ra_parser/src/grammar/items.rs2
-rw-r--r--crates/ra_parser/src/grammar/params.rs35
-rw-r--r--crates/ra_parser/src/grammar/paths.rs2
3 files changed, 18 insertions, 21 deletions
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index b20d224e8..7263c4d69 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -311,7 +311,7 @@ fn fn_def(p: &mut Parser) {
311 type_params::opt_type_param_list(p); 311 type_params::opt_type_param_list(p);
312 312
313 if p.at(T!['(']) { 313 if p.at(T!['(']) {
314 params::param_list_fn(p); 314 params::param_list_fn_def(p);
315 } else { 315 } else {
316 p.error("expected function arguments"); 316 p.error("expected function arguments");
317 } 317 }
diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs
index d9fbc7c94..94edc7f35 100644
--- a/crates/ra_parser/src/grammar/params.rs
+++ b/crates/ra_parser/src/grammar/params.rs
@@ -7,14 +7,14 @@ use super::*;
7// fn b(x: i32) {} 7// fn b(x: i32) {}
8// fn c(x: i32, ) {} 8// fn c(x: i32, ) {}
9// fn d(x: i32, y: ()) {} 9// fn d(x: i32, y: ()) {}
10pub(super) fn param_list_fn(p: &mut Parser) { 10pub(super) fn param_list_fn_def(p: &mut Parser) {
11 list_(p, Flavor::Function) 11 list_(p, Flavor::FnDef)
12} 12}
13 13
14// test param_list_opt_patterns 14// test param_list_opt_patterns
15// fn foo<F: FnMut(&mut Foo<'a>)>(){} 15// fn foo<F: FnMut(&mut Foo<'a>)>(){}
16pub(super) fn param_list_impl_fn(p: &mut Parser) { 16pub(super) fn param_list_fn_trait(p: &mut Parser) {
17 list_(p, Flavor::ImplFn) 17 list_(p, Flavor::FnTrait)
18} 18}
19 19
20pub(super) fn param_list_fn_ptr(p: &mut Parser) { 20pub(super) fn param_list_fn_ptr(p: &mut Parser) {
@@ -27,8 +27,8 @@ pub(super) fn param_list_closure(p: &mut Parser) {
27 27
28#[derive(Debug, Clone, Copy)] 28#[derive(Debug, Clone, Copy)]
29enum Flavor { 29enum Flavor {
30 Function, // Includes trait fn params; omitted param idents are not supported 30 FnDef, // Includes trait fn params; omitted param idents are not supported
31 ImplFn, 31 FnTrait, // Params for `Fn(...)`/`FnMut(...)`/`FnOnce(...)` annotations
32 FnPointer, 32 FnPointer,
33 Closure, 33 Closure,
34} 34}
@@ -38,13 +38,13 @@ fn list_(p: &mut Parser, flavor: Flavor) {
38 38
39 let (bra, ket) = match flavor { 39 let (bra, ket) = match flavor {
40 Closure => (T![|], T![|]), 40 Closure => (T![|], T![|]),
41 Function | ImplFn | FnPointer => (T!['('], T![')']), 41 FnDef | FnTrait | FnPointer => (T!['('], T![')']),
42 }; 42 };
43 43
44 let m = p.start(); 44 let m = p.start();
45 p.bump(bra); 45 p.bump(bra);
46 46
47 if let Function = flavor { 47 if let FnDef = flavor {
48 // test self_param_outer_attr 48 // test self_param_outer_attr
49 // fn f(#[must_use] self) {} 49 // fn f(#[must_use] self) {}
50 attributes::outer_attributes(p); 50 attributes::outer_attributes(p);
@@ -56,10 +56,11 @@ fn list_(p: &mut Parser, flavor: Flavor) {
56 // fn f(#[attr1] pat: Type) {} 56 // fn f(#[attr1] pat: Type) {}
57 attributes::outer_attributes(p); 57 attributes::outer_attributes(p);
58 58
59 if let Function | FnPointer = flavor { 59 // test param_list_vararg
60 if p.at(T![...]) { 60 // extern "C" { fn printf(format: *const i8, ...) -> i32; }
61 break; 61 match flavor {
62 } 62 FnDef | FnPointer if p.eat(T![...]) => break,
63 _ => (),
63 } 64 }
64 65
65 if !p.at_ts(VALUE_PARAMETER_FIRST) { 66 if !p.at_ts(VALUE_PARAMETER_FIRST) {
@@ -71,11 +72,7 @@ fn list_(p: &mut Parser, flavor: Flavor) {
71 p.expect(T![,]); 72 p.expect(T![,]);
72 } 73 }
73 } 74 }
74 // test param_list_vararg 75
75 // extern "C" { fn printf(format: *const i8, ...) -> i32; }
76 if let Function | FnPointer = flavor {
77 p.eat(T![...]);
78 }
79 p.expect(ket); 76 p.expect(ket);
80 m.complete(p, PARAM_LIST); 77 m.complete(p, PARAM_LIST);
81} 78}
@@ -105,13 +102,13 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
105 // fn f3(NewType(a): NewType) {} 102 // fn f3(NewType(a): NewType) {}
106 // fn f4(&&a: &&usize) {} 103 // fn f4(&&a: &&usize) {}
107 // } 104 // }
108 Flavor::Function => { 105 Flavor::FnDef => {
109 patterns::pattern(p); 106 patterns::pattern(p);
110 types::ascription(p); 107 types::ascription(p);
111 } 108 }
112 // test value_parameters_no_patterns 109 // test value_parameters_no_patterns
113 // type F = Box<Fn(i32, &i32, &i32, ())>; 110 // type F = Box<Fn(i32, &i32, &i32, ())>;
114 Flavor::ImplFn => { 111 Flavor::FnTrait => {
115 types::type_(p); 112 types::type_(p);
116 } 113 }
117 // test fn_pointer_param_ident_path 114 // test fn_pointer_param_ident_path
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs
index 186064320..f5bf3d7ce 100644
--- a/crates/ra_parser/src/grammar/paths.rs
+++ b/crates/ra_parser/src/grammar/paths.rs
@@ -99,7 +99,7 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) {
99 // test path_fn_trait_args 99 // test path_fn_trait_args
100 // type F = Box<Fn(i32) -> ()>; 100 // type F = Box<Fn(i32) -> ()>;
101 if p.at(T!['(']) { 101 if p.at(T!['(']) {
102 params::param_list_impl_fn(p); 102 params::param_list_fn_trait(p);
103 opt_fn_ret_type(p); 103 opt_fn_ret_type(p);
104 } else { 104 } else {
105 type_args::opt_type_arg_list(p, false) 105 type_args::opt_type_arg_list(p, false)