aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser/grammar/mod.rs')
-rw-r--r--src/parser/grammar/mod.rs65
1 files changed, 6 insertions, 59 deletions
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs
index 69942e7f1..d4f9b80cf 100644
--- a/src/parser/grammar/mod.rs
+++ b/src/parser/grammar/mod.rs
@@ -26,8 +26,9 @@ mod expressions;
26mod items; 26mod items;
27mod paths; 27mod paths;
28mod patterns; 28mod patterns;
29mod type_args; 29mod params;
30mod type_params; 30mod type_params;
31mod type_args;
31mod types; 32mod types;
32 33
33use { 34use {
@@ -95,67 +96,13 @@ fn abi(p: &mut Parser) {
95 abi.complete(p, ABI); 96 abi.complete(p, ABI);
96} 97}
97 98
98// test fn_value_parameters 99fn fn_ret_type(p: &mut Parser) -> bool {
99// fn a() {}
100// fn b(x: i32) {}
101// fn c(x: i32, ) {}
102// fn d(x: i32, y: ()) {}
103fn fn_value_parameters(p: &mut Parser) {
104 assert!(p.at(L_PAREN));
105 let m = p.start();
106 p.bump();
107 self_param(p);
108 while !p.at(EOF) && !p.at(R_PAREN) {
109 value_parameter(p);
110 if !p.at(R_PAREN) {
111 p.expect(COMMA);
112 }
113 }
114 p.expect(R_PAREN);
115 m.complete(p, PARAM_LIST);
116
117 fn value_parameter(p: &mut Parser) {
118 let m = p.start();
119 patterns::pattern(p);
120 p.expect(COLON);
121 types::type_(p);
122 m.complete(p, VALUE_PARAMETER);
123 }
124
125 // test self_param
126 // impl S {
127 // fn a(self) {}
128 // fn b(&self,) {}
129 // fn c(&'a self,) {}
130 // fn d(&'a mut self, x: i32) {}
131 // }
132 fn self_param(p: &mut Parser) {
133 let la1 = p.nth(1);
134 let la2 = p.nth(2);
135 let la3 = p.nth(3);
136 let n_toks = match (p.current(), la1, la2, la3) {
137 (SELF_KW, _, _, _) => 1,
138 (AMPERSAND, SELF_KW, _, _) => 2,
139 (AMPERSAND, MUT_KW, SELF_KW, _) => 3,
140 (AMPERSAND, LIFETIME, SELF_KW, _) => 3,
141 (AMPERSAND, LIFETIME, MUT_KW, SELF_KW) => 4,
142 _ => return,
143 };
144 let m = p.start();
145 for _ in 0..n_toks {
146 p.bump();
147 }
148 m.complete(p, SELF_PARAM);
149 if !p.at(R_PAREN) {
150 p.expect(COMMA);
151 }
152 }
153}
154
155fn fn_ret_type(p: &mut Parser) {
156 if p.at(THIN_ARROW) { 100 if p.at(THIN_ARROW) {
157 p.bump(); 101 p.bump();
158 types::type_(p); 102 types::type_(p);
103 true
104 } else {
105 false
159 } 106 }
160} 107}
161 108