From eb4c05d572ff0c4e92452232d6591d7a2796e785 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 11 Feb 2018 11:54:09 +0300 Subject: G: reference types --- grammar.ron | 1 + src/parser/grammar/types.rs | 15 +++++++ src/syntax_kinds.rs | 2 + tests/data/parser/inline/0026_reference_type;.rs | 3 ++ tests/data/parser/inline/0026_reference_type;.txt | 50 +++++++++++++++++++++++ 5 files changed, 71 insertions(+) create mode 100644 tests/data/parser/inline/0026_reference_type;.rs create mode 100644 tests/data/parser/inline/0026_reference_type;.txt diff --git a/grammar.ron b/grammar.ron index bc7dd7c55..0905c282a 100644 --- a/grammar.ron +++ b/grammar.ron @@ -108,6 +108,7 @@ Grammar( "POINTER_TYPE", "ARRAY_TYPE", "SLICE_TYPE", + "REFERENCE_TYPE", "EXTERN_BLOCK", "ENUM_VARIANT", diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 4eb333b54..003341db5 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -6,6 +6,7 @@ pub(super) fn type_(p: &mut Parser) { EXCL => never_type(p), STAR => pointer_type(p), L_BRACK => array_or_slice_type(p), + AMPERSAND => reference_type(p), IDENT => path_type(p), _ => { p.error("expected type"); @@ -115,6 +116,20 @@ fn array_or_slice_type(p: &mut Parser) { m.complete(p, kind); } +// test reference_type; +// type A = &(); +// type B = &'static (); +// type C = &mut (); +fn reference_type(p: &mut Parser) { + assert!(p.at(AMPERSAND)); + let m = p.start(); + p.bump(); + p.eat(LIFETIME); + p.eat(MUT_KW); + type_no_plus(p); + m.complete(p, REFERENCE_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 54200f2d1..597550a32 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs @@ -106,6 +106,7 @@ pub enum SyntaxKind { POINTER_TYPE, ARRAY_TYPE, SLICE_TYPE, + REFERENCE_TYPE, EXTERN_BLOCK, ENUM_VARIANT, NAMED_FIELD, @@ -238,6 +239,7 @@ impl SyntaxKind { POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, ARRAY_TYPE => &SyntaxInfo { name: "ARRAY_TYPE" }, SLICE_TYPE => &SyntaxInfo { name: "SLICE_TYPE" }, + REFERENCE_TYPE => &SyntaxInfo { name: "REFERENCE_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/0026_reference_type;.rs b/tests/data/parser/inline/0026_reference_type;.rs new file mode 100644 index 000000000..3ac0badab --- /dev/null +++ b/tests/data/parser/inline/0026_reference_type;.rs @@ -0,0 +1,3 @@ +type A = &(); +type B = &'static (); +type C = &mut (); diff --git a/tests/data/parser/inline/0026_reference_type;.txt b/tests/data/parser/inline/0026_reference_type;.txt new file mode 100644 index 000000000..665c021e1 --- /dev/null +++ b/tests/data/parser/inline/0026_reference_type;.txt @@ -0,0 +1,50 @@ +FILE@[0; 54) + TYPE_ITEM@[0; 14) + TYPE_KW@[0; 4) + NAME@[4; 7) + WHITESPACE@[4; 5) + IDENT@[5; 6) "A" + WHITESPACE@[6; 7) + EQ@[7; 8) + REFERENCE_TYPE@[8; 12) + WHITESPACE@[8; 9) + AMPERSAND@[9; 10) + TUPLE_TYPE@[10; 12) + L_PAREN@[10; 11) + R_PAREN@[11; 12) + SEMI@[12; 13) + WHITESPACE@[13; 14) + TYPE_ITEM@[14; 36) + TYPE_KW@[14; 18) + NAME@[18; 21) + WHITESPACE@[18; 19) + IDENT@[19; 20) "B" + WHITESPACE@[20; 21) + EQ@[21; 22) + REFERENCE_TYPE@[22; 34) + WHITESPACE@[22; 23) + AMPERSAND@[23; 24) + LIFETIME@[24; 31) "'static" + TUPLE_TYPE@[31; 34) + WHITESPACE@[31; 32) + L_PAREN@[32; 33) + R_PAREN@[33; 34) + SEMI@[34; 35) + WHITESPACE@[35; 36) + TYPE_ITEM@[36; 54) + TYPE_KW@[36; 40) + NAME@[40; 43) + WHITESPACE@[40; 41) + IDENT@[41; 42) "C" + WHITESPACE@[42; 43) + EQ@[43; 44) + REFERENCE_TYPE@[44; 52) + WHITESPACE@[44; 45) + AMPERSAND@[45; 46) + MUT_KW@[46; 49) + TUPLE_TYPE@[49; 52) + WHITESPACE@[49; 50) + L_PAREN@[50; 51) + R_PAREN@[51; 52) + SEMI@[52; 53) + WHITESPACE@[53; 54) -- cgit v1.2.3