diff options
author | Aleksey Kladov <[email protected]> | 2018-02-11 08:19:54 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-02-11 08:19:54 +0000 |
commit | ceb94ece2aa6a1b54063c582663fff4c1937d989 (patch) | |
tree | 7095bf13e1465663f92db09b9a3e1207122645bd | |
parent | 2389cf96dd07d8c94da349b10f6f2b750707dfd9 (diff) |
G: pointer types
-rw-r--r-- | grammar.ron | 1 | ||||
-rw-r--r-- | src/parser/grammar/types.rs | 29 | ||||
-rw-r--r-- | src/syntax_kinds.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/inline/0021_pointer_type_no_mutability.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0021_pointer_type_no_mutability.txt | 17 | ||||
-rw-r--r-- | tests/data/parser/inline/0022_pointer_type_mut.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/inline/0022_pointer_type_mut.txt | 35 | ||||
-rw-r--r-- | tests/testutils/src/lib.rs | 15 |
8 files changed, 94 insertions, 8 deletions
diff --git a/grammar.ron b/grammar.ron index 41d48f7b2..b43b58f02 100644 --- a/grammar.ron +++ b/grammar.ron | |||
@@ -105,6 +105,7 @@ Grammar( | |||
105 | "TUPLE_TYPE", | 105 | "TUPLE_TYPE", |
106 | "NEVER_TYPE", | 106 | "NEVER_TYPE", |
107 | "PATH_TYPE", | 107 | "PATH_TYPE", |
108 | "POINTER_TYPE", | ||
108 | 109 | ||
109 | "EXTERN_BLOCK", | 110 | "EXTERN_BLOCK", |
110 | "ENUM_VARIANT", | 111 | "ENUM_VARIANT", |
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 | ||
15 | fn type_no_plus(p: &mut Parser) { | ||
16 | type_(p); | ||
17 | } | ||
18 | |||
14 | fn paren_or_tuple_type(p: &mut Parser) { | 19 | fn 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 | ||
61 | fn 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 | |||
56 | fn path_type(p: &mut Parser) { | 85 | fn 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(); |
diff --git a/src/syntax_kinds.rs b/src/syntax_kinds.rs index 630d3d2a5..181dcc63b 100644 --- a/src/syntax_kinds.rs +++ b/src/syntax_kinds.rs | |||
@@ -103,6 +103,7 @@ pub enum SyntaxKind { | |||
103 | TUPLE_TYPE, | 103 | TUPLE_TYPE, |
104 | NEVER_TYPE, | 104 | NEVER_TYPE, |
105 | PATH_TYPE, | 105 | PATH_TYPE, |
106 | POINTER_TYPE, | ||
106 | EXTERN_BLOCK, | 107 | EXTERN_BLOCK, |
107 | ENUM_VARIANT, | 108 | ENUM_VARIANT, |
108 | NAMED_FIELD, | 109 | NAMED_FIELD, |
@@ -232,6 +233,7 @@ impl SyntaxKind { | |||
232 | TUPLE_TYPE => &SyntaxInfo { name: "TUPLE_TYPE" }, | 233 | TUPLE_TYPE => &SyntaxInfo { name: "TUPLE_TYPE" }, |
233 | NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, | 234 | NEVER_TYPE => &SyntaxInfo { name: "NEVER_TYPE" }, |
234 | PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, | 235 | PATH_TYPE => &SyntaxInfo { name: "PATH_TYPE" }, |
236 | POINTER_TYPE => &SyntaxInfo { name: "POINTER_TYPE" }, | ||
235 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, | 237 | EXTERN_BLOCK => &SyntaxInfo { name: "EXTERN_BLOCK" }, |
236 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, | 238 | ENUM_VARIANT => &SyntaxInfo { name: "ENUM_VARIANT" }, |
237 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, | 239 | NAMED_FIELD => &SyntaxInfo { name: "NAMED_FIELD" }, |
diff --git a/tests/data/parser/inline/0021_pointer_type_no_mutability.rs b/tests/data/parser/inline/0021_pointer_type_no_mutability.rs new file mode 100644 index 000000000..fae705131 --- /dev/null +++ b/tests/data/parser/inline/0021_pointer_type_no_mutability.rs | |||
@@ -0,0 +1 @@ | |||
type T = *(); | |||
diff --git a/tests/data/parser/inline/0021_pointer_type_no_mutability.txt b/tests/data/parser/inline/0021_pointer_type_no_mutability.txt new file mode 100644 index 000000000..f7720a712 --- /dev/null +++ b/tests/data/parser/inline/0021_pointer_type_no_mutability.txt | |||
@@ -0,0 +1,17 @@ | |||
1 | FILE@[0; 14) | ||
2 | TYPE_ITEM@[0; 14) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 7) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 6) "T" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | POINTER_TYPE@[8; 12) | ||
10 | WHITESPACE@[8; 9) | ||
11 | STAR@[9; 10) | ||
12 | err: `expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)` | ||
13 | TUPLE_TYPE@[10; 12) | ||
14 | L_PAREN@[10; 11) | ||
15 | R_PAREN@[11; 12) | ||
16 | SEMI@[12; 13) | ||
17 | WHITESPACE@[13; 14) | ||
diff --git a/tests/data/parser/inline/0022_pointer_type_mut.rs b/tests/data/parser/inline/0022_pointer_type_mut.rs new file mode 100644 index 000000000..04b2bb9ba --- /dev/null +++ b/tests/data/parser/inline/0022_pointer_type_mut.rs | |||
@@ -0,0 +1,2 @@ | |||
1 | type M = *mut (); | ||
2 | type C = *mut (); | ||
diff --git a/tests/data/parser/inline/0022_pointer_type_mut.txt b/tests/data/parser/inline/0022_pointer_type_mut.txt new file mode 100644 index 000000000..c3ab2b887 --- /dev/null +++ b/tests/data/parser/inline/0022_pointer_type_mut.txt | |||
@@ -0,0 +1,35 @@ | |||
1 | FILE@[0; 36) | ||
2 | TYPE_ITEM@[0; 18) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 7) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 6) "M" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | POINTER_TYPE@[8; 16) | ||
10 | WHITESPACE@[8; 9) | ||
11 | STAR@[9; 10) | ||
12 | MUT_KW@[10; 13) | ||
13 | TUPLE_TYPE@[13; 16) | ||
14 | WHITESPACE@[13; 14) | ||
15 | L_PAREN@[14; 15) | ||
16 | R_PAREN@[15; 16) | ||
17 | SEMI@[16; 17) | ||
18 | WHITESPACE@[17; 18) | ||
19 | TYPE_ITEM@[18; 36) | ||
20 | TYPE_KW@[18; 22) | ||
21 | NAME@[22; 25) | ||
22 | WHITESPACE@[22; 23) | ||
23 | IDENT@[23; 24) "C" | ||
24 | WHITESPACE@[24; 25) | ||
25 | EQ@[25; 26) | ||
26 | POINTER_TYPE@[26; 34) | ||
27 | WHITESPACE@[26; 27) | ||
28 | STAR@[27; 28) | ||
29 | MUT_KW@[28; 31) | ||
30 | TUPLE_TYPE@[31; 34) | ||
31 | WHITESPACE@[31; 32) | ||
32 | L_PAREN@[32; 33) | ||
33 | R_PAREN@[33; 34) | ||
34 | SEMI@[34; 35) | ||
35 | WHITESPACE@[35; 36) | ||
diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs index b50e70849..ae1dea810 100644 --- a/tests/testutils/src/lib.rs +++ b/tests/testutils/src/lib.rs | |||
@@ -26,21 +26,20 @@ where | |||
26 | F: Fn(&str) -> String, | 26 | F: Fn(&str) -> String, |
27 | { | 27 | { |
28 | for path in collect_tests(paths) { | 28 | for path in collect_tests(paths) { |
29 | let actual = { | 29 | let input_code = read_text(&path); |
30 | let text = read_text(&path); | 30 | let parse_tree = f(&input_code); |
31 | f(&text) | ||
32 | }; | ||
33 | let path = path.with_extension("txt"); | 31 | let path = path.with_extension("txt"); |
34 | if !path.exists() { | 32 | if !path.exists() { |
35 | println!("\nfile: {}", path.display()); | 33 | println!("\nfile: {}", path.display()); |
36 | println!("No .txt file with expected result, creating..."); | 34 | println!("No .txt file with expected result, creating...\n"); |
37 | file::put_text(&path, actual).unwrap(); | 35 | println!("{}\n{}", input_code, parse_tree); |
36 | file::put_text(&path, parse_tree).unwrap(); | ||
38 | panic!("No expected result") | 37 | panic!("No expected result") |
39 | } | 38 | } |
40 | let expected = read_text(&path); | 39 | let expected = read_text(&path); |
41 | let expected = expected.as_str(); | 40 | let expected = expected.as_str(); |
42 | let actual = actual.as_str(); | 41 | let parse_tree = parse_tree.as_str(); |
43 | assert_equal_text(expected, actual, &path); | 42 | assert_equal_text(expected, parse_tree, &path); |
44 | } | 43 | } |
45 | } | 44 | } |
46 | 45 | ||