From ceb94ece2aa6a1b54063c582663fff4c1937d989 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 11 Feb 2018 11:19:54 +0300 Subject: G: pointer types --- src/parser/grammar/types.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/parser') diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 2ae583bd1..ceadf5f96 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs @@ -4,6 +4,7 @@ pub(super) fn type_(p: &mut Parser) { match p.current() { L_PAREN => paren_or_tuple_type(p), EXCL => never_type(p), + STAR => pointer_type(p), IDENT => path_type(p), _ => { p.error("expected type"); @@ -11,6 +12,10 @@ pub(super) fn type_(p: &mut Parser) { } } +fn type_no_plus(p: &mut Parser) { + type_(p); +} + fn paren_or_tuple_type(p: &mut Parser) { assert!(p.at(L_PAREN)); let m = p.start(); @@ -53,6 +58,30 @@ fn never_type(p: &mut Parser) { m.complete(p, NEVER_TYPE); } +fn pointer_type(p: &mut Parser) { + assert!(p.at(STAR)); + let m = p.start(); + p.bump(); + + match p.current() { + // test pointer_type_mut + // type M = *mut (); + // type C = *mut (); + MUT_KW | CONST_KW => p.bump(), + _ => { + // test pointer_type_no_mutability + // type T = *(); + p.error( + "expected mut or const in raw pointer type \ + (use `*mut T` or `*const T` as appropriate)" + ); + } + }; + + type_no_plus(p); + m.complete(p, POINTER_TYPE); +} + fn path_type(p: &mut Parser) { assert!(p.at(IDENT)); let m = p.start(); -- cgit v1.2.3