diff options
author | Aleksey Kladov <[email protected]> | 2018-08-07 22:53:03 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-07 22:53:03 +0100 |
commit | 64a65a4ff40e0c9b6d9453af79bba013afde2ffa (patch) | |
tree | 9b8b488b35fae3f5497f86d67c18ed5fd63d5c7f | |
parent | 2fb854ccdae6f1f12b60441e5c3b283bdc81fb0a (diff) |
trait items
-rw-r--r-- | src/grammar/items/consts.rs | 5 | ||||
-rw-r--r-- | src/grammar/items/mod.rs | 15 | ||||
-rw-r--r-- | src/grammar/items/traits.rs | 10 | ||||
-rw-r--r-- | tests/data/parser/inline/0090_trait_item_items.rs | 6 | ||||
-rw-r--r-- | tests/data/parser/inline/0090_trait_item_items.txt | 67 | ||||
-rw-r--r-- | tests/data/parser/inline/0091_fn_decl.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0091_fn_decl.txt | 21 |
7 files changed, 120 insertions, 5 deletions
diff --git a/src/grammar/items/consts.rs b/src/grammar/items/consts.rs index ca26a7814..b11949b49 100644 --- a/src/grammar/items/consts.rs +++ b/src/grammar/items/consts.rs | |||
@@ -14,7 +14,8 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) { | |||
14 | p.eat(MUT_KW); // TODO: validator to forbid const mut | 14 | p.eat(MUT_KW); // TODO: validator to forbid const mut |
15 | name(p); | 15 | name(p); |
16 | types::ascription(p); | 16 | types::ascription(p); |
17 | p.expect(EQ); | 17 | if p.eat(EQ) { |
18 | expressions::expr(p); | 18 | expressions::expr(p); |
19 | } | ||
19 | p.expect(SEMI); | 20 | p.expect(SEMI); |
20 | } | 21 | } |
diff --git a/src/grammar/items/mod.rs b/src/grammar/items/mod.rs index 83f1833b5..824f1296c 100644 --- a/src/grammar/items/mod.rs +++ b/src/grammar/items/mod.rs | |||
@@ -240,7 +240,11 @@ fn fn_item(p: &mut Parser) { | |||
240 | // fn foo<T>() where T: Copy {} | 240 | // fn foo<T>() where T: Copy {} |
241 | type_params::where_clause(p); | 241 | type_params::where_clause(p); |
242 | 242 | ||
243 | expressions::block(p); | 243 | // test fn_decl |
244 | // trait T { fn foo(); } | ||
245 | if !p.eat(SEMI) { | ||
246 | expressions::block(p); | ||
247 | } | ||
244 | } | 248 | } |
245 | 249 | ||
246 | // test type_item | 250 | // test type_item |
@@ -255,12 +259,17 @@ fn type_item(p: &mut Parser) { | |||
255 | // type Result<T> = (); | 259 | // type Result<T> = (); |
256 | type_params::type_param_list(p); | 260 | type_params::type_param_list(p); |
257 | 261 | ||
262 | if p.at(COLON) { | ||
263 | type_params::bounds(p); | ||
264 | } | ||
265 | |||
258 | // test type_item_where_clause | 266 | // test type_item_where_clause |
259 | // type Foo where Foo: Copy = (); | 267 | // type Foo where Foo: Copy = (); |
260 | type_params::where_clause(p); | 268 | type_params::where_clause(p); |
261 | 269 | ||
262 | p.expect(EQ); | 270 | if p.eat(EQ) { |
263 | types::type_(p); | 271 | types::type_(p); |
272 | } | ||
264 | p.expect(SEMI); | 273 | p.expect(SEMI); |
265 | } | 274 | } |
266 | 275 | ||
diff --git a/src/grammar/items/traits.rs b/src/grammar/items/traits.rs index 7c0935371..0b9fb2b0b 100644 --- a/src/grammar/items/traits.rs +++ b/src/grammar/items/traits.rs | |||
@@ -12,6 +12,16 @@ pub(super) fn trait_item(p: &mut Parser) { | |||
12 | } | 12 | } |
13 | type_params::where_clause(p); | 13 | type_params::where_clause(p); |
14 | p.expect(L_CURLY); | 14 | p.expect(L_CURLY); |
15 | // test trait_item_items | ||
16 | // impl F { | ||
17 | // type A: Clone; | ||
18 | // const B: i32; | ||
19 | // fn foo() {} | ||
20 | // fn bar(&self); | ||
21 | // } | ||
22 | while !p.at(EOF) && !p.at(R_CURLY) { | ||
23 | item_or_macro(p, true); | ||
24 | } | ||
15 | p.expect(R_CURLY); | 25 | p.expect(R_CURLY); |
16 | } | 26 | } |
17 | 27 | ||
diff --git a/tests/data/parser/inline/0090_trait_item_items.rs b/tests/data/parser/inline/0090_trait_item_items.rs new file mode 100644 index 000000000..a5ec3239f --- /dev/null +++ b/tests/data/parser/inline/0090_trait_item_items.rs | |||
@@ -0,0 +1,6 @@ | |||
1 | impl F { | ||
2 | type A: Clone; | ||
3 | const B: i32; | ||
4 | fn foo() {} | ||
5 | fn bar(&self); | ||
6 | } | ||
diff --git a/tests/data/parser/inline/0090_trait_item_items.txt b/tests/data/parser/inline/0090_trait_item_items.txt new file mode 100644 index 000000000..2350bbe82 --- /dev/null +++ b/tests/data/parser/inline/0090_trait_item_items.txt | |||
@@ -0,0 +1,67 @@ | |||
1 | FILE@[0; 83) | ||
2 | IMPL_ITEM@[0; 82) | ||
3 | IMPL_KW@[0; 4) | ||
4 | WHITESPACE@[4; 5) | ||
5 | PATH_TYPE@[5; 6) | ||
6 | PATH@[5; 6) | ||
7 | PATH_SEGMENT@[5; 6) | ||
8 | NAME_REF@[5; 6) | ||
9 | IDENT@[5; 6) "F" | ||
10 | WHITESPACE@[6; 7) | ||
11 | L_CURLY@[7; 8) | ||
12 | WHITESPACE@[8; 13) | ||
13 | TYPE_ITEM@[13; 27) | ||
14 | TYPE_KW@[13; 17) | ||
15 | WHITESPACE@[17; 18) | ||
16 | NAME@[18; 19) | ||
17 | IDENT@[18; 19) "A" | ||
18 | COLON@[19; 20) | ||
19 | WHITESPACE@[20; 21) | ||
20 | PATH@[21; 26) | ||
21 | PATH_SEGMENT@[21; 26) | ||
22 | NAME_REF@[21; 26) | ||
23 | IDENT@[21; 26) "Clone" | ||
24 | SEMI@[26; 27) | ||
25 | WHITESPACE@[27; 32) | ||
26 | CONST_ITEM@[32; 45) | ||
27 | CONST_KW@[32; 37) | ||
28 | WHITESPACE@[37; 38) | ||
29 | NAME@[38; 39) | ||
30 | IDENT@[38; 39) "B" | ||
31 | COLON@[39; 40) | ||
32 | WHITESPACE@[40; 41) | ||
33 | PATH_TYPE@[41; 44) | ||
34 | PATH@[41; 44) | ||
35 | PATH_SEGMENT@[41; 44) | ||
36 | NAME_REF@[41; 44) | ||
37 | IDENT@[41; 44) "i32" | ||
38 | SEMI@[44; 45) | ||
39 | WHITESPACE@[45; 50) | ||
40 | FN_ITEM@[50; 61) | ||
41 | FN_KW@[50; 52) | ||
42 | WHITESPACE@[52; 53) | ||
43 | NAME@[53; 56) | ||
44 | IDENT@[53; 56) "foo" | ||
45 | PARAM_LIST@[56; 58) | ||
46 | L_PAREN@[56; 57) | ||
47 | R_PAREN@[57; 58) | ||
48 | WHITESPACE@[58; 59) | ||
49 | BLOCK_EXPR@[59; 61) | ||
50 | L_CURLY@[59; 60) | ||
51 | R_CURLY@[60; 61) | ||
52 | WHITESPACE@[61; 66) | ||
53 | FN_ITEM@[66; 80) | ||
54 | FN_KW@[66; 68) | ||
55 | WHITESPACE@[68; 69) | ||
56 | NAME@[69; 72) | ||
57 | IDENT@[69; 72) "bar" | ||
58 | PARAM_LIST@[72; 79) | ||
59 | L_PAREN@[72; 73) | ||
60 | SELF_PARAM@[73; 78) | ||
61 | AMP@[73; 74) | ||
62 | SELF_KW@[74; 78) | ||
63 | R_PAREN@[78; 79) | ||
64 | SEMI@[79; 80) | ||
65 | WHITESPACE@[80; 81) | ||
66 | R_CURLY@[81; 82) | ||
67 | WHITESPACE@[82; 83) | ||
diff --git a/tests/data/parser/inline/0091_fn_decl.rs b/tests/data/parser/inline/0091_fn_decl.rs new file mode 100644 index 000000000..c9f74f7f5 --- /dev/null +++ b/tests/data/parser/inline/0091_fn_decl.rs | |||
@@ -0,0 +1 @@ | |||
trait T { fn foo(); } | |||
diff --git a/tests/data/parser/inline/0091_fn_decl.txt b/tests/data/parser/inline/0091_fn_decl.txt new file mode 100644 index 000000000..e5e5bfc08 --- /dev/null +++ b/tests/data/parser/inline/0091_fn_decl.txt | |||
@@ -0,0 +1,21 @@ | |||
1 | FILE@[0; 22) | ||
2 | TRAIT_ITEM@[0; 21) | ||
3 | TRAIT_KW@[0; 5) | ||
4 | WHITESPACE@[5; 6) | ||
5 | NAME@[6; 7) | ||
6 | IDENT@[6; 7) "T" | ||
7 | WHITESPACE@[7; 8) | ||
8 | L_CURLY@[8; 9) | ||
9 | WHITESPACE@[9; 10) | ||
10 | FN_ITEM@[10; 19) | ||
11 | FN_KW@[10; 12) | ||
12 | WHITESPACE@[12; 13) | ||
13 | NAME@[13; 16) | ||
14 | IDENT@[13; 16) "foo" | ||
15 | PARAM_LIST@[16; 18) | ||
16 | L_PAREN@[16; 17) | ||
17 | R_PAREN@[17; 18) | ||
18 | SEMI@[18; 19) | ||
19 | WHITESPACE@[19; 20) | ||
20 | R_CURLY@[20; 21) | ||
21 | WHITESPACE@[21; 22) | ||