From 2ef16a4121ad497e7fb290445ffe644b6b8ceae6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 12:35:40 +0300 Subject: G: type item --- src/parser/grammar/items/mod.rs | 80 ++++++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 28 deletions(-) (limited to 'src/parser/grammar/items') diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index b73628ec0..ffe86fa97 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs @@ -150,7 +150,14 @@ fn item(p: &mut Parser) { } } } - + FN_KW => { + fn_item(p); + FN_ITEM + } + TYPE_KW => { + type_item(p); + TYPE_ITEM + } MOD_KW => { mod_item(p); MOD_ITEM @@ -163,10 +170,6 @@ fn item(p: &mut Parser) { structs::enum_item(p); ENUM_ITEM } - FN_KW => { - fn_item(p); - FN_ITEM - } L_CURLY => { item.abandon(p); error_block(p, "expected item"); @@ -203,29 +206,6 @@ fn extern_block(p: &mut Parser) { p.expect(R_CURLY); } -fn mod_item(p: &mut Parser) { - assert!(p.at(MOD_KW)); - p.bump(); - - if p.expect(IDENT) && !p.eat(SEMI) { - if p.expect(L_CURLY) { - mod_contents(p, true); - p.expect(R_CURLY); - } - } -} - -fn abi(p: &mut Parser) { - assert!(p.at(EXTERN_KW)); - let abi = p.start(); - p.bump(); - match p.current() { - STRING | RAW_STRING => p.bump(), - _ => (), - } - abi.complete(p, ABI); -} - fn fn_item(p: &mut Parser) { assert!(p.at(FN_KW)); p.bump(); @@ -248,3 +228,47 @@ fn fn_item(p: &mut Parser) { p.expect(R_PAREN); } } + +// test type_item +// type Foo = Bar; +fn type_item(p: &mut Parser) { + assert!(p.at(TYPE_KW)); + p.bump(); + + p.expect(IDENT); + + // test type_item_type_params + // type Result = (); + type_params::list(p); + + // test type_item_where_clause + // type Foo where Foo: Copy = (); + type_params::where_clause(p); + + p.expect(EQ); + types::type_ref(p); + p.expect(SEMI); +} + +fn mod_item(p: &mut Parser) { + assert!(p.at(MOD_KW)); + p.bump(); + + if p.expect(IDENT) && !p.eat(SEMI) { + if p.expect(L_CURLY) { + mod_contents(p, true); + p.expect(R_CURLY); + } + } +} + +fn abi(p: &mut Parser) { + assert!(p.at(EXTERN_KW)); + let abi = p.start(); + p.bump(); + match p.current() { + STRING | RAW_STRING => p.bump(), + _ => (), + } + abi.complete(p, ABI); +} -- cgit v1.2.3