diff options
author | Aleksey Kladov <[email protected]> | 2018-08-17 20:00:13 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-17 20:00:13 +0100 |
commit | d3c90ded2b9a4f75e101fa3abc60cd3aebc439c9 (patch) | |
tree | 6d2388eb68605331a0dd090269372bc98dd038cd /crates/libsyntax2/src/ast | |
parent | 70097504f78c4c41368a0b864a94df95fb9c27f7 (diff) |
Borrowed AST
Diffstat (limited to 'crates/libsyntax2/src/ast')
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs | 436 | ||||
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs.tera | 31 | ||||
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 61 |
3 files changed, 267 insertions, 261 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index 4fc405c8a..e8a87eba5 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs | |||
@@ -1,45 +1,45 @@ | |||
1 | use { | 1 | use { |
2 | ast, | 2 | ast, |
3 | SyntaxNode, OwnedRoot, TreeRoot, AstNode, | 3 | SyntaxNodeRef, AstNode, |
4 | SyntaxKind::*, | 4 | SyntaxKind::*, |
5 | }; | 5 | }; |
6 | 6 | ||
7 | // ArrayType | 7 | // ArrayType |
8 | #[derive(Debug, Clone, Copy)] | 8 | #[derive(Debug, Clone, Copy)] |
9 | pub struct ArrayType<R: TreeRoot = OwnedRoot> { | 9 | pub struct ArrayType<'a> { |
10 | syntax: SyntaxNode<R>, | 10 | syntax: SyntaxNodeRef<'a>, |
11 | } | 11 | } |
12 | 12 | ||
13 | impl<R: TreeRoot> AstNode<R> for ArrayType<R> { | 13 | impl<'a> AstNode<'a> for ArrayType<'a> { |
14 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 14 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
15 | match syntax.kind() { | 15 | match syntax.kind() { |
16 | ARRAY_TYPE => Some(ArrayType { syntax }), | 16 | ARRAY_TYPE => Some(ArrayType { syntax }), |
17 | _ => None, | 17 | _ => None, |
18 | } | 18 | } |
19 | } | 19 | } |
20 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 20 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
21 | } | 21 | } |
22 | 22 | ||
23 | impl<R: TreeRoot> ArrayType<R> {} | 23 | impl<'a> ArrayType<'a> {} |
24 | 24 | ||
25 | // Attr | 25 | // Attr |
26 | #[derive(Debug, Clone, Copy)] | 26 | #[derive(Debug, Clone, Copy)] |
27 | pub struct Attr<R: TreeRoot = OwnedRoot> { | 27 | pub struct Attr<'a> { |
28 | syntax: SyntaxNode<R>, | 28 | syntax: SyntaxNodeRef<'a>, |
29 | } | 29 | } |
30 | 30 | ||
31 | impl<R: TreeRoot> AstNode<R> for Attr<R> { | 31 | impl<'a> AstNode<'a> for Attr<'a> { |
32 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 32 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
33 | match syntax.kind() { | 33 | match syntax.kind() { |
34 | ATTR => Some(Attr { syntax }), | 34 | ATTR => Some(Attr { syntax }), |
35 | _ => None, | 35 | _ => None, |
36 | } | 36 | } |
37 | } | 37 | } |
38 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 38 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
39 | } | 39 | } |
40 | 40 | ||
41 | impl<R: TreeRoot> Attr<R> { | 41 | impl<'a> Attr<'a> { |
42 | pub fn value(&self) -> Option<TokenTree<R>> { | 42 | pub fn value(self) -> Option<TokenTree<'a>> { |
43 | self.syntax() | 43 | self.syntax() |
44 | .children() | 44 | .children() |
45 | .filter_map(TokenTree::cast) | 45 | .filter_map(TokenTree::cast) |
@@ -49,80 +49,80 @@ impl<R: TreeRoot> Attr<R> { | |||
49 | 49 | ||
50 | // ConstDef | 50 | // ConstDef |
51 | #[derive(Debug, Clone, Copy)] | 51 | #[derive(Debug, Clone, Copy)] |
52 | pub struct ConstDef<R: TreeRoot = OwnedRoot> { | 52 | pub struct ConstDef<'a> { |
53 | syntax: SyntaxNode<R>, | 53 | syntax: SyntaxNodeRef<'a>, |
54 | } | 54 | } |
55 | 55 | ||
56 | impl<R: TreeRoot> AstNode<R> for ConstDef<R> { | 56 | impl<'a> AstNode<'a> for ConstDef<'a> { |
57 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 57 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
58 | match syntax.kind() { | 58 | match syntax.kind() { |
59 | CONST_DEF => Some(ConstDef { syntax }), | 59 | CONST_DEF => Some(ConstDef { syntax }), |
60 | _ => None, | 60 | _ => None, |
61 | } | 61 | } |
62 | } | 62 | } |
63 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 63 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
64 | } | 64 | } |
65 | 65 | ||
66 | impl<R: TreeRoot> ast::NameOwner<R> for ConstDef<R> {} | 66 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} |
67 | impl<R: TreeRoot> ast::AttrsOwner<R> for ConstDef<R> {} | 67 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} |
68 | impl<R: TreeRoot> ConstDef<R> {} | 68 | impl<'a> ConstDef<'a> {} |
69 | 69 | ||
70 | // DynTraitType | 70 | // DynTraitType |
71 | #[derive(Debug, Clone, Copy)] | 71 | #[derive(Debug, Clone, Copy)] |
72 | pub struct DynTraitType<R: TreeRoot = OwnedRoot> { | 72 | pub struct DynTraitType<'a> { |
73 | syntax: SyntaxNode<R>, | 73 | syntax: SyntaxNodeRef<'a>, |
74 | } | 74 | } |
75 | 75 | ||
76 | impl<R: TreeRoot> AstNode<R> for DynTraitType<R> { | 76 | impl<'a> AstNode<'a> for DynTraitType<'a> { |
77 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 77 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
78 | match syntax.kind() { | 78 | match syntax.kind() { |
79 | DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), | 79 | DYN_TRAIT_TYPE => Some(DynTraitType { syntax }), |
80 | _ => None, | 80 | _ => None, |
81 | } | 81 | } |
82 | } | 82 | } |
83 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 83 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
84 | } | 84 | } |
85 | 85 | ||
86 | impl<R: TreeRoot> DynTraitType<R> {} | 86 | impl<'a> DynTraitType<'a> {} |
87 | 87 | ||
88 | // EnumDef | 88 | // EnumDef |
89 | #[derive(Debug, Clone, Copy)] | 89 | #[derive(Debug, Clone, Copy)] |
90 | pub struct EnumDef<R: TreeRoot = OwnedRoot> { | 90 | pub struct EnumDef<'a> { |
91 | syntax: SyntaxNode<R>, | 91 | syntax: SyntaxNodeRef<'a>, |
92 | } | 92 | } |
93 | 93 | ||
94 | impl<R: TreeRoot> AstNode<R> for EnumDef<R> { | 94 | impl<'a> AstNode<'a> for EnumDef<'a> { |
95 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 95 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
96 | match syntax.kind() { | 96 | match syntax.kind() { |
97 | ENUM_DEF => Some(EnumDef { syntax }), | 97 | ENUM_DEF => Some(EnumDef { syntax }), |
98 | _ => None, | 98 | _ => None, |
99 | } | 99 | } |
100 | } | 100 | } |
101 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 101 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
102 | } | 102 | } |
103 | 103 | ||
104 | impl<R: TreeRoot> ast::NameOwner<R> for EnumDef<R> {} | 104 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} |
105 | impl<R: TreeRoot> ast::AttrsOwner<R> for EnumDef<R> {} | 105 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} |
106 | impl<R: TreeRoot> EnumDef<R> {} | 106 | impl<'a> EnumDef<'a> {} |
107 | 107 | ||
108 | // File | 108 | // File |
109 | #[derive(Debug, Clone, Copy)] | 109 | #[derive(Debug, Clone, Copy)] |
110 | pub struct File<R: TreeRoot = OwnedRoot> { | 110 | pub struct File<'a> { |
111 | syntax: SyntaxNode<R>, | 111 | syntax: SyntaxNodeRef<'a>, |
112 | } | 112 | } |
113 | 113 | ||
114 | impl<R: TreeRoot> AstNode<R> for File<R> { | 114 | impl<'a> AstNode<'a> for File<'a> { |
115 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 115 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
116 | match syntax.kind() { | 116 | match syntax.kind() { |
117 | FILE => Some(File { syntax }), | 117 | FILE => Some(File { syntax }), |
118 | _ => None, | 118 | _ => None, |
119 | } | 119 | } |
120 | } | 120 | } |
121 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 121 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
122 | } | 122 | } |
123 | 123 | ||
124 | impl<R: TreeRoot> File<R> { | 124 | impl<'a> File<'a> { |
125 | pub fn functions<'a>(&'a self) -> impl Iterator<Item = FnDef<R>> + 'a { | 125 | pub fn functions(self) -> impl Iterator<Item = FnDef<'a>> + 'a { |
126 | self.syntax() | 126 | self.syntax() |
127 | .children() | 127 | .children() |
128 | .filter_map(FnDef::cast) | 128 | .filter_map(FnDef::cast) |
@@ -131,206 +131,206 @@ impl<R: TreeRoot> File<R> { | |||
131 | 131 | ||
132 | // FnDef | 132 | // FnDef |
133 | #[derive(Debug, Clone, Copy)] | 133 | #[derive(Debug, Clone, Copy)] |
134 | pub struct FnDef<R: TreeRoot = OwnedRoot> { | 134 | pub struct FnDef<'a> { |
135 | syntax: SyntaxNode<R>, | 135 | syntax: SyntaxNodeRef<'a>, |
136 | } | 136 | } |
137 | 137 | ||
138 | impl<R: TreeRoot> AstNode<R> for FnDef<R> { | 138 | impl<'a> AstNode<'a> for FnDef<'a> { |
139 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 139 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
140 | match syntax.kind() { | 140 | match syntax.kind() { |
141 | FN_DEF => Some(FnDef { syntax }), | 141 | FN_DEF => Some(FnDef { syntax }), |
142 | _ => None, | 142 | _ => None, |
143 | } | 143 | } |
144 | } | 144 | } |
145 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 145 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
146 | } | 146 | } |
147 | 147 | ||
148 | impl<R: TreeRoot> ast::NameOwner<R> for FnDef<R> {} | 148 | impl<'a> ast::NameOwner<'a> for FnDef<'a> {} |
149 | impl<R: TreeRoot> ast::AttrsOwner<R> for FnDef<R> {} | 149 | impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {} |
150 | impl<R: TreeRoot> FnDef<R> {} | 150 | impl<'a> FnDef<'a> {} |
151 | 151 | ||
152 | // FnPointerType | 152 | // FnPointerType |
153 | #[derive(Debug, Clone, Copy)] | 153 | #[derive(Debug, Clone, Copy)] |
154 | pub struct FnPointerType<R: TreeRoot = OwnedRoot> { | 154 | pub struct FnPointerType<'a> { |
155 | syntax: SyntaxNode<R>, | 155 | syntax: SyntaxNodeRef<'a>, |
156 | } | 156 | } |
157 | 157 | ||
158 | impl<R: TreeRoot> AstNode<R> for FnPointerType<R> { | 158 | impl<'a> AstNode<'a> for FnPointerType<'a> { |
159 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 159 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
160 | match syntax.kind() { | 160 | match syntax.kind() { |
161 | FN_POINTER_TYPE => Some(FnPointerType { syntax }), | 161 | FN_POINTER_TYPE => Some(FnPointerType { syntax }), |
162 | _ => None, | 162 | _ => None, |
163 | } | 163 | } |
164 | } | 164 | } |
165 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 165 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
166 | } | 166 | } |
167 | 167 | ||
168 | impl<R: TreeRoot> FnPointerType<R> {} | 168 | impl<'a> FnPointerType<'a> {} |
169 | 169 | ||
170 | // ForType | 170 | // ForType |
171 | #[derive(Debug, Clone, Copy)] | 171 | #[derive(Debug, Clone, Copy)] |
172 | pub struct ForType<R: TreeRoot = OwnedRoot> { | 172 | pub struct ForType<'a> { |
173 | syntax: SyntaxNode<R>, | 173 | syntax: SyntaxNodeRef<'a>, |
174 | } | 174 | } |
175 | 175 | ||
176 | impl<R: TreeRoot> AstNode<R> for ForType<R> { | 176 | impl<'a> AstNode<'a> for ForType<'a> { |
177 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 177 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
178 | match syntax.kind() { | 178 | match syntax.kind() { |
179 | FOR_TYPE => Some(ForType { syntax }), | 179 | FOR_TYPE => Some(ForType { syntax }), |
180 | _ => None, | 180 | _ => None, |
181 | } | 181 | } |
182 | } | 182 | } |
183 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 183 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
184 | } | 184 | } |
185 | 185 | ||
186 | impl<R: TreeRoot> ForType<R> {} | 186 | impl<'a> ForType<'a> {} |
187 | 187 | ||
188 | // ImplItem | 188 | // ImplItem |
189 | #[derive(Debug, Clone, Copy)] | 189 | #[derive(Debug, Clone, Copy)] |
190 | pub struct ImplItem<R: TreeRoot = OwnedRoot> { | 190 | pub struct ImplItem<'a> { |
191 | syntax: SyntaxNode<R>, | 191 | syntax: SyntaxNodeRef<'a>, |
192 | } | 192 | } |
193 | 193 | ||
194 | impl<R: TreeRoot> AstNode<R> for ImplItem<R> { | 194 | impl<'a> AstNode<'a> for ImplItem<'a> { |
195 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 195 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
196 | match syntax.kind() { | 196 | match syntax.kind() { |
197 | IMPL_ITEM => Some(ImplItem { syntax }), | 197 | IMPL_ITEM => Some(ImplItem { syntax }), |
198 | _ => None, | 198 | _ => None, |
199 | } | 199 | } |
200 | } | 200 | } |
201 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 201 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
202 | } | 202 | } |
203 | 203 | ||
204 | impl<R: TreeRoot> ImplItem<R> {} | 204 | impl<'a> ImplItem<'a> {} |
205 | 205 | ||
206 | // ImplTraitType | 206 | // ImplTraitType |
207 | #[derive(Debug, Clone, Copy)] | 207 | #[derive(Debug, Clone, Copy)] |
208 | pub struct ImplTraitType<R: TreeRoot = OwnedRoot> { | 208 | pub struct ImplTraitType<'a> { |
209 | syntax: SyntaxNode<R>, | 209 | syntax: SyntaxNodeRef<'a>, |
210 | } | 210 | } |
211 | 211 | ||
212 | impl<R: TreeRoot> AstNode<R> for ImplTraitType<R> { | 212 | impl<'a> AstNode<'a> for ImplTraitType<'a> { |
213 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 213 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
214 | match syntax.kind() { | 214 | match syntax.kind() { |
215 | IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), | 215 | IMPL_TRAIT_TYPE => Some(ImplTraitType { syntax }), |
216 | _ => None, | 216 | _ => None, |
217 | } | 217 | } |
218 | } | 218 | } |
219 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 219 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
220 | } | 220 | } |
221 | 221 | ||
222 | impl<R: TreeRoot> ImplTraitType<R> {} | 222 | impl<'a> ImplTraitType<'a> {} |
223 | 223 | ||
224 | // Module | 224 | // Module |
225 | #[derive(Debug, Clone, Copy)] | 225 | #[derive(Debug, Clone, Copy)] |
226 | pub struct Module<R: TreeRoot = OwnedRoot> { | 226 | pub struct Module<'a> { |
227 | syntax: SyntaxNode<R>, | 227 | syntax: SyntaxNodeRef<'a>, |
228 | } | 228 | } |
229 | 229 | ||
230 | impl<R: TreeRoot> AstNode<R> for Module<R> { | 230 | impl<'a> AstNode<'a> for Module<'a> { |
231 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 231 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
232 | match syntax.kind() { | 232 | match syntax.kind() { |
233 | MODULE => Some(Module { syntax }), | 233 | MODULE => Some(Module { syntax }), |
234 | _ => None, | 234 | _ => None, |
235 | } | 235 | } |
236 | } | 236 | } |
237 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 237 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
238 | } | 238 | } |
239 | 239 | ||
240 | impl<R: TreeRoot> ast::NameOwner<R> for Module<R> {} | 240 | impl<'a> ast::NameOwner<'a> for Module<'a> {} |
241 | impl<R: TreeRoot> ast::AttrsOwner<R> for Module<R> {} | 241 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} |
242 | impl<R: TreeRoot> Module<R> {} | 242 | impl<'a> Module<'a> {} |
243 | 243 | ||
244 | // Name | 244 | // Name |
245 | #[derive(Debug, Clone, Copy)] | 245 | #[derive(Debug, Clone, Copy)] |
246 | pub struct Name<R: TreeRoot = OwnedRoot> { | 246 | pub struct Name<'a> { |
247 | syntax: SyntaxNode<R>, | 247 | syntax: SyntaxNodeRef<'a>, |
248 | } | 248 | } |
249 | 249 | ||
250 | impl<R: TreeRoot> AstNode<R> for Name<R> { | 250 | impl<'a> AstNode<'a> for Name<'a> { |
251 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 251 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
252 | match syntax.kind() { | 252 | match syntax.kind() { |
253 | NAME => Some(Name { syntax }), | 253 | NAME => Some(Name { syntax }), |
254 | _ => None, | 254 | _ => None, |
255 | } | 255 | } |
256 | } | 256 | } |
257 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 257 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
258 | } | 258 | } |
259 | 259 | ||
260 | impl<R: TreeRoot> Name<R> {} | 260 | impl<'a> Name<'a> {} |
261 | 261 | ||
262 | // NameRef | 262 | // NameRef |
263 | #[derive(Debug, Clone, Copy)] | 263 | #[derive(Debug, Clone, Copy)] |
264 | pub struct NameRef<R: TreeRoot = OwnedRoot> { | 264 | pub struct NameRef<'a> { |
265 | syntax: SyntaxNode<R>, | 265 | syntax: SyntaxNodeRef<'a>, |
266 | } | 266 | } |
267 | 267 | ||
268 | impl<R: TreeRoot> AstNode<R> for NameRef<R> { | 268 | impl<'a> AstNode<'a> for NameRef<'a> { |
269 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 269 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
270 | match syntax.kind() { | 270 | match syntax.kind() { |
271 | NAME_REF => Some(NameRef { syntax }), | 271 | NAME_REF => Some(NameRef { syntax }), |
272 | _ => None, | 272 | _ => None, |
273 | } | 273 | } |
274 | } | 274 | } |
275 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 275 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
276 | } | 276 | } |
277 | 277 | ||
278 | impl<R: TreeRoot> NameRef<R> {} | 278 | impl<'a> NameRef<'a> {} |
279 | 279 | ||
280 | // NamedField | 280 | // NamedField |
281 | #[derive(Debug, Clone, Copy)] | 281 | #[derive(Debug, Clone, Copy)] |
282 | pub struct NamedField<R: TreeRoot = OwnedRoot> { | 282 | pub struct NamedField<'a> { |
283 | syntax: SyntaxNode<R>, | 283 | syntax: SyntaxNodeRef<'a>, |
284 | } | 284 | } |
285 | 285 | ||
286 | impl<R: TreeRoot> AstNode<R> for NamedField<R> { | 286 | impl<'a> AstNode<'a> for NamedField<'a> { |
287 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 287 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
288 | match syntax.kind() { | 288 | match syntax.kind() { |
289 | NAMED_FIELD => Some(NamedField { syntax }), | 289 | NAMED_FIELD => Some(NamedField { syntax }), |
290 | _ => None, | 290 | _ => None, |
291 | } | 291 | } |
292 | } | 292 | } |
293 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 293 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
294 | } | 294 | } |
295 | 295 | ||
296 | impl<R: TreeRoot> ast::NameOwner<R> for NamedField<R> {} | 296 | impl<'a> ast::NameOwner<'a> for NamedField<'a> {} |
297 | impl<R: TreeRoot> ast::AttrsOwner<R> for NamedField<R> {} | 297 | impl<'a> ast::AttrsOwner<'a> for NamedField<'a> {} |
298 | impl<R: TreeRoot> NamedField<R> {} | 298 | impl<'a> NamedField<'a> {} |
299 | 299 | ||
300 | // NeverType | 300 | // NeverType |
301 | #[derive(Debug, Clone, Copy)] | 301 | #[derive(Debug, Clone, Copy)] |
302 | pub struct NeverType<R: TreeRoot = OwnedRoot> { | 302 | pub struct NeverType<'a> { |
303 | syntax: SyntaxNode<R>, | 303 | syntax: SyntaxNodeRef<'a>, |
304 | } | 304 | } |
305 | 305 | ||
306 | impl<R: TreeRoot> AstNode<R> for NeverType<R> { | 306 | impl<'a> AstNode<'a> for NeverType<'a> { |
307 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 307 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
308 | match syntax.kind() { | 308 | match syntax.kind() { |
309 | NEVER_TYPE => Some(NeverType { syntax }), | 309 | NEVER_TYPE => Some(NeverType { syntax }), |
310 | _ => None, | 310 | _ => None, |
311 | } | 311 | } |
312 | } | 312 | } |
313 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 313 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
314 | } | 314 | } |
315 | 315 | ||
316 | impl<R: TreeRoot> NeverType<R> {} | 316 | impl<'a> NeverType<'a> {} |
317 | 317 | ||
318 | // NominalDef | 318 | // NominalDef |
319 | #[derive(Debug, Clone, Copy)] | 319 | #[derive(Debug, Clone, Copy)] |
320 | pub enum NominalDef<R: TreeRoot = OwnedRoot> { | 320 | pub enum NominalDef<'a> { |
321 | StructDef(StructDef<R>), | 321 | StructDef(StructDef<'a>), |
322 | EnumDef(EnumDef<R>), | 322 | EnumDef(EnumDef<'a>), |
323 | } | 323 | } |
324 | 324 | ||
325 | impl<R: TreeRoot> AstNode<R> for NominalDef<R> { | 325 | impl<'a> AstNode<'a> for NominalDef<'a> { |
326 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 326 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
327 | match syntax.kind() { | 327 | match syntax.kind() { |
328 | STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), | 328 | STRUCT_DEF => Some(NominalDef::StructDef(StructDef { syntax })), |
329 | ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), | 329 | ENUM_DEF => Some(NominalDef::EnumDef(EnumDef { syntax })), |
330 | _ => None, | 330 | _ => None, |
331 | } | 331 | } |
332 | } | 332 | } |
333 | fn syntax(&self) -> &SyntaxNode<R> { | 333 | fn syntax(self) -> SyntaxNodeRef<'a> { |
334 | match self { | 334 | match self { |
335 | NominalDef::StructDef(inner) => inner.syntax(), | 335 | NominalDef::StructDef(inner) => inner.syntax(), |
336 | NominalDef::EnumDef(inner) => inner.syntax(), | 336 | NominalDef::EnumDef(inner) => inner.syntax(), |
@@ -338,157 +338,157 @@ impl<R: TreeRoot> AstNode<R> for NominalDef<R> { | |||
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
341 | impl<R: TreeRoot> ast::AttrsOwner<R> for NominalDef<R> {} | 341 | impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} |
342 | impl<R: TreeRoot> NominalDef<R> {} | 342 | impl<'a> NominalDef<'a> {} |
343 | 343 | ||
344 | // ParenType | 344 | // ParenType |
345 | #[derive(Debug, Clone, Copy)] | 345 | #[derive(Debug, Clone, Copy)] |
346 | pub struct ParenType<R: TreeRoot = OwnedRoot> { | 346 | pub struct ParenType<'a> { |
347 | syntax: SyntaxNode<R>, | 347 | syntax: SyntaxNodeRef<'a>, |
348 | } | 348 | } |
349 | 349 | ||
350 | impl<R: TreeRoot> AstNode<R> for ParenType<R> { | 350 | impl<'a> AstNode<'a> for ParenType<'a> { |
351 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 351 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
352 | match syntax.kind() { | 352 | match syntax.kind() { |
353 | PAREN_TYPE => Some(ParenType { syntax }), | 353 | PAREN_TYPE => Some(ParenType { syntax }), |
354 | _ => None, | 354 | _ => None, |
355 | } | 355 | } |
356 | } | 356 | } |
357 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 357 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
358 | } | 358 | } |
359 | 359 | ||
360 | impl<R: TreeRoot> ParenType<R> {} | 360 | impl<'a> ParenType<'a> {} |
361 | 361 | ||
362 | // PathType | 362 | // PathType |
363 | #[derive(Debug, Clone, Copy)] | 363 | #[derive(Debug, Clone, Copy)] |
364 | pub struct PathType<R: TreeRoot = OwnedRoot> { | 364 | pub struct PathType<'a> { |
365 | syntax: SyntaxNode<R>, | 365 | syntax: SyntaxNodeRef<'a>, |
366 | } | 366 | } |
367 | 367 | ||
368 | impl<R: TreeRoot> AstNode<R> for PathType<R> { | 368 | impl<'a> AstNode<'a> for PathType<'a> { |
369 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 369 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
370 | match syntax.kind() { | 370 | match syntax.kind() { |
371 | PATH_TYPE => Some(PathType { syntax }), | 371 | PATH_TYPE => Some(PathType { syntax }), |
372 | _ => None, | 372 | _ => None, |
373 | } | 373 | } |
374 | } | 374 | } |
375 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 375 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
376 | } | 376 | } |
377 | 377 | ||
378 | impl<R: TreeRoot> PathType<R> {} | 378 | impl<'a> PathType<'a> {} |
379 | 379 | ||
380 | // PlaceholderType | 380 | // PlaceholderType |
381 | #[derive(Debug, Clone, Copy)] | 381 | #[derive(Debug, Clone, Copy)] |
382 | pub struct PlaceholderType<R: TreeRoot = OwnedRoot> { | 382 | pub struct PlaceholderType<'a> { |
383 | syntax: SyntaxNode<R>, | 383 | syntax: SyntaxNodeRef<'a>, |
384 | } | 384 | } |
385 | 385 | ||
386 | impl<R: TreeRoot> AstNode<R> for PlaceholderType<R> { | 386 | impl<'a> AstNode<'a> for PlaceholderType<'a> { |
387 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 387 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
388 | match syntax.kind() { | 388 | match syntax.kind() { |
389 | PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), | 389 | PLACEHOLDER_TYPE => Some(PlaceholderType { syntax }), |
390 | _ => None, | 390 | _ => None, |
391 | } | 391 | } |
392 | } | 392 | } |
393 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 393 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
394 | } | 394 | } |
395 | 395 | ||
396 | impl<R: TreeRoot> PlaceholderType<R> {} | 396 | impl<'a> PlaceholderType<'a> {} |
397 | 397 | ||
398 | // PointerType | 398 | // PointerType |
399 | #[derive(Debug, Clone, Copy)] | 399 | #[derive(Debug, Clone, Copy)] |
400 | pub struct PointerType<R: TreeRoot = OwnedRoot> { | 400 | pub struct PointerType<'a> { |
401 | syntax: SyntaxNode<R>, | 401 | syntax: SyntaxNodeRef<'a>, |
402 | } | 402 | } |
403 | 403 | ||
404 | impl<R: TreeRoot> AstNode<R> for PointerType<R> { | 404 | impl<'a> AstNode<'a> for PointerType<'a> { |
405 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 405 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
406 | match syntax.kind() { | 406 | match syntax.kind() { |
407 | POINTER_TYPE => Some(PointerType { syntax }), | 407 | POINTER_TYPE => Some(PointerType { syntax }), |
408 | _ => None, | 408 | _ => None, |
409 | } | 409 | } |
410 | } | 410 | } |
411 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 411 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
412 | } | 412 | } |
413 | 413 | ||
414 | impl<R: TreeRoot> PointerType<R> {} | 414 | impl<'a> PointerType<'a> {} |
415 | 415 | ||
416 | // ReferenceType | 416 | // ReferenceType |
417 | #[derive(Debug, Clone, Copy)] | 417 | #[derive(Debug, Clone, Copy)] |
418 | pub struct ReferenceType<R: TreeRoot = OwnedRoot> { | 418 | pub struct ReferenceType<'a> { |
419 | syntax: SyntaxNode<R>, | 419 | syntax: SyntaxNodeRef<'a>, |
420 | } | 420 | } |
421 | 421 | ||
422 | impl<R: TreeRoot> AstNode<R> for ReferenceType<R> { | 422 | impl<'a> AstNode<'a> for ReferenceType<'a> { |
423 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 423 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
424 | match syntax.kind() { | 424 | match syntax.kind() { |
425 | REFERENCE_TYPE => Some(ReferenceType { syntax }), | 425 | REFERENCE_TYPE => Some(ReferenceType { syntax }), |
426 | _ => None, | 426 | _ => None, |
427 | } | 427 | } |
428 | } | 428 | } |
429 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 429 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
430 | } | 430 | } |
431 | 431 | ||
432 | impl<R: TreeRoot> ReferenceType<R> {} | 432 | impl<'a> ReferenceType<'a> {} |
433 | 433 | ||
434 | // SliceType | 434 | // SliceType |
435 | #[derive(Debug, Clone, Copy)] | 435 | #[derive(Debug, Clone, Copy)] |
436 | pub struct SliceType<R: TreeRoot = OwnedRoot> { | 436 | pub struct SliceType<'a> { |
437 | syntax: SyntaxNode<R>, | 437 | syntax: SyntaxNodeRef<'a>, |
438 | } | 438 | } |
439 | 439 | ||
440 | impl<R: TreeRoot> AstNode<R> for SliceType<R> { | 440 | impl<'a> AstNode<'a> for SliceType<'a> { |
441 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 441 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
442 | match syntax.kind() { | 442 | match syntax.kind() { |
443 | SLICE_TYPE => Some(SliceType { syntax }), | 443 | SLICE_TYPE => Some(SliceType { syntax }), |
444 | _ => None, | 444 | _ => None, |
445 | } | 445 | } |
446 | } | 446 | } |
447 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 447 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
448 | } | 448 | } |
449 | 449 | ||
450 | impl<R: TreeRoot> SliceType<R> {} | 450 | impl<'a> SliceType<'a> {} |
451 | 451 | ||
452 | // StaticDef | 452 | // StaticDef |
453 | #[derive(Debug, Clone, Copy)] | 453 | #[derive(Debug, Clone, Copy)] |
454 | pub struct StaticDef<R: TreeRoot = OwnedRoot> { | 454 | pub struct StaticDef<'a> { |
455 | syntax: SyntaxNode<R>, | 455 | syntax: SyntaxNodeRef<'a>, |
456 | } | 456 | } |
457 | 457 | ||
458 | impl<R: TreeRoot> AstNode<R> for StaticDef<R> { | 458 | impl<'a> AstNode<'a> for StaticDef<'a> { |
459 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 459 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
460 | match syntax.kind() { | 460 | match syntax.kind() { |
461 | STATIC_DEF => Some(StaticDef { syntax }), | 461 | STATIC_DEF => Some(StaticDef { syntax }), |
462 | _ => None, | 462 | _ => None, |
463 | } | 463 | } |
464 | } | 464 | } |
465 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 465 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
466 | } | 466 | } |
467 | 467 | ||
468 | impl<R: TreeRoot> ast::NameOwner<R> for StaticDef<R> {} | 468 | impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} |
469 | impl<R: TreeRoot> ast::AttrsOwner<R> for StaticDef<R> {} | 469 | impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} |
470 | impl<R: TreeRoot> StaticDef<R> {} | 470 | impl<'a> StaticDef<'a> {} |
471 | 471 | ||
472 | // StructDef | 472 | // StructDef |
473 | #[derive(Debug, Clone, Copy)] | 473 | #[derive(Debug, Clone, Copy)] |
474 | pub struct StructDef<R: TreeRoot = OwnedRoot> { | 474 | pub struct StructDef<'a> { |
475 | syntax: SyntaxNode<R>, | 475 | syntax: SyntaxNodeRef<'a>, |
476 | } | 476 | } |
477 | 477 | ||
478 | impl<R: TreeRoot> AstNode<R> for StructDef<R> { | 478 | impl<'a> AstNode<'a> for StructDef<'a> { |
479 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 479 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
480 | match syntax.kind() { | 480 | match syntax.kind() { |
481 | STRUCT_DEF => Some(StructDef { syntax }), | 481 | STRUCT_DEF => Some(StructDef { syntax }), |
482 | _ => None, | 482 | _ => None, |
483 | } | 483 | } |
484 | } | 484 | } |
485 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 485 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
486 | } | 486 | } |
487 | 487 | ||
488 | impl<R: TreeRoot> ast::NameOwner<R> for StructDef<R> {} | 488 | impl<'a> ast::NameOwner<'a> for StructDef<'a> {} |
489 | impl<R: TreeRoot> ast::AttrsOwner<R> for StructDef<R> {} | 489 | impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} |
490 | impl<R: TreeRoot> StructDef<R> { | 490 | impl<'a> StructDef<'a> { |
491 | pub fn fields<'a>(&'a self) -> impl Iterator<Item = NamedField<R>> + 'a { | 491 | pub fn fields(self) -> impl Iterator<Item = NamedField<'a>> + 'a { |
492 | self.syntax() | 492 | self.syntax() |
493 | .children() | 493 | .children() |
494 | .filter_map(NamedField::cast) | 494 | .filter_map(NamedField::cast) |
@@ -497,100 +497,100 @@ impl<R: TreeRoot> StructDef<R> { | |||
497 | 497 | ||
498 | // TokenTree | 498 | // TokenTree |
499 | #[derive(Debug, Clone, Copy)] | 499 | #[derive(Debug, Clone, Copy)] |
500 | pub struct TokenTree<R: TreeRoot = OwnedRoot> { | 500 | pub struct TokenTree<'a> { |
501 | syntax: SyntaxNode<R>, | 501 | syntax: SyntaxNodeRef<'a>, |
502 | } | 502 | } |
503 | 503 | ||
504 | impl<R: TreeRoot> AstNode<R> for TokenTree<R> { | 504 | impl<'a> AstNode<'a> for TokenTree<'a> { |
505 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 505 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
506 | match syntax.kind() { | 506 | match syntax.kind() { |
507 | TOKEN_TREE => Some(TokenTree { syntax }), | 507 | TOKEN_TREE => Some(TokenTree { syntax }), |
508 | _ => None, | 508 | _ => None, |
509 | } | 509 | } |
510 | } | 510 | } |
511 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 511 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
512 | } | 512 | } |
513 | 513 | ||
514 | impl<R: TreeRoot> TokenTree<R> {} | 514 | impl<'a> TokenTree<'a> {} |
515 | 515 | ||
516 | // TraitDef | 516 | // TraitDef |
517 | #[derive(Debug, Clone, Copy)] | 517 | #[derive(Debug, Clone, Copy)] |
518 | pub struct TraitDef<R: TreeRoot = OwnedRoot> { | 518 | pub struct TraitDef<'a> { |
519 | syntax: SyntaxNode<R>, | 519 | syntax: SyntaxNodeRef<'a>, |
520 | } | 520 | } |
521 | 521 | ||
522 | impl<R: TreeRoot> AstNode<R> for TraitDef<R> { | 522 | impl<'a> AstNode<'a> for TraitDef<'a> { |
523 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 523 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
524 | match syntax.kind() { | 524 | match syntax.kind() { |
525 | TRAIT_DEF => Some(TraitDef { syntax }), | 525 | TRAIT_DEF => Some(TraitDef { syntax }), |
526 | _ => None, | 526 | _ => None, |
527 | } | 527 | } |
528 | } | 528 | } |
529 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 529 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
530 | } | 530 | } |
531 | 531 | ||
532 | impl<R: TreeRoot> ast::NameOwner<R> for TraitDef<R> {} | 532 | impl<'a> ast::NameOwner<'a> for TraitDef<'a> {} |
533 | impl<R: TreeRoot> ast::AttrsOwner<R> for TraitDef<R> {} | 533 | impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {} |
534 | impl<R: TreeRoot> TraitDef<R> {} | 534 | impl<'a> TraitDef<'a> {} |
535 | 535 | ||
536 | // TupleType | 536 | // TupleType |
537 | #[derive(Debug, Clone, Copy)] | 537 | #[derive(Debug, Clone, Copy)] |
538 | pub struct TupleType<R: TreeRoot = OwnedRoot> { | 538 | pub struct TupleType<'a> { |
539 | syntax: SyntaxNode<R>, | 539 | syntax: SyntaxNodeRef<'a>, |
540 | } | 540 | } |
541 | 541 | ||
542 | impl<R: TreeRoot> AstNode<R> for TupleType<R> { | 542 | impl<'a> AstNode<'a> for TupleType<'a> { |
543 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 543 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
544 | match syntax.kind() { | 544 | match syntax.kind() { |
545 | TUPLE_TYPE => Some(TupleType { syntax }), | 545 | TUPLE_TYPE => Some(TupleType { syntax }), |
546 | _ => None, | 546 | _ => None, |
547 | } | 547 | } |
548 | } | 548 | } |
549 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 549 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
550 | } | 550 | } |
551 | 551 | ||
552 | impl<R: TreeRoot> TupleType<R> {} | 552 | impl<'a> TupleType<'a> {} |
553 | 553 | ||
554 | // TypeDef | 554 | // TypeDef |
555 | #[derive(Debug, Clone, Copy)] | 555 | #[derive(Debug, Clone, Copy)] |
556 | pub struct TypeDef<R: TreeRoot = OwnedRoot> { | 556 | pub struct TypeDef<'a> { |
557 | syntax: SyntaxNode<R>, | 557 | syntax: SyntaxNodeRef<'a>, |
558 | } | 558 | } |
559 | 559 | ||
560 | impl<R: TreeRoot> AstNode<R> for TypeDef<R> { | 560 | impl<'a> AstNode<'a> for TypeDef<'a> { |
561 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 561 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
562 | match syntax.kind() { | 562 | match syntax.kind() { |
563 | TYPE_DEF => Some(TypeDef { syntax }), | 563 | TYPE_DEF => Some(TypeDef { syntax }), |
564 | _ => None, | 564 | _ => None, |
565 | } | 565 | } |
566 | } | 566 | } |
567 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 567 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
568 | } | 568 | } |
569 | 569 | ||
570 | impl<R: TreeRoot> ast::NameOwner<R> for TypeDef<R> {} | 570 | impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} |
571 | impl<R: TreeRoot> ast::AttrsOwner<R> for TypeDef<R> {} | 571 | impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} |
572 | impl<R: TreeRoot> TypeDef<R> {} | 572 | impl<'a> TypeDef<'a> {} |
573 | 573 | ||
574 | // TypeRef | 574 | // TypeRef |
575 | #[derive(Debug, Clone, Copy)] | 575 | #[derive(Debug, Clone, Copy)] |
576 | pub enum TypeRef<R: TreeRoot = OwnedRoot> { | 576 | pub enum TypeRef<'a> { |
577 | ParenType(ParenType<R>), | 577 | ParenType(ParenType<'a>), |
578 | TupleType(TupleType<R>), | 578 | TupleType(TupleType<'a>), |
579 | NeverType(NeverType<R>), | 579 | NeverType(NeverType<'a>), |
580 | PathType(PathType<R>), | 580 | PathType(PathType<'a>), |
581 | PointerType(PointerType<R>), | 581 | PointerType(PointerType<'a>), |
582 | ArrayType(ArrayType<R>), | 582 | ArrayType(ArrayType<'a>), |
583 | SliceType(SliceType<R>), | 583 | SliceType(SliceType<'a>), |
584 | ReferenceType(ReferenceType<R>), | 584 | ReferenceType(ReferenceType<'a>), |
585 | PlaceholderType(PlaceholderType<R>), | 585 | PlaceholderType(PlaceholderType<'a>), |
586 | FnPointerType(FnPointerType<R>), | 586 | FnPointerType(FnPointerType<'a>), |
587 | ForType(ForType<R>), | 587 | ForType(ForType<'a>), |
588 | ImplTraitType(ImplTraitType<R>), | 588 | ImplTraitType(ImplTraitType<'a>), |
589 | DynTraitType(DynTraitType<R>), | 589 | DynTraitType(DynTraitType<'a>), |
590 | } | 590 | } |
591 | 591 | ||
592 | impl<R: TreeRoot> AstNode<R> for TypeRef<R> { | 592 | impl<'a> AstNode<'a> for TypeRef<'a> { |
593 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 593 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
594 | match syntax.kind() { | 594 | match syntax.kind() { |
595 | PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })), | 595 | PAREN_TYPE => Some(TypeRef::ParenType(ParenType { syntax })), |
596 | TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })), | 596 | TUPLE_TYPE => Some(TypeRef::TupleType(TupleType { syntax })), |
@@ -608,7 +608,7 @@ impl<R: TreeRoot> AstNode<R> for TypeRef<R> { | |||
608 | _ => None, | 608 | _ => None, |
609 | } | 609 | } |
610 | } | 610 | } |
611 | fn syntax(&self) -> &SyntaxNode<R> { | 611 | fn syntax(self) -> SyntaxNodeRef<'a> { |
612 | match self { | 612 | match self { |
613 | TypeRef::ParenType(inner) => inner.syntax(), | 613 | TypeRef::ParenType(inner) => inner.syntax(), |
614 | TypeRef::TupleType(inner) => inner.syntax(), | 614 | TypeRef::TupleType(inner) => inner.syntax(), |
@@ -627,5 +627,5 @@ impl<R: TreeRoot> AstNode<R> for TypeRef<R> { | |||
627 | } | 627 | } |
628 | } | 628 | } |
629 | 629 | ||
630 | impl<R: TreeRoot> TypeRef<R> {} | 630 | impl<'a> TypeRef<'a> {} |
631 | 631 | ||
diff --git a/crates/libsyntax2/src/ast/generated.rs.tera b/crates/libsyntax2/src/ast/generated.rs.tera index f83da0326..0572cceaa 100644 --- a/crates/libsyntax2/src/ast/generated.rs.tera +++ b/crates/libsyntax2/src/ast/generated.rs.tera | |||
@@ -1,21 +1,20 @@ | |||
1 | use std::sync::Arc; | ||
2 | use { | 1 | use { |
3 | ast, | 2 | ast, |
4 | SyntaxNode, SyntaxRoot, TreeRoot, AstNode, | 3 | SyntaxNodeRef, AstNode, |
5 | SyntaxKind::*, | 4 | SyntaxKind::*, |
6 | }; | 5 | }; |
7 | {% for node, methods in ast %} | 6 | {% for node, methods in ast %} |
8 | // {{ node }} | 7 | // {{ node }} |
9 | {%- if methods.enum %} | 8 | {%- if methods.enum %} |
10 | #[derive(Debug, Clone, Copy)] | 9 | #[derive(Debug, Clone, Copy)] |
11 | pub enum {{ node }}<R: TreeRoot = Arc<SyntaxRoot>> { | 10 | pub enum {{ node }}<'a> { |
12 | {%- for kind in methods.enum %} | 11 | {%- for kind in methods.enum %} |
13 | {{ kind }}({{ kind }}<R>), | 12 | {{ kind }}({{ kind }}<'a>), |
14 | {%- endfor %} | 13 | {%- endfor %} |
15 | } | 14 | } |
16 | 15 | ||
17 | impl<R: TreeRoot> AstNode<R> for {{ node }}<R> { | 16 | impl<'a> AstNode<'a> for {{ node }}<'a> { |
18 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 17 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
19 | match syntax.kind() { | 18 | match syntax.kind() { |
20 | {%- for kind in methods.enum %} | 19 | {%- for kind in methods.enum %} |
21 | {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })), | 20 | {{ kind | SCREAM }} => Some({{ node }}::{{ kind }}({{ kind }} { syntax })), |
@@ -23,7 +22,7 @@ impl<R: TreeRoot> AstNode<R> for {{ node }}<R> { | |||
23 | _ => None, | 22 | _ => None, |
24 | } | 23 | } |
25 | } | 24 | } |
26 | fn syntax(&self) -> &SyntaxNode<R> { | 25 | fn syntax(self) -> SyntaxNodeRef<'a> { |
27 | match self { | 26 | match self { |
28 | {%- for kind in methods.enum %} | 27 | {%- for kind in methods.enum %} |
29 | {{ node }}::{{ kind }}(inner) => inner.syntax(), | 28 | {{ node }}::{{ kind }}(inner) => inner.syntax(), |
@@ -33,32 +32,32 @@ impl<R: TreeRoot> AstNode<R> for {{ node }}<R> { | |||
33 | } | 32 | } |
34 | {% else %} | 33 | {% else %} |
35 | #[derive(Debug, Clone, Copy)] | 34 | #[derive(Debug, Clone, Copy)] |
36 | pub struct {{ node }}<R: TreeRoot = Arc<SyntaxRoot>> { | 35 | pub struct {{ node }}<'a> { |
37 | syntax: SyntaxNode<R>, | 36 | syntax: SyntaxNodeRef<'a>, |
38 | } | 37 | } |
39 | 38 | ||
40 | impl<R: TreeRoot> AstNode<R> for {{ node }}<R> { | 39 | impl<'a> AstNode<'a> for {{ node }}<'a> { |
41 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> { | 40 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
42 | match syntax.kind() { | 41 | match syntax.kind() { |
43 | {{ node | SCREAM }} => Some({{ node }} { syntax }), | 42 | {{ node | SCREAM }} => Some({{ node }} { syntax }), |
44 | _ => None, | 43 | _ => None, |
45 | } | 44 | } |
46 | } | 45 | } |
47 | fn syntax(&self) -> &SyntaxNode<R> { &self.syntax } | 46 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
48 | } | 47 | } |
49 | {% endif %} | 48 | {% endif %} |
50 | {% if methods.traits -%} | 49 | {% if methods.traits -%} |
51 | {%- for t in methods.traits -%} | 50 | {%- for t in methods.traits -%} |
52 | impl<R: TreeRoot> ast::{{ t }}<R> for {{ node }}<R> {} | 51 | impl<'a> ast::{{ t }}<'a> for {{ node }}<'a> {} |
53 | {% endfor -%} | 52 | {% endfor -%} |
54 | {%- endif -%} | 53 | {%- endif -%} |
55 | 54 | ||
56 | impl<R: TreeRoot> {{ node }}<R> { | 55 | impl<'a> {{ node }}<'a> { |
57 | {%- if methods.collections -%} | 56 | {%- if methods.collections -%} |
58 | {%- for m in methods.collections -%} | 57 | {%- for m in methods.collections -%} |
59 | {%- set method_name = m.0 -%} | 58 | {%- set method_name = m.0 -%} |
60 | {%- set ChildName = m.1 %} | 59 | {%- set ChildName = m.1 %} |
61 | pub fn {{ method_name }}<'a>(&'a self) -> impl Iterator<Item = {{ ChildName }}<R>> + 'a { | 60 | pub fn {{ method_name }}(self) -> impl Iterator<Item = {{ ChildName }}<'a>> + 'a { |
62 | self.syntax() | 61 | self.syntax() |
63 | .children() | 62 | .children() |
64 | .filter_map({{ ChildName }}::cast) | 63 | .filter_map({{ ChildName }}::cast) |
@@ -70,7 +69,7 @@ impl<R: TreeRoot> {{ node }}<R> { | |||
70 | {%- for m in methods.options -%} | 69 | {%- for m in methods.options -%} |
71 | {%- set method_name = m.0 -%} | 70 | {%- set method_name = m.0 -%} |
72 | {%- set ChildName = m.1 %} | 71 | {%- set ChildName = m.1 %} |
73 | pub fn {{ method_name }}(&self) -> Option<{{ ChildName }}<R>> { | 72 | pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> { |
74 | self.syntax() | 73 | self.syntax() |
75 | .children() | 74 | .children() |
76 | .filter_map({{ ChildName }}::cast) | 75 | .filter_map({{ ChildName }}::cast) |
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index b52230e9c..46509b5ec 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs | |||
@@ -4,22 +4,19 @@ use itertools::Itertools; | |||
4 | use smol_str::SmolStr; | 4 | use smol_str::SmolStr; |
5 | 5 | ||
6 | use { | 6 | use { |
7 | SyntaxNode, SyntaxNodeRef, OwnedRoot, TreeRoot, SyntaxError, | 7 | SyntaxNode, SyntaxNodeRef, TreeRoot, SyntaxError, |
8 | SyntaxKind::*, | 8 | SyntaxKind::*, |
9 | }; | 9 | }; |
10 | pub use self::generated::*; | 10 | pub use self::generated::*; |
11 | 11 | ||
12 | pub trait AstNode<R: TreeRoot> { | 12 | pub trait AstNode<'a>: Clone + Copy { |
13 | fn cast(syntax: SyntaxNode<R>) -> Option<Self> | 13 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> |
14 | where Self: Sized; | 14 | where Self: Sized; |
15 | fn syntax(&self) -> &SyntaxNode<R>; | 15 | fn syntax(self) -> SyntaxNodeRef<'a>; |
16 | fn syntax_ref<'a>(&'a self) -> SyntaxNodeRef<'a> where R: 'a { | ||
17 | self.syntax().as_ref() | ||
18 | } | ||
19 | } | 16 | } |
20 | 17 | ||
21 | pub trait NameOwner<R: TreeRoot>: AstNode<R> { | 18 | pub trait NameOwner<'a>: AstNode<'a> { |
22 | fn name(&self) -> Option<Name<R>> { | 19 | fn name(self) -> Option<Name<'a>> { |
23 | self.syntax() | 20 | self.syntax() |
24 | .children() | 21 | .children() |
25 | .filter_map(Name::cast) | 22 | .filter_map(Name::cast) |
@@ -27,27 +24,37 @@ pub trait NameOwner<R: TreeRoot>: AstNode<R> { | |||
27 | } | 24 | } |
28 | } | 25 | } |
29 | 26 | ||
30 | pub trait AttrsOwner<R: TreeRoot>: AstNode<R> { | 27 | pub trait AttrsOwner<'a>: AstNode<'a> { |
31 | fn attrs<'a>(&'a self) -> Box<Iterator<Item=Attr<R>> + 'a> where R: 'a { | 28 | fn attrs(&self) -> Box<Iterator<Item=Attr<'a>> + 'a> { |
32 | let it = self.syntax().children() | 29 | let it = self.syntax().children() |
33 | .filter_map(Attr::cast); | 30 | .filter_map(Attr::cast); |
34 | Box::new(it) | 31 | Box::new(it) |
35 | } | 32 | } |
36 | } | 33 | } |
37 | 34 | ||
38 | impl File<OwnedRoot> { | 35 | #[derive(Clone, Debug)] |
39 | pub fn parse(text: &str) -> Self { | 36 | pub struct ParsedFile { |
40 | File::cast(::parse(text)).unwrap() | 37 | root: SyntaxNode |
41 | } | ||
42 | } | 38 | } |
43 | 39 | ||
44 | impl<R: TreeRoot> File<R> { | 40 | impl ParsedFile { |
41 | pub fn parse(text: &str) -> Self { | ||
42 | let root = ::parse(text); | ||
43 | ParsedFile { root } | ||
44 | } | ||
45 | pub fn ast(&self) -> File { | ||
46 | File::cast(self.syntax()).unwrap() | ||
47 | } | ||
48 | pub fn syntax(&self) -> SyntaxNodeRef { | ||
49 | self.root.as_ref() | ||
50 | } | ||
45 | pub fn errors(&self) -> Vec<SyntaxError> { | 51 | pub fn errors(&self) -> Vec<SyntaxError> { |
46 | self.syntax().root.syntax_root().errors.clone() | 52 | self.syntax().root.syntax_root().errors.clone() |
47 | } | 53 | } |
54 | |||
48 | } | 55 | } |
49 | 56 | ||
50 | impl<R: TreeRoot> FnDef<R> { | 57 | impl<'a> FnDef<'a> { |
51 | pub fn has_atom_attr(&self, atom: &str) -> bool { | 58 | pub fn has_atom_attr(&self, atom: &str) -> bool { |
52 | self.attrs() | 59 | self.attrs() |
53 | .filter_map(|x| x.as_atom()) | 60 | .filter_map(|x| x.as_atom()) |
@@ -55,7 +62,7 @@ impl<R: TreeRoot> FnDef<R> { | |||
55 | } | 62 | } |
56 | } | 63 | } |
57 | 64 | ||
58 | impl<R: TreeRoot> Attr<R> { | 65 | impl<'a> Attr<'a> { |
59 | pub fn as_atom(&self) -> Option<SmolStr> { | 66 | pub fn as_atom(&self) -> Option<SmolStr> { |
60 | let tt = self.value()?; | 67 | let tt = self.value()?; |
61 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; | 68 | let (_bra, attr, _ket) = tt.syntax().children().collect_tuple()?; |
@@ -66,7 +73,7 @@ impl<R: TreeRoot> Attr<R> { | |||
66 | } | 73 | } |
67 | } | 74 | } |
68 | 75 | ||
69 | pub fn as_call(&self) -> Option<(SmolStr, TokenTree<R>)> { | 76 | pub fn as_call(&self) -> Option<(SmolStr, TokenTree<'a>)> { |
70 | let tt = self.value()?; | 77 | let tt = self.value()?; |
71 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; | 78 | let (_bra, attr, args, _ket) = tt.syntax().children().collect_tuple()?; |
72 | let args = TokenTree::cast(args)?; | 79 | let args = TokenTree::cast(args)?; |
@@ -78,7 +85,7 @@ impl<R: TreeRoot> Attr<R> { | |||
78 | } | 85 | } |
79 | } | 86 | } |
80 | 87 | ||
81 | impl<R: TreeRoot> Name<R> { | 88 | impl<'a> Name<'a> { |
82 | pub fn text(&self) -> SmolStr { | 89 | pub fn text(&self) -> SmolStr { |
83 | let ident = self.syntax().first_child() | 90 | let ident = self.syntax().first_child() |
84 | .unwrap(); | 91 | .unwrap(); |
@@ -86,7 +93,7 @@ impl<R: TreeRoot> Name<R> { | |||
86 | } | 93 | } |
87 | } | 94 | } |
88 | 95 | ||
89 | impl<R: TreeRoot> NameRef<R> { | 96 | impl<'a> NameRef<'a> { |
90 | pub fn text(&self) -> SmolStr { | 97 | pub fn text(&self) -> SmolStr { |
91 | let ident = self.syntax().first_child() | 98 | let ident = self.syntax().first_child() |
92 | .unwrap(); | 99 | .unwrap(); |
@@ -94,22 +101,22 @@ impl<R: TreeRoot> NameRef<R> { | |||
94 | } | 101 | } |
95 | } | 102 | } |
96 | 103 | ||
97 | impl <R: TreeRoot> ImplItem<R> { | 104 | impl<'a> ImplItem<'a> { |
98 | pub fn target_type(&self) -> Option<TypeRef<R>> { | 105 | pub fn target_type(&self) -> Option<TypeRef<'a>> { |
99 | match self.target() { | 106 | match self.target() { |
100 | (Some(t), None) | (_, Some(t)) => Some(t), | 107 | (Some(t), None) | (_, Some(t)) => Some(t), |
101 | _ => None, | 108 | _ => None, |
102 | } | 109 | } |
103 | } | 110 | } |
104 | 111 | ||
105 | pub fn target_trait(&self) -> Option<TypeRef<R>> { | 112 | pub fn target_trait(&self) -> Option<TypeRef<'a>> { |
106 | match self.target() { | 113 | match self.target() { |
107 | (Some(t), Some(_)) => Some(t), | 114 | (Some(t), Some(_)) => Some(t), |
108 | _ => None, | 115 | _ => None, |
109 | } | 116 | } |
110 | } | 117 | } |
111 | 118 | ||
112 | fn target(&self) -> (Option<TypeRef<R>>, Option<TypeRef<R>>) { | 119 | fn target(&self) -> (Option<TypeRef<'a>>, Option<TypeRef<'a>>) { |
113 | let mut types = self.syntax().children().filter_map(TypeRef::cast); | 120 | let mut types = self.syntax().children().filter_map(TypeRef::cast); |
114 | let first = types.next(); | 121 | let first = types.next(); |
115 | let second = types.next(); | 122 | let second = types.next(); |
@@ -117,9 +124,9 @@ impl <R: TreeRoot> ImplItem<R> { | |||
117 | } | 124 | } |
118 | } | 125 | } |
119 | 126 | ||
120 | impl <R: TreeRoot> Module<R> { | 127 | impl<'a> Module<'a> { |
121 | pub fn has_semi(&self) -> bool { | 128 | pub fn has_semi(&self) -> bool { |
122 | match self.syntax_ref().last_child() { | 129 | match self.syntax().last_child() { |
123 | None => false, | 130 | None => false, |
124 | Some(node) => node.kind() == SEMI, | 131 | Some(node) => node.kind() == SEMI, |
125 | } | 132 | } |