diff options
-rw-r--r-- | src/parser/grammar/items/mod.rs | 11 | ||||
-rw-r--r-- | src/parser/grammar/items/traits.rs | 7 | ||||
-rw-r--r-- | src/parser/grammar/type_params.rs | 52 | ||||
-rw-r--r-- | tests/data/parser/inline/0055_self_param.txt | 77 | ||||
-rw-r--r-- | tests/data/parser/inline/0056_trait_item.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0056_trait_item.txt | 36 | ||||
-rw-r--r-- | tests/data/parser/inline/0057_auto_trait.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0057_auto_trait.txt | 12 |
8 files changed, 174 insertions, 23 deletions
diff --git a/src/parser/grammar/items/mod.rs b/src/parser/grammar/items/mod.rs index 12bcf7924..037cdca53 100644 --- a/src/parser/grammar/items/mod.rs +++ b/src/parser/grammar/items/mod.rs | |||
@@ -149,6 +149,17 @@ fn item(p: &mut Parser) { | |||
149 | } | 149 | } |
150 | } | 150 | } |
151 | } | 151 | } |
152 | TRAIT_KW => { | ||
153 | traits::trait_item(p); | ||
154 | TRAIT_ITEM | ||
155 | } | ||
156 | // test auto_trait | ||
157 | // auto trait T {} | ||
158 | IDENT if p.at_contextual_kw("auto") && la == TRAIT_KW => { | ||
159 | p.bump_remap(AUTO_KW); | ||
160 | traits::trait_item(p); | ||
161 | TRAIT_ITEM | ||
162 | } | ||
152 | IMPL_KW => { | 163 | IMPL_KW => { |
153 | traits::impl_item(p); | 164 | traits::impl_item(p); |
154 | IMPL_ITEM | 165 | IMPL_ITEM |
diff --git a/src/parser/grammar/items/traits.rs b/src/parser/grammar/items/traits.rs index 7d657ced0..60158fe41 100644 --- a/src/parser/grammar/items/traits.rs +++ b/src/parser/grammar/items/traits.rs | |||
@@ -1,9 +1,16 @@ | |||
1 | use super::*; | 1 | use super::*; |
2 | 2 | ||
3 | // test trait_item | ||
4 | // trait T<U>: Hash + Clone where U: Copy {} | ||
3 | pub(super) fn trait_item(p: &mut Parser) { | 5 | pub(super) fn trait_item(p: &mut Parser) { |
4 | assert!(p.at(TRAIT_KW)); | 6 | assert!(p.at(TRAIT_KW)); |
5 | p.bump(); | 7 | p.bump(); |
6 | name(p); | 8 | name(p); |
9 | type_params::list(p); | ||
10 | if p.at(COLON) { | ||
11 | type_params::bounds(p); | ||
12 | } | ||
13 | type_params::where_clause(p); | ||
7 | p.expect(L_CURLY); | 14 | p.expect(L_CURLY); |
8 | p.expect(R_CURLY); | 15 | p.expect(R_CURLY); |
9 | } | 16 | } |
diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index ba0d4bfe8..3648ab5f3 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs | |||
@@ -39,29 +39,8 @@ pub(super) fn list(p: &mut Parser) { | |||
39 | assert!(p.at(IDENT)); | 39 | assert!(p.at(IDENT)); |
40 | let m = p.start(); | 40 | let m = p.start(); |
41 | p.bump(); | 41 | p.bump(); |
42 | if p.eat(COLON) { | 42 | if p.at(COLON) { |
43 | // test type_param_bounds | 43 | bounds(p); |
44 | // struct S<T: 'a + ?Sized + (Copy)>; | ||
45 | loop { | ||
46 | let has_paren = p.eat(L_PAREN); | ||
47 | p.eat(QUESTION); | ||
48 | if p.at(FOR_KW) { | ||
49 | //TODO | ||
50 | } | ||
51 | if p.at(LIFETIME) { | ||
52 | p.bump(); | ||
53 | } else if paths::is_path_start(p) { | ||
54 | paths::type_path(p); | ||
55 | } else { | ||
56 | break; | ||
57 | } | ||
58 | if has_paren { | ||
59 | p.expect(R_PAREN); | ||
60 | } | ||
61 | if !p.eat(PLUS) { | ||
62 | break; | ||
63 | } | ||
64 | } | ||
65 | } | 44 | } |
66 | // test type_param_default | 45 | // test type_param_default |
67 | // struct S<T = i32>; | 46 | // struct S<T = i32>; |
@@ -73,6 +52,33 @@ pub(super) fn list(p: &mut Parser) { | |||
73 | } | 52 | } |
74 | } | 53 | } |
75 | 54 | ||
55 | // test type_param_bounds | ||
56 | // struct S<T: 'a + ?Sized + (Copy)>; | ||
57 | pub(super) fn bounds(p: &mut Parser) { | ||
58 | assert!(p.at(COLON)); | ||
59 | p.bump(); | ||
60 | loop { | ||
61 | let has_paren = p.eat(L_PAREN); | ||
62 | p.eat(QUESTION); | ||
63 | if p.at(FOR_KW) { | ||
64 | //TODO | ||
65 | } | ||
66 | if p.at(LIFETIME) { | ||
67 | p.bump(); | ||
68 | } else if paths::is_path_start(p) { | ||
69 | paths::type_path(p); | ||
70 | } else { | ||
71 | break; | ||
72 | } | ||
73 | if has_paren { | ||
74 | p.expect(R_PAREN); | ||
75 | } | ||
76 | if !p.eat(PLUS) { | ||
77 | break; | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | |||
76 | pub(super) fn where_clause(p: &mut Parser) { | 82 | pub(super) fn where_clause(p: &mut Parser) { |
77 | if p.at(WHERE_KW) { | 83 | if p.at(WHERE_KW) { |
78 | let m = p.start(); | 84 | let m = p.start(); |
diff --git a/tests/data/parser/inline/0055_self_param.txt b/tests/data/parser/inline/0055_self_param.txt new file mode 100644 index 000000000..70aa81207 --- /dev/null +++ b/tests/data/parser/inline/0055_self_param.txt | |||
@@ -0,0 +1,77 @@ | |||
1 | FILE@[0; 80) | ||
2 | IMPL_ITEM@[0; 80) | ||
3 | IMPL_KW@[0; 4) | ||
4 | PATH_TYPE@[4; 7) | ||
5 | PATH@[4; 7) | ||
6 | PATH_SEGMENT@[4; 7) | ||
7 | NAME_REF@[4; 7) | ||
8 | WHITESPACE@[4; 5) | ||
9 | IDENT@[5; 6) "S" | ||
10 | WHITESPACE@[6; 7) | ||
11 | L_CURLY@[7; 8) | ||
12 | FN_ITEM@[8; 31) | ||
13 | WHITESPACE@[8; 13) | ||
14 | FN_KW@[13; 15) | ||
15 | NAME@[15; 17) | ||
16 | WHITESPACE@[15; 16) | ||
17 | IDENT@[16; 17) "a" | ||
18 | PARAM_LIST@[17; 24) | ||
19 | L_PAREN@[17; 18) | ||
20 | SELF_PARAM@[18; 22) | ||
21 | SELF_KW@[18; 22) | ||
22 | R_PAREN@[22; 23) | ||
23 | WHITESPACE@[23; 24) | ||
24 | BLOCK@[24; 31) | ||
25 | L_CURLY@[24; 25) | ||
26 | R_CURLY@[25; 26) | ||
27 | WHITESPACE@[26; 31) | ||
28 | FN_ITEM@[31; 51) | ||
29 | FN_KW@[31; 33) | ||
30 | NAME@[33; 35) | ||
31 | WHITESPACE@[33; 34) | ||
32 | IDENT@[34; 35) "b" | ||
33 | PARAM_LIST@[35; 44) | ||
34 | L_PAREN@[35; 36) | ||
35 | SELF_PARAM@[36; 41) | ||
36 | AMPERSAND@[36; 37) | ||
37 | SELF_KW@[37; 41) | ||
38 | COMMA@[41; 42) | ||
39 | R_PAREN@[42; 43) | ||
40 | WHITESPACE@[43; 44) | ||
41 | BLOCK@[44; 51) | ||
42 | L_CURLY@[44; 45) | ||
43 | R_CURLY@[45; 46) | ||
44 | WHITESPACE@[46; 51) | ||
45 | FN_ITEM@[51; 78) | ||
46 | FN_KW@[51; 53) | ||
47 | NAME@[53; 55) | ||
48 | WHITESPACE@[53; 54) | ||
49 | IDENT@[54; 55) "c" | ||
50 | PARAM_LIST@[55; 75) | ||
51 | L_PAREN@[55; 56) | ||
52 | SELF_PARAM@[56; 65) | ||
53 | AMPERSAND@[56; 57) | ||
54 | MUT_KW@[57; 60) | ||
55 | WHITESPACE@[60; 61) | ||
56 | SELF_KW@[61; 65) | ||
57 | COMMA@[65; 66) | ||
58 | VALUE_PARAMETER@[66; 73) | ||
59 | BIND_PAT@[66; 68) | ||
60 | NAME@[66; 68) | ||
61 | WHITESPACE@[66; 67) | ||
62 | IDENT@[67; 68) "x" | ||
63 | COLON@[68; 69) | ||
64 | PATH_TYPE@[69; 73) | ||
65 | PATH@[69; 73) | ||
66 | PATH_SEGMENT@[69; 73) | ||
67 | NAME_REF@[69; 73) | ||
68 | WHITESPACE@[69; 70) | ||
69 | IDENT@[70; 73) "i32" | ||
70 | R_PAREN@[73; 74) | ||
71 | WHITESPACE@[74; 75) | ||
72 | BLOCK@[75; 78) | ||
73 | L_CURLY@[75; 76) | ||
74 | R_CURLY@[76; 77) | ||
75 | WHITESPACE@[77; 78) | ||
76 | R_CURLY@[78; 79) | ||
77 | WHITESPACE@[79; 80) | ||
diff --git a/tests/data/parser/inline/0056_trait_item.rs b/tests/data/parser/inline/0056_trait_item.rs new file mode 100644 index 000000000..4385afca9 --- /dev/null +++ b/tests/data/parser/inline/0056_trait_item.rs | |||
@@ -0,0 +1 @@ | |||
trait T<U>: Hash + Clone where U: Copy {} | |||
diff --git a/tests/data/parser/inline/0056_trait_item.txt b/tests/data/parser/inline/0056_trait_item.txt new file mode 100644 index 000000000..87efc78e9 --- /dev/null +++ b/tests/data/parser/inline/0056_trait_item.txt | |||
@@ -0,0 +1,36 @@ | |||
1 | FILE@[0; 42) | ||
2 | TRAIT_ITEM@[0; 42) | ||
3 | TRAIT_KW@[0; 5) | ||
4 | NAME@[5; 7) | ||
5 | WHITESPACE@[5; 6) | ||
6 | IDENT@[6; 7) "T" | ||
7 | TYPE_PARAM_LIST@[7; 10) | ||
8 | L_ANGLE@[7; 8) | ||
9 | TYPE_PARAM@[8; 9) | ||
10 | IDENT@[8; 9) "U" | ||
11 | R_ANGLE@[9; 10) | ||
12 | COLON@[10; 11) | ||
13 | PATH@[11; 17) | ||
14 | PATH_SEGMENT@[11; 17) | ||
15 | NAME_REF@[11; 17) | ||
16 | WHITESPACE@[11; 12) | ||
17 | IDENT@[12; 16) "Hash" | ||
18 | WHITESPACE@[16; 17) | ||
19 | PLUS@[17; 18) | ||
20 | PATH@[18; 25) | ||
21 | PATH_SEGMENT@[18; 25) | ||
22 | NAME_REF@[18; 25) | ||
23 | WHITESPACE@[18; 19) | ||
24 | IDENT@[19; 24) "Clone" | ||
25 | WHITESPACE@[24; 25) | ||
26 | WHERE_CLAUSE@[25; 39) | ||
27 | WHERE_KW@[25; 30) | ||
28 | WHITESPACE@[30; 31) | ||
29 | IDENT@[31; 32) "U" | ||
30 | COLON@[32; 33) | ||
31 | WHITESPACE@[33; 34) | ||
32 | IDENT@[34; 38) "Copy" | ||
33 | WHITESPACE@[38; 39) | ||
34 | L_CURLY@[39; 40) | ||
35 | R_CURLY@[40; 41) | ||
36 | WHITESPACE@[41; 42) | ||
diff --git a/tests/data/parser/inline/0057_auto_trait.rs b/tests/data/parser/inline/0057_auto_trait.rs new file mode 100644 index 000000000..72adf6035 --- /dev/null +++ b/tests/data/parser/inline/0057_auto_trait.rs | |||
@@ -0,0 +1 @@ | |||
auto trait T {} | |||
diff --git a/tests/data/parser/inline/0057_auto_trait.txt b/tests/data/parser/inline/0057_auto_trait.txt new file mode 100644 index 000000000..9d098f10b --- /dev/null +++ b/tests/data/parser/inline/0057_auto_trait.txt | |||
@@ -0,0 +1,12 @@ | |||
1 | FILE@[0; 16) | ||
2 | TRAIT_ITEM@[0; 16) | ||
3 | AUTO_KW@[0; 4) | ||
4 | WHITESPACE@[4; 5) | ||
5 | TRAIT_KW@[5; 10) | ||
6 | NAME@[10; 13) | ||
7 | WHITESPACE@[10; 11) | ||
8 | IDENT@[11; 12) "T" | ||
9 | WHITESPACE@[12; 13) | ||
10 | L_CURLY@[13; 14) | ||
11 | R_CURLY@[14; 15) | ||
12 | WHITESPACE@[15; 16) | ||