From c8910b0683dfc9ad88d440c22cef71c263837997 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 11 Feb 2018 23:32:49 +0300 Subject: [PATCH] G: for type --- grammar.ron | 1 + src/parser/grammar/types.rs | 12 +++++++++ src/syntax_kinds.rs | 2 ++ tests/data/parser/inline/0031_for_type.rs | 1 + tests/data/parser/inline/0031_for_type.txt | 29 ++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 tests/data/parser/inline/0031_for_type.rs create mode 100644 tests/data/parser/inline/0031_for_type.txt diff --git a/grammar.ron b/grammar.ron index d5ad595534..fbb3c384ab 100644 --- a/grammar.ron +++ b/grammar.ron @@ -111,6 +111,7 @@ Grammar( "REFERENCE_TYPE", "PLACEHOLDER_TYPE", "FN_POINTER_TYPE", + "FOR_TYPE", "EXTERN_BLOCK", "ENUM_VARIANT", diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index a4967a00a8..c25517a514 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -9,6 +9,7 @@ pub(super) fn type_(p: &mut Parser) { AMPERSAND => reference_type(p), UNDERSCORE => placeholder_type(p), FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), + FOR_KW => for_type(p), IDENT => path_type(p), _ => { p.error("expected type"); @@ -166,6 +167,17 @@ fn fn_pointer_type(p: &mut Parser) { m.complete(p, FN_POINTER_TYPE); } +// test for_type +// type A = for<'a> fn() -> (); +fn for_type(p: &mut Parser) { + assert!(p.at(FOR_KW)); + let m = p.start(); + p.bump(); + type_params::list(p); + type_(p); + m.complete(p, FOR_TYPE); +} + fn path_type(p: &mut Parser) { assert!(p.at(IDENT)); let m = p.start(); diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index db0f51bebb..537a80417e 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -109,6 +109,7 @@ pub enum SyntaxKind { REFERENCE_TYPE, PLACEHOLDER_TYPE, FN_POINTER_TYPE, + FOR_TYPE, EXTERN_BLOCK, ENUM_VARIANT, NAMED_FIELD, @@ -244,6 +245,7 @@ impl SyntaxKind { REFERENCE_TYPE => &SyntaxInfo { name: "REFERENCE_TYPE" }, PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" }, FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, + FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, diff --git a/tests/data/parser/inline/0031_for_type.rs b/tests/data/parser/inline/0031_for_type.rs new file mode 100644 index 0000000000..4d6a18c6bb --- /dev/null +++ b/tests/data/parser/inline/0031_for_type.rs @@ -0,0 +1 @@ +type A = for<'a> fn() -> (); diff --git a/tests/data/parser/inline/0031_for_type.txt b/tests/data/parser/inline/0031_for_type.txt new file mode 100644 index 0000000000..0211950bc6 --- /dev/null +++ b/tests/data/parser/inline/0031_for_type.txt @@ -0,0 +1,29 @@ +FILE@[0; 29) + TYPE_ITEM@[0; 29) + TYPE_KW@[0; 4) + NAME@[4; 7) + WHITESPACE@[4; 5) + IDENT@[5; 6) "A" + WHITESPACE@[6; 7) + EQ@[7; 8) + FOR_TYPE@[8; 27) + WHITESPACE@[8; 9) + FOR_KW@[9; 12) + TYPE_PARAM_LIST@[12; 17) + L_ANGLE@[12; 13) + LIFETIME_PARAM@[13; 15) + LIFETIME@[13; 15) "'a" + R_ANGLE@[15; 16) + WHITESPACE@[16; 17) + FN_POINTER_TYPE@[17; 27) + FN_KW@[17; 19) + L_PAREN@[19; 20) + R_PAREN@[20; 21) + WHITESPACE@[21; 22) + THIN_ARROW@[22; 24) + TUPLE_TYPE@[24; 27) + WHITESPACE@[24; 25) + L_PAREN@[25; 26) + R_PAREN@[26; 27) + SEMI@[27; 28) + WHITESPACE@[28; 29)