From 64a65a4ff40e0c9b6d9453af79bba013afde2ffa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 8 Aug 2018 00:53:03 +0300 Subject: trait items --- src/grammar/items/consts.rs | 5 +++-- src/grammar/items/mod.rs | 15 ++++++++++++--- src/grammar/items/traits.rs | 10 ++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) (limited to 'src/grammar') diff --git a/src/grammar/items/consts.rs b/src/grammar/items/consts.rs index ca26a7814..b11949b49 100644 --- a/src/grammar/items/consts.rs +++ b/src/grammar/items/consts.rs @@ -14,7 +14,8 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) { p.eat(MUT_KW); // TODO: validator to forbid const mut name(p); types::ascription(p); - p.expect(EQ); - expressions::expr(p); + if p.eat(EQ) { + expressions::expr(p); + } p.expect(SEMI); } diff --git a/src/grammar/items/mod.rs b/src/grammar/items/mod.rs index 83f1833b5..824f1296c 100644 --- a/src/grammar/items/mod.rs +++ b/src/grammar/items/mod.rs @@ -240,7 +240,11 @@ fn fn_item(p: &mut Parser) { // fn foo() where T: Copy {} type_params::where_clause(p); - expressions::block(p); + // test fn_decl + // trait T { fn foo(); } + if !p.eat(SEMI) { + expressions::block(p); + } } // test type_item @@ -255,12 +259,17 @@ fn type_item(p: &mut Parser) { // type Result = (); type_params::type_param_list(p); + if p.at(COLON) { + type_params::bounds(p); + } + // test type_item_where_clause // type Foo where Foo: Copy = (); type_params::where_clause(p); - p.expect(EQ); - types::type_(p); + if p.eat(EQ) { + types::type_(p); + } p.expect(SEMI); } diff --git a/src/grammar/items/traits.rs b/src/grammar/items/traits.rs index 7c0935371..0b9fb2b0b 100644 --- a/src/grammar/items/traits.rs +++ b/src/grammar/items/traits.rs @@ -12,6 +12,16 @@ pub(super) fn trait_item(p: &mut Parser) { } type_params::where_clause(p); p.expect(L_CURLY); + // test trait_item_items + // impl F { + // type A: Clone; + // const B: i32; + // fn foo() {} + // fn bar(&self); + // } + while !p.at(EOF) && !p.at(R_CURLY) { + item_or_macro(p, true); + } p.expect(R_CURLY); } -- cgit v1.2.3