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 +++++++++++++++++++++++++-------------- src/parser/grammar/type_params.rs | 3 ++ src/parser/grammar/types.rs | 11 +++++- 3 files changed, 65 insertions(+), 29 deletions(-) (limited to 'src/parser/grammar') 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); +} diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index 12c9a5362..73c3cf8b8 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs @@ -71,5 +71,8 @@ pub(super) fn list(p: &mut Parser) { pub(super) fn where_clause(p: &mut Parser) { if p.at(WHERE_KW) { p.bump(); + p.expect(IDENT); + p.expect(COLON); + p.expect(IDENT); } } diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 1a3d44a0a..c798edd08 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -1,5 +1,14 @@ use super::*; pub(super) fn type_ref(p: &mut Parser) { - p.expect(IDENT); + match p.current() { + IDENT => p.bump(), + L_PAREN => { + p.bump(); + p.expect(R_PAREN); + } + _ => { + p.error("expected type"); + } + } } -- cgit v1.2.3 From dd6e5371ebddeaeecb3d1e2d3d6c8b3c9050bb05 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 10 Feb 2018 12:53:07 +0300 Subject: G: where clause --- src/parser/grammar/type_params.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/parser/grammar') diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index 73c3cf8b8..8f62a471c 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs @@ -70,9 +70,11 @@ pub(super) fn list(p: &mut Parser) { pub(super) fn where_clause(p: &mut Parser) { if p.at(WHERE_KW) { + let m = p.start(); p.bump(); p.expect(IDENT); p.expect(COLON); p.expect(IDENT); + m.complete(p, WHERE_CLAUSE); } } -- cgit v1.2.3