diff options
Diffstat (limited to 'src/parser/grammar/mod.rs')
-rw-r--r-- | src/parser/grammar/mod.rs | 65 |
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; | |||
26 | mod items; | 26 | mod items; |
27 | mod paths; | 27 | mod paths; |
28 | mod patterns; | 28 | mod patterns; |
29 | mod type_args; | 29 | mod params; |
30 | mod type_params; | 30 | mod type_params; |
31 | mod type_args; | ||
31 | mod types; | 32 | mod types; |
32 | 33 | ||
33 | use { | 34 | use { |
@@ -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 | 99 | fn 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: ()) {} | ||
103 | fn 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 | |||
155 | fn 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 | ||