aboutsummaryrefslogtreecommitdiff
path: root/src/parser
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-11 08:19:54 +0000
committerAleksey Kladov <[email protected]>2018-02-11 08:19:54 +0000
commitceb94ece2aa6a1b54063c582663fff4c1937d989 (patch)
tree7095bf13e1465663f92db09b9a3e1207122645bd /src/parser
parent2389cf96dd07d8c94da349b10f6f2b750707dfd9 (diff)
G: pointer types
Diffstat (limited to 'src/parser')
-rw-r--r--src/parser/grammar/types.rs29
1 files changed, 29 insertions, 0 deletions
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) {
4 match p.current() { 4 match p.current() {
5 L_PAREN => paren_or_tuple_type(p), 5 L_PAREN => paren_or_tuple_type(p),
6 EXCL => never_type(p), 6 EXCL => never_type(p),
7 STAR => pointer_type(p),
7 IDENT => path_type(p), 8 IDENT => path_type(p),
8 _ => { 9 _ => {
9 p.error("expected type"); 10 p.error("expected type");
@@ -11,6 +12,10 @@ pub(super) fn type_(p: &mut Parser) {
11 } 12 }
12} 13}
13 14
15fn type_no_plus(p: &mut Parser) {
16 type_(p);
17}
18
14fn paren_or_tuple_type(p: &mut Parser) { 19fn paren_or_tuple_type(p: &mut Parser) {
15 assert!(p.at(L_PAREN)); 20 assert!(p.at(L_PAREN));
16 let m = p.start(); 21 let m = p.start();
@@ -53,6 +58,30 @@ fn never_type(p: &mut Parser) {
53 m.complete(p, NEVER_TYPE); 58 m.complete(p, NEVER_TYPE);
54} 59}
55 60
61fn pointer_type(p: &mut Parser) {
62 assert!(p.at(STAR));
63 let m = p.start();
64 p.bump();
65
66 match p.current() {
67 // test pointer_type_mut
68 // type M = *mut ();
69 // type C = *mut ();
70 MUT_KW | CONST_KW => p.bump(),
71 _ => {
72 // test pointer_type_no_mutability
73 // type T = *();
74 p.error(
75 "expected mut or const in raw pointer type \
76 (use `*mut T` or `*const T` as appropriate)"
77 );
78 }
79 };
80
81 type_no_plus(p);
82 m.complete(p, POINTER_TYPE);
83}
84
56fn path_type(p: &mut Parser) { 85fn path_type(p: &mut Parser) {
57 assert!(p.at(IDENT)); 86 assert!(p.at(IDENT));
58 let m = p.start(); 87 let m = p.start();