diff options
author | Aleksey Kladov <[email protected]> | 2020-08-13 16:58:35 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-08-13 16:59:27 +0100 |
commit | 6bc2633c90cedad057c5201d1ab7f67b57247004 (patch) | |
tree | 4293492e643f9a604c5f30e051289bcea182694c /crates/parser/src/grammar/items | |
parent | 1b0c7701cc97cd7bef8bb9729011d4cf291a60c5 (diff) |
Align parser names with grammar
Diffstat (limited to 'crates/parser/src/grammar/items')
-rw-r--r-- | crates/parser/src/grammar/items/adt.rs | 34 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/consts.rs | 4 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/traits.rs | 38 | ||||
-rw-r--r-- | crates/parser/src/grammar/items/use_item.rs | 4 |
4 files changed, 29 insertions, 51 deletions
diff --git a/crates/parser/src/grammar/items/adt.rs b/crates/parser/src/grammar/items/adt.rs index addfb59d4..67c0c5697 100644 --- a/crates/parser/src/grammar/items/adt.rs +++ b/crates/parser/src/grammar/items/adt.rs | |||
@@ -2,13 +2,13 @@ | |||
2 | 2 | ||
3 | use super::*; | 3 | use super::*; |
4 | 4 | ||
5 | pub(super) fn struct_def(p: &mut Parser, m: Marker) { | 5 | pub(super) fn strukt(p: &mut Parser, m: Marker) { |
6 | assert!(p.at(T![struct])); | 6 | assert!(p.at(T![struct])); |
7 | p.bump(T![struct]); | 7 | p.bump(T![struct]); |
8 | struct_or_union(p, m, T![struct], STRUCT); | 8 | struct_or_union(p, m, T![struct], STRUCT); |
9 | } | 9 | } |
10 | 10 | ||
11 | pub(super) fn union_def(p: &mut Parser, m: Marker) { | 11 | pub(super) fn union(p: &mut Parser, m: Marker) { |
12 | assert!(p.at_contextual_kw("union")); | 12 | assert!(p.at_contextual_kw("union")); |
13 | p.bump_remap(T![union]); | 13 | p.bump_remap(T![union]); |
14 | struct_or_union(p, m, T![union], UNION); | 14 | struct_or_union(p, m, T![union], UNION); |
@@ -16,7 +16,7 @@ pub(super) fn union_def(p: &mut Parser, m: Marker) { | |||
16 | 16 | ||
17 | fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { | 17 | fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { |
18 | name_r(p, ITEM_RECOVERY_SET); | 18 | name_r(p, ITEM_RECOVERY_SET); |
19 | type_params::opt_type_param_list(p); | 19 | type_params::opt_generic_param_list(p); |
20 | match p.current() { | 20 | match p.current() { |
21 | T![where] => { | 21 | T![where] => { |
22 | type_params::opt_where_clause(p); | 22 | type_params::opt_where_clause(p); |
@@ -24,7 +24,7 @@ fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { | |||
24 | T![;] => { | 24 | T![;] => { |
25 | p.bump(T![;]); | 25 | p.bump(T![;]); |
26 | } | 26 | } |
27 | T!['{'] => record_field_def_list(p), | 27 | T!['{'] => record_field_list(p), |
28 | _ => { | 28 | _ => { |
29 | //FIXME: special case `(` error message | 29 | //FIXME: special case `(` error message |
30 | p.error("expected `;` or `{`"); | 30 | p.error("expected `;` or `{`"); |
@@ -34,9 +34,9 @@ fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { | |||
34 | T![;] if kw == T![struct] => { | 34 | T![;] if kw == T![struct] => { |
35 | p.bump(T![;]); | 35 | p.bump(T![;]); |
36 | } | 36 | } |
37 | T!['{'] => record_field_def_list(p), | 37 | T!['{'] => record_field_list(p), |
38 | T!['('] if kw == T![struct] => { | 38 | T!['('] if kw == T![struct] => { |
39 | tuple_field_def_list(p); | 39 | tuple_field_list(p); |
40 | // test tuple_struct_where | 40 | // test tuple_struct_where |
41 | // struct Test<T>(T) where T: Clone; | 41 | // struct Test<T>(T) where T: Clone; |
42 | // struct Test<T>(T); | 42 | // struct Test<T>(T); |
@@ -53,21 +53,21 @@ fn struct_or_union(p: &mut Parser, m: Marker, kw: SyntaxKind, def: SyntaxKind) { | |||
53 | m.complete(p, def); | 53 | m.complete(p, def); |
54 | } | 54 | } |
55 | 55 | ||
56 | pub(super) fn enum_def(p: &mut Parser, m: Marker) { | 56 | pub(super) fn enum_(p: &mut Parser, m: Marker) { |
57 | assert!(p.at(T![enum])); | 57 | assert!(p.at(T![enum])); |
58 | p.bump(T![enum]); | 58 | p.bump(T![enum]); |
59 | name_r(p, ITEM_RECOVERY_SET); | 59 | name_r(p, ITEM_RECOVERY_SET); |
60 | type_params::opt_type_param_list(p); | 60 | type_params::opt_generic_param_list(p); |
61 | type_params::opt_where_clause(p); | 61 | type_params::opt_where_clause(p); |
62 | if p.at(T!['{']) { | 62 | if p.at(T!['{']) { |
63 | enum_variant_list(p); | 63 | variant_list(p); |
64 | } else { | 64 | } else { |
65 | p.error("expected `{`") | 65 | p.error("expected `{`") |
66 | } | 66 | } |
67 | m.complete(p, ENUM); | 67 | m.complete(p, ENUM); |
68 | } | 68 | } |
69 | 69 | ||
70 | pub(crate) fn enum_variant_list(p: &mut Parser) { | 70 | pub(crate) fn variant_list(p: &mut Parser) { |
71 | assert!(p.at(T!['{'])); | 71 | assert!(p.at(T!['{'])); |
72 | let m = p.start(); | 72 | let m = p.start(); |
73 | p.bump(T!['{']); | 73 | p.bump(T!['{']); |
@@ -77,12 +77,12 @@ pub(crate) fn enum_variant_list(p: &mut Parser) { | |||
77 | continue; | 77 | continue; |
78 | } | 78 | } |
79 | let var = p.start(); | 79 | let var = p.start(); |
80 | attributes::outer_attributes(p); | 80 | attributes::outer_attrs(p); |
81 | if p.at(IDENT) { | 81 | if p.at(IDENT) { |
82 | name(p); | 82 | name(p); |
83 | match p.current() { | 83 | match p.current() { |
84 | T!['{'] => record_field_def_list(p), | 84 | T!['{'] => record_field_list(p), |
85 | T!['('] => tuple_field_def_list(p), | 85 | T!['('] => tuple_field_list(p), |
86 | _ => (), | 86 | _ => (), |
87 | } | 87 | } |
88 | 88 | ||
@@ -104,7 +104,7 @@ pub(crate) fn enum_variant_list(p: &mut Parser) { | |||
104 | m.complete(p, VARIANT_LIST); | 104 | m.complete(p, VARIANT_LIST); |
105 | } | 105 | } |
106 | 106 | ||
107 | pub(crate) fn record_field_def_list(p: &mut Parser) { | 107 | pub(crate) fn record_field_list(p: &mut Parser) { |
108 | assert!(p.at(T!['{'])); | 108 | assert!(p.at(T!['{'])); |
109 | let m = p.start(); | 109 | let m = p.start(); |
110 | p.bump(T!['{']); | 110 | p.bump(T!['{']); |
@@ -128,7 +128,7 @@ pub(crate) fn record_field_def_list(p: &mut Parser) { | |||
128 | // #[serde(with = "url_serde")] | 128 | // #[serde(with = "url_serde")] |
129 | // pub uri: Uri, | 129 | // pub uri: Uri, |
130 | // } | 130 | // } |
131 | attributes::outer_attributes(p); | 131 | attributes::outer_attrs(p); |
132 | opt_visibility(p); | 132 | opt_visibility(p); |
133 | if p.at(IDENT) { | 133 | if p.at(IDENT) { |
134 | name(p); | 134 | name(p); |
@@ -142,7 +142,7 @@ pub(crate) fn record_field_def_list(p: &mut Parser) { | |||
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
145 | fn tuple_field_def_list(p: &mut Parser) { | 145 | fn tuple_field_list(p: &mut Parser) { |
146 | assert!(p.at(T!['('])); | 146 | assert!(p.at(T!['('])); |
147 | let m = p.start(); | 147 | let m = p.start(); |
148 | if !p.expect(T!['(']) { | 148 | if !p.expect(T!['(']) { |
@@ -159,7 +159,7 @@ fn tuple_field_def_list(p: &mut Parser) { | |||
159 | // enum S { | 159 | // enum S { |
160 | // Uri(#[serde(with = "url_serde")] Uri), | 160 | // Uri(#[serde(with = "url_serde")] Uri), |
161 | // } | 161 | // } |
162 | attributes::outer_attributes(p); | 162 | attributes::outer_attrs(p); |
163 | opt_visibility(p); | 163 | opt_visibility(p); |
164 | if !p.at_ts(types::TYPE_FIRST) { | 164 | if !p.at_ts(types::TYPE_FIRST) { |
165 | p.error("expected a type"); | 165 | p.error("expected a type"); |
diff --git a/crates/parser/src/grammar/items/consts.rs b/crates/parser/src/grammar/items/consts.rs index 35ad766dc..eb7d1f828 100644 --- a/crates/parser/src/grammar/items/consts.rs +++ b/crates/parser/src/grammar/items/consts.rs | |||
@@ -2,11 +2,11 @@ | |||
2 | 2 | ||
3 | use super::*; | 3 | use super::*; |
4 | 4 | ||
5 | pub(super) fn static_def(p: &mut Parser, m: Marker) { | 5 | pub(super) fn static_(p: &mut Parser, m: Marker) { |
6 | const_or_static(p, m, T![static], STATIC) | 6 | const_or_static(p, m, T![static], STATIC) |
7 | } | 7 | } |
8 | 8 | ||
9 | pub(super) fn const_def(p: &mut Parser, m: Marker) { | 9 | pub(super) fn konst(p: &mut Parser, m: Marker) { |
10 | const_or_static(p, m, T![const], CONST) | 10 | const_or_static(p, m, T![const], CONST) |
11 | } | 11 | } |
12 | 12 | ||
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index 751ce65f2..8394020da 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs | |||
@@ -5,11 +5,11 @@ use super::*; | |||
5 | // test trait_item | 5 | // test trait_item |
6 | // trait T<U>: Hash + Clone where U: Copy {} | 6 | // trait T<U>: Hash + Clone where U: Copy {} |
7 | // trait X<U: Debug + Display>: Hash + Clone where U: Copy {} | 7 | // trait X<U: Debug + Display>: Hash + Clone where U: Copy {} |
8 | pub(super) fn trait_def(p: &mut Parser) { | 8 | pub(super) fn trait_(p: &mut Parser) { |
9 | assert!(p.at(T![trait])); | 9 | assert!(p.at(T![trait])); |
10 | p.bump(T![trait]); | 10 | p.bump(T![trait]); |
11 | name_r(p, ITEM_RECOVERY_SET); | 11 | name_r(p, ITEM_RECOVERY_SET); |
12 | type_params::opt_type_param_list(p); | 12 | type_params::opt_generic_param_list(p); |
13 | // test trait_alias | 13 | // test trait_alias |
14 | // trait Z<U> = T<U>; | 14 | // trait Z<U> = T<U>; |
15 | // trait Z<U> = T<U> where U: Copy; | 15 | // trait Z<U> = T<U> where U: Copy; |
@@ -25,41 +25,19 @@ pub(super) fn trait_def(p: &mut Parser) { | |||
25 | } | 25 | } |
26 | type_params::opt_where_clause(p); | 26 | type_params::opt_where_clause(p); |
27 | if p.at(T!['{']) { | 27 | if p.at(T!['{']) { |
28 | trait_item_list(p); | 28 | assoc_item_list(p); |
29 | } else { | 29 | } else { |
30 | p.error("expected `{`"); | 30 | p.error("expected `{`"); |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | // test trait_item_list | ||
35 | // impl F { | ||
36 | // type A: Clone; | ||
37 | // const B: i32; | ||
38 | // fn foo() {} | ||
39 | // fn bar(&self); | ||
40 | // } | ||
41 | pub(crate) fn trait_item_list(p: &mut Parser) { | ||
42 | assert!(p.at(T!['{'])); | ||
43 | let m = p.start(); | ||
44 | p.bump(T!['{']); | ||
45 | while !p.at(EOF) && !p.at(T!['}']) { | ||
46 | if p.at(T!['{']) { | ||
47 | error_block(p, "expected an item"); | ||
48 | continue; | ||
49 | } | ||
50 | item_or_macro(p, true); | ||
51 | } | ||
52 | p.expect(T!['}']); | ||
53 | m.complete(p, ASSOC_ITEM_LIST); | ||
54 | } | ||
55 | |||
56 | // test impl_def | 34 | // test impl_def |
57 | // impl Foo {} | 35 | // impl Foo {} |
58 | pub(super) fn impl_def(p: &mut Parser) { | 36 | pub(super) fn impl_(p: &mut Parser) { |
59 | assert!(p.at(T![impl])); | 37 | assert!(p.at(T![impl])); |
60 | p.bump(T![impl]); | 38 | p.bump(T![impl]); |
61 | if choose_type_params_over_qpath(p) { | 39 | if choose_type_params_over_qpath(p) { |
62 | type_params::opt_type_param_list(p); | 40 | type_params::opt_generic_param_list(p); |
63 | } | 41 | } |
64 | 42 | ||
65 | // FIXME: never type | 43 | // FIXME: never type |
@@ -74,7 +52,7 @@ pub(super) fn impl_def(p: &mut Parser) { | |||
74 | } | 52 | } |
75 | type_params::opt_where_clause(p); | 53 | type_params::opt_where_clause(p); |
76 | if p.at(T!['{']) { | 54 | if p.at(T!['{']) { |
77 | impl_item_list(p); | 55 | assoc_item_list(p); |
78 | } else { | 56 | } else { |
79 | p.error("expected `{`"); | 57 | p.error("expected `{`"); |
80 | } | 58 | } |
@@ -87,7 +65,7 @@ pub(super) fn impl_def(p: &mut Parser) { | |||
87 | // fn foo() {} | 65 | // fn foo() {} |
88 | // fn bar(&self) {} | 66 | // fn bar(&self) {} |
89 | // } | 67 | // } |
90 | pub(crate) fn impl_item_list(p: &mut Parser) { | 68 | pub(crate) fn assoc_item_list(p: &mut Parser) { |
91 | assert!(p.at(T!['{'])); | 69 | assert!(p.at(T!['{'])); |
92 | let m = p.start(); | 70 | let m = p.start(); |
93 | p.bump(T!['{']); | 71 | p.bump(T!['{']); |
@@ -97,7 +75,7 @@ pub(crate) fn impl_item_list(p: &mut Parser) { | |||
97 | // //! This is a doc comment | 75 | // //! This is a doc comment |
98 | // #![doc("This is also a doc comment")] | 76 | // #![doc("This is also a doc comment")] |
99 | // } | 77 | // } |
100 | attributes::inner_attributes(p); | 78 | attributes::inner_attrs(p); |
101 | 79 | ||
102 | while !p.at(EOF) && !p.at(T!['}']) { | 80 | while !p.at(EOF) && !p.at(T!['}']) { |
103 | if p.at(T!['{']) { | 81 | if p.at(T!['{']) { |
diff --git a/crates/parser/src/grammar/items/use_item.rs b/crates/parser/src/grammar/items/use_item.rs index 8e836a77e..20e6a13cf 100644 --- a/crates/parser/src/grammar/items/use_item.rs +++ b/crates/parser/src/grammar/items/use_item.rs | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | use super::*; | 3 | use super::*; |
4 | 4 | ||
5 | pub(super) fn use_item(p: &mut Parser, m: Marker) { | 5 | pub(super) fn use_(p: &mut Parser, m: Marker) { |
6 | assert!(p.at(T![use])); | 6 | assert!(p.at(T![use])); |
7 | p.bump(T![use]); | 7 | p.bump(T![use]); |
8 | use_tree(p, true); | 8 | use_tree(p, true); |
@@ -80,7 +80,7 @@ fn use_tree(p: &mut Parser, top_level: bool) { | |||
80 | // running::out::of::synonyms::for_::different::* | 80 | // running::out::of::synonyms::for_::different::* |
81 | // }; | 81 | // }; |
82 | // use Trait as _; | 82 | // use Trait as _; |
83 | opt_alias(p); | 83 | opt_rename(p); |
84 | } | 84 | } |
85 | T![:] if p.at(T![::]) => { | 85 | T![:] if p.at(T![::]) => { |
86 | p.bump(T![::]); | 86 | p.bump(T![::]); |