From 8ca02acb5a574c312dcb3842904b99b282d45883 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 28 Jan 2018 18:53:53 +0300 Subject: Generic params in structs --- src/parser/event_parser/grammar/items/mod.rs | 44 +++++++++++++++++++++++- src/parser/event_parser/grammar/items/structs.rs | 2 +- 2 files changed, 44 insertions(+), 2 deletions(-) (limited to 'src/parser/event_parser/grammar/items') diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index 867776415..f10fb230b 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs @@ -59,7 +59,49 @@ fn item(p: &mut Parser) { item.complete(p, item_kind); } -fn generic_parameters(_: &mut Parser) {} +fn type_param_list(p: &mut Parser) { + if !p.at(L_ANGLE) { + return; + } + let m = p.start(); + p.bump(); + + while !p.at(EOF) && !p.at(R_ANGLE) { + match p.current() { + LIFETIME => lifetime_param(p), + IDENT => type_param(p), + _ => p.err_and_bump("expected type parameter"), + } + if !p.at(R_ANGLE) && !p.expect(COMMA) { + break; + } + } + p.expect(R_ANGLE); + m.complete(p, TYPE_PARAM_LIST); + + fn lifetime_param(p: &mut Parser) { + assert!(p.at(LIFETIME)); + let m = p.start(); + p.bump(); + if p.eat(COLON) { + while p.at(LIFETIME) { + p.bump(); + if !p.eat(PLUS) { + break; + } + } + } + m.complete(p, LIFETIME_PARAM); + } + + fn type_param(p: &mut Parser) { + assert!(p.at(IDENT)); + let m = p.start(); + p.bump(); + m.complete(p, TYPE_PARAM); + //TODO: bounds + } +} fn where_clause(_: &mut Parser) {} diff --git a/src/parser/event_parser/grammar/items/structs.rs b/src/parser/event_parser/grammar/items/structs.rs index b31cf18df..0934f3d28 100644 --- a/src/parser/event_parser/grammar/items/structs.rs +++ b/src/parser/event_parser/grammar/items/structs.rs @@ -7,7 +7,7 @@ pub(super) fn struct_item(p: &mut Parser) { if !p.expect(IDENT) { return; } - generic_parameters(p); + type_param_list(p); match p.current() { WHERE_KW => { where_clause(p); -- cgit v1.2.3