From 1af8eb9c08f974a1b3beecfebadeb03144ef337d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 22:41:29 +0300 Subject: impl trait type --- src/grammar.ron | 1 + src/parser/grammar/type_params.rs | 5 +++++ src/parser/grammar/types.rs | 11 +++++++++++ src/syntax_kinds/generated.rs | 2 ++ 4 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/grammar.ron b/src/grammar.ron index aa01cb205..df7b4083b 100644 --- a/src/grammar.ron +++ b/src/grammar.ron @@ -118,6 +118,7 @@ Grammar( "PLACEHOLDER_TYPE", "FN_POINTER_TYPE", "FOR_TYPE", + "IMPL_TRAIT_TYPE", "REF_PAT", "BIND_PAT", diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index ccb44c0df..2affd47cc 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs @@ -57,6 +57,10 @@ pub(super) fn list(p: &mut Parser) { pub(super) fn bounds(p: &mut Parser) { assert!(p.at(COLON)); p.bump(); + bounds_without_colon(p); +} + +pub(super) fn bounds_without_colon(p: &mut Parser) { loop { let has_paren = p.eat(L_PAREN); p.eat(QUESTION); @@ -79,6 +83,7 @@ pub(super) fn bounds(p: &mut Parser) { } } + pub(super) fn where_clause(p: &mut Parser) { if p.at(WHERE_KW) { let m = p.start(); diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 014086521..31871ceec 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -10,6 +10,7 @@ pub(super) fn type_(p: &mut Parser) { UNDERSCORE => placeholder_type(p), FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), FOR_KW => for_type(p), + IMPL_KW => impl_trait_type(p), _ if paths::is_path_start(p) => path_type(p), _ => { p.error("expected type"); @@ -183,6 +184,16 @@ fn for_type(p: &mut Parser) { m.complete(p, FOR_TYPE); } +// test impl_trait_type +// type A = impl Iterator> + 'a; +fn impl_trait_type(p: &mut Parser) { + assert!(p.at(IMPL_KW)); + let m = p.start(); + p.bump(); + type_params::bounds_without_colon(p); + m.complete(p, IMPL_TRAIT_TYPE); +} + // test path_type // type A = Foo; // type B = ::Foo; diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index a37fdea0b..156d42db4 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs @@ -111,6 +111,7 @@ pub enum SyntaxKind { PLACEHOLDER_TYPE, FN_POINTER_TYPE, FOR_TYPE, + IMPL_TRAIT_TYPE, REF_PAT, BIND_PAT, PLACEHOLDER_PAT, @@ -271,6 +272,7 @@ impl SyntaxKind { PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" }, FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, + IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" }, REF_PAT => &SyntaxInfo { name: "REF_PAT" }, BIND_PAT => &SyntaxInfo { name: "BIND_PAT" }, PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, -- cgit v1.2.3