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 ++ tests/data/parser/inline/0063_impl_trait_type.rs | 1 + tests/data/parser/inline/0063_impl_trait_type.txt | 39 +++++++++++++++++++++++ 6 files changed, 59 insertions(+) create mode 100644 tests/data/parser/inline/0063_impl_trait_type.rs create mode 100644 tests/data/parser/inline/0063_impl_trait_type.txt 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" }, diff --git a/tests/data/parser/inline/0063_impl_trait_type.rs b/tests/data/parser/inline/0063_impl_trait_type.rs new file mode 100644 index 000000000..54c5a7c46 --- /dev/null +++ b/tests/data/parser/inline/0063_impl_trait_type.rs @@ -0,0 +1 @@ +type A = impl Iterator> + 'a; diff --git a/tests/data/parser/inline/0063_impl_trait_type.txt b/tests/data/parser/inline/0063_impl_trait_type.txt new file mode 100644 index 000000000..1a7d8618f --- /dev/null +++ b/tests/data/parser/inline/0063_impl_trait_type.txt @@ -0,0 +1,39 @@ +FILE@[0; 43) + TYPE_ITEM@[0; 43) + TYPE_KW@[0; 4) + NAME@[4; 7) + WHITESPACE@[4; 5) + IDENT@[5; 6) "A" + WHITESPACE@[6; 7) + EQ@[7; 8) + IMPL_TRAIT_TYPE@[8; 41) + WHITESPACE@[8; 9) + IMPL_KW@[9; 13) + PATH@[13; 37) + PATH_SEGMENT@[13; 37) + NAME_REF@[13; 22) + WHITESPACE@[13; 14) + IDENT@[14; 22) "Iterator" + TYPE_ARG_LIST@[22; 37) + L_ANGLE@[22; 23) + ASSOC_TYPE_ARG@[23; 35) + NAME_REF@[23; 27) + IDENT@[23; 27) "Item" + EQ@[27; 28) + PATH_TYPE@[28; 35) + PATH@[28; 35) + PATH_SEGMENT@[28; 35) + NAME_REF@[28; 31) + IDENT@[28; 31) "Foo" + TYPE_ARG_LIST@[31; 35) + L_ANGLE@[31; 32) + LIFETIME_ARG@[32; 34) + LIFETIME@[32; 34) "'a" + R_ANGLE@[34; 35) + R_ANGLE@[35; 36) + WHITESPACE@[36; 37) + PLUS@[37; 38) + WHITESPACE@[38; 39) + LIFETIME@[39; 41) "'a" + SEMI@[41; 42) + WHITESPACE@[42; 43) -- cgit v1.2.3