From 892acc5b36552995515f91d2bc14ae82f81d7b8d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 18:03:50 +0300 Subject: impl items --- src/parser/grammar/items/traits.rs | 11 +++++++++++ src/parser/grammar/mod.rs | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) (limited to 'src/parser/grammar') 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) { } type_params::where_clause(p); p.expect(L_CURLY); + + // test impl_item_items + // impl F { + // type A = i32; + // const B: i32 = 92; + // fn foo() {} + // fn bar(&self) {} + // } + while !p.at(EOF) && !p.at(R_CURLY) { + item(p); + } p.expect(R_CURLY); } 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) { assert!(p.at(L_PAREN)); let m = p.start(); p.bump(); + self_param(p); while !p.at(EOF) && !p.at(R_PAREN) { value_parameter(p); if !p.at(R_PAREN) { @@ -120,6 +121,29 @@ fn fn_value_parameters(p: &mut Parser) { types::type_(p); m.complete(p, VALUE_PARAMETER); } + + // test self_param + // impl S { + // fn a(self) {} + // fn b(&self,) {} + // fn c(&mut self, x: i32) {} + // } + fn self_param(p: &mut Parser) { + let la1 = p.nth(1); + let la2 = p.nth(2); + let n_toks = match (p.current(), la1, la2) { + (SELF_KW, _, _) => 1, + (AMPERSAND, SELF_KW, _) => 2, + (AMPERSAND, MUT_KW, SELF_KW) => 3, + _ => return, + }; + let m = p.start(); + for _ in 0..n_toks { p.bump(); } + m.complete(p, SELF_PARAM); + if !p.at(R_PAREN) { + p.expect(COMMA); + } + } } fn fn_ret_type(p: &mut Parser) { -- cgit v1.2.3