aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-07-31 16:03:50 +0100
committerAleksey Kladov <[email protected]>2018-07-31 16:03:50 +0100
commit892acc5b36552995515f91d2bc14ae82f81d7b8d (patch)
treee046cfbec482330e34a196f0f132fc738bf563f4 /src/parser
parentedf2b17a572b56371cfc29bbc3a686edcb12782c (diff)
impl items
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/grammar/items/traits.rs11
-rw-r--r--src/parser/grammar/mod.rs24
2 files changed, 35 insertions, 0 deletions
diff --git a/src/parser/grammar/items/traits.rs b/src/parser/grammar/items/traits.rs
index 812cacfb7..7d657ced0 100644
--- a/src/parser/grammar/items/traits.rs
+++ b/src/parser/grammar/items/traits.rs
@@ -29,6 +29,17 @@ pub(super) fn impl_item(p: &mut Parser) {
29 } 29 }
30 type_params::where_clause(p); 30 type_params::where_clause(p);
31 p.expect(L_CURLY); 31 p.expect(L_CURLY);
32
33 // test impl_item_items
34 // impl F {
35 // type A = i32;
36 // const B: i32 = 92;
37 // fn foo() {}
38 // fn bar(&self) {}
39 // }
40 while !p.at(EOF) && !p.at(R_CURLY) {
41 item(p);
42 }
32 p.expect(R_CURLY); 43 p.expect(R_CURLY);
33} 44}
34 45
diff --git a/src/parser/grammar/mod.rs b/src/parser/grammar/mod.rs
index 498b45d44..b8847fb68 100644
--- a/src/parser/grammar/mod.rs
+++ b/src/parser/grammar/mod.rs
@@ -104,6 +104,7 @@ fn fn_value_parameters(p: &mut Parser) {
104 assert!(p.at(L_PAREN)); 104 assert!(p.at(L_PAREN));
105 let m = p.start(); 105 let m = p.start();
106 p.bump(); 106 p.bump();
107 self_param(p);
107 while !p.at(EOF) && !p.at(R_PAREN) { 108 while !p.at(EOF) && !p.at(R_PAREN) {
108 value_parameter(p); 109 value_parameter(p);
109 if !p.at(R_PAREN) { 110 if !p.at(R_PAREN) {
@@ -120,6 +121,29 @@ fn fn_value_parameters(p: &mut Parser) {
120 types::type_(p); 121 types::type_(p);
121 m.complete(p, VALUE_PARAMETER); 122 m.complete(p, VALUE_PARAMETER);
122 } 123 }
124
125 // test self_param
126 // impl S {
127 // fn a(self) {}
128 // fn b(&self,) {}
129 // fn c(&mut self, x: i32) {}
130 // }
131 fn self_param(p: &mut Parser) {
132 let la1 = p.nth(1);
133 let la2 = p.nth(2);
134 let n_toks = match (p.current(), la1, la2) {
135 (SELF_KW, _, _) => 1,
136 (AMPERSAND, SELF_KW, _) => 2,
137 (AMPERSAND, MUT_KW, SELF_KW) => 3,
138 _ => return,
139 };
140 let m = p.start();
141 for _ in 0..n_toks { p.bump(); }
142 m.complete(p, SELF_PARAM);
143 if !p.at(R_PAREN) {
144 p.expect(COMMA);
145 }
146 }
123} 147}
124 148
125fn fn_ret_type(p: &mut Parser) { 149fn fn_ret_type(p: &mut Parser) {