From 197a2e6fefd45627920cfb9bbca24b446e5a7c89 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jan 2018 22:53:19 +0300 Subject: G: type_parameter_list --- src/parser/event_parser/grammar/items/mod.rs | 26 +++++++++++++++++++++++++- src/parser/event_parser/grammar/paths.rs | 13 +++++++++++-- src/syntax_kinds.rs | 15 +++++++++++++++ 3 files changed, 51 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/parser/event_parser/grammar/items/mod.rs b/src/parser/event_parser/grammar/items/mod.rs index 0a50fffc1..4d8783735 100644 --- a/src/parser/event_parser/grammar/items/mod.rs +++ b/src/parser/event_parser/grammar/items/mod.rs @@ -103,8 +103,32 @@ fn type_param_list(p: &mut Parser) { assert!(p.at(IDENT)); let m = p.start(); p.bump(); + if p.eat(COLON) { + loop { + let has_paren = p.eat(L_PAREN); + p.eat(QUESTION); + if p.at(FOR_KW) { + //TODO + } + if p.at(LIFETIME) { + p.bump(); + } else if paths::is_path_start(p) { + paths::type_path(p); + } else { + break; + } + if has_paren { + p.expect(R_PAREN); + } + if !p.eat(PLUS) { + break; + } + } + } + if p.at(EQ) { + types::type_ref(p) + } m.complete(p, TYPE_PARAM); - //TODO: bounds } } diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index a254ab05e..bf3c8aedd 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs @@ -1,10 +1,18 @@ use super::*; -pub(crate) fn is_path_start(p: &Parser) -> bool { +pub(super) fn is_path_start(p: &Parser) -> bool { AnyOf(&[IDENT, SELF_KW, SUPER_KW, COLONCOLON]).is_ahead(p) } -pub(crate) fn use_path(p: &mut Parser) { +pub(super) fn use_path(p: &mut Parser) { + path(p) +} + +pub(super) fn type_path(p: &mut Parser) { + path(p) +} + +fn path(p: &mut Parser) { if !is_path_start(p) { return; } @@ -24,6 +32,7 @@ pub(crate) fn use_path(p: &mut Parser) { } } + fn path_segment(p: &mut Parser, first: bool) { let segment = p.start(); if first { diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 519326f48..cd4c753a9 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -23,6 +23,11 @@ pub enum SyntaxKind { SUPER_KW, IN_KW, WHERE_KW, + FOR_KW, + LOOP_KW, + WHILE_KW, + IF_KW, + MATCH_KW, ERROR, IDENT, UNDERSCORE, @@ -125,6 +130,11 @@ impl SyntaxKind { SUPER_KW => &SyntaxInfo { name: "SUPER_KW" }, IN_KW => &SyntaxInfo { name: "IN_KW" }, WHERE_KW => &SyntaxInfo { name: "WHERE_KW" }, + FOR_KW => &SyntaxInfo { name: "FOR_KW" }, + LOOP_KW => &SyntaxInfo { name: "LOOP_KW" }, + WHILE_KW => &SyntaxInfo { name: "WHILE_KW" }, + IF_KW => &SyntaxInfo { name: "IF_KW" }, + MATCH_KW => &SyntaxInfo { name: "MATCH_KW" }, ERROR => &SyntaxInfo { name: "ERROR" }, IDENT => &SyntaxInfo { name: "IDENT" }, UNDERSCORE => &SyntaxInfo { name: "UNDERSCORE" }, @@ -223,6 +233,11 @@ pub(crate) fn ident_to_keyword(ident: &str) -> Option { "super" => Some(SUPER_KW), "in" => Some(IN_KW), "where" => Some(WHERE_KW), + "for" => Some(FOR_KW), + "loop" => Some(LOOP_KW), + "while" => Some(WHILE_KW), + "if" => Some(IF_KW), + "match" => Some(MATCH_KW), _ => None, } } -- cgit v1.2.3 From 7a02097b717c6f7055a92c52dca65c374b06f057 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jan 2018 22:56:13 +0300 Subject: Formatting --- src/parser/event_parser/grammar/paths.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/parser/event_parser/grammar/paths.rs b/src/parser/event_parser/grammar/paths.rs index bf3c8aedd..4c0d2c8b4 100644 --- a/src/parser/event_parser/grammar/paths.rs +++ b/src/parser/event_parser/grammar/paths.rs @@ -32,7 +32,6 @@ fn path(p: &mut Parser) { } } - fn path_segment(p: &mut Parser, first: bool) { let segment = p.start(); if first { -- cgit v1.2.3