From 555c4ae37560493fd901aad41951ad1664043459 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 11 Feb 2018 11:37:08 +0300 Subject: G: slice & array types --- src/parser/grammar/types.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/parser') diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index ceadf5f96..4eb333b54 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -5,6 +5,7 @@ pub(super) fn type_(p: &mut Parser) { L_PAREN => paren_or_tuple_type(p), EXCL => never_type(p), STAR => pointer_type(p), + L_BRACK => array_or_slice_type(p), IDENT => path_type(p), _ => { p.error("expected type"); @@ -82,6 +83,38 @@ fn pointer_type(p: &mut Parser) { m.complete(p, POINTER_TYPE); } +fn array_or_slice_type(p: &mut Parser) { + assert!(p.at(L_BRACK)); + let m = p.start(); + p.bump(); + + type_(p); + let kind = match p.current() { + // test slice_type + // type T = [()]; + R_BRACK => { + p.bump(); + SLICE_TYPE + }, + + // test array_type + // type T = [(); 92]; + SEMI => { + p.bump(); + expressions::expr(p); + p.expect(R_BRACK); + ARRAY_TYPE + } + // test array_type_missing_semi + // type T = [() 92]; + _ => { + p.error("expected `;` or `]`"); + SLICE_TYPE + } + }; + m.complete(p, kind); +} + fn path_type(p: &mut Parser) { assert!(p.at(IDENT)); let m = p.start(); -- cgit v1.2.3