diff options
Diffstat (limited to 'crates/ra_syntax/src')
24 files changed, 2631 insertions, 647 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 420d9090c..bf056131e 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -9,6 +9,8 @@ | |||
9 | 9 | ||
10 | #![cfg_attr(rustfmt, rustfmt_skip)] | 10 | #![cfg_attr(rustfmt, rustfmt_skip)] |
11 | 11 | ||
12 | use std::hash::{Hash, Hasher}; | ||
13 | |||
12 | use crate::{ | 14 | use crate::{ |
13 | ast, | 15 | ast, |
14 | SyntaxNode, SyntaxNodeRef, AstNode, | 16 | SyntaxNode, SyntaxNodeRef, AstNode, |
@@ -17,12 +19,20 @@ use crate::{ | |||
17 | }; | 19 | }; |
18 | 20 | ||
19 | // ArgList | 21 | // ArgList |
20 | #[derive(Debug, Clone, Copy)] | 22 | #[derive(Debug, Clone, Copy,)] |
21 | pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 23 | pub struct ArgListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
22 | syntax: SyntaxNode<R>, | 24 | pub(crate) syntax: SyntaxNode<R>, |
23 | } | 25 | } |
24 | pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; | 26 | pub type ArgList<'a> = ArgListNode<RefRoot<'a>>; |
25 | 27 | ||
28 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArgListNode<R1>> for ArgListNode<R2> { | ||
29 | fn eq(&self, other: &ArgListNode<R1>) -> bool { self.syntax == other.syntax } | ||
30 | } | ||
31 | impl<R: TreeRoot<RaTypes>> Eq for ArgListNode<R> {} | ||
32 | impl<R: TreeRoot<RaTypes>> Hash for ArgListNode<R> { | ||
33 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
34 | } | ||
35 | |||
26 | impl<'a> AstNode<'a> for ArgList<'a> { | 36 | impl<'a> AstNode<'a> for ArgList<'a> { |
27 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 37 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
28 | match syntax.kind() { | 38 | match syntax.kind() { |
@@ -50,12 +60,20 @@ impl<'a> ArgList<'a> { | |||
50 | } | 60 | } |
51 | 61 | ||
52 | // ArrayExpr | 62 | // ArrayExpr |
53 | #[derive(Debug, Clone, Copy)] | 63 | #[derive(Debug, Clone, Copy,)] |
54 | pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 64 | pub struct ArrayExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
55 | syntax: SyntaxNode<R>, | 65 | pub(crate) syntax: SyntaxNode<R>, |
56 | } | 66 | } |
57 | pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; | 67 | pub type ArrayExpr<'a> = ArrayExprNode<RefRoot<'a>>; |
58 | 68 | ||
69 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayExprNode<R1>> for ArrayExprNode<R2> { | ||
70 | fn eq(&self, other: &ArrayExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
71 | } | ||
72 | impl<R: TreeRoot<RaTypes>> Eq for ArrayExprNode<R> {} | ||
73 | impl<R: TreeRoot<RaTypes>> Hash for ArrayExprNode<R> { | ||
74 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
75 | } | ||
76 | |||
59 | impl<'a> AstNode<'a> for ArrayExpr<'a> { | 77 | impl<'a> AstNode<'a> for ArrayExpr<'a> { |
60 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 78 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
61 | match syntax.kind() { | 79 | match syntax.kind() { |
@@ -79,12 +97,20 @@ impl<R: TreeRoot<RaTypes>> ArrayExprNode<R> { | |||
79 | impl<'a> ArrayExpr<'a> {} | 97 | impl<'a> ArrayExpr<'a> {} |
80 | 98 | ||
81 | // ArrayType | 99 | // ArrayType |
82 | #[derive(Debug, Clone, Copy)] | 100 | #[derive(Debug, Clone, Copy,)] |
83 | pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 101 | pub struct ArrayTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
84 | syntax: SyntaxNode<R>, | 102 | pub(crate) syntax: SyntaxNode<R>, |
85 | } | 103 | } |
86 | pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>; | 104 | pub type ArrayType<'a> = ArrayTypeNode<RefRoot<'a>>; |
87 | 105 | ||
106 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ArrayTypeNode<R1>> for ArrayTypeNode<R2> { | ||
107 | fn eq(&self, other: &ArrayTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
108 | } | ||
109 | impl<R: TreeRoot<RaTypes>> Eq for ArrayTypeNode<R> {} | ||
110 | impl<R: TreeRoot<RaTypes>> Hash for ArrayTypeNode<R> { | ||
111 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
112 | } | ||
113 | |||
88 | impl<'a> AstNode<'a> for ArrayType<'a> { | 114 | impl<'a> AstNode<'a> for ArrayType<'a> { |
89 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 115 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
90 | match syntax.kind() { | 116 | match syntax.kind() { |
@@ -108,12 +134,20 @@ impl<R: TreeRoot<RaTypes>> ArrayTypeNode<R> { | |||
108 | impl<'a> ArrayType<'a> {} | 134 | impl<'a> ArrayType<'a> {} |
109 | 135 | ||
110 | // Attr | 136 | // Attr |
111 | #[derive(Debug, Clone, Copy)] | 137 | #[derive(Debug, Clone, Copy,)] |
112 | pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 138 | pub struct AttrNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
113 | syntax: SyntaxNode<R>, | 139 | pub(crate) syntax: SyntaxNode<R>, |
114 | } | 140 | } |
115 | pub type Attr<'a> = AttrNode<RefRoot<'a>>; | 141 | pub type Attr<'a> = AttrNode<RefRoot<'a>>; |
116 | 142 | ||
143 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<AttrNode<R1>> for AttrNode<R2> { | ||
144 | fn eq(&self, other: &AttrNode<R1>) -> bool { self.syntax == other.syntax } | ||
145 | } | ||
146 | impl<R: TreeRoot<RaTypes>> Eq for AttrNode<R> {} | ||
147 | impl<R: TreeRoot<RaTypes>> Hash for AttrNode<R> { | ||
148 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
149 | } | ||
150 | |||
117 | impl<'a> AstNode<'a> for Attr<'a> { | 151 | impl<'a> AstNode<'a> for Attr<'a> { |
118 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 152 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
119 | match syntax.kind() { | 153 | match syntax.kind() { |
@@ -141,12 +175,20 @@ impl<'a> Attr<'a> { | |||
141 | } | 175 | } |
142 | 176 | ||
143 | // BinExpr | 177 | // BinExpr |
144 | #[derive(Debug, Clone, Copy)] | 178 | #[derive(Debug, Clone, Copy,)] |
145 | pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 179 | pub struct BinExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
146 | syntax: SyntaxNode<R>, | 180 | pub(crate) syntax: SyntaxNode<R>, |
147 | } | 181 | } |
148 | pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>; | 182 | pub type BinExpr<'a> = BinExprNode<RefRoot<'a>>; |
149 | 183 | ||
184 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BinExprNode<R1>> for BinExprNode<R2> { | ||
185 | fn eq(&self, other: &BinExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
186 | } | ||
187 | impl<R: TreeRoot<RaTypes>> Eq for BinExprNode<R> {} | ||
188 | impl<R: TreeRoot<RaTypes>> Hash for BinExprNode<R> { | ||
189 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
190 | } | ||
191 | |||
150 | impl<'a> AstNode<'a> for BinExpr<'a> { | 192 | impl<'a> AstNode<'a> for BinExpr<'a> { |
151 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 193 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
152 | match syntax.kind() { | 194 | match syntax.kind() { |
@@ -170,12 +212,20 @@ impl<R: TreeRoot<RaTypes>> BinExprNode<R> { | |||
170 | impl<'a> BinExpr<'a> {} | 212 | impl<'a> BinExpr<'a> {} |
171 | 213 | ||
172 | // BindPat | 214 | // BindPat |
173 | #[derive(Debug, Clone, Copy)] | 215 | #[derive(Debug, Clone, Copy,)] |
174 | pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 216 | pub struct BindPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
175 | syntax: SyntaxNode<R>, | 217 | pub(crate) syntax: SyntaxNode<R>, |
176 | } | 218 | } |
177 | pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; | 219 | pub type BindPat<'a> = BindPatNode<RefRoot<'a>>; |
178 | 220 | ||
221 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BindPatNode<R1>> for BindPatNode<R2> { | ||
222 | fn eq(&self, other: &BindPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
223 | } | ||
224 | impl<R: TreeRoot<RaTypes>> Eq for BindPatNode<R> {} | ||
225 | impl<R: TreeRoot<RaTypes>> Hash for BindPatNode<R> { | ||
226 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
227 | } | ||
228 | |||
179 | impl<'a> AstNode<'a> for BindPat<'a> { | 229 | impl<'a> AstNode<'a> for BindPat<'a> { |
180 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 230 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
181 | match syntax.kind() { | 231 | match syntax.kind() { |
@@ -200,12 +250,20 @@ impl<'a> ast::NameOwner<'a> for BindPat<'a> {} | |||
200 | impl<'a> BindPat<'a> {} | 250 | impl<'a> BindPat<'a> {} |
201 | 251 | ||
202 | // Block | 252 | // Block |
203 | #[derive(Debug, Clone, Copy)] | 253 | #[derive(Debug, Clone, Copy,)] |
204 | pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 254 | pub struct BlockNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
205 | syntax: SyntaxNode<R>, | 255 | pub(crate) syntax: SyntaxNode<R>, |
206 | } | 256 | } |
207 | pub type Block<'a> = BlockNode<RefRoot<'a>>; | 257 | pub type Block<'a> = BlockNode<RefRoot<'a>>; |
208 | 258 | ||
259 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockNode<R1>> for BlockNode<R2> { | ||
260 | fn eq(&self, other: &BlockNode<R1>) -> bool { self.syntax == other.syntax } | ||
261 | } | ||
262 | impl<R: TreeRoot<RaTypes>> Eq for BlockNode<R> {} | ||
263 | impl<R: TreeRoot<RaTypes>> Hash for BlockNode<R> { | ||
264 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
265 | } | ||
266 | |||
209 | impl<'a> AstNode<'a> for Block<'a> { | 267 | impl<'a> AstNode<'a> for Block<'a> { |
210 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 268 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
211 | match syntax.kind() { | 269 | match syntax.kind() { |
@@ -237,12 +295,20 @@ impl<'a> Block<'a> { | |||
237 | } | 295 | } |
238 | 296 | ||
239 | // BlockExpr | 297 | // BlockExpr |
240 | #[derive(Debug, Clone, Copy)] | 298 | #[derive(Debug, Clone, Copy,)] |
241 | pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 299 | pub struct BlockExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
242 | syntax: SyntaxNode<R>, | 300 | pub(crate) syntax: SyntaxNode<R>, |
243 | } | 301 | } |
244 | pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; | 302 | pub type BlockExpr<'a> = BlockExprNode<RefRoot<'a>>; |
245 | 303 | ||
304 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BlockExprNode<R1>> for BlockExprNode<R2> { | ||
305 | fn eq(&self, other: &BlockExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
306 | } | ||
307 | impl<R: TreeRoot<RaTypes>> Eq for BlockExprNode<R> {} | ||
308 | impl<R: TreeRoot<RaTypes>> Hash for BlockExprNode<R> { | ||
309 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
310 | } | ||
311 | |||
246 | impl<'a> AstNode<'a> for BlockExpr<'a> { | 312 | impl<'a> AstNode<'a> for BlockExpr<'a> { |
247 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 313 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
248 | match syntax.kind() { | 314 | match syntax.kind() { |
@@ -270,12 +336,20 @@ impl<'a> BlockExpr<'a> { | |||
270 | } | 336 | } |
271 | 337 | ||
272 | // BreakExpr | 338 | // BreakExpr |
273 | #[derive(Debug, Clone, Copy)] | 339 | #[derive(Debug, Clone, Copy,)] |
274 | pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 340 | pub struct BreakExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
275 | syntax: SyntaxNode<R>, | 341 | pub(crate) syntax: SyntaxNode<R>, |
276 | } | 342 | } |
277 | pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; | 343 | pub type BreakExpr<'a> = BreakExprNode<RefRoot<'a>>; |
278 | 344 | ||
345 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<BreakExprNode<R1>> for BreakExprNode<R2> { | ||
346 | fn eq(&self, other: &BreakExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
347 | } | ||
348 | impl<R: TreeRoot<RaTypes>> Eq for BreakExprNode<R> {} | ||
349 | impl<R: TreeRoot<RaTypes>> Hash for BreakExprNode<R> { | ||
350 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
351 | } | ||
352 | |||
279 | impl<'a> AstNode<'a> for BreakExpr<'a> { | 353 | impl<'a> AstNode<'a> for BreakExpr<'a> { |
280 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 354 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
281 | match syntax.kind() { | 355 | match syntax.kind() { |
@@ -298,13 +372,95 @@ impl<R: TreeRoot<RaTypes>> BreakExprNode<R> { | |||
298 | 372 | ||
299 | impl<'a> BreakExpr<'a> {} | 373 | impl<'a> BreakExpr<'a> {} |
300 | 374 | ||
375 | // Byte | ||
376 | #[derive(Debug, Clone, Copy,)] | ||
377 | pub struct ByteNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
378 | pub(crate) syntax: SyntaxNode<R>, | ||
379 | } | ||
380 | pub type Byte<'a> = ByteNode<RefRoot<'a>>; | ||
381 | |||
382 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteNode<R1>> for ByteNode<R2> { | ||
383 | fn eq(&self, other: &ByteNode<R1>) -> bool { self.syntax == other.syntax } | ||
384 | } | ||
385 | impl<R: TreeRoot<RaTypes>> Eq for ByteNode<R> {} | ||
386 | impl<R: TreeRoot<RaTypes>> Hash for ByteNode<R> { | ||
387 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
388 | } | ||
389 | |||
390 | impl<'a> AstNode<'a> for Byte<'a> { | ||
391 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
392 | match syntax.kind() { | ||
393 | BYTE => Some(Byte { syntax }), | ||
394 | _ => None, | ||
395 | } | ||
396 | } | ||
397 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
398 | } | ||
399 | |||
400 | impl<R: TreeRoot<RaTypes>> ByteNode<R> { | ||
401 | pub fn borrowed(&self) -> Byte { | ||
402 | ByteNode { syntax: self.syntax.borrowed() } | ||
403 | } | ||
404 | pub fn owned(&self) -> ByteNode { | ||
405 | ByteNode { syntax: self.syntax.owned() } | ||
406 | } | ||
407 | } | ||
408 | |||
409 | |||
410 | impl<'a> Byte<'a> {} | ||
411 | |||
412 | // ByteString | ||
413 | #[derive(Debug, Clone, Copy,)] | ||
414 | pub struct ByteStringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
415 | pub(crate) syntax: SyntaxNode<R>, | ||
416 | } | ||
417 | pub type ByteString<'a> = ByteStringNode<RefRoot<'a>>; | ||
418 | |||
419 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ByteStringNode<R1>> for ByteStringNode<R2> { | ||
420 | fn eq(&self, other: &ByteStringNode<R1>) -> bool { self.syntax == other.syntax } | ||
421 | } | ||
422 | impl<R: TreeRoot<RaTypes>> Eq for ByteStringNode<R> {} | ||
423 | impl<R: TreeRoot<RaTypes>> Hash for ByteStringNode<R> { | ||
424 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
425 | } | ||
426 | |||
427 | impl<'a> AstNode<'a> for ByteString<'a> { | ||
428 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
429 | match syntax.kind() { | ||
430 | BYTE_STRING => Some(ByteString { syntax }), | ||
431 | _ => None, | ||
432 | } | ||
433 | } | ||
434 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
435 | } | ||
436 | |||
437 | impl<R: TreeRoot<RaTypes>> ByteStringNode<R> { | ||
438 | pub fn borrowed(&self) -> ByteString { | ||
439 | ByteStringNode { syntax: self.syntax.borrowed() } | ||
440 | } | ||
441 | pub fn owned(&self) -> ByteStringNode { | ||
442 | ByteStringNode { syntax: self.syntax.owned() } | ||
443 | } | ||
444 | } | ||
445 | |||
446 | |||
447 | impl<'a> ByteString<'a> {} | ||
448 | |||
301 | // CallExpr | 449 | // CallExpr |
302 | #[derive(Debug, Clone, Copy)] | 450 | #[derive(Debug, Clone, Copy,)] |
303 | pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 451 | pub struct CallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
304 | syntax: SyntaxNode<R>, | 452 | pub(crate) syntax: SyntaxNode<R>, |
305 | } | 453 | } |
306 | pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>; | 454 | pub type CallExpr<'a> = CallExprNode<RefRoot<'a>>; |
307 | 455 | ||
456 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CallExprNode<R1>> for CallExprNode<R2> { | ||
457 | fn eq(&self, other: &CallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
458 | } | ||
459 | impl<R: TreeRoot<RaTypes>> Eq for CallExprNode<R> {} | ||
460 | impl<R: TreeRoot<RaTypes>> Hash for CallExprNode<R> { | ||
461 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
462 | } | ||
463 | |||
308 | impl<'a> AstNode<'a> for CallExpr<'a> { | 464 | impl<'a> AstNode<'a> for CallExpr<'a> { |
309 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 465 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
310 | match syntax.kind() { | 466 | match syntax.kind() { |
@@ -333,12 +489,20 @@ impl<'a> CallExpr<'a> { | |||
333 | } | 489 | } |
334 | 490 | ||
335 | // CastExpr | 491 | // CastExpr |
336 | #[derive(Debug, Clone, Copy)] | 492 | #[derive(Debug, Clone, Copy,)] |
337 | pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 493 | pub struct CastExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
338 | syntax: SyntaxNode<R>, | 494 | pub(crate) syntax: SyntaxNode<R>, |
339 | } | 495 | } |
340 | pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; | 496 | pub type CastExpr<'a> = CastExprNode<RefRoot<'a>>; |
341 | 497 | ||
498 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CastExprNode<R1>> for CastExprNode<R2> { | ||
499 | fn eq(&self, other: &CastExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
500 | } | ||
501 | impl<R: TreeRoot<RaTypes>> Eq for CastExprNode<R> {} | ||
502 | impl<R: TreeRoot<RaTypes>> Hash for CastExprNode<R> { | ||
503 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
504 | } | ||
505 | |||
342 | impl<'a> AstNode<'a> for CastExpr<'a> { | 506 | impl<'a> AstNode<'a> for CastExpr<'a> { |
343 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 507 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
344 | match syntax.kind() { | 508 | match syntax.kind() { |
@@ -362,12 +526,20 @@ impl<R: TreeRoot<RaTypes>> CastExprNode<R> { | |||
362 | impl<'a> CastExpr<'a> {} | 526 | impl<'a> CastExpr<'a> {} |
363 | 527 | ||
364 | // Char | 528 | // Char |
365 | #[derive(Debug, Clone, Copy)] | 529 | #[derive(Debug, Clone, Copy,)] |
366 | pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 530 | pub struct CharNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
367 | syntax: SyntaxNode<R>, | 531 | pub(crate) syntax: SyntaxNode<R>, |
368 | } | 532 | } |
369 | pub type Char<'a> = CharNode<RefRoot<'a>>; | 533 | pub type Char<'a> = CharNode<RefRoot<'a>>; |
370 | 534 | ||
535 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CharNode<R1>> for CharNode<R2> { | ||
536 | fn eq(&self, other: &CharNode<R1>) -> bool { self.syntax == other.syntax } | ||
537 | } | ||
538 | impl<R: TreeRoot<RaTypes>> Eq for CharNode<R> {} | ||
539 | impl<R: TreeRoot<RaTypes>> Hash for CharNode<R> { | ||
540 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
541 | } | ||
542 | |||
371 | impl<'a> AstNode<'a> for Char<'a> { | 543 | impl<'a> AstNode<'a> for Char<'a> { |
372 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 544 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
373 | match syntax.kind() { | 545 | match syntax.kind() { |
@@ -391,12 +563,20 @@ impl<R: TreeRoot<RaTypes>> CharNode<R> { | |||
391 | impl<'a> Char<'a> {} | 563 | impl<'a> Char<'a> {} |
392 | 564 | ||
393 | // Comment | 565 | // Comment |
394 | #[derive(Debug, Clone, Copy)] | 566 | #[derive(Debug, Clone, Copy,)] |
395 | pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 567 | pub struct CommentNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
396 | syntax: SyntaxNode<R>, | 568 | pub(crate) syntax: SyntaxNode<R>, |
397 | } | 569 | } |
398 | pub type Comment<'a> = CommentNode<RefRoot<'a>>; | 570 | pub type Comment<'a> = CommentNode<RefRoot<'a>>; |
399 | 571 | ||
572 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<CommentNode<R1>> for CommentNode<R2> { | ||
573 | fn eq(&self, other: &CommentNode<R1>) -> bool { self.syntax == other.syntax } | ||
574 | } | ||
575 | impl<R: TreeRoot<RaTypes>> Eq for CommentNode<R> {} | ||
576 | impl<R: TreeRoot<RaTypes>> Hash for CommentNode<R> { | ||
577 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
578 | } | ||
579 | |||
400 | impl<'a> AstNode<'a> for Comment<'a> { | 580 | impl<'a> AstNode<'a> for Comment<'a> { |
401 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 581 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
402 | match syntax.kind() { | 582 | match syntax.kind() { |
@@ -420,12 +600,20 @@ impl<R: TreeRoot<RaTypes>> CommentNode<R> { | |||
420 | impl<'a> Comment<'a> {} | 600 | impl<'a> Comment<'a> {} |
421 | 601 | ||
422 | // Condition | 602 | // Condition |
423 | #[derive(Debug, Clone, Copy)] | 603 | #[derive(Debug, Clone, Copy,)] |
424 | pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 604 | pub struct ConditionNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
425 | syntax: SyntaxNode<R>, | 605 | pub(crate) syntax: SyntaxNode<R>, |
426 | } | 606 | } |
427 | pub type Condition<'a> = ConditionNode<RefRoot<'a>>; | 607 | pub type Condition<'a> = ConditionNode<RefRoot<'a>>; |
428 | 608 | ||
609 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConditionNode<R1>> for ConditionNode<R2> { | ||
610 | fn eq(&self, other: &ConditionNode<R1>) -> bool { self.syntax == other.syntax } | ||
611 | } | ||
612 | impl<R: TreeRoot<RaTypes>> Eq for ConditionNode<R> {} | ||
613 | impl<R: TreeRoot<RaTypes>> Hash for ConditionNode<R> { | ||
614 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
615 | } | ||
616 | |||
429 | impl<'a> AstNode<'a> for Condition<'a> { | 617 | impl<'a> AstNode<'a> for Condition<'a> { |
430 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 618 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
431 | match syntax.kind() { | 619 | match syntax.kind() { |
@@ -457,12 +645,20 @@ impl<'a> Condition<'a> { | |||
457 | } | 645 | } |
458 | 646 | ||
459 | // ConstDef | 647 | // ConstDef |
460 | #[derive(Debug, Clone, Copy)] | 648 | #[derive(Debug, Clone, Copy,)] |
461 | pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 649 | pub struct ConstDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
462 | syntax: SyntaxNode<R>, | 650 | pub(crate) syntax: SyntaxNode<R>, |
463 | } | 651 | } |
464 | pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; | 652 | pub type ConstDef<'a> = ConstDefNode<RefRoot<'a>>; |
465 | 653 | ||
654 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ConstDefNode<R1>> for ConstDefNode<R2> { | ||
655 | fn eq(&self, other: &ConstDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
656 | } | ||
657 | impl<R: TreeRoot<RaTypes>> Eq for ConstDefNode<R> {} | ||
658 | impl<R: TreeRoot<RaTypes>> Hash for ConstDefNode<R> { | ||
659 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
660 | } | ||
661 | |||
466 | impl<'a> AstNode<'a> for ConstDef<'a> { | 662 | impl<'a> AstNode<'a> for ConstDef<'a> { |
467 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 663 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
468 | match syntax.kind() { | 664 | match syntax.kind() { |
@@ -486,15 +682,24 @@ impl<R: TreeRoot<RaTypes>> ConstDefNode<R> { | |||
486 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} | 682 | impl<'a> ast::NameOwner<'a> for ConstDef<'a> {} |
487 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} | 683 | impl<'a> ast::TypeParamsOwner<'a> for ConstDef<'a> {} |
488 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} | 684 | impl<'a> ast::AttrsOwner<'a> for ConstDef<'a> {} |
685 | impl<'a> ast::DocCommentsOwner<'a> for ConstDef<'a> {} | ||
489 | impl<'a> ConstDef<'a> {} | 686 | impl<'a> ConstDef<'a> {} |
490 | 687 | ||
491 | // ContinueExpr | 688 | // ContinueExpr |
492 | #[derive(Debug, Clone, Copy)] | 689 | #[derive(Debug, Clone, Copy,)] |
493 | pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 690 | pub struct ContinueExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
494 | syntax: SyntaxNode<R>, | 691 | pub(crate) syntax: SyntaxNode<R>, |
495 | } | 692 | } |
496 | pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; | 693 | pub type ContinueExpr<'a> = ContinueExprNode<RefRoot<'a>>; |
497 | 694 | ||
695 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ContinueExprNode<R1>> for ContinueExprNode<R2> { | ||
696 | fn eq(&self, other: &ContinueExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
697 | } | ||
698 | impl<R: TreeRoot<RaTypes>> Eq for ContinueExprNode<R> {} | ||
699 | impl<R: TreeRoot<RaTypes>> Hash for ContinueExprNode<R> { | ||
700 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
701 | } | ||
702 | |||
498 | impl<'a> AstNode<'a> for ContinueExpr<'a> { | 703 | impl<'a> AstNode<'a> for ContinueExpr<'a> { |
499 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 704 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
500 | match syntax.kind() { | 705 | match syntax.kind() { |
@@ -518,12 +723,20 @@ impl<R: TreeRoot<RaTypes>> ContinueExprNode<R> { | |||
518 | impl<'a> ContinueExpr<'a> {} | 723 | impl<'a> ContinueExpr<'a> {} |
519 | 724 | ||
520 | // DynTraitType | 725 | // DynTraitType |
521 | #[derive(Debug, Clone, Copy)] | 726 | #[derive(Debug, Clone, Copy,)] |
522 | pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 727 | pub struct DynTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
523 | syntax: SyntaxNode<R>, | 728 | pub(crate) syntax: SyntaxNode<R>, |
524 | } | 729 | } |
525 | pub type DynTraitType<'a> = DynTraitTypeNode<RefRoot<'a>>; | 730 | pub type DynTraitType<'a> = DynTraitTypeNode<RefRoot<'a>>; |
526 | 731 | ||
732 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<DynTraitTypeNode<R1>> for DynTraitTypeNode<R2> { | ||
733 | fn eq(&self, other: &DynTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
734 | } | ||
735 | impl<R: TreeRoot<RaTypes>> Eq for DynTraitTypeNode<R> {} | ||
736 | impl<R: TreeRoot<RaTypes>> Hash for DynTraitTypeNode<R> { | ||
737 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
738 | } | ||
739 | |||
527 | impl<'a> AstNode<'a> for DynTraitType<'a> { | 740 | impl<'a> AstNode<'a> for DynTraitType<'a> { |
528 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 741 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
529 | match syntax.kind() { | 742 | match syntax.kind() { |
@@ -547,12 +760,20 @@ impl<R: TreeRoot<RaTypes>> DynTraitTypeNode<R> { | |||
547 | impl<'a> DynTraitType<'a> {} | 760 | impl<'a> DynTraitType<'a> {} |
548 | 761 | ||
549 | // EnumDef | 762 | // EnumDef |
550 | #[derive(Debug, Clone, Copy)] | 763 | #[derive(Debug, Clone, Copy,)] |
551 | pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 764 | pub struct EnumDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
552 | syntax: SyntaxNode<R>, | 765 | pub(crate) syntax: SyntaxNode<R>, |
553 | } | 766 | } |
554 | pub type EnumDef<'a> = EnumDefNode<RefRoot<'a>>; | 767 | pub type EnumDef<'a> = EnumDefNode<RefRoot<'a>>; |
555 | 768 | ||
769 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<EnumDefNode<R1>> for EnumDefNode<R2> { | ||
770 | fn eq(&self, other: &EnumDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
771 | } | ||
772 | impl<R: TreeRoot<RaTypes>> Eq for EnumDefNode<R> {} | ||
773 | impl<R: TreeRoot<RaTypes>> Hash for EnumDefNode<R> { | ||
774 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
775 | } | ||
776 | |||
556 | impl<'a> AstNode<'a> for EnumDef<'a> { | 777 | impl<'a> AstNode<'a> for EnumDef<'a> { |
557 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 778 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
558 | match syntax.kind() { | 779 | match syntax.kind() { |
@@ -576,10 +797,11 @@ impl<R: TreeRoot<RaTypes>> EnumDefNode<R> { | |||
576 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} | 797 | impl<'a> ast::NameOwner<'a> for EnumDef<'a> {} |
577 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} | 798 | impl<'a> ast::TypeParamsOwner<'a> for EnumDef<'a> {} |
578 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} | 799 | impl<'a> ast::AttrsOwner<'a> for EnumDef<'a> {} |
800 | impl<'a> ast::DocCommentsOwner<'a> for EnumDef<'a> {} | ||
579 | impl<'a> EnumDef<'a> {} | 801 | impl<'a> EnumDef<'a> {} |
580 | 802 | ||
581 | // Expr | 803 | // Expr |
582 | #[derive(Debug, Clone, Copy)] | 804 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
583 | pub enum Expr<'a> { | 805 | pub enum Expr<'a> { |
584 | TupleExpr(TupleExpr<'a>), | 806 | TupleExpr(TupleExpr<'a>), |
585 | ArrayExpr(ArrayExpr<'a>), | 807 | ArrayExpr(ArrayExpr<'a>), |
@@ -694,12 +916,20 @@ impl<'a> AstNode<'a> for Expr<'a> { | |||
694 | impl<'a> Expr<'a> {} | 916 | impl<'a> Expr<'a> {} |
695 | 917 | ||
696 | // ExprStmt | 918 | // ExprStmt |
697 | #[derive(Debug, Clone, Copy)] | 919 | #[derive(Debug, Clone, Copy,)] |
698 | pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 920 | pub struct ExprStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
699 | syntax: SyntaxNode<R>, | 921 | pub(crate) syntax: SyntaxNode<R>, |
700 | } | 922 | } |
701 | pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; | 923 | pub type ExprStmt<'a> = ExprStmtNode<RefRoot<'a>>; |
702 | 924 | ||
925 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExprStmtNode<R1>> for ExprStmtNode<R2> { | ||
926 | fn eq(&self, other: &ExprStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
927 | } | ||
928 | impl<R: TreeRoot<RaTypes>> Eq for ExprStmtNode<R> {} | ||
929 | impl<R: TreeRoot<RaTypes>> Hash for ExprStmtNode<R> { | ||
930 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
931 | } | ||
932 | |||
703 | impl<'a> AstNode<'a> for ExprStmt<'a> { | 933 | impl<'a> AstNode<'a> for ExprStmt<'a> { |
704 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 934 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
705 | match syntax.kind() { | 935 | match syntax.kind() { |
@@ -727,12 +957,20 @@ impl<'a> ExprStmt<'a> { | |||
727 | } | 957 | } |
728 | 958 | ||
729 | // ExternCrateItem | 959 | // ExternCrateItem |
730 | #[derive(Debug, Clone, Copy)] | 960 | #[derive(Debug, Clone, Copy,)] |
731 | pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 961 | pub struct ExternCrateItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
732 | syntax: SyntaxNode<R>, | 962 | pub(crate) syntax: SyntaxNode<R>, |
733 | } | 963 | } |
734 | pub type ExternCrateItem<'a> = ExternCrateItemNode<RefRoot<'a>>; | 964 | pub type ExternCrateItem<'a> = ExternCrateItemNode<RefRoot<'a>>; |
735 | 965 | ||
966 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ExternCrateItemNode<R1>> for ExternCrateItemNode<R2> { | ||
967 | fn eq(&self, other: &ExternCrateItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
968 | } | ||
969 | impl<R: TreeRoot<RaTypes>> Eq for ExternCrateItemNode<R> {} | ||
970 | impl<R: TreeRoot<RaTypes>> Hash for ExternCrateItemNode<R> { | ||
971 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
972 | } | ||
973 | |||
736 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { | 974 | impl<'a> AstNode<'a> for ExternCrateItem<'a> { |
737 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 975 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
738 | match syntax.kind() { | 976 | match syntax.kind() { |
@@ -756,12 +994,20 @@ impl<R: TreeRoot<RaTypes>> ExternCrateItemNode<R> { | |||
756 | impl<'a> ExternCrateItem<'a> {} | 994 | impl<'a> ExternCrateItem<'a> {} |
757 | 995 | ||
758 | // FieldExpr | 996 | // FieldExpr |
759 | #[derive(Debug, Clone, Copy)] | 997 | #[derive(Debug, Clone, Copy,)] |
760 | pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 998 | pub struct FieldExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
761 | syntax: SyntaxNode<R>, | 999 | pub(crate) syntax: SyntaxNode<R>, |
762 | } | 1000 | } |
763 | pub type FieldExpr<'a> = FieldExprNode<RefRoot<'a>>; | 1001 | pub type FieldExpr<'a> = FieldExprNode<RefRoot<'a>>; |
764 | 1002 | ||
1003 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldExprNode<R1>> for FieldExprNode<R2> { | ||
1004 | fn eq(&self, other: &FieldExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1005 | } | ||
1006 | impl<R: TreeRoot<RaTypes>> Eq for FieldExprNode<R> {} | ||
1007 | impl<R: TreeRoot<RaTypes>> Hash for FieldExprNode<R> { | ||
1008 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1009 | } | ||
1010 | |||
765 | impl<'a> AstNode<'a> for FieldExpr<'a> { | 1011 | impl<'a> AstNode<'a> for FieldExpr<'a> { |
766 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1012 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
767 | match syntax.kind() { | 1013 | match syntax.kind() { |
@@ -785,12 +1031,20 @@ impl<R: TreeRoot<RaTypes>> FieldExprNode<R> { | |||
785 | impl<'a> FieldExpr<'a> {} | 1031 | impl<'a> FieldExpr<'a> {} |
786 | 1032 | ||
787 | // FieldPatList | 1033 | // FieldPatList |
788 | #[derive(Debug, Clone, Copy)] | 1034 | #[derive(Debug, Clone, Copy,)] |
789 | pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1035 | pub struct FieldPatListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
790 | syntax: SyntaxNode<R>, | 1036 | pub(crate) syntax: SyntaxNode<R>, |
791 | } | 1037 | } |
792 | pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; | 1038 | pub type FieldPatList<'a> = FieldPatListNode<RefRoot<'a>>; |
793 | 1039 | ||
1040 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FieldPatListNode<R1>> for FieldPatListNode<R2> { | ||
1041 | fn eq(&self, other: &FieldPatListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1042 | } | ||
1043 | impl<R: TreeRoot<RaTypes>> Eq for FieldPatListNode<R> {} | ||
1044 | impl<R: TreeRoot<RaTypes>> Hash for FieldPatListNode<R> { | ||
1045 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1046 | } | ||
1047 | |||
794 | impl<'a> AstNode<'a> for FieldPatList<'a> { | 1048 | impl<'a> AstNode<'a> for FieldPatList<'a> { |
795 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1049 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
796 | match syntax.kind() { | 1050 | match syntax.kind() { |
@@ -814,12 +1068,20 @@ impl<R: TreeRoot<RaTypes>> FieldPatListNode<R> { | |||
814 | impl<'a> FieldPatList<'a> {} | 1068 | impl<'a> FieldPatList<'a> {} |
815 | 1069 | ||
816 | // FnDef | 1070 | // FnDef |
817 | #[derive(Debug, Clone, Copy)] | 1071 | #[derive(Debug, Clone, Copy,)] |
818 | pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1072 | pub struct FnDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
819 | syntax: SyntaxNode<R>, | 1073 | pub(crate) syntax: SyntaxNode<R>, |
820 | } | 1074 | } |
821 | pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; | 1075 | pub type FnDef<'a> = FnDefNode<RefRoot<'a>>; |
822 | 1076 | ||
1077 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnDefNode<R1>> for FnDefNode<R2> { | ||
1078 | fn eq(&self, other: &FnDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
1079 | } | ||
1080 | impl<R: TreeRoot<RaTypes>> Eq for FnDefNode<R> {} | ||
1081 | impl<R: TreeRoot<RaTypes>> Hash for FnDefNode<R> { | ||
1082 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1083 | } | ||
1084 | |||
823 | impl<'a> AstNode<'a> for FnDef<'a> { | 1085 | impl<'a> AstNode<'a> for FnDef<'a> { |
824 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1086 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
825 | match syntax.kind() { | 1087 | match syntax.kind() { |
@@ -859,12 +1121,20 @@ impl<'a> FnDef<'a> { | |||
859 | } | 1121 | } |
860 | 1122 | ||
861 | // FnPointerType | 1123 | // FnPointerType |
862 | #[derive(Debug, Clone, Copy)] | 1124 | #[derive(Debug, Clone, Copy,)] |
863 | pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1125 | pub struct FnPointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
864 | syntax: SyntaxNode<R>, | 1126 | pub(crate) syntax: SyntaxNode<R>, |
865 | } | 1127 | } |
866 | pub type FnPointerType<'a> = FnPointerTypeNode<RefRoot<'a>>; | 1128 | pub type FnPointerType<'a> = FnPointerTypeNode<RefRoot<'a>>; |
867 | 1129 | ||
1130 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<FnPointerTypeNode<R1>> for FnPointerTypeNode<R2> { | ||
1131 | fn eq(&self, other: &FnPointerTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1132 | } | ||
1133 | impl<R: TreeRoot<RaTypes>> Eq for FnPointerTypeNode<R> {} | ||
1134 | impl<R: TreeRoot<RaTypes>> Hash for FnPointerTypeNode<R> { | ||
1135 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1136 | } | ||
1137 | |||
868 | impl<'a> AstNode<'a> for FnPointerType<'a> { | 1138 | impl<'a> AstNode<'a> for FnPointerType<'a> { |
869 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1139 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
870 | match syntax.kind() { | 1140 | match syntax.kind() { |
@@ -888,12 +1158,20 @@ impl<R: TreeRoot<RaTypes>> FnPointerTypeNode<R> { | |||
888 | impl<'a> FnPointerType<'a> {} | 1158 | impl<'a> FnPointerType<'a> {} |
889 | 1159 | ||
890 | // ForExpr | 1160 | // ForExpr |
891 | #[derive(Debug, Clone, Copy)] | 1161 | #[derive(Debug, Clone, Copy,)] |
892 | pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1162 | pub struct ForExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
893 | syntax: SyntaxNode<R>, | 1163 | pub(crate) syntax: SyntaxNode<R>, |
894 | } | 1164 | } |
895 | pub type ForExpr<'a> = ForExprNode<RefRoot<'a>>; | 1165 | pub type ForExpr<'a> = ForExprNode<RefRoot<'a>>; |
896 | 1166 | ||
1167 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForExprNode<R1>> for ForExprNode<R2> { | ||
1168 | fn eq(&self, other: &ForExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1169 | } | ||
1170 | impl<R: TreeRoot<RaTypes>> Eq for ForExprNode<R> {} | ||
1171 | impl<R: TreeRoot<RaTypes>> Hash for ForExprNode<R> { | ||
1172 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1173 | } | ||
1174 | |||
897 | impl<'a> AstNode<'a> for ForExpr<'a> { | 1175 | impl<'a> AstNode<'a> for ForExpr<'a> { |
898 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1176 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
899 | match syntax.kind() { | 1177 | match syntax.kind() { |
@@ -926,12 +1204,20 @@ impl<'a> ForExpr<'a> { | |||
926 | } | 1204 | } |
927 | 1205 | ||
928 | // ForType | 1206 | // ForType |
929 | #[derive(Debug, Clone, Copy)] | 1207 | #[derive(Debug, Clone, Copy,)] |
930 | pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1208 | pub struct ForTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
931 | syntax: SyntaxNode<R>, | 1209 | pub(crate) syntax: SyntaxNode<R>, |
932 | } | 1210 | } |
933 | pub type ForType<'a> = ForTypeNode<RefRoot<'a>>; | 1211 | pub type ForType<'a> = ForTypeNode<RefRoot<'a>>; |
934 | 1212 | ||
1213 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ForTypeNode<R1>> for ForTypeNode<R2> { | ||
1214 | fn eq(&self, other: &ForTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1215 | } | ||
1216 | impl<R: TreeRoot<RaTypes>> Eq for ForTypeNode<R> {} | ||
1217 | impl<R: TreeRoot<RaTypes>> Hash for ForTypeNode<R> { | ||
1218 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1219 | } | ||
1220 | |||
935 | impl<'a> AstNode<'a> for ForType<'a> { | 1221 | impl<'a> AstNode<'a> for ForType<'a> { |
936 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1222 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
937 | match syntax.kind() { | 1223 | match syntax.kind() { |
@@ -955,12 +1241,20 @@ impl<R: TreeRoot<RaTypes>> ForTypeNode<R> { | |||
955 | impl<'a> ForType<'a> {} | 1241 | impl<'a> ForType<'a> {} |
956 | 1242 | ||
957 | // IfExpr | 1243 | // IfExpr |
958 | #[derive(Debug, Clone, Copy)] | 1244 | #[derive(Debug, Clone, Copy,)] |
959 | pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1245 | pub struct IfExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
960 | syntax: SyntaxNode<R>, | 1246 | pub(crate) syntax: SyntaxNode<R>, |
961 | } | 1247 | } |
962 | pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; | 1248 | pub type IfExpr<'a> = IfExprNode<RefRoot<'a>>; |
963 | 1249 | ||
1250 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IfExprNode<R1>> for IfExprNode<R2> { | ||
1251 | fn eq(&self, other: &IfExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1252 | } | ||
1253 | impl<R: TreeRoot<RaTypes>> Eq for IfExprNode<R> {} | ||
1254 | impl<R: TreeRoot<RaTypes>> Hash for IfExprNode<R> { | ||
1255 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1256 | } | ||
1257 | |||
964 | impl<'a> AstNode<'a> for IfExpr<'a> { | 1258 | impl<'a> AstNode<'a> for IfExpr<'a> { |
965 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1259 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
966 | match syntax.kind() { | 1260 | match syntax.kind() { |
@@ -988,12 +1282,20 @@ impl<'a> IfExpr<'a> { | |||
988 | } | 1282 | } |
989 | 1283 | ||
990 | // ImplItem | 1284 | // ImplItem |
991 | #[derive(Debug, Clone, Copy)] | 1285 | #[derive(Debug, Clone, Copy,)] |
992 | pub struct ImplItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1286 | pub struct ImplItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
993 | syntax: SyntaxNode<R>, | 1287 | pub(crate) syntax: SyntaxNode<R>, |
994 | } | 1288 | } |
995 | pub type ImplItem<'a> = ImplItemNode<RefRoot<'a>>; | 1289 | pub type ImplItem<'a> = ImplItemNode<RefRoot<'a>>; |
996 | 1290 | ||
1291 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplItemNode<R1>> for ImplItemNode<R2> { | ||
1292 | fn eq(&self, other: &ImplItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
1293 | } | ||
1294 | impl<R: TreeRoot<RaTypes>> Eq for ImplItemNode<R> {} | ||
1295 | impl<R: TreeRoot<RaTypes>> Hash for ImplItemNode<R> { | ||
1296 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1297 | } | ||
1298 | |||
997 | impl<'a> AstNode<'a> for ImplItem<'a> { | 1299 | impl<'a> AstNode<'a> for ImplItem<'a> { |
998 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1300 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
999 | match syntax.kind() { | 1301 | match syntax.kind() { |
@@ -1017,12 +1319,20 @@ impl<R: TreeRoot<RaTypes>> ImplItemNode<R> { | |||
1017 | impl<'a> ImplItem<'a> {} | 1319 | impl<'a> ImplItem<'a> {} |
1018 | 1320 | ||
1019 | // ImplTraitType | 1321 | // ImplTraitType |
1020 | #[derive(Debug, Clone, Copy)] | 1322 | #[derive(Debug, Clone, Copy,)] |
1021 | pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1323 | pub struct ImplTraitTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1022 | syntax: SyntaxNode<R>, | 1324 | pub(crate) syntax: SyntaxNode<R>, |
1023 | } | 1325 | } |
1024 | pub type ImplTraitType<'a> = ImplTraitTypeNode<RefRoot<'a>>; | 1326 | pub type ImplTraitType<'a> = ImplTraitTypeNode<RefRoot<'a>>; |
1025 | 1327 | ||
1328 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplTraitTypeNode<R1>> for ImplTraitTypeNode<R2> { | ||
1329 | fn eq(&self, other: &ImplTraitTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1330 | } | ||
1331 | impl<R: TreeRoot<RaTypes>> Eq for ImplTraitTypeNode<R> {} | ||
1332 | impl<R: TreeRoot<RaTypes>> Hash for ImplTraitTypeNode<R> { | ||
1333 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1334 | } | ||
1335 | |||
1026 | impl<'a> AstNode<'a> for ImplTraitType<'a> { | 1336 | impl<'a> AstNode<'a> for ImplTraitType<'a> { |
1027 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1337 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1028 | match syntax.kind() { | 1338 | match syntax.kind() { |
@@ -1046,12 +1356,20 @@ impl<R: TreeRoot<RaTypes>> ImplTraitTypeNode<R> { | |||
1046 | impl<'a> ImplTraitType<'a> {} | 1356 | impl<'a> ImplTraitType<'a> {} |
1047 | 1357 | ||
1048 | // IndexExpr | 1358 | // IndexExpr |
1049 | #[derive(Debug, Clone, Copy)] | 1359 | #[derive(Debug, Clone, Copy,)] |
1050 | pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1360 | pub struct IndexExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1051 | syntax: SyntaxNode<R>, | 1361 | pub(crate) syntax: SyntaxNode<R>, |
1052 | } | 1362 | } |
1053 | pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; | 1363 | pub type IndexExpr<'a> = IndexExprNode<RefRoot<'a>>; |
1054 | 1364 | ||
1365 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<IndexExprNode<R1>> for IndexExprNode<R2> { | ||
1366 | fn eq(&self, other: &IndexExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1367 | } | ||
1368 | impl<R: TreeRoot<RaTypes>> Eq for IndexExprNode<R> {} | ||
1369 | impl<R: TreeRoot<RaTypes>> Hash for IndexExprNode<R> { | ||
1370 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1371 | } | ||
1372 | |||
1055 | impl<'a> AstNode<'a> for IndexExpr<'a> { | 1373 | impl<'a> AstNode<'a> for IndexExpr<'a> { |
1056 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1374 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1057 | match syntax.kind() { | 1375 | match syntax.kind() { |
@@ -1075,12 +1393,20 @@ impl<R: TreeRoot<RaTypes>> IndexExprNode<R> { | |||
1075 | impl<'a> IndexExpr<'a> {} | 1393 | impl<'a> IndexExpr<'a> {} |
1076 | 1394 | ||
1077 | // ItemList | 1395 | // ItemList |
1078 | #[derive(Debug, Clone, Copy)] | 1396 | #[derive(Debug, Clone, Copy,)] |
1079 | pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1397 | pub struct ItemListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1080 | syntax: SyntaxNode<R>, | 1398 | pub(crate) syntax: SyntaxNode<R>, |
1081 | } | 1399 | } |
1082 | pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; | 1400 | pub type ItemList<'a> = ItemListNode<RefRoot<'a>>; |
1083 | 1401 | ||
1402 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ItemListNode<R1>> for ItemListNode<R2> { | ||
1403 | fn eq(&self, other: &ItemListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1404 | } | ||
1405 | impl<R: TreeRoot<RaTypes>> Eq for ItemListNode<R> {} | ||
1406 | impl<R: TreeRoot<RaTypes>> Hash for ItemListNode<R> { | ||
1407 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1408 | } | ||
1409 | |||
1084 | impl<'a> AstNode<'a> for ItemList<'a> { | 1410 | impl<'a> AstNode<'a> for ItemList<'a> { |
1085 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1411 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1086 | match syntax.kind() { | 1412 | match syntax.kind() { |
@@ -1106,12 +1432,20 @@ impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} | |||
1106 | impl<'a> ItemList<'a> {} | 1432 | impl<'a> ItemList<'a> {} |
1107 | 1433 | ||
1108 | // Label | 1434 | // Label |
1109 | #[derive(Debug, Clone, Copy)] | 1435 | #[derive(Debug, Clone, Copy,)] |
1110 | pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1436 | pub struct LabelNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1111 | syntax: SyntaxNode<R>, | 1437 | pub(crate) syntax: SyntaxNode<R>, |
1112 | } | 1438 | } |
1113 | pub type Label<'a> = LabelNode<RefRoot<'a>>; | 1439 | pub type Label<'a> = LabelNode<RefRoot<'a>>; |
1114 | 1440 | ||
1441 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LabelNode<R1>> for LabelNode<R2> { | ||
1442 | fn eq(&self, other: &LabelNode<R1>) -> bool { self.syntax == other.syntax } | ||
1443 | } | ||
1444 | impl<R: TreeRoot<RaTypes>> Eq for LabelNode<R> {} | ||
1445 | impl<R: TreeRoot<RaTypes>> Hash for LabelNode<R> { | ||
1446 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1447 | } | ||
1448 | |||
1115 | impl<'a> AstNode<'a> for Label<'a> { | 1449 | impl<'a> AstNode<'a> for Label<'a> { |
1116 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1450 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1117 | match syntax.kind() { | 1451 | match syntax.kind() { |
@@ -1135,12 +1469,20 @@ impl<R: TreeRoot<RaTypes>> LabelNode<R> { | |||
1135 | impl<'a> Label<'a> {} | 1469 | impl<'a> Label<'a> {} |
1136 | 1470 | ||
1137 | // LambdaExpr | 1471 | // LambdaExpr |
1138 | #[derive(Debug, Clone, Copy)] | 1472 | #[derive(Debug, Clone, Copy,)] |
1139 | pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1473 | pub struct LambdaExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1140 | syntax: SyntaxNode<R>, | 1474 | pub(crate) syntax: SyntaxNode<R>, |
1141 | } | 1475 | } |
1142 | pub type LambdaExpr<'a> = LambdaExprNode<RefRoot<'a>>; | 1476 | pub type LambdaExpr<'a> = LambdaExprNode<RefRoot<'a>>; |
1143 | 1477 | ||
1478 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LambdaExprNode<R1>> for LambdaExprNode<R2> { | ||
1479 | fn eq(&self, other: &LambdaExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1480 | } | ||
1481 | impl<R: TreeRoot<RaTypes>> Eq for LambdaExprNode<R> {} | ||
1482 | impl<R: TreeRoot<RaTypes>> Hash for LambdaExprNode<R> { | ||
1483 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1484 | } | ||
1485 | |||
1144 | impl<'a> AstNode<'a> for LambdaExpr<'a> { | 1486 | impl<'a> AstNode<'a> for LambdaExpr<'a> { |
1145 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1487 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1146 | match syntax.kind() { | 1488 | match syntax.kind() { |
@@ -1172,12 +1514,20 @@ impl<'a> LambdaExpr<'a> { | |||
1172 | } | 1514 | } |
1173 | 1515 | ||
1174 | // LetStmt | 1516 | // LetStmt |
1175 | #[derive(Debug, Clone, Copy)] | 1517 | #[derive(Debug, Clone, Copy,)] |
1176 | pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1518 | pub struct LetStmtNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1177 | syntax: SyntaxNode<R>, | 1519 | pub(crate) syntax: SyntaxNode<R>, |
1178 | } | 1520 | } |
1179 | pub type LetStmt<'a> = LetStmtNode<RefRoot<'a>>; | 1521 | pub type LetStmt<'a> = LetStmtNode<RefRoot<'a>>; |
1180 | 1522 | ||
1523 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LetStmtNode<R1>> for LetStmtNode<R2> { | ||
1524 | fn eq(&self, other: &LetStmtNode<R1>) -> bool { self.syntax == other.syntax } | ||
1525 | } | ||
1526 | impl<R: TreeRoot<RaTypes>> Eq for LetStmtNode<R> {} | ||
1527 | impl<R: TreeRoot<RaTypes>> Hash for LetStmtNode<R> { | ||
1528 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1529 | } | ||
1530 | |||
1181 | impl<'a> AstNode<'a> for LetStmt<'a> { | 1531 | impl<'a> AstNode<'a> for LetStmt<'a> { |
1182 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1532 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1183 | match syntax.kind() { | 1533 | match syntax.kind() { |
@@ -1209,12 +1559,20 @@ impl<'a> LetStmt<'a> { | |||
1209 | } | 1559 | } |
1210 | 1560 | ||
1211 | // Lifetime | 1561 | // Lifetime |
1212 | #[derive(Debug, Clone, Copy)] | 1562 | #[derive(Debug, Clone, Copy,)] |
1213 | pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1563 | pub struct LifetimeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1214 | syntax: SyntaxNode<R>, | 1564 | pub(crate) syntax: SyntaxNode<R>, |
1215 | } | 1565 | } |
1216 | pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; | 1566 | pub type Lifetime<'a> = LifetimeNode<RefRoot<'a>>; |
1217 | 1567 | ||
1568 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeNode<R1>> for LifetimeNode<R2> { | ||
1569 | fn eq(&self, other: &LifetimeNode<R1>) -> bool { self.syntax == other.syntax } | ||
1570 | } | ||
1571 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeNode<R> {} | ||
1572 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeNode<R> { | ||
1573 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1574 | } | ||
1575 | |||
1218 | impl<'a> AstNode<'a> for Lifetime<'a> { | 1576 | impl<'a> AstNode<'a> for Lifetime<'a> { |
1219 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1577 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1220 | match syntax.kind() { | 1578 | match syntax.kind() { |
@@ -1238,12 +1596,20 @@ impl<R: TreeRoot<RaTypes>> LifetimeNode<R> { | |||
1238 | impl<'a> Lifetime<'a> {} | 1596 | impl<'a> Lifetime<'a> {} |
1239 | 1597 | ||
1240 | // LifetimeParam | 1598 | // LifetimeParam |
1241 | #[derive(Debug, Clone, Copy)] | 1599 | #[derive(Debug, Clone, Copy,)] |
1242 | pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1600 | pub struct LifetimeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1243 | syntax: SyntaxNode<R>, | 1601 | pub(crate) syntax: SyntaxNode<R>, |
1244 | } | 1602 | } |
1245 | pub type LifetimeParam<'a> = LifetimeParamNode<RefRoot<'a>>; | 1603 | pub type LifetimeParam<'a> = LifetimeParamNode<RefRoot<'a>>; |
1246 | 1604 | ||
1605 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LifetimeParamNode<R1>> for LifetimeParamNode<R2> { | ||
1606 | fn eq(&self, other: &LifetimeParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
1607 | } | ||
1608 | impl<R: TreeRoot<RaTypes>> Eq for LifetimeParamNode<R> {} | ||
1609 | impl<R: TreeRoot<RaTypes>> Hash for LifetimeParamNode<R> { | ||
1610 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1611 | } | ||
1612 | |||
1247 | impl<'a> AstNode<'a> for LifetimeParam<'a> { | 1613 | impl<'a> AstNode<'a> for LifetimeParam<'a> { |
1248 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1614 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1249 | match syntax.kind() { | 1615 | match syntax.kind() { |
@@ -1271,12 +1637,20 @@ impl<'a> LifetimeParam<'a> { | |||
1271 | } | 1637 | } |
1272 | 1638 | ||
1273 | // Literal | 1639 | // Literal |
1274 | #[derive(Debug, Clone, Copy)] | 1640 | #[derive(Debug, Clone, Copy,)] |
1275 | pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1641 | pub struct LiteralNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1276 | syntax: SyntaxNode<R>, | 1642 | pub(crate) syntax: SyntaxNode<R>, |
1277 | } | 1643 | } |
1278 | pub type Literal<'a> = LiteralNode<RefRoot<'a>>; | 1644 | pub type Literal<'a> = LiteralNode<RefRoot<'a>>; |
1279 | 1645 | ||
1646 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LiteralNode<R1>> for LiteralNode<R2> { | ||
1647 | fn eq(&self, other: &LiteralNode<R1>) -> bool { self.syntax == other.syntax } | ||
1648 | } | ||
1649 | impl<R: TreeRoot<RaTypes>> Eq for LiteralNode<R> {} | ||
1650 | impl<R: TreeRoot<RaTypes>> Hash for LiteralNode<R> { | ||
1651 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1652 | } | ||
1653 | |||
1280 | impl<'a> AstNode<'a> for Literal<'a> { | 1654 | impl<'a> AstNode<'a> for Literal<'a> { |
1281 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1655 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1282 | match syntax.kind() { | 1656 | match syntax.kind() { |
@@ -1300,12 +1674,20 @@ impl<R: TreeRoot<RaTypes>> LiteralNode<R> { | |||
1300 | impl<'a> Literal<'a> {} | 1674 | impl<'a> Literal<'a> {} |
1301 | 1675 | ||
1302 | // LoopExpr | 1676 | // LoopExpr |
1303 | #[derive(Debug, Clone, Copy)] | 1677 | #[derive(Debug, Clone, Copy,)] |
1304 | pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1678 | pub struct LoopExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1305 | syntax: SyntaxNode<R>, | 1679 | pub(crate) syntax: SyntaxNode<R>, |
1306 | } | 1680 | } |
1307 | pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; | 1681 | pub type LoopExpr<'a> = LoopExprNode<RefRoot<'a>>; |
1308 | 1682 | ||
1683 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<LoopExprNode<R1>> for LoopExprNode<R2> { | ||
1684 | fn eq(&self, other: &LoopExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1685 | } | ||
1686 | impl<R: TreeRoot<RaTypes>> Eq for LoopExprNode<R> {} | ||
1687 | impl<R: TreeRoot<RaTypes>> Hash for LoopExprNode<R> { | ||
1688 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1689 | } | ||
1690 | |||
1309 | impl<'a> AstNode<'a> for LoopExpr<'a> { | 1691 | impl<'a> AstNode<'a> for LoopExpr<'a> { |
1310 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1692 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1311 | match syntax.kind() { | 1693 | match syntax.kind() { |
@@ -1330,12 +1712,20 @@ impl<'a> ast::LoopBodyOwner<'a> for LoopExpr<'a> {} | |||
1330 | impl<'a> LoopExpr<'a> {} | 1712 | impl<'a> LoopExpr<'a> {} |
1331 | 1713 | ||
1332 | // MatchArm | 1714 | // MatchArm |
1333 | #[derive(Debug, Clone, Copy)] | 1715 | #[derive(Debug, Clone, Copy,)] |
1334 | pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1716 | pub struct MatchArmNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1335 | syntax: SyntaxNode<R>, | 1717 | pub(crate) syntax: SyntaxNode<R>, |
1336 | } | 1718 | } |
1337 | pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; | 1719 | pub type MatchArm<'a> = MatchArmNode<RefRoot<'a>>; |
1338 | 1720 | ||
1721 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmNode<R1>> for MatchArmNode<R2> { | ||
1722 | fn eq(&self, other: &MatchArmNode<R1>) -> bool { self.syntax == other.syntax } | ||
1723 | } | ||
1724 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmNode<R> {} | ||
1725 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmNode<R> { | ||
1726 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1727 | } | ||
1728 | |||
1339 | impl<'a> AstNode<'a> for MatchArm<'a> { | 1729 | impl<'a> AstNode<'a> for MatchArm<'a> { |
1340 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1730 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1341 | match syntax.kind() { | 1731 | match syntax.kind() { |
@@ -1371,12 +1761,20 @@ impl<'a> MatchArm<'a> { | |||
1371 | } | 1761 | } |
1372 | 1762 | ||
1373 | // MatchArmList | 1763 | // MatchArmList |
1374 | #[derive(Debug, Clone, Copy)] | 1764 | #[derive(Debug, Clone, Copy,)] |
1375 | pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1765 | pub struct MatchArmListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1376 | syntax: SyntaxNode<R>, | 1766 | pub(crate) syntax: SyntaxNode<R>, |
1377 | } | 1767 | } |
1378 | pub type MatchArmList<'a> = MatchArmListNode<RefRoot<'a>>; | 1768 | pub type MatchArmList<'a> = MatchArmListNode<RefRoot<'a>>; |
1379 | 1769 | ||
1770 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchArmListNode<R1>> for MatchArmListNode<R2> { | ||
1771 | fn eq(&self, other: &MatchArmListNode<R1>) -> bool { self.syntax == other.syntax } | ||
1772 | } | ||
1773 | impl<R: TreeRoot<RaTypes>> Eq for MatchArmListNode<R> {} | ||
1774 | impl<R: TreeRoot<RaTypes>> Hash for MatchArmListNode<R> { | ||
1775 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1776 | } | ||
1777 | |||
1380 | impl<'a> AstNode<'a> for MatchArmList<'a> { | 1778 | impl<'a> AstNode<'a> for MatchArmList<'a> { |
1381 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1779 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1382 | match syntax.kind() { | 1780 | match syntax.kind() { |
@@ -1404,12 +1802,20 @@ impl<'a> MatchArmList<'a> { | |||
1404 | } | 1802 | } |
1405 | 1803 | ||
1406 | // MatchExpr | 1804 | // MatchExpr |
1407 | #[derive(Debug, Clone, Copy)] | 1805 | #[derive(Debug, Clone, Copy,)] |
1408 | pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1806 | pub struct MatchExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1409 | syntax: SyntaxNode<R>, | 1807 | pub(crate) syntax: SyntaxNode<R>, |
1410 | } | 1808 | } |
1411 | pub type MatchExpr<'a> = MatchExprNode<RefRoot<'a>>; | 1809 | pub type MatchExpr<'a> = MatchExprNode<RefRoot<'a>>; |
1412 | 1810 | ||
1811 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchExprNode<R1>> for MatchExprNode<R2> { | ||
1812 | fn eq(&self, other: &MatchExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1813 | } | ||
1814 | impl<R: TreeRoot<RaTypes>> Eq for MatchExprNode<R> {} | ||
1815 | impl<R: TreeRoot<RaTypes>> Hash for MatchExprNode<R> { | ||
1816 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1817 | } | ||
1818 | |||
1413 | impl<'a> AstNode<'a> for MatchExpr<'a> { | 1819 | impl<'a> AstNode<'a> for MatchExpr<'a> { |
1414 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1820 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1415 | match syntax.kind() { | 1821 | match syntax.kind() { |
@@ -1441,12 +1847,20 @@ impl<'a> MatchExpr<'a> { | |||
1441 | } | 1847 | } |
1442 | 1848 | ||
1443 | // MatchGuard | 1849 | // MatchGuard |
1444 | #[derive(Debug, Clone, Copy)] | 1850 | #[derive(Debug, Clone, Copy,)] |
1445 | pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1851 | pub struct MatchGuardNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1446 | syntax: SyntaxNode<R>, | 1852 | pub(crate) syntax: SyntaxNode<R>, |
1447 | } | 1853 | } |
1448 | pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; | 1854 | pub type MatchGuard<'a> = MatchGuardNode<RefRoot<'a>>; |
1449 | 1855 | ||
1856 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MatchGuardNode<R1>> for MatchGuardNode<R2> { | ||
1857 | fn eq(&self, other: &MatchGuardNode<R1>) -> bool { self.syntax == other.syntax } | ||
1858 | } | ||
1859 | impl<R: TreeRoot<RaTypes>> Eq for MatchGuardNode<R> {} | ||
1860 | impl<R: TreeRoot<RaTypes>> Hash for MatchGuardNode<R> { | ||
1861 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1862 | } | ||
1863 | |||
1450 | impl<'a> AstNode<'a> for MatchGuard<'a> { | 1864 | impl<'a> AstNode<'a> for MatchGuard<'a> { |
1451 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1865 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1452 | match syntax.kind() { | 1866 | match syntax.kind() { |
@@ -1470,12 +1884,20 @@ impl<R: TreeRoot<RaTypes>> MatchGuardNode<R> { | |||
1470 | impl<'a> MatchGuard<'a> {} | 1884 | impl<'a> MatchGuard<'a> {} |
1471 | 1885 | ||
1472 | // MethodCallExpr | 1886 | // MethodCallExpr |
1473 | #[derive(Debug, Clone, Copy)] | 1887 | #[derive(Debug, Clone, Copy,)] |
1474 | pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1888 | pub struct MethodCallExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1475 | syntax: SyntaxNode<R>, | 1889 | pub(crate) syntax: SyntaxNode<R>, |
1476 | } | 1890 | } |
1477 | pub type MethodCallExpr<'a> = MethodCallExprNode<RefRoot<'a>>; | 1891 | pub type MethodCallExpr<'a> = MethodCallExprNode<RefRoot<'a>>; |
1478 | 1892 | ||
1893 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<MethodCallExprNode<R1>> for MethodCallExprNode<R2> { | ||
1894 | fn eq(&self, other: &MethodCallExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
1895 | } | ||
1896 | impl<R: TreeRoot<RaTypes>> Eq for MethodCallExprNode<R> {} | ||
1897 | impl<R: TreeRoot<RaTypes>> Hash for MethodCallExprNode<R> { | ||
1898 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1899 | } | ||
1900 | |||
1479 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { | 1901 | impl<'a> AstNode<'a> for MethodCallExpr<'a> { |
1480 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1902 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1481 | match syntax.kind() { | 1903 | match syntax.kind() { |
@@ -1504,12 +1926,20 @@ impl<'a> MethodCallExpr<'a> { | |||
1504 | } | 1926 | } |
1505 | 1927 | ||
1506 | // Module | 1928 | // Module |
1507 | #[derive(Debug, Clone, Copy)] | 1929 | #[derive(Debug, Clone, Copy,)] |
1508 | pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 1930 | pub struct ModuleNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1509 | syntax: SyntaxNode<R>, | 1931 | pub(crate) syntax: SyntaxNode<R>, |
1510 | } | 1932 | } |
1511 | pub type Module<'a> = ModuleNode<RefRoot<'a>>; | 1933 | pub type Module<'a> = ModuleNode<RefRoot<'a>>; |
1512 | 1934 | ||
1935 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ModuleNode<R1>> for ModuleNode<R2> { | ||
1936 | fn eq(&self, other: &ModuleNode<R1>) -> bool { self.syntax == other.syntax } | ||
1937 | } | ||
1938 | impl<R: TreeRoot<RaTypes>> Eq for ModuleNode<R> {} | ||
1939 | impl<R: TreeRoot<RaTypes>> Hash for ModuleNode<R> { | ||
1940 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
1941 | } | ||
1942 | |||
1513 | impl<'a> AstNode<'a> for Module<'a> { | 1943 | impl<'a> AstNode<'a> for Module<'a> { |
1514 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 1944 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1515 | match syntax.kind() { | 1945 | match syntax.kind() { |
@@ -1532,6 +1962,7 @@ impl<R: TreeRoot<RaTypes>> ModuleNode<R> { | |||
1532 | 1962 | ||
1533 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 1963 | impl<'a> ast::NameOwner<'a> for Module<'a> {} |
1534 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 1964 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} |
1965 | impl<'a> ast::DocCommentsOwner<'a> for Module<'a> {} | ||
1535 | impl<'a> Module<'a> { | 1966 | impl<'a> Module<'a> { |
1536 | pub fn item_list(self) -> Option<ItemList<'a>> { | 1967 | pub fn item_list(self) -> Option<ItemList<'a>> { |
1537 | super::child_opt(self) | 1968 | super::child_opt(self) |
@@ -1539,7 +1970,7 @@ impl<'a> Module<'a> { | |||
1539 | } | 1970 | } |
1540 | 1971 | ||
1541 | // ModuleItem | 1972 | // ModuleItem |
1542 | #[derive(Debug, Clone, Copy)] | 1973 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1543 | pub enum ModuleItem<'a> { | 1974 | pub enum ModuleItem<'a> { |
1544 | StructDef(StructDef<'a>), | 1975 | StructDef(StructDef<'a>), |
1545 | EnumDef(EnumDef<'a>), | 1976 | EnumDef(EnumDef<'a>), |
@@ -1591,12 +2022,20 @@ impl<'a> AstNode<'a> for ModuleItem<'a> { | |||
1591 | impl<'a> ModuleItem<'a> {} | 2022 | impl<'a> ModuleItem<'a> {} |
1592 | 2023 | ||
1593 | // Name | 2024 | // Name |
1594 | #[derive(Debug, Clone, Copy)] | 2025 | #[derive(Debug, Clone, Copy,)] |
1595 | pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2026 | pub struct NameNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1596 | syntax: SyntaxNode<R>, | 2027 | pub(crate) syntax: SyntaxNode<R>, |
1597 | } | 2028 | } |
1598 | pub type Name<'a> = NameNode<RefRoot<'a>>; | 2029 | pub type Name<'a> = NameNode<RefRoot<'a>>; |
1599 | 2030 | ||
2031 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameNode<R1>> for NameNode<R2> { | ||
2032 | fn eq(&self, other: &NameNode<R1>) -> bool { self.syntax == other.syntax } | ||
2033 | } | ||
2034 | impl<R: TreeRoot<RaTypes>> Eq for NameNode<R> {} | ||
2035 | impl<R: TreeRoot<RaTypes>> Hash for NameNode<R> { | ||
2036 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2037 | } | ||
2038 | |||
1600 | impl<'a> AstNode<'a> for Name<'a> { | 2039 | impl<'a> AstNode<'a> for Name<'a> { |
1601 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2040 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1602 | match syntax.kind() { | 2041 | match syntax.kind() { |
@@ -1620,12 +2059,20 @@ impl<R: TreeRoot<RaTypes>> NameNode<R> { | |||
1620 | impl<'a> Name<'a> {} | 2059 | impl<'a> Name<'a> {} |
1621 | 2060 | ||
1622 | // NameRef | 2061 | // NameRef |
1623 | #[derive(Debug, Clone, Copy)] | 2062 | #[derive(Debug, Clone, Copy,)] |
1624 | pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2063 | pub struct NameRefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1625 | syntax: SyntaxNode<R>, | 2064 | pub(crate) syntax: SyntaxNode<R>, |
1626 | } | 2065 | } |
1627 | pub type NameRef<'a> = NameRefNode<RefRoot<'a>>; | 2066 | pub type NameRef<'a> = NameRefNode<RefRoot<'a>>; |
1628 | 2067 | ||
2068 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NameRefNode<R1>> for NameRefNode<R2> { | ||
2069 | fn eq(&self, other: &NameRefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2070 | } | ||
2071 | impl<R: TreeRoot<RaTypes>> Eq for NameRefNode<R> {} | ||
2072 | impl<R: TreeRoot<RaTypes>> Hash for NameRefNode<R> { | ||
2073 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2074 | } | ||
2075 | |||
1629 | impl<'a> AstNode<'a> for NameRef<'a> { | 2076 | impl<'a> AstNode<'a> for NameRef<'a> { |
1630 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2077 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1631 | match syntax.kind() { | 2078 | match syntax.kind() { |
@@ -1649,12 +2096,20 @@ impl<R: TreeRoot<RaTypes>> NameRefNode<R> { | |||
1649 | impl<'a> NameRef<'a> {} | 2096 | impl<'a> NameRef<'a> {} |
1650 | 2097 | ||
1651 | // NamedField | 2098 | // NamedField |
1652 | #[derive(Debug, Clone, Copy)] | 2099 | #[derive(Debug, Clone, Copy,)] |
1653 | pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2100 | pub struct NamedFieldNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1654 | syntax: SyntaxNode<R>, | 2101 | pub(crate) syntax: SyntaxNode<R>, |
1655 | } | 2102 | } |
1656 | pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; | 2103 | pub type NamedField<'a> = NamedFieldNode<RefRoot<'a>>; |
1657 | 2104 | ||
2105 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldNode<R1>> for NamedFieldNode<R2> { | ||
2106 | fn eq(&self, other: &NamedFieldNode<R1>) -> bool { self.syntax == other.syntax } | ||
2107 | } | ||
2108 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldNode<R> {} | ||
2109 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldNode<R> { | ||
2110 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2111 | } | ||
2112 | |||
1658 | impl<'a> AstNode<'a> for NamedField<'a> { | 2113 | impl<'a> AstNode<'a> for NamedField<'a> { |
1659 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2114 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1660 | match syntax.kind() { | 2115 | match syntax.kind() { |
@@ -1678,12 +2133,20 @@ impl<R: TreeRoot<RaTypes>> NamedFieldNode<R> { | |||
1678 | impl<'a> NamedField<'a> {} | 2133 | impl<'a> NamedField<'a> {} |
1679 | 2134 | ||
1680 | // NamedFieldDef | 2135 | // NamedFieldDef |
1681 | #[derive(Debug, Clone, Copy)] | 2136 | #[derive(Debug, Clone, Copy,)] |
1682 | pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2137 | pub struct NamedFieldDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1683 | syntax: SyntaxNode<R>, | 2138 | pub(crate) syntax: SyntaxNode<R>, |
1684 | } | 2139 | } |
1685 | pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; | 2140 | pub type NamedFieldDef<'a> = NamedFieldDefNode<RefRoot<'a>>; |
1686 | 2141 | ||
2142 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldDefNode<R1>> for NamedFieldDefNode<R2> { | ||
2143 | fn eq(&self, other: &NamedFieldDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
2144 | } | ||
2145 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldDefNode<R> {} | ||
2146 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldDefNode<R> { | ||
2147 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2148 | } | ||
2149 | |||
1687 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { | 2150 | impl<'a> AstNode<'a> for NamedFieldDef<'a> { |
1688 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2151 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1689 | match syntax.kind() { | 2152 | match syntax.kind() { |
@@ -1709,12 +2172,20 @@ impl<'a> ast::AttrsOwner<'a> for NamedFieldDef<'a> {} | |||
1709 | impl<'a> NamedFieldDef<'a> {} | 2172 | impl<'a> NamedFieldDef<'a> {} |
1710 | 2173 | ||
1711 | // NamedFieldList | 2174 | // NamedFieldList |
1712 | #[derive(Debug, Clone, Copy)] | 2175 | #[derive(Debug, Clone, Copy,)] |
1713 | pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2176 | pub struct NamedFieldListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1714 | syntax: SyntaxNode<R>, | 2177 | pub(crate) syntax: SyntaxNode<R>, |
1715 | } | 2178 | } |
1716 | pub type NamedFieldList<'a> = NamedFieldListNode<RefRoot<'a>>; | 2179 | pub type NamedFieldList<'a> = NamedFieldListNode<RefRoot<'a>>; |
1717 | 2180 | ||
2181 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NamedFieldListNode<R1>> for NamedFieldListNode<R2> { | ||
2182 | fn eq(&self, other: &NamedFieldListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2183 | } | ||
2184 | impl<R: TreeRoot<RaTypes>> Eq for NamedFieldListNode<R> {} | ||
2185 | impl<R: TreeRoot<RaTypes>> Hash for NamedFieldListNode<R> { | ||
2186 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2187 | } | ||
2188 | |||
1718 | impl<'a> AstNode<'a> for NamedFieldList<'a> { | 2189 | impl<'a> AstNode<'a> for NamedFieldList<'a> { |
1719 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2190 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1720 | match syntax.kind() { | 2191 | match syntax.kind() { |
@@ -1738,12 +2209,20 @@ impl<R: TreeRoot<RaTypes>> NamedFieldListNode<R> { | |||
1738 | impl<'a> NamedFieldList<'a> {} | 2209 | impl<'a> NamedFieldList<'a> {} |
1739 | 2210 | ||
1740 | // NeverType | 2211 | // NeverType |
1741 | #[derive(Debug, Clone, Copy)] | 2212 | #[derive(Debug, Clone, Copy,)] |
1742 | pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2213 | pub struct NeverTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1743 | syntax: SyntaxNode<R>, | 2214 | pub(crate) syntax: SyntaxNode<R>, |
1744 | } | 2215 | } |
1745 | pub type NeverType<'a> = NeverTypeNode<RefRoot<'a>>; | 2216 | pub type NeverType<'a> = NeverTypeNode<RefRoot<'a>>; |
1746 | 2217 | ||
2218 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<NeverTypeNode<R1>> for NeverTypeNode<R2> { | ||
2219 | fn eq(&self, other: &NeverTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2220 | } | ||
2221 | impl<R: TreeRoot<RaTypes>> Eq for NeverTypeNode<R> {} | ||
2222 | impl<R: TreeRoot<RaTypes>> Hash for NeverTypeNode<R> { | ||
2223 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2224 | } | ||
2225 | |||
1747 | impl<'a> AstNode<'a> for NeverType<'a> { | 2226 | impl<'a> AstNode<'a> for NeverType<'a> { |
1748 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2227 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1749 | match syntax.kind() { | 2228 | match syntax.kind() { |
@@ -1767,7 +2246,7 @@ impl<R: TreeRoot<RaTypes>> NeverTypeNode<R> { | |||
1767 | impl<'a> NeverType<'a> {} | 2246 | impl<'a> NeverType<'a> {} |
1768 | 2247 | ||
1769 | // NominalDef | 2248 | // NominalDef |
1770 | #[derive(Debug, Clone, Copy)] | 2249 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1771 | pub enum NominalDef<'a> { | 2250 | pub enum NominalDef<'a> { |
1772 | StructDef(StructDef<'a>), | 2251 | StructDef(StructDef<'a>), |
1773 | EnumDef(EnumDef<'a>), | 2252 | EnumDef(EnumDef<'a>), |
@@ -1795,12 +2274,20 @@ impl<'a> ast::AttrsOwner<'a> for NominalDef<'a> {} | |||
1795 | impl<'a> NominalDef<'a> {} | 2274 | impl<'a> NominalDef<'a> {} |
1796 | 2275 | ||
1797 | // Param | 2276 | // Param |
1798 | #[derive(Debug, Clone, Copy)] | 2277 | #[derive(Debug, Clone, Copy,)] |
1799 | pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2278 | pub struct ParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1800 | syntax: SyntaxNode<R>, | 2279 | pub(crate) syntax: SyntaxNode<R>, |
1801 | } | 2280 | } |
1802 | pub type Param<'a> = ParamNode<RefRoot<'a>>; | 2281 | pub type Param<'a> = ParamNode<RefRoot<'a>>; |
1803 | 2282 | ||
2283 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamNode<R1>> for ParamNode<R2> { | ||
2284 | fn eq(&self, other: &ParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
2285 | } | ||
2286 | impl<R: TreeRoot<RaTypes>> Eq for ParamNode<R> {} | ||
2287 | impl<R: TreeRoot<RaTypes>> Hash for ParamNode<R> { | ||
2288 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2289 | } | ||
2290 | |||
1804 | impl<'a> AstNode<'a> for Param<'a> { | 2291 | impl<'a> AstNode<'a> for Param<'a> { |
1805 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2292 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1806 | match syntax.kind() { | 2293 | match syntax.kind() { |
@@ -1828,12 +2315,20 @@ impl<'a> Param<'a> { | |||
1828 | } | 2315 | } |
1829 | 2316 | ||
1830 | // ParamList | 2317 | // ParamList |
1831 | #[derive(Debug, Clone, Copy)] | 2318 | #[derive(Debug, Clone, Copy,)] |
1832 | pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2319 | pub struct ParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1833 | syntax: SyntaxNode<R>, | 2320 | pub(crate) syntax: SyntaxNode<R>, |
1834 | } | 2321 | } |
1835 | pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; | 2322 | pub type ParamList<'a> = ParamListNode<RefRoot<'a>>; |
1836 | 2323 | ||
2324 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParamListNode<R1>> for ParamListNode<R2> { | ||
2325 | fn eq(&self, other: &ParamListNode<R1>) -> bool { self.syntax == other.syntax } | ||
2326 | } | ||
2327 | impl<R: TreeRoot<RaTypes>> Eq for ParamListNode<R> {} | ||
2328 | impl<R: TreeRoot<RaTypes>> Hash for ParamListNode<R> { | ||
2329 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2330 | } | ||
2331 | |||
1837 | impl<'a> AstNode<'a> for ParamList<'a> { | 2332 | impl<'a> AstNode<'a> for ParamList<'a> { |
1838 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2333 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1839 | match syntax.kind() { | 2334 | match syntax.kind() { |
@@ -1865,12 +2360,20 @@ impl<'a> ParamList<'a> { | |||
1865 | } | 2360 | } |
1866 | 2361 | ||
1867 | // ParenExpr | 2362 | // ParenExpr |
1868 | #[derive(Debug, Clone, Copy)] | 2363 | #[derive(Debug, Clone, Copy,)] |
1869 | pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2364 | pub struct ParenExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1870 | syntax: SyntaxNode<R>, | 2365 | pub(crate) syntax: SyntaxNode<R>, |
1871 | } | 2366 | } |
1872 | pub type ParenExpr<'a> = ParenExprNode<RefRoot<'a>>; | 2367 | pub type ParenExpr<'a> = ParenExprNode<RefRoot<'a>>; |
1873 | 2368 | ||
2369 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenExprNode<R1>> for ParenExprNode<R2> { | ||
2370 | fn eq(&self, other: &ParenExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2371 | } | ||
2372 | impl<R: TreeRoot<RaTypes>> Eq for ParenExprNode<R> {} | ||
2373 | impl<R: TreeRoot<RaTypes>> Hash for ParenExprNode<R> { | ||
2374 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2375 | } | ||
2376 | |||
1874 | impl<'a> AstNode<'a> for ParenExpr<'a> { | 2377 | impl<'a> AstNode<'a> for ParenExpr<'a> { |
1875 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2378 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1876 | match syntax.kind() { | 2379 | match syntax.kind() { |
@@ -1894,12 +2397,20 @@ impl<R: TreeRoot<RaTypes>> ParenExprNode<R> { | |||
1894 | impl<'a> ParenExpr<'a> {} | 2397 | impl<'a> ParenExpr<'a> {} |
1895 | 2398 | ||
1896 | // ParenType | 2399 | // ParenType |
1897 | #[derive(Debug, Clone, Copy)] | 2400 | #[derive(Debug, Clone, Copy,)] |
1898 | pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2401 | pub struct ParenTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1899 | syntax: SyntaxNode<R>, | 2402 | pub(crate) syntax: SyntaxNode<R>, |
1900 | } | 2403 | } |
1901 | pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; | 2404 | pub type ParenType<'a> = ParenTypeNode<RefRoot<'a>>; |
1902 | 2405 | ||
2406 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ParenTypeNode<R1>> for ParenTypeNode<R2> { | ||
2407 | fn eq(&self, other: &ParenTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2408 | } | ||
2409 | impl<R: TreeRoot<RaTypes>> Eq for ParenTypeNode<R> {} | ||
2410 | impl<R: TreeRoot<RaTypes>> Hash for ParenTypeNode<R> { | ||
2411 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2412 | } | ||
2413 | |||
1903 | impl<'a> AstNode<'a> for ParenType<'a> { | 2414 | impl<'a> AstNode<'a> for ParenType<'a> { |
1904 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2415 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1905 | match syntax.kind() { | 2416 | match syntax.kind() { |
@@ -1923,7 +2434,7 @@ impl<R: TreeRoot<RaTypes>> ParenTypeNode<R> { | |||
1923 | impl<'a> ParenType<'a> {} | 2434 | impl<'a> ParenType<'a> {} |
1924 | 2435 | ||
1925 | // Pat | 2436 | // Pat |
1926 | #[derive(Debug, Clone, Copy)] | 2437 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
1927 | pub enum Pat<'a> { | 2438 | pub enum Pat<'a> { |
1928 | RefPat(RefPat<'a>), | 2439 | RefPat(RefPat<'a>), |
1929 | BindPat(BindPat<'a>), | 2440 | BindPat(BindPat<'a>), |
@@ -1972,12 +2483,20 @@ impl<'a> AstNode<'a> for Pat<'a> { | |||
1972 | impl<'a> Pat<'a> {} | 2483 | impl<'a> Pat<'a> {} |
1973 | 2484 | ||
1974 | // Path | 2485 | // Path |
1975 | #[derive(Debug, Clone, Copy)] | 2486 | #[derive(Debug, Clone, Copy,)] |
1976 | pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2487 | pub struct PathNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
1977 | syntax: SyntaxNode<R>, | 2488 | pub(crate) syntax: SyntaxNode<R>, |
1978 | } | 2489 | } |
1979 | pub type Path<'a> = PathNode<RefRoot<'a>>; | 2490 | pub type Path<'a> = PathNode<RefRoot<'a>>; |
1980 | 2491 | ||
2492 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathNode<R1>> for PathNode<R2> { | ||
2493 | fn eq(&self, other: &PathNode<R1>) -> bool { self.syntax == other.syntax } | ||
2494 | } | ||
2495 | impl<R: TreeRoot<RaTypes>> Eq for PathNode<R> {} | ||
2496 | impl<R: TreeRoot<RaTypes>> Hash for PathNode<R> { | ||
2497 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2498 | } | ||
2499 | |||
1981 | impl<'a> AstNode<'a> for Path<'a> { | 2500 | impl<'a> AstNode<'a> for Path<'a> { |
1982 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2501 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
1983 | match syntax.kind() { | 2502 | match syntax.kind() { |
@@ -2009,12 +2528,20 @@ impl<'a> Path<'a> { | |||
2009 | } | 2528 | } |
2010 | 2529 | ||
2011 | // PathExpr | 2530 | // PathExpr |
2012 | #[derive(Debug, Clone, Copy)] | 2531 | #[derive(Debug, Clone, Copy,)] |
2013 | pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2532 | pub struct PathExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2014 | syntax: SyntaxNode<R>, | 2533 | pub(crate) syntax: SyntaxNode<R>, |
2015 | } | 2534 | } |
2016 | pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; | 2535 | pub type PathExpr<'a> = PathExprNode<RefRoot<'a>>; |
2017 | 2536 | ||
2537 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathExprNode<R1>> for PathExprNode<R2> { | ||
2538 | fn eq(&self, other: &PathExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2539 | } | ||
2540 | impl<R: TreeRoot<RaTypes>> Eq for PathExprNode<R> {} | ||
2541 | impl<R: TreeRoot<RaTypes>> Hash for PathExprNode<R> { | ||
2542 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2543 | } | ||
2544 | |||
2018 | impl<'a> AstNode<'a> for PathExpr<'a> { | 2545 | impl<'a> AstNode<'a> for PathExpr<'a> { |
2019 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2546 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2020 | match syntax.kind() { | 2547 | match syntax.kind() { |
@@ -2042,12 +2569,20 @@ impl<'a> PathExpr<'a> { | |||
2042 | } | 2569 | } |
2043 | 2570 | ||
2044 | // PathPat | 2571 | // PathPat |
2045 | #[derive(Debug, Clone, Copy)] | 2572 | #[derive(Debug, Clone, Copy,)] |
2046 | pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2573 | pub struct PathPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2047 | syntax: SyntaxNode<R>, | 2574 | pub(crate) syntax: SyntaxNode<R>, |
2048 | } | 2575 | } |
2049 | pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; | 2576 | pub type PathPat<'a> = PathPatNode<RefRoot<'a>>; |
2050 | 2577 | ||
2578 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathPatNode<R1>> for PathPatNode<R2> { | ||
2579 | fn eq(&self, other: &PathPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2580 | } | ||
2581 | impl<R: TreeRoot<RaTypes>> Eq for PathPatNode<R> {} | ||
2582 | impl<R: TreeRoot<RaTypes>> Hash for PathPatNode<R> { | ||
2583 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2584 | } | ||
2585 | |||
2051 | impl<'a> AstNode<'a> for PathPat<'a> { | 2586 | impl<'a> AstNode<'a> for PathPat<'a> { |
2052 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2587 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2053 | match syntax.kind() { | 2588 | match syntax.kind() { |
@@ -2071,12 +2606,20 @@ impl<R: TreeRoot<RaTypes>> PathPatNode<R> { | |||
2071 | impl<'a> PathPat<'a> {} | 2606 | impl<'a> PathPat<'a> {} |
2072 | 2607 | ||
2073 | // PathSegment | 2608 | // PathSegment |
2074 | #[derive(Debug, Clone, Copy)] | 2609 | #[derive(Debug, Clone, Copy,)] |
2075 | pub struct PathSegmentNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2610 | pub struct PathSegmentNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2076 | syntax: SyntaxNode<R>, | 2611 | pub(crate) syntax: SyntaxNode<R>, |
2077 | } | 2612 | } |
2078 | pub type PathSegment<'a> = PathSegmentNode<RefRoot<'a>>; | 2613 | pub type PathSegment<'a> = PathSegmentNode<RefRoot<'a>>; |
2079 | 2614 | ||
2615 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathSegmentNode<R1>> for PathSegmentNode<R2> { | ||
2616 | fn eq(&self, other: &PathSegmentNode<R1>) -> bool { self.syntax == other.syntax } | ||
2617 | } | ||
2618 | impl<R: TreeRoot<RaTypes>> Eq for PathSegmentNode<R> {} | ||
2619 | impl<R: TreeRoot<RaTypes>> Hash for PathSegmentNode<R> { | ||
2620 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2621 | } | ||
2622 | |||
2080 | impl<'a> AstNode<'a> for PathSegment<'a> { | 2623 | impl<'a> AstNode<'a> for PathSegment<'a> { |
2081 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2624 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2082 | match syntax.kind() { | 2625 | match syntax.kind() { |
@@ -2104,12 +2647,20 @@ impl<'a> PathSegment<'a> { | |||
2104 | } | 2647 | } |
2105 | 2648 | ||
2106 | // PathType | 2649 | // PathType |
2107 | #[derive(Debug, Clone, Copy)] | 2650 | #[derive(Debug, Clone, Copy,)] |
2108 | pub struct PathTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2651 | pub struct PathTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2109 | syntax: SyntaxNode<R>, | 2652 | pub(crate) syntax: SyntaxNode<R>, |
2110 | } | 2653 | } |
2111 | pub type PathType<'a> = PathTypeNode<RefRoot<'a>>; | 2654 | pub type PathType<'a> = PathTypeNode<RefRoot<'a>>; |
2112 | 2655 | ||
2656 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PathTypeNode<R1>> for PathTypeNode<R2> { | ||
2657 | fn eq(&self, other: &PathTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2658 | } | ||
2659 | impl<R: TreeRoot<RaTypes>> Eq for PathTypeNode<R> {} | ||
2660 | impl<R: TreeRoot<RaTypes>> Hash for PathTypeNode<R> { | ||
2661 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2662 | } | ||
2663 | |||
2113 | impl<'a> AstNode<'a> for PathType<'a> { | 2664 | impl<'a> AstNode<'a> for PathType<'a> { |
2114 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2665 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2115 | match syntax.kind() { | 2666 | match syntax.kind() { |
@@ -2133,12 +2684,20 @@ impl<R: TreeRoot<RaTypes>> PathTypeNode<R> { | |||
2133 | impl<'a> PathType<'a> {} | 2684 | impl<'a> PathType<'a> {} |
2134 | 2685 | ||
2135 | // PlaceholderPat | 2686 | // PlaceholderPat |
2136 | #[derive(Debug, Clone, Copy)] | 2687 | #[derive(Debug, Clone, Copy,)] |
2137 | pub struct PlaceholderPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2688 | pub struct PlaceholderPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2138 | syntax: SyntaxNode<R>, | 2689 | pub(crate) syntax: SyntaxNode<R>, |
2139 | } | 2690 | } |
2140 | pub type PlaceholderPat<'a> = PlaceholderPatNode<RefRoot<'a>>; | 2691 | pub type PlaceholderPat<'a> = PlaceholderPatNode<RefRoot<'a>>; |
2141 | 2692 | ||
2693 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderPatNode<R1>> for PlaceholderPatNode<R2> { | ||
2694 | fn eq(&self, other: &PlaceholderPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2695 | } | ||
2696 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderPatNode<R> {} | ||
2697 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderPatNode<R> { | ||
2698 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2699 | } | ||
2700 | |||
2142 | impl<'a> AstNode<'a> for PlaceholderPat<'a> { | 2701 | impl<'a> AstNode<'a> for PlaceholderPat<'a> { |
2143 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2702 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2144 | match syntax.kind() { | 2703 | match syntax.kind() { |
@@ -2162,12 +2721,20 @@ impl<R: TreeRoot<RaTypes>> PlaceholderPatNode<R> { | |||
2162 | impl<'a> PlaceholderPat<'a> {} | 2721 | impl<'a> PlaceholderPat<'a> {} |
2163 | 2722 | ||
2164 | // PlaceholderType | 2723 | // PlaceholderType |
2165 | #[derive(Debug, Clone, Copy)] | 2724 | #[derive(Debug, Clone, Copy,)] |
2166 | pub struct PlaceholderTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2725 | pub struct PlaceholderTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2167 | syntax: SyntaxNode<R>, | 2726 | pub(crate) syntax: SyntaxNode<R>, |
2168 | } | 2727 | } |
2169 | pub type PlaceholderType<'a> = PlaceholderTypeNode<RefRoot<'a>>; | 2728 | pub type PlaceholderType<'a> = PlaceholderTypeNode<RefRoot<'a>>; |
2170 | 2729 | ||
2730 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PlaceholderTypeNode<R1>> for PlaceholderTypeNode<R2> { | ||
2731 | fn eq(&self, other: &PlaceholderTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2732 | } | ||
2733 | impl<R: TreeRoot<RaTypes>> Eq for PlaceholderTypeNode<R> {} | ||
2734 | impl<R: TreeRoot<RaTypes>> Hash for PlaceholderTypeNode<R> { | ||
2735 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2736 | } | ||
2737 | |||
2171 | impl<'a> AstNode<'a> for PlaceholderType<'a> { | 2738 | impl<'a> AstNode<'a> for PlaceholderType<'a> { |
2172 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2739 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2173 | match syntax.kind() { | 2740 | match syntax.kind() { |
@@ -2191,12 +2758,20 @@ impl<R: TreeRoot<RaTypes>> PlaceholderTypeNode<R> { | |||
2191 | impl<'a> PlaceholderType<'a> {} | 2758 | impl<'a> PlaceholderType<'a> {} |
2192 | 2759 | ||
2193 | // PointerType | 2760 | // PointerType |
2194 | #[derive(Debug, Clone, Copy)] | 2761 | #[derive(Debug, Clone, Copy,)] |
2195 | pub struct PointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2762 | pub struct PointerTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2196 | syntax: SyntaxNode<R>, | 2763 | pub(crate) syntax: SyntaxNode<R>, |
2197 | } | 2764 | } |
2198 | pub type PointerType<'a> = PointerTypeNode<RefRoot<'a>>; | 2765 | pub type PointerType<'a> = PointerTypeNode<RefRoot<'a>>; |
2199 | 2766 | ||
2767 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PointerTypeNode<R1>> for PointerTypeNode<R2> { | ||
2768 | fn eq(&self, other: &PointerTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2769 | } | ||
2770 | impl<R: TreeRoot<RaTypes>> Eq for PointerTypeNode<R> {} | ||
2771 | impl<R: TreeRoot<RaTypes>> Hash for PointerTypeNode<R> { | ||
2772 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2773 | } | ||
2774 | |||
2200 | impl<'a> AstNode<'a> for PointerType<'a> { | 2775 | impl<'a> AstNode<'a> for PointerType<'a> { |
2201 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2776 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2202 | match syntax.kind() { | 2777 | match syntax.kind() { |
@@ -2220,12 +2795,20 @@ impl<R: TreeRoot<RaTypes>> PointerTypeNode<R> { | |||
2220 | impl<'a> PointerType<'a> {} | 2795 | impl<'a> PointerType<'a> {} |
2221 | 2796 | ||
2222 | // PrefixExpr | 2797 | // PrefixExpr |
2223 | #[derive(Debug, Clone, Copy)] | 2798 | #[derive(Debug, Clone, Copy,)] |
2224 | pub struct PrefixExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2799 | pub struct PrefixExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2225 | syntax: SyntaxNode<R>, | 2800 | pub(crate) syntax: SyntaxNode<R>, |
2226 | } | 2801 | } |
2227 | pub type PrefixExpr<'a> = PrefixExprNode<RefRoot<'a>>; | 2802 | pub type PrefixExpr<'a> = PrefixExprNode<RefRoot<'a>>; |
2228 | 2803 | ||
2804 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<PrefixExprNode<R1>> for PrefixExprNode<R2> { | ||
2805 | fn eq(&self, other: &PrefixExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2806 | } | ||
2807 | impl<R: TreeRoot<RaTypes>> Eq for PrefixExprNode<R> {} | ||
2808 | impl<R: TreeRoot<RaTypes>> Hash for PrefixExprNode<R> { | ||
2809 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2810 | } | ||
2811 | |||
2229 | impl<'a> AstNode<'a> for PrefixExpr<'a> { | 2812 | impl<'a> AstNode<'a> for PrefixExpr<'a> { |
2230 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2813 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2231 | match syntax.kind() { | 2814 | match syntax.kind() { |
@@ -2249,12 +2832,20 @@ impl<R: TreeRoot<RaTypes>> PrefixExprNode<R> { | |||
2249 | impl<'a> PrefixExpr<'a> {} | 2832 | impl<'a> PrefixExpr<'a> {} |
2250 | 2833 | ||
2251 | // RangeExpr | 2834 | // RangeExpr |
2252 | #[derive(Debug, Clone, Copy)] | 2835 | #[derive(Debug, Clone, Copy,)] |
2253 | pub struct RangeExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2836 | pub struct RangeExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2254 | syntax: SyntaxNode<R>, | 2837 | pub(crate) syntax: SyntaxNode<R>, |
2255 | } | 2838 | } |
2256 | pub type RangeExpr<'a> = RangeExprNode<RefRoot<'a>>; | 2839 | pub type RangeExpr<'a> = RangeExprNode<RefRoot<'a>>; |
2257 | 2840 | ||
2841 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangeExprNode<R1>> for RangeExprNode<R2> { | ||
2842 | fn eq(&self, other: &RangeExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2843 | } | ||
2844 | impl<R: TreeRoot<RaTypes>> Eq for RangeExprNode<R> {} | ||
2845 | impl<R: TreeRoot<RaTypes>> Hash for RangeExprNode<R> { | ||
2846 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2847 | } | ||
2848 | |||
2258 | impl<'a> AstNode<'a> for RangeExpr<'a> { | 2849 | impl<'a> AstNode<'a> for RangeExpr<'a> { |
2259 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2850 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2260 | match syntax.kind() { | 2851 | match syntax.kind() { |
@@ -2278,12 +2869,20 @@ impl<R: TreeRoot<RaTypes>> RangeExprNode<R> { | |||
2278 | impl<'a> RangeExpr<'a> {} | 2869 | impl<'a> RangeExpr<'a> {} |
2279 | 2870 | ||
2280 | // RangePat | 2871 | // RangePat |
2281 | #[derive(Debug, Clone, Copy)] | 2872 | #[derive(Debug, Clone, Copy,)] |
2282 | pub struct RangePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2873 | pub struct RangePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2283 | syntax: SyntaxNode<R>, | 2874 | pub(crate) syntax: SyntaxNode<R>, |
2284 | } | 2875 | } |
2285 | pub type RangePat<'a> = RangePatNode<RefRoot<'a>>; | 2876 | pub type RangePat<'a> = RangePatNode<RefRoot<'a>>; |
2286 | 2877 | ||
2878 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RangePatNode<R1>> for RangePatNode<R2> { | ||
2879 | fn eq(&self, other: &RangePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2880 | } | ||
2881 | impl<R: TreeRoot<RaTypes>> Eq for RangePatNode<R> {} | ||
2882 | impl<R: TreeRoot<RaTypes>> Hash for RangePatNode<R> { | ||
2883 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2884 | } | ||
2885 | |||
2287 | impl<'a> AstNode<'a> for RangePat<'a> { | 2886 | impl<'a> AstNode<'a> for RangePat<'a> { |
2288 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2887 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2289 | match syntax.kind() { | 2888 | match syntax.kind() { |
@@ -2307,12 +2906,20 @@ impl<R: TreeRoot<RaTypes>> RangePatNode<R> { | |||
2307 | impl<'a> RangePat<'a> {} | 2906 | impl<'a> RangePat<'a> {} |
2308 | 2907 | ||
2309 | // RefExpr | 2908 | // RefExpr |
2310 | #[derive(Debug, Clone, Copy)] | 2909 | #[derive(Debug, Clone, Copy,)] |
2311 | pub struct RefExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2910 | pub struct RefExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2312 | syntax: SyntaxNode<R>, | 2911 | pub(crate) syntax: SyntaxNode<R>, |
2313 | } | 2912 | } |
2314 | pub type RefExpr<'a> = RefExprNode<RefRoot<'a>>; | 2913 | pub type RefExpr<'a> = RefExprNode<RefRoot<'a>>; |
2315 | 2914 | ||
2915 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefExprNode<R1>> for RefExprNode<R2> { | ||
2916 | fn eq(&self, other: &RefExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
2917 | } | ||
2918 | impl<R: TreeRoot<RaTypes>> Eq for RefExprNode<R> {} | ||
2919 | impl<R: TreeRoot<RaTypes>> Hash for RefExprNode<R> { | ||
2920 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2921 | } | ||
2922 | |||
2316 | impl<'a> AstNode<'a> for RefExpr<'a> { | 2923 | impl<'a> AstNode<'a> for RefExpr<'a> { |
2317 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2924 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2318 | match syntax.kind() { | 2925 | match syntax.kind() { |
@@ -2336,12 +2943,20 @@ impl<R: TreeRoot<RaTypes>> RefExprNode<R> { | |||
2336 | impl<'a> RefExpr<'a> {} | 2943 | impl<'a> RefExpr<'a> {} |
2337 | 2944 | ||
2338 | // RefPat | 2945 | // RefPat |
2339 | #[derive(Debug, Clone, Copy)] | 2946 | #[derive(Debug, Clone, Copy,)] |
2340 | pub struct RefPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2947 | pub struct RefPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2341 | syntax: SyntaxNode<R>, | 2948 | pub(crate) syntax: SyntaxNode<R>, |
2342 | } | 2949 | } |
2343 | pub type RefPat<'a> = RefPatNode<RefRoot<'a>>; | 2950 | pub type RefPat<'a> = RefPatNode<RefRoot<'a>>; |
2344 | 2951 | ||
2952 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RefPatNode<R1>> for RefPatNode<R2> { | ||
2953 | fn eq(&self, other: &RefPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
2954 | } | ||
2955 | impl<R: TreeRoot<RaTypes>> Eq for RefPatNode<R> {} | ||
2956 | impl<R: TreeRoot<RaTypes>> Hash for RefPatNode<R> { | ||
2957 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2958 | } | ||
2959 | |||
2345 | impl<'a> AstNode<'a> for RefPat<'a> { | 2960 | impl<'a> AstNode<'a> for RefPat<'a> { |
2346 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2961 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2347 | match syntax.kind() { | 2962 | match syntax.kind() { |
@@ -2365,12 +2980,20 @@ impl<R: TreeRoot<RaTypes>> RefPatNode<R> { | |||
2365 | impl<'a> RefPat<'a> {} | 2980 | impl<'a> RefPat<'a> {} |
2366 | 2981 | ||
2367 | // ReferenceType | 2982 | // ReferenceType |
2368 | #[derive(Debug, Clone, Copy)] | 2983 | #[derive(Debug, Clone, Copy,)] |
2369 | pub struct ReferenceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 2984 | pub struct ReferenceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2370 | syntax: SyntaxNode<R>, | 2985 | pub(crate) syntax: SyntaxNode<R>, |
2371 | } | 2986 | } |
2372 | pub type ReferenceType<'a> = ReferenceTypeNode<RefRoot<'a>>; | 2987 | pub type ReferenceType<'a> = ReferenceTypeNode<RefRoot<'a>>; |
2373 | 2988 | ||
2989 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReferenceTypeNode<R1>> for ReferenceTypeNode<R2> { | ||
2990 | fn eq(&self, other: &ReferenceTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
2991 | } | ||
2992 | impl<R: TreeRoot<RaTypes>> Eq for ReferenceTypeNode<R> {} | ||
2993 | impl<R: TreeRoot<RaTypes>> Hash for ReferenceTypeNode<R> { | ||
2994 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
2995 | } | ||
2996 | |||
2374 | impl<'a> AstNode<'a> for ReferenceType<'a> { | 2997 | impl<'a> AstNode<'a> for ReferenceType<'a> { |
2375 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 2998 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2376 | match syntax.kind() { | 2999 | match syntax.kind() { |
@@ -2394,12 +3017,20 @@ impl<R: TreeRoot<RaTypes>> ReferenceTypeNode<R> { | |||
2394 | impl<'a> ReferenceType<'a> {} | 3017 | impl<'a> ReferenceType<'a> {} |
2395 | 3018 | ||
2396 | // RetType | 3019 | // RetType |
2397 | #[derive(Debug, Clone, Copy)] | 3020 | #[derive(Debug, Clone, Copy,)] |
2398 | pub struct RetTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3021 | pub struct RetTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2399 | syntax: SyntaxNode<R>, | 3022 | pub(crate) syntax: SyntaxNode<R>, |
2400 | } | 3023 | } |
2401 | pub type RetType<'a> = RetTypeNode<RefRoot<'a>>; | 3024 | pub type RetType<'a> = RetTypeNode<RefRoot<'a>>; |
2402 | 3025 | ||
3026 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<RetTypeNode<R1>> for RetTypeNode<R2> { | ||
3027 | fn eq(&self, other: &RetTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3028 | } | ||
3029 | impl<R: TreeRoot<RaTypes>> Eq for RetTypeNode<R> {} | ||
3030 | impl<R: TreeRoot<RaTypes>> Hash for RetTypeNode<R> { | ||
3031 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3032 | } | ||
3033 | |||
2403 | impl<'a> AstNode<'a> for RetType<'a> { | 3034 | impl<'a> AstNode<'a> for RetType<'a> { |
2404 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3035 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2405 | match syntax.kind() { | 3036 | match syntax.kind() { |
@@ -2423,12 +3054,20 @@ impl<R: TreeRoot<RaTypes>> RetTypeNode<R> { | |||
2423 | impl<'a> RetType<'a> {} | 3054 | impl<'a> RetType<'a> {} |
2424 | 3055 | ||
2425 | // ReturnExpr | 3056 | // ReturnExpr |
2426 | #[derive(Debug, Clone, Copy)] | 3057 | #[derive(Debug, Clone, Copy,)] |
2427 | pub struct ReturnExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3058 | pub struct ReturnExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2428 | syntax: SyntaxNode<R>, | 3059 | pub(crate) syntax: SyntaxNode<R>, |
2429 | } | 3060 | } |
2430 | pub type ReturnExpr<'a> = ReturnExprNode<RefRoot<'a>>; | 3061 | pub type ReturnExpr<'a> = ReturnExprNode<RefRoot<'a>>; |
2431 | 3062 | ||
3063 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ReturnExprNode<R1>> for ReturnExprNode<R2> { | ||
3064 | fn eq(&self, other: &ReturnExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3065 | } | ||
3066 | impl<R: TreeRoot<RaTypes>> Eq for ReturnExprNode<R> {} | ||
3067 | impl<R: TreeRoot<RaTypes>> Hash for ReturnExprNode<R> { | ||
3068 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3069 | } | ||
3070 | |||
2432 | impl<'a> AstNode<'a> for ReturnExpr<'a> { | 3071 | impl<'a> AstNode<'a> for ReturnExpr<'a> { |
2433 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3072 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2434 | match syntax.kind() { | 3073 | match syntax.kind() { |
@@ -2451,48 +3090,21 @@ impl<R: TreeRoot<RaTypes>> ReturnExprNode<R> { | |||
2451 | 3090 | ||
2452 | impl<'a> ReturnExpr<'a> {} | 3091 | impl<'a> ReturnExpr<'a> {} |
2453 | 3092 | ||
2454 | // Root | ||
2455 | #[derive(Debug, Clone, Copy)] | ||
2456 | pub struct RootNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
2457 | syntax: SyntaxNode<R>, | ||
2458 | } | ||
2459 | pub type Root<'a> = RootNode<RefRoot<'a>>; | ||
2460 | |||
2461 | impl<'a> AstNode<'a> for Root<'a> { | ||
2462 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
2463 | match syntax.kind() { | ||
2464 | ROOT => Some(Root { syntax }), | ||
2465 | _ => None, | ||
2466 | } | ||
2467 | } | ||
2468 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
2469 | } | ||
2470 | |||
2471 | impl<R: TreeRoot<RaTypes>> RootNode<R> { | ||
2472 | pub fn borrowed(&self) -> Root { | ||
2473 | RootNode { syntax: self.syntax.borrowed() } | ||
2474 | } | ||
2475 | pub fn owned(&self) -> RootNode { | ||
2476 | RootNode { syntax: self.syntax.owned() } | ||
2477 | } | ||
2478 | } | ||
2479 | |||
2480 | |||
2481 | impl<'a> ast::ModuleItemOwner<'a> for Root<'a> {} | ||
2482 | impl<'a> ast::FnDefOwner<'a> for Root<'a> {} | ||
2483 | impl<'a> Root<'a> { | ||
2484 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | ||
2485 | super::children(self) | ||
2486 | } | ||
2487 | } | ||
2488 | |||
2489 | // SelfParam | 3093 | // SelfParam |
2490 | #[derive(Debug, Clone, Copy)] | 3094 | #[derive(Debug, Clone, Copy,)] |
2491 | pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3095 | pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2492 | syntax: SyntaxNode<R>, | 3096 | pub(crate) syntax: SyntaxNode<R>, |
2493 | } | 3097 | } |
2494 | pub type SelfParam<'a> = SelfParamNode<RefRoot<'a>>; | 3098 | pub type SelfParam<'a> = SelfParamNode<RefRoot<'a>>; |
2495 | 3099 | ||
3100 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfParamNode<R1>> for SelfParamNode<R2> { | ||
3101 | fn eq(&self, other: &SelfParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
3102 | } | ||
3103 | impl<R: TreeRoot<RaTypes>> Eq for SelfParamNode<R> {} | ||
3104 | impl<R: TreeRoot<RaTypes>> Hash for SelfParamNode<R> { | ||
3105 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3106 | } | ||
3107 | |||
2496 | impl<'a> AstNode<'a> for SelfParam<'a> { | 3108 | impl<'a> AstNode<'a> for SelfParam<'a> { |
2497 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3109 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2498 | match syntax.kind() { | 3110 | match syntax.kind() { |
@@ -2516,12 +3128,20 @@ impl<R: TreeRoot<RaTypes>> SelfParamNode<R> { | |||
2516 | impl<'a> SelfParam<'a> {} | 3128 | impl<'a> SelfParam<'a> {} |
2517 | 3129 | ||
2518 | // SlicePat | 3130 | // SlicePat |
2519 | #[derive(Debug, Clone, Copy)] | 3131 | #[derive(Debug, Clone, Copy,)] |
2520 | pub struct SlicePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3132 | pub struct SlicePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2521 | syntax: SyntaxNode<R>, | 3133 | pub(crate) syntax: SyntaxNode<R>, |
2522 | } | 3134 | } |
2523 | pub type SlicePat<'a> = SlicePatNode<RefRoot<'a>>; | 3135 | pub type SlicePat<'a> = SlicePatNode<RefRoot<'a>>; |
2524 | 3136 | ||
3137 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SlicePatNode<R1>> for SlicePatNode<R2> { | ||
3138 | fn eq(&self, other: &SlicePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3139 | } | ||
3140 | impl<R: TreeRoot<RaTypes>> Eq for SlicePatNode<R> {} | ||
3141 | impl<R: TreeRoot<RaTypes>> Hash for SlicePatNode<R> { | ||
3142 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3143 | } | ||
3144 | |||
2525 | impl<'a> AstNode<'a> for SlicePat<'a> { | 3145 | impl<'a> AstNode<'a> for SlicePat<'a> { |
2526 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3146 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2527 | match syntax.kind() { | 3147 | match syntax.kind() { |
@@ -2545,12 +3165,20 @@ impl<R: TreeRoot<RaTypes>> SlicePatNode<R> { | |||
2545 | impl<'a> SlicePat<'a> {} | 3165 | impl<'a> SlicePat<'a> {} |
2546 | 3166 | ||
2547 | // SliceType | 3167 | // SliceType |
2548 | #[derive(Debug, Clone, Copy)] | 3168 | #[derive(Debug, Clone, Copy,)] |
2549 | pub struct SliceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3169 | pub struct SliceTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2550 | syntax: SyntaxNode<R>, | 3170 | pub(crate) syntax: SyntaxNode<R>, |
2551 | } | 3171 | } |
2552 | pub type SliceType<'a> = SliceTypeNode<RefRoot<'a>>; | 3172 | pub type SliceType<'a> = SliceTypeNode<RefRoot<'a>>; |
2553 | 3173 | ||
3174 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SliceTypeNode<R1>> for SliceTypeNode<R2> { | ||
3175 | fn eq(&self, other: &SliceTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3176 | } | ||
3177 | impl<R: TreeRoot<RaTypes>> Eq for SliceTypeNode<R> {} | ||
3178 | impl<R: TreeRoot<RaTypes>> Hash for SliceTypeNode<R> { | ||
3179 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3180 | } | ||
3181 | |||
2554 | impl<'a> AstNode<'a> for SliceType<'a> { | 3182 | impl<'a> AstNode<'a> for SliceType<'a> { |
2555 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3183 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2556 | match syntax.kind() { | 3184 | match syntax.kind() { |
@@ -2573,13 +3201,64 @@ impl<R: TreeRoot<RaTypes>> SliceTypeNode<R> { | |||
2573 | 3201 | ||
2574 | impl<'a> SliceType<'a> {} | 3202 | impl<'a> SliceType<'a> {} |
2575 | 3203 | ||
3204 | // SourceFile | ||
3205 | #[derive(Debug, Clone, Copy,)] | ||
3206 | pub struct SourceFileNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
3207 | pub(crate) syntax: SyntaxNode<R>, | ||
3208 | } | ||
3209 | pub type SourceFile<'a> = SourceFileNode<RefRoot<'a>>; | ||
3210 | |||
3211 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SourceFileNode<R1>> for SourceFileNode<R2> { | ||
3212 | fn eq(&self, other: &SourceFileNode<R1>) -> bool { self.syntax == other.syntax } | ||
3213 | } | ||
3214 | impl<R: TreeRoot<RaTypes>> Eq for SourceFileNode<R> {} | ||
3215 | impl<R: TreeRoot<RaTypes>> Hash for SourceFileNode<R> { | ||
3216 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3217 | } | ||
3218 | |||
3219 | impl<'a> AstNode<'a> for SourceFile<'a> { | ||
3220 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
3221 | match syntax.kind() { | ||
3222 | SOURCE_FILE => Some(SourceFile { syntax }), | ||
3223 | _ => None, | ||
3224 | } | ||
3225 | } | ||
3226 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
3227 | } | ||
3228 | |||
3229 | impl<R: TreeRoot<RaTypes>> SourceFileNode<R> { | ||
3230 | pub fn borrowed(&self) -> SourceFile { | ||
3231 | SourceFileNode { syntax: self.syntax.borrowed() } | ||
3232 | } | ||
3233 | pub fn owned(&self) -> SourceFileNode { | ||
3234 | SourceFileNode { syntax: self.syntax.owned() } | ||
3235 | } | ||
3236 | } | ||
3237 | |||
3238 | |||
3239 | impl<'a> ast::ModuleItemOwner<'a> for SourceFile<'a> {} | ||
3240 | impl<'a> ast::FnDefOwner<'a> for SourceFile<'a> {} | ||
3241 | impl<'a> SourceFile<'a> { | ||
3242 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | ||
3243 | super::children(self) | ||
3244 | } | ||
3245 | } | ||
3246 | |||
2576 | // StaticDef | 3247 | // StaticDef |
2577 | #[derive(Debug, Clone, Copy)] | 3248 | #[derive(Debug, Clone, Copy,)] |
2578 | pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3249 | pub struct StaticDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2579 | syntax: SyntaxNode<R>, | 3250 | pub(crate) syntax: SyntaxNode<R>, |
2580 | } | 3251 | } |
2581 | pub type StaticDef<'a> = StaticDefNode<RefRoot<'a>>; | 3252 | pub type StaticDef<'a> = StaticDefNode<RefRoot<'a>>; |
2582 | 3253 | ||
3254 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StaticDefNode<R1>> for StaticDefNode<R2> { | ||
3255 | fn eq(&self, other: &StaticDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3256 | } | ||
3257 | impl<R: TreeRoot<RaTypes>> Eq for StaticDefNode<R> {} | ||
3258 | impl<R: TreeRoot<RaTypes>> Hash for StaticDefNode<R> { | ||
3259 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3260 | } | ||
3261 | |||
2583 | impl<'a> AstNode<'a> for StaticDef<'a> { | 3262 | impl<'a> AstNode<'a> for StaticDef<'a> { |
2584 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3263 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2585 | match syntax.kind() { | 3264 | match syntax.kind() { |
@@ -2603,10 +3282,11 @@ impl<R: TreeRoot<RaTypes>> StaticDefNode<R> { | |||
2603 | impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} | 3282 | impl<'a> ast::NameOwner<'a> for StaticDef<'a> {} |
2604 | impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {} | 3283 | impl<'a> ast::TypeParamsOwner<'a> for StaticDef<'a> {} |
2605 | impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} | 3284 | impl<'a> ast::AttrsOwner<'a> for StaticDef<'a> {} |
3285 | impl<'a> ast::DocCommentsOwner<'a> for StaticDef<'a> {} | ||
2606 | impl<'a> StaticDef<'a> {} | 3286 | impl<'a> StaticDef<'a> {} |
2607 | 3287 | ||
2608 | // Stmt | 3288 | // Stmt |
2609 | #[derive(Debug, Clone, Copy)] | 3289 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
2610 | pub enum Stmt<'a> { | 3290 | pub enum Stmt<'a> { |
2611 | ExprStmt(ExprStmt<'a>), | 3291 | ExprStmt(ExprStmt<'a>), |
2612 | LetStmt(LetStmt<'a>), | 3292 | LetStmt(LetStmt<'a>), |
@@ -2630,13 +3310,58 @@ impl<'a> AstNode<'a> for Stmt<'a> { | |||
2630 | 3310 | ||
2631 | impl<'a> Stmt<'a> {} | 3311 | impl<'a> Stmt<'a> {} |
2632 | 3312 | ||
3313 | // String | ||
3314 | #[derive(Debug, Clone, Copy,)] | ||
3315 | pub struct StringNode<R: TreeRoot<RaTypes> = OwnedRoot> { | ||
3316 | pub(crate) syntax: SyntaxNode<R>, | ||
3317 | } | ||
3318 | pub type String<'a> = StringNode<RefRoot<'a>>; | ||
3319 | |||
3320 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StringNode<R1>> for StringNode<R2> { | ||
3321 | fn eq(&self, other: &StringNode<R1>) -> bool { self.syntax == other.syntax } | ||
3322 | } | ||
3323 | impl<R: TreeRoot<RaTypes>> Eq for StringNode<R> {} | ||
3324 | impl<R: TreeRoot<RaTypes>> Hash for StringNode<R> { | ||
3325 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3326 | } | ||
3327 | |||
3328 | impl<'a> AstNode<'a> for String<'a> { | ||
3329 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | ||
3330 | match syntax.kind() { | ||
3331 | STRING => Some(String { syntax }), | ||
3332 | _ => None, | ||
3333 | } | ||
3334 | } | ||
3335 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | ||
3336 | } | ||
3337 | |||
3338 | impl<R: TreeRoot<RaTypes>> StringNode<R> { | ||
3339 | pub fn borrowed(&self) -> String { | ||
3340 | StringNode { syntax: self.syntax.borrowed() } | ||
3341 | } | ||
3342 | pub fn owned(&self) -> StringNode { | ||
3343 | StringNode { syntax: self.syntax.owned() } | ||
3344 | } | ||
3345 | } | ||
3346 | |||
3347 | |||
3348 | impl<'a> String<'a> {} | ||
3349 | |||
2633 | // StructDef | 3350 | // StructDef |
2634 | #[derive(Debug, Clone, Copy)] | 3351 | #[derive(Debug, Clone, Copy,)] |
2635 | pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3352 | pub struct StructDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2636 | syntax: SyntaxNode<R>, | 3353 | pub(crate) syntax: SyntaxNode<R>, |
2637 | } | 3354 | } |
2638 | pub type StructDef<'a> = StructDefNode<RefRoot<'a>>; | 3355 | pub type StructDef<'a> = StructDefNode<RefRoot<'a>>; |
2639 | 3356 | ||
3357 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructDefNode<R1>> for StructDefNode<R2> { | ||
3358 | fn eq(&self, other: &StructDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3359 | } | ||
3360 | impl<R: TreeRoot<RaTypes>> Eq for StructDefNode<R> {} | ||
3361 | impl<R: TreeRoot<RaTypes>> Hash for StructDefNode<R> { | ||
3362 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3363 | } | ||
3364 | |||
2640 | impl<'a> AstNode<'a> for StructDef<'a> { | 3365 | impl<'a> AstNode<'a> for StructDef<'a> { |
2641 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3366 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2642 | match syntax.kind() { | 3367 | match syntax.kind() { |
@@ -2660,6 +3385,7 @@ impl<R: TreeRoot<RaTypes>> StructDefNode<R> { | |||
2660 | impl<'a> ast::NameOwner<'a> for StructDef<'a> {} | 3385 | impl<'a> ast::NameOwner<'a> for StructDef<'a> {} |
2661 | impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {} | 3386 | impl<'a> ast::TypeParamsOwner<'a> for StructDef<'a> {} |
2662 | impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} | 3387 | impl<'a> ast::AttrsOwner<'a> for StructDef<'a> {} |
3388 | impl<'a> ast::DocCommentsOwner<'a> for StructDef<'a> {} | ||
2663 | impl<'a> StructDef<'a> { | 3389 | impl<'a> StructDef<'a> { |
2664 | pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a { | 3390 | pub fn fields(self) -> impl Iterator<Item = NamedFieldDef<'a>> + 'a { |
2665 | super::children(self) | 3391 | super::children(self) |
@@ -2667,12 +3393,20 @@ impl<'a> StructDef<'a> { | |||
2667 | } | 3393 | } |
2668 | 3394 | ||
2669 | // StructLit | 3395 | // StructLit |
2670 | #[derive(Debug, Clone, Copy)] | 3396 | #[derive(Debug, Clone, Copy,)] |
2671 | pub struct StructLitNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3397 | pub struct StructLitNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2672 | syntax: SyntaxNode<R>, | 3398 | pub(crate) syntax: SyntaxNode<R>, |
2673 | } | 3399 | } |
2674 | pub type StructLit<'a> = StructLitNode<RefRoot<'a>>; | 3400 | pub type StructLit<'a> = StructLitNode<RefRoot<'a>>; |
2675 | 3401 | ||
3402 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructLitNode<R1>> for StructLitNode<R2> { | ||
3403 | fn eq(&self, other: &StructLitNode<R1>) -> bool { self.syntax == other.syntax } | ||
3404 | } | ||
3405 | impl<R: TreeRoot<RaTypes>> Eq for StructLitNode<R> {} | ||
3406 | impl<R: TreeRoot<RaTypes>> Hash for StructLitNode<R> { | ||
3407 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3408 | } | ||
3409 | |||
2676 | impl<'a> AstNode<'a> for StructLit<'a> { | 3410 | impl<'a> AstNode<'a> for StructLit<'a> { |
2677 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3411 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2678 | match syntax.kind() { | 3412 | match syntax.kind() { |
@@ -2696,12 +3430,20 @@ impl<R: TreeRoot<RaTypes>> StructLitNode<R> { | |||
2696 | impl<'a> StructLit<'a> {} | 3430 | impl<'a> StructLit<'a> {} |
2697 | 3431 | ||
2698 | // StructPat | 3432 | // StructPat |
2699 | #[derive(Debug, Clone, Copy)] | 3433 | #[derive(Debug, Clone, Copy,)] |
2700 | pub struct StructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3434 | pub struct StructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2701 | syntax: SyntaxNode<R>, | 3435 | pub(crate) syntax: SyntaxNode<R>, |
2702 | } | 3436 | } |
2703 | pub type StructPat<'a> = StructPatNode<RefRoot<'a>>; | 3437 | pub type StructPat<'a> = StructPatNode<RefRoot<'a>>; |
2704 | 3438 | ||
3439 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<StructPatNode<R1>> for StructPatNode<R2> { | ||
3440 | fn eq(&self, other: &StructPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3441 | } | ||
3442 | impl<R: TreeRoot<RaTypes>> Eq for StructPatNode<R> {} | ||
3443 | impl<R: TreeRoot<RaTypes>> Hash for StructPatNode<R> { | ||
3444 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3445 | } | ||
3446 | |||
2705 | impl<'a> AstNode<'a> for StructPat<'a> { | 3447 | impl<'a> AstNode<'a> for StructPat<'a> { |
2706 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3448 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2707 | match syntax.kind() { | 3449 | match syntax.kind() { |
@@ -2725,12 +3467,20 @@ impl<R: TreeRoot<RaTypes>> StructPatNode<R> { | |||
2725 | impl<'a> StructPat<'a> {} | 3467 | impl<'a> StructPat<'a> {} |
2726 | 3468 | ||
2727 | // TokenTree | 3469 | // TokenTree |
2728 | #[derive(Debug, Clone, Copy)] | 3470 | #[derive(Debug, Clone, Copy,)] |
2729 | pub struct TokenTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3471 | pub struct TokenTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2730 | syntax: SyntaxNode<R>, | 3472 | pub(crate) syntax: SyntaxNode<R>, |
2731 | } | 3473 | } |
2732 | pub type TokenTree<'a> = TokenTreeNode<RefRoot<'a>>; | 3474 | pub type TokenTree<'a> = TokenTreeNode<RefRoot<'a>>; |
2733 | 3475 | ||
3476 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TokenTreeNode<R1>> for TokenTreeNode<R2> { | ||
3477 | fn eq(&self, other: &TokenTreeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3478 | } | ||
3479 | impl<R: TreeRoot<RaTypes>> Eq for TokenTreeNode<R> {} | ||
3480 | impl<R: TreeRoot<RaTypes>> Hash for TokenTreeNode<R> { | ||
3481 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3482 | } | ||
3483 | |||
2734 | impl<'a> AstNode<'a> for TokenTree<'a> { | 3484 | impl<'a> AstNode<'a> for TokenTree<'a> { |
2735 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3485 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2736 | match syntax.kind() { | 3486 | match syntax.kind() { |
@@ -2754,12 +3504,20 @@ impl<R: TreeRoot<RaTypes>> TokenTreeNode<R> { | |||
2754 | impl<'a> TokenTree<'a> {} | 3504 | impl<'a> TokenTree<'a> {} |
2755 | 3505 | ||
2756 | // TraitDef | 3506 | // TraitDef |
2757 | #[derive(Debug, Clone, Copy)] | 3507 | #[derive(Debug, Clone, Copy,)] |
2758 | pub struct TraitDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3508 | pub struct TraitDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2759 | syntax: SyntaxNode<R>, | 3509 | pub(crate) syntax: SyntaxNode<R>, |
2760 | } | 3510 | } |
2761 | pub type TraitDef<'a> = TraitDefNode<RefRoot<'a>>; | 3511 | pub type TraitDef<'a> = TraitDefNode<RefRoot<'a>>; |
2762 | 3512 | ||
3513 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TraitDefNode<R1>> for TraitDefNode<R2> { | ||
3514 | fn eq(&self, other: &TraitDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3515 | } | ||
3516 | impl<R: TreeRoot<RaTypes>> Eq for TraitDefNode<R> {} | ||
3517 | impl<R: TreeRoot<RaTypes>> Hash for TraitDefNode<R> { | ||
3518 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3519 | } | ||
3520 | |||
2763 | impl<'a> AstNode<'a> for TraitDef<'a> { | 3521 | impl<'a> AstNode<'a> for TraitDef<'a> { |
2764 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3522 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2765 | match syntax.kind() { | 3523 | match syntax.kind() { |
@@ -2782,15 +3540,24 @@ impl<R: TreeRoot<RaTypes>> TraitDefNode<R> { | |||
2782 | 3540 | ||
2783 | impl<'a> ast::NameOwner<'a> for TraitDef<'a> {} | 3541 | impl<'a> ast::NameOwner<'a> for TraitDef<'a> {} |
2784 | impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {} | 3542 | impl<'a> ast::AttrsOwner<'a> for TraitDef<'a> {} |
3543 | impl<'a> ast::DocCommentsOwner<'a> for TraitDef<'a> {} | ||
2785 | impl<'a> TraitDef<'a> {} | 3544 | impl<'a> TraitDef<'a> {} |
2786 | 3545 | ||
2787 | // TryExpr | 3546 | // TryExpr |
2788 | #[derive(Debug, Clone, Copy)] | 3547 | #[derive(Debug, Clone, Copy,)] |
2789 | pub struct TryExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3548 | pub struct TryExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2790 | syntax: SyntaxNode<R>, | 3549 | pub(crate) syntax: SyntaxNode<R>, |
2791 | } | 3550 | } |
2792 | pub type TryExpr<'a> = TryExprNode<RefRoot<'a>>; | 3551 | pub type TryExpr<'a> = TryExprNode<RefRoot<'a>>; |
2793 | 3552 | ||
3553 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TryExprNode<R1>> for TryExprNode<R2> { | ||
3554 | fn eq(&self, other: &TryExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3555 | } | ||
3556 | impl<R: TreeRoot<RaTypes>> Eq for TryExprNode<R> {} | ||
3557 | impl<R: TreeRoot<RaTypes>> Hash for TryExprNode<R> { | ||
3558 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3559 | } | ||
3560 | |||
2794 | impl<'a> AstNode<'a> for TryExpr<'a> { | 3561 | impl<'a> AstNode<'a> for TryExpr<'a> { |
2795 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3562 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2796 | match syntax.kind() { | 3563 | match syntax.kind() { |
@@ -2814,12 +3581,20 @@ impl<R: TreeRoot<RaTypes>> TryExprNode<R> { | |||
2814 | impl<'a> TryExpr<'a> {} | 3581 | impl<'a> TryExpr<'a> {} |
2815 | 3582 | ||
2816 | // TupleExpr | 3583 | // TupleExpr |
2817 | #[derive(Debug, Clone, Copy)] | 3584 | #[derive(Debug, Clone, Copy,)] |
2818 | pub struct TupleExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3585 | pub struct TupleExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2819 | syntax: SyntaxNode<R>, | 3586 | pub(crate) syntax: SyntaxNode<R>, |
2820 | } | 3587 | } |
2821 | pub type TupleExpr<'a> = TupleExprNode<RefRoot<'a>>; | 3588 | pub type TupleExpr<'a> = TupleExprNode<RefRoot<'a>>; |
2822 | 3589 | ||
3590 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleExprNode<R1>> for TupleExprNode<R2> { | ||
3591 | fn eq(&self, other: &TupleExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
3592 | } | ||
3593 | impl<R: TreeRoot<RaTypes>> Eq for TupleExprNode<R> {} | ||
3594 | impl<R: TreeRoot<RaTypes>> Hash for TupleExprNode<R> { | ||
3595 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3596 | } | ||
3597 | |||
2823 | impl<'a> AstNode<'a> for TupleExpr<'a> { | 3598 | impl<'a> AstNode<'a> for TupleExpr<'a> { |
2824 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3599 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2825 | match syntax.kind() { | 3600 | match syntax.kind() { |
@@ -2843,12 +3618,20 @@ impl<R: TreeRoot<RaTypes>> TupleExprNode<R> { | |||
2843 | impl<'a> TupleExpr<'a> {} | 3618 | impl<'a> TupleExpr<'a> {} |
2844 | 3619 | ||
2845 | // TuplePat | 3620 | // TuplePat |
2846 | #[derive(Debug, Clone, Copy)] | 3621 | #[derive(Debug, Clone, Copy,)] |
2847 | pub struct TuplePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3622 | pub struct TuplePatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2848 | syntax: SyntaxNode<R>, | 3623 | pub(crate) syntax: SyntaxNode<R>, |
2849 | } | 3624 | } |
2850 | pub type TuplePat<'a> = TuplePatNode<RefRoot<'a>>; | 3625 | pub type TuplePat<'a> = TuplePatNode<RefRoot<'a>>; |
2851 | 3626 | ||
3627 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TuplePatNode<R1>> for TuplePatNode<R2> { | ||
3628 | fn eq(&self, other: &TuplePatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3629 | } | ||
3630 | impl<R: TreeRoot<RaTypes>> Eq for TuplePatNode<R> {} | ||
3631 | impl<R: TreeRoot<RaTypes>> Hash for TuplePatNode<R> { | ||
3632 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3633 | } | ||
3634 | |||
2852 | impl<'a> AstNode<'a> for TuplePat<'a> { | 3635 | impl<'a> AstNode<'a> for TuplePat<'a> { |
2853 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3636 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2854 | match syntax.kind() { | 3637 | match syntax.kind() { |
@@ -2872,12 +3655,20 @@ impl<R: TreeRoot<RaTypes>> TuplePatNode<R> { | |||
2872 | impl<'a> TuplePat<'a> {} | 3655 | impl<'a> TuplePat<'a> {} |
2873 | 3656 | ||
2874 | // TupleStructPat | 3657 | // TupleStructPat |
2875 | #[derive(Debug, Clone, Copy)] | 3658 | #[derive(Debug, Clone, Copy,)] |
2876 | pub struct TupleStructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3659 | pub struct TupleStructPatNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2877 | syntax: SyntaxNode<R>, | 3660 | pub(crate) syntax: SyntaxNode<R>, |
2878 | } | 3661 | } |
2879 | pub type TupleStructPat<'a> = TupleStructPatNode<RefRoot<'a>>; | 3662 | pub type TupleStructPat<'a> = TupleStructPatNode<RefRoot<'a>>; |
2880 | 3663 | ||
3664 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleStructPatNode<R1>> for TupleStructPatNode<R2> { | ||
3665 | fn eq(&self, other: &TupleStructPatNode<R1>) -> bool { self.syntax == other.syntax } | ||
3666 | } | ||
3667 | impl<R: TreeRoot<RaTypes>> Eq for TupleStructPatNode<R> {} | ||
3668 | impl<R: TreeRoot<RaTypes>> Hash for TupleStructPatNode<R> { | ||
3669 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3670 | } | ||
3671 | |||
2881 | impl<'a> AstNode<'a> for TupleStructPat<'a> { | 3672 | impl<'a> AstNode<'a> for TupleStructPat<'a> { |
2882 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3673 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2883 | match syntax.kind() { | 3674 | match syntax.kind() { |
@@ -2901,12 +3692,20 @@ impl<R: TreeRoot<RaTypes>> TupleStructPatNode<R> { | |||
2901 | impl<'a> TupleStructPat<'a> {} | 3692 | impl<'a> TupleStructPat<'a> {} |
2902 | 3693 | ||
2903 | // TupleType | 3694 | // TupleType |
2904 | #[derive(Debug, Clone, Copy)] | 3695 | #[derive(Debug, Clone, Copy,)] |
2905 | pub struct TupleTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3696 | pub struct TupleTypeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2906 | syntax: SyntaxNode<R>, | 3697 | pub(crate) syntax: SyntaxNode<R>, |
2907 | } | 3698 | } |
2908 | pub type TupleType<'a> = TupleTypeNode<RefRoot<'a>>; | 3699 | pub type TupleType<'a> = TupleTypeNode<RefRoot<'a>>; |
2909 | 3700 | ||
3701 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TupleTypeNode<R1>> for TupleTypeNode<R2> { | ||
3702 | fn eq(&self, other: &TupleTypeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3703 | } | ||
3704 | impl<R: TreeRoot<RaTypes>> Eq for TupleTypeNode<R> {} | ||
3705 | impl<R: TreeRoot<RaTypes>> Hash for TupleTypeNode<R> { | ||
3706 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3707 | } | ||
3708 | |||
2910 | impl<'a> AstNode<'a> for TupleType<'a> { | 3709 | impl<'a> AstNode<'a> for TupleType<'a> { |
2911 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3710 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2912 | match syntax.kind() { | 3711 | match syntax.kind() { |
@@ -2930,12 +3729,20 @@ impl<R: TreeRoot<RaTypes>> TupleTypeNode<R> { | |||
2930 | impl<'a> TupleType<'a> {} | 3729 | impl<'a> TupleType<'a> {} |
2931 | 3730 | ||
2932 | // TypeDef | 3731 | // TypeDef |
2933 | #[derive(Debug, Clone, Copy)] | 3732 | #[derive(Debug, Clone, Copy,)] |
2934 | pub struct TypeDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3733 | pub struct TypeDefNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2935 | syntax: SyntaxNode<R>, | 3734 | pub(crate) syntax: SyntaxNode<R>, |
2936 | } | 3735 | } |
2937 | pub type TypeDef<'a> = TypeDefNode<RefRoot<'a>>; | 3736 | pub type TypeDef<'a> = TypeDefNode<RefRoot<'a>>; |
2938 | 3737 | ||
3738 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeDefNode<R1>> for TypeDefNode<R2> { | ||
3739 | fn eq(&self, other: &TypeDefNode<R1>) -> bool { self.syntax == other.syntax } | ||
3740 | } | ||
3741 | impl<R: TreeRoot<RaTypes>> Eq for TypeDefNode<R> {} | ||
3742 | impl<R: TreeRoot<RaTypes>> Hash for TypeDefNode<R> { | ||
3743 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3744 | } | ||
3745 | |||
2939 | impl<'a> AstNode<'a> for TypeDef<'a> { | 3746 | impl<'a> AstNode<'a> for TypeDef<'a> { |
2940 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3747 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2941 | match syntax.kind() { | 3748 | match syntax.kind() { |
@@ -2959,15 +3766,24 @@ impl<R: TreeRoot<RaTypes>> TypeDefNode<R> { | |||
2959 | impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} | 3766 | impl<'a> ast::NameOwner<'a> for TypeDef<'a> {} |
2960 | impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {} | 3767 | impl<'a> ast::TypeParamsOwner<'a> for TypeDef<'a> {} |
2961 | impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} | 3768 | impl<'a> ast::AttrsOwner<'a> for TypeDef<'a> {} |
3769 | impl<'a> ast::DocCommentsOwner<'a> for TypeDef<'a> {} | ||
2962 | impl<'a> TypeDef<'a> {} | 3770 | impl<'a> TypeDef<'a> {} |
2963 | 3771 | ||
2964 | // TypeParam | 3772 | // TypeParam |
2965 | #[derive(Debug, Clone, Copy)] | 3773 | #[derive(Debug, Clone, Copy,)] |
2966 | pub struct TypeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3774 | pub struct TypeParamNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2967 | syntax: SyntaxNode<R>, | 3775 | pub(crate) syntax: SyntaxNode<R>, |
2968 | } | 3776 | } |
2969 | pub type TypeParam<'a> = TypeParamNode<RefRoot<'a>>; | 3777 | pub type TypeParam<'a> = TypeParamNode<RefRoot<'a>>; |
2970 | 3778 | ||
3779 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamNode<R1>> for TypeParamNode<R2> { | ||
3780 | fn eq(&self, other: &TypeParamNode<R1>) -> bool { self.syntax == other.syntax } | ||
3781 | } | ||
3782 | impl<R: TreeRoot<RaTypes>> Eq for TypeParamNode<R> {} | ||
3783 | impl<R: TreeRoot<RaTypes>> Hash for TypeParamNode<R> { | ||
3784 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3785 | } | ||
3786 | |||
2971 | impl<'a> AstNode<'a> for TypeParam<'a> { | 3787 | impl<'a> AstNode<'a> for TypeParam<'a> { |
2972 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3788 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
2973 | match syntax.kind() { | 3789 | match syntax.kind() { |
@@ -2992,12 +3808,20 @@ impl<'a> ast::NameOwner<'a> for TypeParam<'a> {} | |||
2992 | impl<'a> TypeParam<'a> {} | 3808 | impl<'a> TypeParam<'a> {} |
2993 | 3809 | ||
2994 | // TypeParamList | 3810 | // TypeParamList |
2995 | #[derive(Debug, Clone, Copy)] | 3811 | #[derive(Debug, Clone, Copy,)] |
2996 | pub struct TypeParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3812 | pub struct TypeParamListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
2997 | syntax: SyntaxNode<R>, | 3813 | pub(crate) syntax: SyntaxNode<R>, |
2998 | } | 3814 | } |
2999 | pub type TypeParamList<'a> = TypeParamListNode<RefRoot<'a>>; | 3815 | pub type TypeParamList<'a> = TypeParamListNode<RefRoot<'a>>; |
3000 | 3816 | ||
3817 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<TypeParamListNode<R1>> for TypeParamListNode<R2> { | ||
3818 | fn eq(&self, other: &TypeParamListNode<R1>) -> bool { self.syntax == other.syntax } | ||
3819 | } | ||
3820 | impl<R: TreeRoot<RaTypes>> Eq for TypeParamListNode<R> {} | ||
3821 | impl<R: TreeRoot<RaTypes>> Hash for TypeParamListNode<R> { | ||
3822 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3823 | } | ||
3824 | |||
3001 | impl<'a> AstNode<'a> for TypeParamList<'a> { | 3825 | impl<'a> AstNode<'a> for TypeParamList<'a> { |
3002 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3826 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
3003 | match syntax.kind() { | 3827 | match syntax.kind() { |
@@ -3029,7 +3853,7 @@ impl<'a> TypeParamList<'a> { | |||
3029 | } | 3853 | } |
3030 | 3854 | ||
3031 | // TypeRef | 3855 | // TypeRef |
3032 | #[derive(Debug, Clone, Copy)] | 3856 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
3033 | pub enum TypeRef<'a> { | 3857 | pub enum TypeRef<'a> { |
3034 | ParenType(ParenType<'a>), | 3858 | ParenType(ParenType<'a>), |
3035 | TupleType(TupleType<'a>), | 3859 | TupleType(TupleType<'a>), |
@@ -3087,12 +3911,20 @@ impl<'a> AstNode<'a> for TypeRef<'a> { | |||
3087 | impl<'a> TypeRef<'a> {} | 3911 | impl<'a> TypeRef<'a> {} |
3088 | 3912 | ||
3089 | // UseItem | 3913 | // UseItem |
3090 | #[derive(Debug, Clone, Copy)] | 3914 | #[derive(Debug, Clone, Copy,)] |
3091 | pub struct UseItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3915 | pub struct UseItemNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
3092 | syntax: SyntaxNode<R>, | 3916 | pub(crate) syntax: SyntaxNode<R>, |
3093 | } | 3917 | } |
3094 | pub type UseItem<'a> = UseItemNode<RefRoot<'a>>; | 3918 | pub type UseItem<'a> = UseItemNode<RefRoot<'a>>; |
3095 | 3919 | ||
3920 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseItemNode<R1>> for UseItemNode<R2> { | ||
3921 | fn eq(&self, other: &UseItemNode<R1>) -> bool { self.syntax == other.syntax } | ||
3922 | } | ||
3923 | impl<R: TreeRoot<RaTypes>> Eq for UseItemNode<R> {} | ||
3924 | impl<R: TreeRoot<RaTypes>> Hash for UseItemNode<R> { | ||
3925 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3926 | } | ||
3927 | |||
3096 | impl<'a> AstNode<'a> for UseItem<'a> { | 3928 | impl<'a> AstNode<'a> for UseItem<'a> { |
3097 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3929 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
3098 | match syntax.kind() { | 3930 | match syntax.kind() { |
@@ -3120,12 +3952,20 @@ impl<'a> UseItem<'a> { | |||
3120 | } | 3952 | } |
3121 | 3953 | ||
3122 | // UseTree | 3954 | // UseTree |
3123 | #[derive(Debug, Clone, Copy)] | 3955 | #[derive(Debug, Clone, Copy,)] |
3124 | pub struct UseTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 3956 | pub struct UseTreeNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
3125 | syntax: SyntaxNode<R>, | 3957 | pub(crate) syntax: SyntaxNode<R>, |
3126 | } | 3958 | } |
3127 | pub type UseTree<'a> = UseTreeNode<RefRoot<'a>>; | 3959 | pub type UseTree<'a> = UseTreeNode<RefRoot<'a>>; |
3128 | 3960 | ||
3961 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeNode<R1>> for UseTreeNode<R2> { | ||
3962 | fn eq(&self, other: &UseTreeNode<R1>) -> bool { self.syntax == other.syntax } | ||
3963 | } | ||
3964 | impl<R: TreeRoot<RaTypes>> Eq for UseTreeNode<R> {} | ||
3965 | impl<R: TreeRoot<RaTypes>> Hash for UseTreeNode<R> { | ||
3966 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
3967 | } | ||
3968 | |||
3129 | impl<'a> AstNode<'a> for UseTree<'a> { | 3969 | impl<'a> AstNode<'a> for UseTree<'a> { |
3130 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 3970 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
3131 | match syntax.kind() { | 3971 | match syntax.kind() { |
@@ -3157,12 +3997,20 @@ impl<'a> UseTree<'a> { | |||
3157 | } | 3997 | } |
3158 | 3998 | ||
3159 | // UseTreeList | 3999 | // UseTreeList |
3160 | #[derive(Debug, Clone, Copy)] | 4000 | #[derive(Debug, Clone, Copy,)] |
3161 | pub struct UseTreeListNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 4001 | pub struct UseTreeListNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
3162 | syntax: SyntaxNode<R>, | 4002 | pub(crate) syntax: SyntaxNode<R>, |
3163 | } | 4003 | } |
3164 | pub type UseTreeList<'a> = UseTreeListNode<RefRoot<'a>>; | 4004 | pub type UseTreeList<'a> = UseTreeListNode<RefRoot<'a>>; |
3165 | 4005 | ||
4006 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<UseTreeListNode<R1>> for UseTreeListNode<R2> { | ||
4007 | fn eq(&self, other: &UseTreeListNode<R1>) -> bool { self.syntax == other.syntax } | ||
4008 | } | ||
4009 | impl<R: TreeRoot<RaTypes>> Eq for UseTreeListNode<R> {} | ||
4010 | impl<R: TreeRoot<RaTypes>> Hash for UseTreeListNode<R> { | ||
4011 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4012 | } | ||
4013 | |||
3166 | impl<'a> AstNode<'a> for UseTreeList<'a> { | 4014 | impl<'a> AstNode<'a> for UseTreeList<'a> { |
3167 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 4015 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
3168 | match syntax.kind() { | 4016 | match syntax.kind() { |
@@ -3190,12 +4038,20 @@ impl<'a> UseTreeList<'a> { | |||
3190 | } | 4038 | } |
3191 | 4039 | ||
3192 | // WhereClause | 4040 | // WhereClause |
3193 | #[derive(Debug, Clone, Copy)] | 4041 | #[derive(Debug, Clone, Copy,)] |
3194 | pub struct WhereClauseNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 4042 | pub struct WhereClauseNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
3195 | syntax: SyntaxNode<R>, | 4043 | pub(crate) syntax: SyntaxNode<R>, |
3196 | } | 4044 | } |
3197 | pub type WhereClause<'a> = WhereClauseNode<RefRoot<'a>>; | 4045 | pub type WhereClause<'a> = WhereClauseNode<RefRoot<'a>>; |
3198 | 4046 | ||
4047 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhereClauseNode<R1>> for WhereClauseNode<R2> { | ||
4048 | fn eq(&self, other: &WhereClauseNode<R1>) -> bool { self.syntax == other.syntax } | ||
4049 | } | ||
4050 | impl<R: TreeRoot<RaTypes>> Eq for WhereClauseNode<R> {} | ||
4051 | impl<R: TreeRoot<RaTypes>> Hash for WhereClauseNode<R> { | ||
4052 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4053 | } | ||
4054 | |||
3199 | impl<'a> AstNode<'a> for WhereClause<'a> { | 4055 | impl<'a> AstNode<'a> for WhereClause<'a> { |
3200 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 4056 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
3201 | match syntax.kind() { | 4057 | match syntax.kind() { |
@@ -3219,12 +4075,20 @@ impl<R: TreeRoot<RaTypes>> WhereClauseNode<R> { | |||
3219 | impl<'a> WhereClause<'a> {} | 4075 | impl<'a> WhereClause<'a> {} |
3220 | 4076 | ||
3221 | // WhileExpr | 4077 | // WhileExpr |
3222 | #[derive(Debug, Clone, Copy)] | 4078 | #[derive(Debug, Clone, Copy,)] |
3223 | pub struct WhileExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 4079 | pub struct WhileExprNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
3224 | syntax: SyntaxNode<R>, | 4080 | pub(crate) syntax: SyntaxNode<R>, |
3225 | } | 4081 | } |
3226 | pub type WhileExpr<'a> = WhileExprNode<RefRoot<'a>>; | 4082 | pub type WhileExpr<'a> = WhileExprNode<RefRoot<'a>>; |
3227 | 4083 | ||
4084 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhileExprNode<R1>> for WhileExprNode<R2> { | ||
4085 | fn eq(&self, other: &WhileExprNode<R1>) -> bool { self.syntax == other.syntax } | ||
4086 | } | ||
4087 | impl<R: TreeRoot<RaTypes>> Eq for WhileExprNode<R> {} | ||
4088 | impl<R: TreeRoot<RaTypes>> Hash for WhileExprNode<R> { | ||
4089 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4090 | } | ||
4091 | |||
3228 | impl<'a> AstNode<'a> for WhileExpr<'a> { | 4092 | impl<'a> AstNode<'a> for WhileExpr<'a> { |
3229 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 4093 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
3230 | match syntax.kind() { | 4094 | match syntax.kind() { |
@@ -3253,12 +4117,20 @@ impl<'a> WhileExpr<'a> { | |||
3253 | } | 4117 | } |
3254 | 4118 | ||
3255 | // Whitespace | 4119 | // Whitespace |
3256 | #[derive(Debug, Clone, Copy)] | 4120 | #[derive(Debug, Clone, Copy,)] |
3257 | pub struct WhitespaceNode<R: TreeRoot<RaTypes> = OwnedRoot> { | 4121 | pub struct WhitespaceNode<R: TreeRoot<RaTypes> = OwnedRoot> { |
3258 | syntax: SyntaxNode<R>, | 4122 | pub(crate) syntax: SyntaxNode<R>, |
3259 | } | 4123 | } |
3260 | pub type Whitespace<'a> = WhitespaceNode<RefRoot<'a>>; | 4124 | pub type Whitespace<'a> = WhitespaceNode<RefRoot<'a>>; |
3261 | 4125 | ||
4126 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<WhitespaceNode<R1>> for WhitespaceNode<R2> { | ||
4127 | fn eq(&self, other: &WhitespaceNode<R1>) -> bool { self.syntax == other.syntax } | ||
4128 | } | ||
4129 | impl<R: TreeRoot<RaTypes>> Eq for WhitespaceNode<R> {} | ||
4130 | impl<R: TreeRoot<RaTypes>> Hash for WhitespaceNode<R> { | ||
4131 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
4132 | } | ||
4133 | |||
3262 | impl<'a> AstNode<'a> for Whitespace<'a> { | 4134 | impl<'a> AstNode<'a> for Whitespace<'a> { |
3263 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 4135 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
3264 | match syntax.kind() { | 4136 | match syntax.kind() { |
diff --git a/crates/ra_syntax/src/ast/generated.rs.tera b/crates/ra_syntax/src/ast/generated.rs.tera index d4fc6b5bd..131ee09ec 100644 --- a/crates/ra_syntax/src/ast/generated.rs.tera +++ b/crates/ra_syntax/src/ast/generated.rs.tera | |||
@@ -11,6 +11,8 @@ the below applies to the result of this template | |||
11 | 11 | ||
12 | #![cfg_attr(rustfmt, rustfmt_skip)] | 12 | #![cfg_attr(rustfmt, rustfmt_skip)] |
13 | 13 | ||
14 | use std::hash::{Hash, Hasher}; | ||
15 | |||
14 | use crate::{ | 16 | use crate::{ |
15 | ast, | 17 | ast, |
16 | SyntaxNode, SyntaxNodeRef, AstNode, | 18 | SyntaxNode, SyntaxNodeRef, AstNode, |
@@ -21,7 +23,7 @@ use crate::{ | |||
21 | // {{ node }} | 23 | // {{ node }} |
22 | 24 | ||
23 | {%- if methods.enum %} | 25 | {%- if methods.enum %} |
24 | #[derive(Debug, Clone, Copy)] | 26 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
25 | pub enum {{ node }}<'a> { | 27 | pub enum {{ node }}<'a> { |
26 | {%- for kind in methods.enum %} | 28 | {%- for kind in methods.enum %} |
27 | {{ kind }}({{ kind }}<'a>), | 29 | {{ kind }}({{ kind }}<'a>), |
@@ -46,12 +48,20 @@ impl<'a> AstNode<'a> for {{ node }}<'a> { | |||
46 | } | 48 | } |
47 | } | 49 | } |
48 | {% else %} | 50 | {% else %} |
49 | #[derive(Debug, Clone, Copy)] | 51 | #[derive(Debug, Clone, Copy,)] |
50 | pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> { | 52 | pub struct {{ node }}Node<R: TreeRoot<RaTypes> = OwnedRoot> { |
51 | syntax: SyntaxNode<R>, | 53 | pub(crate) syntax: SyntaxNode<R>, |
52 | } | 54 | } |
53 | pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>; | 55 | pub type {{ node }}<'a> = {{ node }}Node<RefRoot<'a>>; |
54 | 56 | ||
57 | impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<{{node}}Node<R1>> for {{node}}Node<R2> { | ||
58 | fn eq(&self, other: &{{node}}Node<R1>) -> bool { self.syntax == other.syntax } | ||
59 | } | ||
60 | impl<R: TreeRoot<RaTypes>> Eq for {{node}}Node<R> {} | ||
61 | impl<R: TreeRoot<RaTypes>> Hash for {{node}}Node<R> { | ||
62 | fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) } | ||
63 | } | ||
64 | |||
55 | impl<'a> AstNode<'a> for {{ node }}<'a> { | 65 | impl<'a> AstNode<'a> for {{ node }}<'a> { |
56 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { | 66 | fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> { |
57 | match syntax.kind() { | 67 | match syntax.kind() { |
diff --git a/crates/ra_syntax/src/ast/mod.rs b/crates/ra_syntax/src/ast/mod.rs index d93f92672..7077e3492 100644 --- a/crates/ra_syntax/src/ast/mod.rs +++ b/crates/ra_syntax/src/ast/mod.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | mod generated; | 1 | mod generated; |
2 | 2 | ||
3 | use std::marker::PhantomData; | 3 | use std::marker::PhantomData; |
4 | use std::string::String as RustString; | ||
4 | 5 | ||
5 | use itertools::Itertools; | 6 | use itertools::Itertools; |
6 | 7 | ||
@@ -76,7 +77,7 @@ pub trait DocCommentsOwner<'a>: AstNode<'a> { | |||
76 | 77 | ||
77 | /// Returns the textual content of a doc comment block as a single string. | 78 | /// Returns the textual content of a doc comment block as a single string. |
78 | /// That is, strips leading `///` and joins lines | 79 | /// That is, strips leading `///` and joins lines |
79 | fn doc_comment_text(self) -> String { | 80 | fn doc_comment_text(self) -> RustString { |
80 | self.doc_comments() | 81 | self.doc_comments() |
81 | .map(|comment| { | 82 | .map(|comment| { |
82 | let prefix = comment.prefix(); | 83 | let prefix = comment.prefix(); |
@@ -133,6 +134,24 @@ impl<'a> Char<'a> { | |||
133 | } | 134 | } |
134 | } | 135 | } |
135 | 136 | ||
137 | impl<'a> Byte<'a> { | ||
138 | pub fn text(&self) -> &SmolStr { | ||
139 | &self.syntax().leaf_text().unwrap() | ||
140 | } | ||
141 | } | ||
142 | |||
143 | impl<'a> ByteString<'a> { | ||
144 | pub fn text(&self) -> &SmolStr { | ||
145 | &self.syntax().leaf_text().unwrap() | ||
146 | } | ||
147 | } | ||
148 | |||
149 | impl<'a> String<'a> { | ||
150 | pub fn text(&self) -> &SmolStr { | ||
151 | &self.syntax().leaf_text().unwrap() | ||
152 | } | ||
153 | } | ||
154 | |||
136 | impl<'a> Comment<'a> { | 155 | impl<'a> Comment<'a> { |
137 | pub fn text(&self) -> &SmolStr { | 156 | pub fn text(&self) -> &SmolStr { |
138 | self.syntax().leaf_text().unwrap() | 157 | self.syntax().leaf_text().unwrap() |
@@ -296,6 +315,15 @@ impl<'a> PathSegment<'a> { | |||
296 | } | 315 | } |
297 | } | 316 | } |
298 | 317 | ||
318 | impl<'a> UseTreeList<'a> { | ||
319 | pub fn parent_use_tree(self) -> UseTree<'a> { | ||
320 | self.syntax() | ||
321 | .parent() | ||
322 | .and_then(UseTree::cast) | ||
323 | .expect("UseTreeLists are always nested in UseTrees") | ||
324 | } | ||
325 | } | ||
326 | |||
299 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { | 327 | fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { |
300 | children(parent).next() | 328 | children(parent).next() |
301 | } | 329 | } |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 2ed165c52..53cd2118f 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -116,7 +116,7 @@ Grammar( | |||
116 | "SHEBANG", | 116 | "SHEBANG", |
117 | ], | 117 | ], |
118 | nodes: [ | 118 | nodes: [ |
119 | "ROOT", | 119 | "SOURCE_FILE", |
120 | 120 | ||
121 | "STRUCT_DEF", | 121 | "STRUCT_DEF", |
122 | "ENUM_DEF", | 122 | "ENUM_DEF", |
@@ -239,7 +239,7 @@ Grammar( | |||
239 | "ARG_LIST", | 239 | "ARG_LIST", |
240 | ], | 240 | ], |
241 | ast: { | 241 | ast: { |
242 | "Root": ( | 242 | "SourceFile": ( |
243 | traits: [ "ModuleItemOwner", "FnDefOwner" ], | 243 | traits: [ "ModuleItemOwner", "FnDefOwner" ], |
244 | collections: [ | 244 | collections: [ |
245 | ["modules", "Module"], | 245 | ["modules", "Module"], |
@@ -260,6 +260,7 @@ Grammar( | |||
260 | "NameOwner", | 260 | "NameOwner", |
261 | "TypeParamsOwner", | 261 | "TypeParamsOwner", |
262 | "AttrsOwner", | 262 | "AttrsOwner", |
263 | "DocCommentsOwner" | ||
263 | ], | 264 | ], |
264 | collections: [ | 265 | collections: [ |
265 | ["fields", "NamedFieldDef"] | 266 | ["fields", "NamedFieldDef"] |
@@ -270,10 +271,11 @@ Grammar( | |||
270 | "NameOwner", | 271 | "NameOwner", |
271 | "TypeParamsOwner", | 272 | "TypeParamsOwner", |
272 | "AttrsOwner", | 273 | "AttrsOwner", |
274 | "DocCommentsOwner" | ||
273 | ] ), | 275 | ] ), |
274 | "TraitDef": ( traits: ["NameOwner", "AttrsOwner"] ), | 276 | "TraitDef": ( traits: ["NameOwner", "AttrsOwner", "DocCommentsOwner"] ), |
275 | "Module": ( | 277 | "Module": ( |
276 | traits: ["NameOwner", "AttrsOwner" ], | 278 | traits: ["NameOwner", "AttrsOwner", "DocCommentsOwner" ], |
277 | options: [ "ItemList" ] | 279 | options: [ "ItemList" ] |
278 | ), | 280 | ), |
279 | "ItemList": ( | 281 | "ItemList": ( |
@@ -283,16 +285,19 @@ Grammar( | |||
283 | "NameOwner", | 285 | "NameOwner", |
284 | "TypeParamsOwner", | 286 | "TypeParamsOwner", |
285 | "AttrsOwner", | 287 | "AttrsOwner", |
288 | "DocCommentsOwner" | ||
286 | ] ), | 289 | ] ), |
287 | "StaticDef": ( traits: [ | 290 | "StaticDef": ( traits: [ |
288 | "NameOwner", | 291 | "NameOwner", |
289 | "TypeParamsOwner", | 292 | "TypeParamsOwner", |
290 | "AttrsOwner", | 293 | "AttrsOwner", |
294 | "DocCommentsOwner" | ||
291 | ] ), | 295 | ] ), |
292 | "TypeDef": ( traits: [ | 296 | "TypeDef": ( traits: [ |
293 | "NameOwner", | 297 | "NameOwner", |
294 | "TypeParamsOwner", | 298 | "TypeParamsOwner", |
295 | "AttrsOwner", | 299 | "AttrsOwner", |
300 | "DocCommentsOwner" | ||
296 | ] ), | 301 | ] ), |
297 | "ImplItem": (), | 302 | "ImplItem": (), |
298 | 303 | ||
@@ -406,6 +411,9 @@ Grammar( | |||
406 | "PrefixExpr": (), | 411 | "PrefixExpr": (), |
407 | "RangeExpr": (), | 412 | "RangeExpr": (), |
408 | "BinExpr": (), | 413 | "BinExpr": (), |
414 | "String": (), | ||
415 | "Byte": (), | ||
416 | "ByteString": (), | ||
409 | "Char": (), | 417 | "Char": (), |
410 | "Literal": (), | 418 | "Literal": (), |
411 | 419 | ||
diff --git a/crates/ra_syntax/src/grammar/mod.rs b/crates/ra_syntax/src/grammar/mod.rs index 95c437983..06a37d648 100644 --- a/crates/ra_syntax/src/grammar/mod.rs +++ b/crates/ra_syntax/src/grammar/mod.rs | |||
@@ -53,7 +53,7 @@ pub(crate) fn root(p: &mut Parser) { | |||
53 | let m = p.start(); | 53 | let m = p.start(); |
54 | p.eat(SHEBANG); | 54 | p.eat(SHEBANG); |
55 | items::mod_contents(p, false); | 55 | items::mod_contents(p, false); |
56 | m.complete(p, ROOT); | 56 | m.complete(p, SOURCE_FILE); |
57 | } | 57 | } |
58 | 58 | ||
59 | #[derive(Clone, Copy, PartialEq, Eq)] | 59 | #[derive(Clone, Copy, PartialEq, Eq)] |
diff --git a/crates/ra_syntax/src/lexer/ptr.rs b/crates/ra_syntax/src/lexer/ptr.rs index 4c291b9c4..7e4df51aa 100644 --- a/crates/ra_syntax/src/lexer/ptr.rs +++ b/crates/ra_syntax/src/lexer/ptr.rs | |||
@@ -30,8 +30,7 @@ impl<'s> Ptr<'s> { | |||
30 | /// Gets the nth character from the current. | 30 | /// Gets the nth character from the current. |
31 | /// For example, 0 will return the current token, 1 will return the next, etc. | 31 | /// For example, 0 will return the current token, 1 will return the next, etc. |
32 | pub fn nth(&self, n: u32) -> Option<char> { | 32 | pub fn nth(&self, n: u32) -> Option<char> { |
33 | let mut chars = self.chars().peekable(); | 33 | self.chars().nth(n as usize) |
34 | chars.by_ref().nth(n as usize) | ||
35 | } | 34 | } |
36 | 35 | ||
37 | /// Checks whether the current character is `c`. | 36 | /// Checks whether the current character is `c`. |
diff --git a/crates/ra_syntax/src/lib.rs b/crates/ra_syntax/src/lib.rs index 123002825..330f68053 100644 --- a/crates/ra_syntax/src/lib.rs +++ b/crates/ra_syntax/src/lib.rs | |||
@@ -20,6 +20,7 @@ | |||
20 | #![allow(missing_docs)] | 20 | #![allow(missing_docs)] |
21 | //#![warn(unreachable_pub)] // rust-lang/rust#47816 | 21 | //#![warn(unreachable_pub)] // rust-lang/rust#47816 |
22 | 22 | ||
23 | extern crate arrayvec; | ||
23 | extern crate drop_bomb; | 24 | extern crate drop_bomb; |
24 | extern crate itertools; | 25 | extern crate itertools; |
25 | extern crate parking_lot; | 26 | extern crate parking_lot; |
@@ -60,49 +61,47 @@ pub use crate::{ | |||
60 | 61 | ||
61 | use crate::yellow::GreenNode; | 62 | use crate::yellow::GreenNode; |
62 | 63 | ||
63 | /// File represents a parse tree for a single Rust file. | 64 | /// `SourceFileNode` represents a parse tree for a single Rust file. |
64 | #[derive(Clone, Debug, Hash, PartialEq, Eq)] | 65 | pub use crate::ast::SourceFileNode; |
65 | pub struct File { | ||
66 | root: SyntaxNode, | ||
67 | } | ||
68 | 66 | ||
69 | impl File { | 67 | impl SourceFileNode { |
70 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> File { | 68 | fn new(green: GreenNode, errors: Vec<SyntaxError>) -> SourceFileNode { |
71 | let root = SyntaxNode::new(green, errors); | 69 | let root = SyntaxNode::new(green, errors); |
72 | if cfg!(debug_assertions) { | 70 | if cfg!(debug_assertions) { |
73 | utils::validate_block_structure(root.borrowed()); | 71 | utils::validate_block_structure(root.borrowed()); |
74 | } | 72 | } |
75 | File { root } | 73 | assert_eq!(root.kind(), SyntaxKind::SOURCE_FILE); |
74 | ast::SourceFileNode { syntax: root } | ||
76 | } | 75 | } |
77 | pub fn parse(text: &str) -> File { | 76 | pub fn parse(text: &str) -> SourceFileNode { |
78 | let tokens = tokenize(&text); | 77 | let tokens = tokenize(&text); |
79 | let (green, errors) = | 78 | let (green, errors) = |
80 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); | 79 | parser_impl::parse_with(yellow::GreenBuilder::new(), text, &tokens, grammar::root); |
81 | File::new(green, errors) | 80 | SourceFileNode::new(green, errors) |
82 | } | 81 | } |
83 | pub fn reparse(&self, edit: &AtomEdit) -> File { | 82 | pub fn reparse(&self, edit: &AtomEdit) -> SourceFileNode { |
84 | self.incremental_reparse(edit) | 83 | self.incremental_reparse(edit) |
85 | .unwrap_or_else(|| self.full_reparse(edit)) | 84 | .unwrap_or_else(|| self.full_reparse(edit)) |
86 | } | 85 | } |
87 | pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<File> { | 86 | pub fn incremental_reparse(&self, edit: &AtomEdit) -> Option<SourceFileNode> { |
88 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) | 87 | reparsing::incremental_reparse(self.syntax(), edit, self.errors()) |
89 | .map(|(green_node, errors)| File::new(green_node, errors)) | 88 | .map(|(green_node, errors)| SourceFileNode::new(green_node, errors)) |
90 | } | 89 | } |
91 | fn full_reparse(&self, edit: &AtomEdit) -> File { | 90 | fn full_reparse(&self, edit: &AtomEdit) -> SourceFileNode { |
92 | let text = | 91 | let text = |
93 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); | 92 | text_utils::replace_range(self.syntax().text().to_string(), edit.delete, &edit.insert); |
94 | File::parse(&text) | 93 | SourceFileNode::parse(&text) |
95 | } | 94 | } |
96 | /// Typed AST representation of the parse tree. | 95 | /// Typed AST representation of the parse tree. |
97 | pub fn ast(&self) -> ast::Root { | 96 | pub fn ast(&self) -> ast::SourceFile { |
98 | ast::Root::cast(self.syntax()).unwrap() | 97 | self.borrowed() |
99 | } | 98 | } |
100 | /// Untyped homogeneous representation of the parse tree. | 99 | /// Untyped homogeneous representation of the parse tree. |
101 | pub fn syntax(&self) -> SyntaxNodeRef { | 100 | pub fn syntax(&self) -> SyntaxNodeRef { |
102 | self.root.borrowed() | 101 | self.syntax.borrowed() |
103 | } | 102 | } |
104 | pub fn errors(&self) -> Vec<SyntaxError> { | 103 | pub fn errors(&self) -> Vec<SyntaxError> { |
105 | let mut errors = self.root.root_data().clone(); | 104 | let mut errors = self.syntax.root_data().clone(); |
106 | errors.extend(validation::validate(self)); | 105 | errors.extend(validation::validate(self)); |
107 | errors | 106 | errors |
108 | } | 107 | } |
diff --git a/crates/ra_syntax/src/parser_impl/event.rs b/crates/ra_syntax/src/parser_impl/event.rs index bf9c1cef0..3d8b062d5 100644 --- a/crates/ra_syntax/src/parser_impl/event.rs +++ b/crates/ra_syntax/src/parser_impl/event.rs | |||
@@ -172,7 +172,7 @@ impl<'a, S: Sink> EventProcessor<'a, S> { | |||
172 | } | 172 | } |
173 | 173 | ||
174 | fn start(&mut self, kind: SyntaxKind) { | 174 | fn start(&mut self, kind: SyntaxKind) { |
175 | if kind == ROOT { | 175 | if kind == SOURCE_FILE { |
176 | self.sink.start_internal(kind); | 176 | self.sink.start_internal(kind); |
177 | return; | 177 | return; |
178 | } | 178 | } |
diff --git a/crates/ra_syntax/src/reparsing.rs b/crates/ra_syntax/src/reparsing.rs index 3c4ea5c22..d48133166 100644 --- a/crates/ra_syntax/src/reparsing.rs +++ b/crates/ra_syntax/src/reparsing.rs | |||
@@ -180,7 +180,7 @@ fn merge_errors( | |||
180 | #[cfg(test)] | 180 | #[cfg(test)] |
181 | mod tests { | 181 | mod tests { |
182 | use super::{ | 182 | use super::{ |
183 | super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, File}, | 183 | super::{test_utils::extract_range, text_utils::replace_range, utils::dump_tree, SourceFileNode}, |
184 | reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef, | 184 | reparse_block, reparse_leaf, AtomEdit, GreenNode, SyntaxError, SyntaxNodeRef, |
185 | }; | 185 | }; |
186 | 186 | ||
@@ -192,9 +192,9 @@ mod tests { | |||
192 | let (range, before) = extract_range(before); | 192 | let (range, before) = extract_range(before); |
193 | let after = replace_range(before.clone(), range, replace_with); | 193 | let after = replace_range(before.clone(), range, replace_with); |
194 | 194 | ||
195 | let fully_reparsed = File::parse(&after); | 195 | let fully_reparsed = SourceFileNode::parse(&after); |
196 | let incrementally_reparsed = { | 196 | let incrementally_reparsed = { |
197 | let f = File::parse(&before); | 197 | let f = SourceFileNode::parse(&before); |
198 | let edit = AtomEdit { | 198 | let edit = AtomEdit { |
199 | delete: range, | 199 | delete: range, |
200 | insert: replace_with.to_string(), | 200 | insert: replace_with.to_string(), |
@@ -203,7 +203,7 @@ mod tests { | |||
203 | reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); | 203 | reparser(f.syntax(), &edit).expect("cannot incrementally reparse"); |
204 | let green_root = node.replace_with(green); | 204 | let green_root = node.replace_with(green); |
205 | let errors = super::merge_errors(f.errors(), new_errors, node, &edit); | 205 | let errors = super::merge_errors(f.errors(), new_errors, node, &edit); |
206 | File::new(green_root, errors) | 206 | SourceFileNode::new(green_root, errors) |
207 | }; | 207 | }; |
208 | 208 | ||
209 | assert_eq_text!( | 209 | assert_eq_text!( |
diff --git a/crates/ra_syntax/src/string_lexing/byte.rs b/crates/ra_syntax/src/string_lexing/byte.rs new file mode 100644 index 000000000..24424349c --- /dev/null +++ b/crates/ra_syntax/src/string_lexing/byte.rs | |||
@@ -0,0 +1,51 @@ | |||
1 | use super::parser::Parser; | ||
2 | use super::CharComponent; | ||
3 | |||
4 | pub fn parse_byte_literal(src: &str) -> ByteComponentIterator { | ||
5 | ByteComponentIterator { | ||
6 | parser: Parser::new(src), | ||
7 | has_closing_quote: false, | ||
8 | } | ||
9 | } | ||
10 | |||
11 | pub struct ByteComponentIterator<'a> { | ||
12 | parser: Parser<'a>, | ||
13 | pub has_closing_quote: bool, | ||
14 | } | ||
15 | |||
16 | impl<'a> Iterator for ByteComponentIterator<'a> { | ||
17 | type Item = CharComponent; | ||
18 | fn next(&mut self) -> Option<CharComponent> { | ||
19 | if self.parser.pos == 0 { | ||
20 | assert!( | ||
21 | self.parser.advance() == 'b', | ||
22 | "Byte literal should start with a `b`" | ||
23 | ); | ||
24 | |||
25 | assert!( | ||
26 | self.parser.advance() == '\'', | ||
27 | "Byte literal should start with a `b`, followed by a quote" | ||
28 | ); | ||
29 | } | ||
30 | |||
31 | if let Some(component) = self.parser.parse_char_component() { | ||
32 | return Some(component); | ||
33 | } | ||
34 | |||
35 | // We get here when there are no char components left to parse | ||
36 | if self.parser.peek() == Some('\'') { | ||
37 | self.parser.advance(); | ||
38 | self.has_closing_quote = true; | ||
39 | } | ||
40 | |||
41 | assert!( | ||
42 | self.parser.peek() == None, | ||
43 | "byte literal should leave no unparsed input: src = {}, pos = {}, length = {}", | ||
44 | self.parser.src, | ||
45 | self.parser.pos, | ||
46 | self.parser.src.len() | ||
47 | ); | ||
48 | |||
49 | None | ||
50 | } | ||
51 | } | ||
diff --git a/crates/ra_syntax/src/string_lexing/byte_string.rs b/crates/ra_syntax/src/string_lexing/byte_string.rs new file mode 100644 index 000000000..5b6dda760 --- /dev/null +++ b/crates/ra_syntax/src/string_lexing/byte_string.rs | |||
@@ -0,0 +1,51 @@ | |||
1 | use super::parser::Parser; | ||
2 | use super::StringComponent; | ||
3 | |||
4 | pub fn parse_byte_string_literal(src: &str) -> ByteStringComponentIterator { | ||
5 | ByteStringComponentIterator { | ||
6 | parser: Parser::new(src), | ||
7 | has_closing_quote: false, | ||
8 | } | ||
9 | } | ||
10 | |||
11 | pub struct ByteStringComponentIterator<'a> { | ||
12 | parser: Parser<'a>, | ||
13 | pub has_closing_quote: bool, | ||
14 | } | ||
15 | |||
16 | impl<'a> Iterator for ByteStringComponentIterator<'a> { | ||
17 | type Item = StringComponent; | ||
18 | fn next(&mut self) -> Option<StringComponent> { | ||
19 | if self.parser.pos == 0 { | ||
20 | assert!( | ||
21 | self.parser.advance() == 'b', | ||
22 | "byte string literal should start with a `b`" | ||
23 | ); | ||
24 | |||
25 | assert!( | ||
26 | self.parser.advance() == '"', | ||
27 | "byte string literal should start with a `b`, followed by double quotes" | ||
28 | ); | ||
29 | } | ||
30 | |||
31 | if let Some(component) = self.parser.parse_string_component() { | ||
32 | return Some(component); | ||
33 | } | ||
34 | |||
35 | // We get here when there are no char components left to parse | ||
36 | if self.parser.peek() == Some('"') { | ||
37 | self.parser.advance(); | ||
38 | self.has_closing_quote = true; | ||
39 | } | ||
40 | |||
41 | assert!( | ||
42 | self.parser.peek() == None, | ||
43 | "byte string literal should leave no unparsed input: src = {}, pos = {}, length = {}", | ||
44 | self.parser.src, | ||
45 | self.parser.pos, | ||
46 | self.parser.src.len() | ||
47 | ); | ||
48 | |||
49 | None | ||
50 | } | ||
51 | } | ||
diff --git a/crates/ra_syntax/src/string_lexing/char.rs b/crates/ra_syntax/src/string_lexing/char.rs new file mode 100644 index 000000000..885c03b14 --- /dev/null +++ b/crates/ra_syntax/src/string_lexing/char.rs | |||
@@ -0,0 +1,176 @@ | |||
1 | use super::parser::Parser; | ||
2 | use super::CharComponent; | ||
3 | |||
4 | pub fn parse_char_literal(src: &str) -> CharComponentIterator { | ||
5 | CharComponentIterator { | ||
6 | parser: Parser::new(src), | ||
7 | has_closing_quote: false, | ||
8 | } | ||
9 | } | ||
10 | |||
11 | pub struct CharComponentIterator<'a> { | ||
12 | parser: Parser<'a>, | ||
13 | pub has_closing_quote: bool, | ||
14 | } | ||
15 | |||
16 | impl<'a> Iterator for CharComponentIterator<'a> { | ||
17 | type Item = CharComponent; | ||
18 | fn next(&mut self) -> Option<CharComponent> { | ||
19 | if self.parser.pos == 0 { | ||
20 | assert!( | ||
21 | self.parser.advance() == '\'', | ||
22 | "char literal should start with a quote" | ||
23 | ); | ||
24 | } | ||
25 | |||
26 | if let Some(component) = self.parser.parse_char_component() { | ||
27 | return Some(component); | ||
28 | } | ||
29 | |||
30 | // We get here when there are no char components left to parse | ||
31 | if self.parser.peek() == Some('\'') { | ||
32 | self.parser.advance(); | ||
33 | self.has_closing_quote = true; | ||
34 | } | ||
35 | |||
36 | assert!( | ||
37 | self.parser.peek() == None, | ||
38 | "char literal should leave no unparsed input: src = {}, pos = {}, length = {}", | ||
39 | self.parser.src, | ||
40 | self.parser.pos, | ||
41 | self.parser.src.len() | ||
42 | ); | ||
43 | |||
44 | None | ||
45 | } | ||
46 | } | ||
47 | |||
48 | #[cfg(test)] | ||
49 | mod tests { | ||
50 | use rowan::TextRange; | ||
51 | use crate::string_lexing::{ | ||
52 | CharComponent, | ||
53 | CharComponentKind::*, | ||
54 | }; | ||
55 | |||
56 | fn parse(src: &str) -> (bool, Vec<CharComponent>) { | ||
57 | let component_iterator = &mut super::parse_char_literal(src); | ||
58 | let components: Vec<_> = component_iterator.collect(); | ||
59 | (component_iterator.has_closing_quote, components) | ||
60 | } | ||
61 | |||
62 | fn unclosed_char_component(src: &str) -> CharComponent { | ||
63 | let (has_closing_quote, components) = parse(src); | ||
64 | assert!(!has_closing_quote, "char should not have closing quote"); | ||
65 | assert!(components.len() == 1); | ||
66 | components[0].clone() | ||
67 | } | ||
68 | |||
69 | fn closed_char_component(src: &str) -> CharComponent { | ||
70 | let (has_closing_quote, components) = parse(src); | ||
71 | assert!(has_closing_quote, "char should have closing quote"); | ||
72 | assert!( | ||
73 | components.len() == 1, | ||
74 | "Literal: {}\nComponents: {:#?}", | ||
75 | src, | ||
76 | components | ||
77 | ); | ||
78 | components[0].clone() | ||
79 | } | ||
80 | |||
81 | fn closed_char_components(src: &str) -> Vec<CharComponent> { | ||
82 | let (has_closing_quote, components) = parse(src); | ||
83 | assert!(has_closing_quote, "char should have closing quote"); | ||
84 | components | ||
85 | } | ||
86 | |||
87 | fn range_closed(src: &str) -> TextRange { | ||
88 | TextRange::from_to(1.into(), (src.len() as u32 - 1).into()) | ||
89 | } | ||
90 | |||
91 | fn range_unclosed(src: &str) -> TextRange { | ||
92 | TextRange::from_to(1.into(), (src.len() as u32).into()) | ||
93 | } | ||
94 | |||
95 | #[test] | ||
96 | fn test_unicode_escapes() { | ||
97 | let unicode_escapes = &[r"{DEAD}", "{BEEF}", "{FF}", "{}", ""]; | ||
98 | for escape in unicode_escapes { | ||
99 | let escape_sequence = format!(r"'\u{}'", escape); | ||
100 | let component = closed_char_component(&escape_sequence); | ||
101 | let expected_range = range_closed(&escape_sequence); | ||
102 | assert_eq!(component.kind, UnicodeEscape); | ||
103 | assert_eq!(component.range, expected_range); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | #[test] | ||
108 | fn test_unicode_escapes_unclosed() { | ||
109 | let unicode_escapes = &["{DEAD", "{BEEF", "{FF"]; | ||
110 | for escape in unicode_escapes { | ||
111 | let escape_sequence = format!(r"'\u{}'", escape); | ||
112 | let component = unclosed_char_component(&escape_sequence); | ||
113 | let expected_range = range_unclosed(&escape_sequence); | ||
114 | assert_eq!(component.kind, UnicodeEscape); | ||
115 | assert_eq!(component.range, expected_range); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | #[test] | ||
120 | fn test_empty_char() { | ||
121 | let (has_closing_quote, components) = parse("''"); | ||
122 | assert!(has_closing_quote, "char should have closing quote"); | ||
123 | assert!(components.len() == 0); | ||
124 | } | ||
125 | |||
126 | #[test] | ||
127 | fn test_unclosed_char() { | ||
128 | let component = unclosed_char_component("'a"); | ||
129 | assert!(component.kind == CodePoint); | ||
130 | assert!(component.range == TextRange::from_to(1.into(), 2.into())); | ||
131 | } | ||
132 | |||
133 | #[test] | ||
134 | fn test_digit_escapes() { | ||
135 | let literals = &[r"", r"5", r"55"]; | ||
136 | |||
137 | for literal in literals { | ||
138 | let lit_text = format!(r"'\x{}'", literal); | ||
139 | let component = closed_char_component(&lit_text); | ||
140 | assert!(component.kind == AsciiCodeEscape); | ||
141 | assert!(component.range == range_closed(&lit_text)); | ||
142 | } | ||
143 | |||
144 | // More than 2 digits starts a new codepoint | ||
145 | let components = closed_char_components(r"'\x555'"); | ||
146 | assert!(components.len() == 2); | ||
147 | assert!(components[1].kind == CodePoint); | ||
148 | } | ||
149 | |||
150 | #[test] | ||
151 | fn test_ascii_escapes() { | ||
152 | let literals = &[ | ||
153 | r"\'", "\\\"", // equivalent to \" | ||
154 | r"\n", r"\r", r"\t", r"\\", r"\0", | ||
155 | ]; | ||
156 | |||
157 | for literal in literals { | ||
158 | let lit_text = format!("'{}'", literal); | ||
159 | let component = closed_char_component(&lit_text); | ||
160 | assert!(component.kind == AsciiEscape); | ||
161 | assert!(component.range == range_closed(&lit_text)); | ||
162 | } | ||
163 | } | ||
164 | |||
165 | #[test] | ||
166 | fn test_no_escapes() { | ||
167 | let literals = &['"', 'n', 'r', 't', '0', 'x', 'u']; | ||
168 | |||
169 | for &literal in literals { | ||
170 | let lit_text = format!("'{}'", literal); | ||
171 | let component = closed_char_component(&lit_text); | ||
172 | assert!(component.kind == CodePoint); | ||
173 | assert!(component.range == range_closed(&lit_text)); | ||
174 | } | ||
175 | } | ||
176 | } | ||
diff --git a/crates/ra_syntax/src/string_lexing/mod.rs b/crates/ra_syntax/src/string_lexing/mod.rs index f0812ff28..94853331f 100644 --- a/crates/ra_syntax/src/string_lexing/mod.rs +++ b/crates/ra_syntax/src/string_lexing/mod.rs | |||
@@ -1,301 +1,13 @@ | |||
1 | use self::CharComponentKind::*; | 1 | mod parser; |
2 | use rowan::{TextRange, TextUnit}; | 2 | mod byte; |
3 | 3 | mod byte_string; | |
4 | pub fn parse_char_literal(src: &str) -> CharComponentIterator { | 4 | mod char; |
5 | CharComponentIterator { | 5 | mod string; |
6 | parser: Parser::new(src), | 6 | |
7 | has_closing_quote: false, | 7 | pub use self::{ |
8 | } | 8 | byte::parse_byte_literal, |
9 | } | 9 | byte_string::parse_byte_string_literal, |
10 | 10 | char::parse_char_literal, | |
11 | #[derive(Debug, Eq, PartialEq, Clone)] | 11 | parser::{CharComponent, CharComponentKind, StringComponent, StringComponentKind}, |
12 | pub struct CharComponent { | 12 | string::parse_string_literal, |
13 | pub range: TextRange, | 13 | }; |
14 | pub kind: CharComponentKind, | ||
15 | } | ||
16 | |||
17 | impl CharComponent { | ||
18 | fn new(range: TextRange, kind: CharComponentKind) -> CharComponent { | ||
19 | CharComponent { range, kind } | ||
20 | } | ||
21 | } | ||
22 | |||
23 | #[derive(Debug, Eq, PartialEq, Clone)] | ||
24 | pub enum CharComponentKind { | ||
25 | CodePoint, | ||
26 | AsciiEscape, | ||
27 | AsciiCodeEscape, | ||
28 | UnicodeEscape, | ||
29 | } | ||
30 | |||
31 | pub struct CharComponentIterator<'a> { | ||
32 | parser: Parser<'a>, | ||
33 | pub has_closing_quote: bool, | ||
34 | } | ||
35 | |||
36 | impl<'a> Iterator for CharComponentIterator<'a> { | ||
37 | type Item = CharComponent; | ||
38 | fn next(&mut self) -> Option<CharComponent> { | ||
39 | if self.parser.pos == 0 { | ||
40 | assert!( | ||
41 | self.parser.advance() == '\'', | ||
42 | "char literal should start with a quote" | ||
43 | ); | ||
44 | } | ||
45 | |||
46 | if let Some(component) = self.parser.parse_char_component() { | ||
47 | return Some(component); | ||
48 | } | ||
49 | |||
50 | // We get here when there are no char components left to parse | ||
51 | if self.parser.peek() == Some('\'') { | ||
52 | self.parser.advance(); | ||
53 | self.has_closing_quote = true; | ||
54 | } | ||
55 | |||
56 | assert!( | ||
57 | self.parser.peek() == None, | ||
58 | "char literal should leave no unparsed input: src = {}, pos = {}, length = {}", | ||
59 | self.parser.src, | ||
60 | self.parser.pos, | ||
61 | self.parser.src.len() | ||
62 | ); | ||
63 | |||
64 | None | ||
65 | } | ||
66 | } | ||
67 | |||
68 | pub struct Parser<'a> { | ||
69 | src: &'a str, | ||
70 | pos: usize, | ||
71 | } | ||
72 | |||
73 | impl<'a> Parser<'a> { | ||
74 | pub fn new(src: &'a str) -> Parser<'a> { | ||
75 | Parser { src, pos: 0 } | ||
76 | } | ||
77 | |||
78 | // Utility methods | ||
79 | |||
80 | pub fn peek(&self) -> Option<char> { | ||
81 | if self.pos == self.src.len() { | ||
82 | return None; | ||
83 | } | ||
84 | |||
85 | self.src[self.pos..].chars().next() | ||
86 | } | ||
87 | |||
88 | pub fn advance(&mut self) -> char { | ||
89 | let next = self | ||
90 | .peek() | ||
91 | .expect("cannot advance if end of input is reached"); | ||
92 | self.pos += next.len_utf8(); | ||
93 | next | ||
94 | } | ||
95 | |||
96 | pub fn get_pos(&self) -> TextUnit { | ||
97 | (self.pos as u32).into() | ||
98 | } | ||
99 | |||
100 | // Char parsing methods | ||
101 | |||
102 | fn parse_unicode_escape(&mut self, start: TextUnit) -> CharComponent { | ||
103 | match self.peek() { | ||
104 | Some('{') => { | ||
105 | self.advance(); | ||
106 | |||
107 | // Parse anything until we reach `}` | ||
108 | while let Some(next) = self.peek() { | ||
109 | self.advance(); | ||
110 | if next == '}' { | ||
111 | break; | ||
112 | } | ||
113 | } | ||
114 | |||
115 | let end = self.get_pos(); | ||
116 | CharComponent::new(TextRange::from_to(start, end), UnicodeEscape) | ||
117 | } | ||
118 | Some(_) | None => { | ||
119 | let end = self.get_pos(); | ||
120 | CharComponent::new(TextRange::from_to(start, end), UnicodeEscape) | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | |||
125 | fn parse_ascii_code_escape(&mut self, start: TextUnit) -> CharComponent { | ||
126 | let code_start = self.get_pos(); | ||
127 | while let Some(next) = self.peek() { | ||
128 | if next == '\'' || (self.get_pos() - code_start == 2.into()) { | ||
129 | break; | ||
130 | } | ||
131 | |||
132 | self.advance(); | ||
133 | } | ||
134 | |||
135 | let end = self.get_pos(); | ||
136 | CharComponent::new(TextRange::from_to(start, end), AsciiCodeEscape) | ||
137 | } | ||
138 | |||
139 | fn parse_escape(&mut self, start: TextUnit) -> CharComponent { | ||
140 | if self.peek().is_none() { | ||
141 | return CharComponent::new(TextRange::from_to(start, start), AsciiEscape); | ||
142 | } | ||
143 | |||
144 | let next = self.advance(); | ||
145 | let end = self.get_pos(); | ||
146 | let range = TextRange::from_to(start, end); | ||
147 | match next { | ||
148 | 'x' => self.parse_ascii_code_escape(start), | ||
149 | 'u' => self.parse_unicode_escape(start), | ||
150 | _ => CharComponent::new(range, AsciiEscape), | ||
151 | } | ||
152 | } | ||
153 | |||
154 | pub fn parse_char_component(&mut self) -> Option<CharComponent> { | ||
155 | let next = self.peek()?; | ||
156 | |||
157 | // Ignore character close | ||
158 | if next == '\'' { | ||
159 | return None; | ||
160 | } | ||
161 | |||
162 | let start = self.get_pos(); | ||
163 | self.advance(); | ||
164 | |||
165 | if next == '\\' { | ||
166 | Some(self.parse_escape(start)) | ||
167 | } else { | ||
168 | let end = self.get_pos(); | ||
169 | Some(CharComponent::new( | ||
170 | TextRange::from_to(start, end), | ||
171 | CodePoint, | ||
172 | )) | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | |||
177 | #[cfg(test)] | ||
178 | mod tests { | ||
179 | use super::*; | ||
180 | |||
181 | fn parse(src: &str) -> (bool, Vec<CharComponent>) { | ||
182 | let component_iterator = &mut super::parse_char_literal(src); | ||
183 | let components: Vec<_> = component_iterator.collect(); | ||
184 | (component_iterator.has_closing_quote, components) | ||
185 | } | ||
186 | |||
187 | fn unclosed_char_component(src: &str) -> CharComponent { | ||
188 | let (has_closing_quote, components) = parse(src); | ||
189 | assert!(!has_closing_quote, "char should not have closing quote"); | ||
190 | assert!(components.len() == 1); | ||
191 | components[0].clone() | ||
192 | } | ||
193 | |||
194 | fn closed_char_component(src: &str) -> CharComponent { | ||
195 | let (has_closing_quote, components) = parse(src); | ||
196 | assert!(has_closing_quote, "char should have closing quote"); | ||
197 | assert!( | ||
198 | components.len() == 1, | ||
199 | "Literal: {}\nComponents: {:#?}", | ||
200 | src, | ||
201 | components | ||
202 | ); | ||
203 | components[0].clone() | ||
204 | } | ||
205 | |||
206 | fn closed_char_components(src: &str) -> Vec<CharComponent> { | ||
207 | let (has_closing_quote, components) = parse(src); | ||
208 | assert!(has_closing_quote, "char should have closing quote"); | ||
209 | components | ||
210 | } | ||
211 | |||
212 | fn range_closed(src: &str) -> TextRange { | ||
213 | TextRange::from_to(1.into(), (src.len() as u32 - 1).into()) | ||
214 | } | ||
215 | |||
216 | fn range_unclosed(src: &str) -> TextRange { | ||
217 | TextRange::from_to(1.into(), (src.len() as u32).into()) | ||
218 | } | ||
219 | |||
220 | #[test] | ||
221 | fn test_unicode_escapes() { | ||
222 | let unicode_escapes = &[r"{DEAD}", "{BEEF}", "{FF}", ""]; | ||
223 | for escape in unicode_escapes { | ||
224 | let escape_sequence = format!(r"'\u{}'", escape); | ||
225 | let component = closed_char_component(&escape_sequence); | ||
226 | let expected_range = range_closed(&escape_sequence); | ||
227 | assert_eq!(component.kind, CharComponentKind::UnicodeEscape); | ||
228 | assert_eq!(component.range, expected_range); | ||
229 | } | ||
230 | } | ||
231 | |||
232 | #[test] | ||
233 | fn test_unicode_escapes_unclosed() { | ||
234 | let unicode_escapes = &["{DEAD", "{BEEF", "{FF"]; | ||
235 | for escape in unicode_escapes { | ||
236 | let escape_sequence = format!(r"'\u{}'", escape); | ||
237 | let component = unclosed_char_component(&escape_sequence); | ||
238 | let expected_range = range_unclosed(&escape_sequence); | ||
239 | assert_eq!(component.kind, CharComponentKind::UnicodeEscape); | ||
240 | assert_eq!(component.range, expected_range); | ||
241 | } | ||
242 | } | ||
243 | |||
244 | #[test] | ||
245 | fn test_empty_char() { | ||
246 | let (has_closing_quote, components) = parse("''"); | ||
247 | assert!(has_closing_quote, "char should have closing quote"); | ||
248 | assert!(components.len() == 0); | ||
249 | } | ||
250 | |||
251 | #[test] | ||
252 | fn test_unclosed_char() { | ||
253 | let component = unclosed_char_component("'a"); | ||
254 | assert!(component.kind == CodePoint); | ||
255 | assert!(component.range == TextRange::from_to(1.into(), 2.into())); | ||
256 | } | ||
257 | |||
258 | #[test] | ||
259 | fn test_digit_escapes() { | ||
260 | let literals = &[r"", r"5", r"55"]; | ||
261 | |||
262 | for literal in literals { | ||
263 | let lit_text = format!(r"'\x{}'", literal); | ||
264 | let component = closed_char_component(&lit_text); | ||
265 | assert!(component.kind == CharComponentKind::AsciiCodeEscape); | ||
266 | assert!(component.range == range_closed(&lit_text)); | ||
267 | } | ||
268 | |||
269 | // More than 2 digits starts a new codepoint | ||
270 | let components = closed_char_components(r"'\x555'"); | ||
271 | assert!(components.len() == 2); | ||
272 | assert!(components[1].kind == CharComponentKind::CodePoint); | ||
273 | } | ||
274 | |||
275 | #[test] | ||
276 | fn test_ascii_escapes() { | ||
277 | let literals = &[ | ||
278 | r"\'", "\\\"", // equivalent to \" | ||
279 | r"\n", r"\r", r"\t", r"\\", r"\0", | ||
280 | ]; | ||
281 | |||
282 | for literal in literals { | ||
283 | let lit_text = format!("'{}'", literal); | ||
284 | let component = closed_char_component(&lit_text); | ||
285 | assert!(component.kind == CharComponentKind::AsciiEscape); | ||
286 | assert!(component.range == range_closed(&lit_text)); | ||
287 | } | ||
288 | } | ||
289 | |||
290 | #[test] | ||
291 | fn test_no_escapes() { | ||
292 | let literals = &['"', 'n', 'r', 't', '0', 'x', 'u']; | ||
293 | |||
294 | for &literal in literals { | ||
295 | let lit_text = format!("'{}'", literal); | ||
296 | let component = closed_char_component(&lit_text); | ||
297 | assert!(component.kind == CharComponentKind::CodePoint); | ||
298 | assert!(component.range == range_closed(&lit_text)); | ||
299 | } | ||
300 | } | ||
301 | } | ||
diff --git a/crates/ra_syntax/src/string_lexing/parser.rs b/crates/ra_syntax/src/string_lexing/parser.rs new file mode 100644 index 000000000..4a6d5bc93 --- /dev/null +++ b/crates/ra_syntax/src/string_lexing/parser.rs | |||
@@ -0,0 +1,201 @@ | |||
1 | use rowan::{TextRange, TextUnit}; | ||
2 | |||
3 | use self::CharComponentKind::*; | ||
4 | |||
5 | pub struct Parser<'a> { | ||
6 | pub(super) src: &'a str, | ||
7 | pub(super) pos: usize, | ||
8 | } | ||
9 | |||
10 | impl<'a> Parser<'a> { | ||
11 | pub fn new(src: &'a str) -> Parser<'a> { | ||
12 | Parser { src, pos: 0 } | ||
13 | } | ||
14 | |||
15 | // Utility methods | ||
16 | |||
17 | pub fn peek(&self) -> Option<char> { | ||
18 | if self.pos == self.src.len() { | ||
19 | return None; | ||
20 | } | ||
21 | |||
22 | self.src[self.pos..].chars().next() | ||
23 | } | ||
24 | |||
25 | pub fn advance(&mut self) -> char { | ||
26 | let next = self | ||
27 | .peek() | ||
28 | .expect("cannot advance if end of input is reached"); | ||
29 | self.pos += next.len_utf8(); | ||
30 | next | ||
31 | } | ||
32 | |||
33 | pub fn skip_whitespace(&mut self) { | ||
34 | while self.peek().map(|c| c.is_whitespace()) == Some(true) { | ||
35 | self.advance(); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | pub fn get_pos(&self) -> TextUnit { | ||
40 | (self.pos as u32).into() | ||
41 | } | ||
42 | |||
43 | // Char parsing methods | ||
44 | |||
45 | fn parse_unicode_escape(&mut self, start: TextUnit) -> CharComponent { | ||
46 | match self.peek() { | ||
47 | Some('{') => { | ||
48 | self.advance(); | ||
49 | |||
50 | // Parse anything until we reach `}` | ||
51 | while let Some(next) = self.peek() { | ||
52 | self.advance(); | ||
53 | if next == '}' { | ||
54 | break; | ||
55 | } | ||
56 | } | ||
57 | |||
58 | let end = self.get_pos(); | ||
59 | CharComponent::new(TextRange::from_to(start, end), UnicodeEscape) | ||
60 | } | ||
61 | Some(_) | None => { | ||
62 | let end = self.get_pos(); | ||
63 | CharComponent::new(TextRange::from_to(start, end), UnicodeEscape) | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | |||
68 | fn parse_ascii_code_escape(&mut self, start: TextUnit) -> CharComponent { | ||
69 | let code_start = self.get_pos(); | ||
70 | while let Some(next) = self.peek() { | ||
71 | if next == '\'' || (self.get_pos() - code_start == 2.into()) { | ||
72 | break; | ||
73 | } | ||
74 | |||
75 | self.advance(); | ||
76 | } | ||
77 | |||
78 | let end = self.get_pos(); | ||
79 | CharComponent::new(TextRange::from_to(start, end), AsciiCodeEscape) | ||
80 | } | ||
81 | |||
82 | fn parse_escape(&mut self, start: TextUnit) -> CharComponent { | ||
83 | if self.peek().is_none() { | ||
84 | return CharComponent::new(TextRange::from_to(start, start), AsciiEscape); | ||
85 | } | ||
86 | |||
87 | let next = self.advance(); | ||
88 | let end = self.get_pos(); | ||
89 | let range = TextRange::from_to(start, end); | ||
90 | match next { | ||
91 | 'x' => self.parse_ascii_code_escape(start), | ||
92 | 'u' => self.parse_unicode_escape(start), | ||
93 | _ => CharComponent::new(range, AsciiEscape), | ||
94 | } | ||
95 | } | ||
96 | |||
97 | pub fn parse_char_component(&mut self) -> Option<CharComponent> { | ||
98 | let next = self.peek()?; | ||
99 | |||
100 | // Ignore character close | ||
101 | if next == '\'' { | ||
102 | return None; | ||
103 | } | ||
104 | |||
105 | let start = self.get_pos(); | ||
106 | self.advance(); | ||
107 | |||
108 | if next == '\\' { | ||
109 | Some(self.parse_escape(start)) | ||
110 | } else { | ||
111 | let end = self.get_pos(); | ||
112 | Some(CharComponent::new( | ||
113 | TextRange::from_to(start, end), | ||
114 | CodePoint, | ||
115 | )) | ||
116 | } | ||
117 | } | ||
118 | |||
119 | pub fn parse_ignore_newline(&mut self, start: TextUnit) -> Option<StringComponent> { | ||
120 | // In string literals, when a `\` occurs immediately before the newline, the `\`, | ||
121 | // the newline, and all whitespace at the beginning of the next line are ignored | ||
122 | match self.peek() { | ||
123 | Some('\n') | Some('\r') => { | ||
124 | self.skip_whitespace(); | ||
125 | Some(StringComponent::new( | ||
126 | TextRange::from_to(start, self.get_pos()), | ||
127 | StringComponentKind::IgnoreNewline, | ||
128 | )) | ||
129 | } | ||
130 | _ => None, | ||
131 | } | ||
132 | } | ||
133 | |||
134 | pub fn parse_string_component(&mut self) -> Option<StringComponent> { | ||
135 | let next = self.peek()?; | ||
136 | |||
137 | // Ignore string close | ||
138 | if next == '"' { | ||
139 | return None; | ||
140 | } | ||
141 | |||
142 | let start = self.get_pos(); | ||
143 | self.advance(); | ||
144 | |||
145 | if next == '\\' { | ||
146 | // Strings can use `\` to ignore newlines, so we first try to parse one of those | ||
147 | // before falling back to parsing char escapes | ||
148 | self.parse_ignore_newline(start).or_else(|| { | ||
149 | let char_component = self.parse_escape(start); | ||
150 | Some(StringComponent::new( | ||
151 | char_component.range, | ||
152 | StringComponentKind::Char(char_component.kind), | ||
153 | )) | ||
154 | }) | ||
155 | } else { | ||
156 | let end = self.get_pos(); | ||
157 | Some(StringComponent::new( | ||
158 | TextRange::from_to(start, end), | ||
159 | StringComponentKind::Char(CodePoint), | ||
160 | )) | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | |||
165 | #[derive(Debug, Eq, PartialEq, Clone)] | ||
166 | pub struct StringComponent { | ||
167 | pub range: TextRange, | ||
168 | pub kind: StringComponentKind, | ||
169 | } | ||
170 | |||
171 | impl StringComponent { | ||
172 | fn new(range: TextRange, kind: StringComponentKind) -> StringComponent { | ||
173 | StringComponent { range, kind } | ||
174 | } | ||
175 | } | ||
176 | |||
177 | #[derive(Debug, Eq, PartialEq, Clone)] | ||
178 | pub enum StringComponentKind { | ||
179 | IgnoreNewline, | ||
180 | Char(CharComponentKind), | ||
181 | } | ||
182 | |||
183 | #[derive(Debug, Eq, PartialEq, Clone)] | ||
184 | pub struct CharComponent { | ||
185 | pub range: TextRange, | ||
186 | pub kind: CharComponentKind, | ||
187 | } | ||
188 | |||
189 | impl CharComponent { | ||
190 | fn new(range: TextRange, kind: CharComponentKind) -> CharComponent { | ||
191 | CharComponent { range, kind } | ||
192 | } | ||
193 | } | ||
194 | |||
195 | #[derive(Debug, Eq, PartialEq, Clone)] | ||
196 | pub enum CharComponentKind { | ||
197 | CodePoint, | ||
198 | AsciiEscape, | ||
199 | AsciiCodeEscape, | ||
200 | UnicodeEscape, | ||
201 | } | ||
diff --git a/crates/ra_syntax/src/string_lexing/string.rs b/crates/ra_syntax/src/string_lexing/string.rs new file mode 100644 index 000000000..1b23029c6 --- /dev/null +++ b/crates/ra_syntax/src/string_lexing/string.rs | |||
@@ -0,0 +1,46 @@ | |||
1 | use super::parser::Parser; | ||
2 | use super::StringComponent; | ||
3 | |||
4 | pub fn parse_string_literal(src: &str) -> StringComponentIterator { | ||
5 | StringComponentIterator { | ||
6 | parser: Parser::new(src), | ||
7 | has_closing_quote: false, | ||
8 | } | ||
9 | } | ||
10 | |||
11 | pub struct StringComponentIterator<'a> { | ||
12 | parser: Parser<'a>, | ||
13 | pub has_closing_quote: bool, | ||
14 | } | ||
15 | |||
16 | impl<'a> Iterator for StringComponentIterator<'a> { | ||
17 | type Item = StringComponent; | ||
18 | fn next(&mut self) -> Option<StringComponent> { | ||
19 | if self.parser.pos == 0 { | ||
20 | assert!( | ||
21 | self.parser.advance() == '"', | ||
22 | "string literal should start with double quotes" | ||
23 | ); | ||
24 | } | ||
25 | |||
26 | if let Some(component) = self.parser.parse_string_component() { | ||
27 | return Some(component); | ||
28 | } | ||
29 | |||
30 | // We get here when there are no char components left to parse | ||
31 | if self.parser.peek() == Some('"') { | ||
32 | self.parser.advance(); | ||
33 | self.has_closing_quote = true; | ||
34 | } | ||
35 | |||
36 | assert!( | ||
37 | self.parser.peek() == None, | ||
38 | "string literal should leave no unparsed input: src = {}, pos = {}, length = {}", | ||
39 | self.parser.src, | ||
40 | self.parser.pos, | ||
41 | self.parser.src.len() | ||
42 | ); | ||
43 | |||
44 | None | ||
45 | } | ||
46 | } | ||
diff --git a/crates/ra_syntax/src/syntax_kinds/generated.rs b/crates/ra_syntax/src/syntax_kinds/generated.rs index 6568f1a37..c43a8bf65 100644 --- a/crates/ra_syntax/src/syntax_kinds/generated.rs +++ b/crates/ra_syntax/src/syntax_kinds/generated.rs | |||
@@ -117,7 +117,7 @@ pub enum SyntaxKind { | |||
117 | RAW_BYTE_STRING, | 117 | RAW_BYTE_STRING, |
118 | COMMENT, | 118 | COMMENT, |
119 | SHEBANG, | 119 | SHEBANG, |
120 | ROOT, | 120 | SOURCE_FILE, |
121 | STRUCT_DEF, | 121 | STRUCT_DEF, |
122 | ENUM_DEF, | 122 | ENUM_DEF, |
123 | FN_DEF, | 123 | FN_DEF, |
@@ -378,7 +378,7 @@ impl SyntaxKind { | |||
378 | RAW_BYTE_STRING => &SyntaxInfo { name: "RAW_BYTE_STRING" }, | 378 | RAW_BYTE_STRING => &SyntaxInfo { name: "RAW_BYTE_STRING" }, |
379 | COMMENT => &SyntaxInfo { name: "COMMENT" }, | 379 | COMMENT => &SyntaxInfo { name: "COMMENT" }, |
380 | SHEBANG => &SyntaxInfo { name: "SHEBANG" }, | 380 | SHEBANG => &SyntaxInfo { name: "SHEBANG" }, |
381 | ROOT => &SyntaxInfo { name: "ROOT" }, | 381 | SOURCE_FILE => &SyntaxInfo { name: "SOURCE_FILE" }, |
382 | STRUCT_DEF => &SyntaxInfo { name: "STRUCT_DEF" }, | 382 | STRUCT_DEF => &SyntaxInfo { name: "STRUCT_DEF" }, |
383 | ENUM_DEF => &SyntaxInfo { name: "ENUM_DEF" }, | 383 | ENUM_DEF => &SyntaxInfo { name: "ENUM_DEF" }, |
384 | FN_DEF => &SyntaxInfo { name: "FN_DEF" }, | 384 | FN_DEF => &SyntaxInfo { name: "FN_DEF" }, |
diff --git a/crates/ra_syntax/src/utils.rs b/crates/ra_syntax/src/utils.rs index 288d7edd4..5bbdf80bb 100644 --- a/crates/ra_syntax/src/utils.rs +++ b/crates/ra_syntax/src/utils.rs | |||
@@ -1,5 +1,6 @@ | |||
1 | use crate::{File, SyntaxKind, SyntaxNodeRef, WalkEvent}; | 1 | use crate::{SourceFileNode, SyntaxKind, SyntaxNodeRef, WalkEvent}; |
2 | use std::fmt::Write; | 2 | use std::fmt::Write; |
3 | use std::str; | ||
3 | 4 | ||
4 | /// Parse a file and create a string representation of the resulting parse tree. | 5 | /// Parse a file and create a string representation of the resulting parse tree. |
5 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | 6 | pub fn dump_tree(syntax: SyntaxNodeRef) -> String { |
@@ -44,7 +45,7 @@ pub fn dump_tree(syntax: SyntaxNodeRef) -> String { | |||
44 | } | 45 | } |
45 | 46 | ||
46 | pub fn check_fuzz_invariants(text: &str) { | 47 | pub fn check_fuzz_invariants(text: &str) { |
47 | let file = File::parse(text); | 48 | let file = SourceFileNode::parse(text); |
48 | let root = file.syntax(); | 49 | let root = file.syntax(); |
49 | validate_block_structure(root); | 50 | validate_block_structure(root); |
50 | let _ = file.ast(); | 51 | let _ = file.ast(); |
diff --git a/crates/ra_syntax/src/validation.rs b/crates/ra_syntax/src/validation.rs deleted file mode 100644 index 009f5052f..000000000 --- a/crates/ra_syntax/src/validation.rs +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | use crate::{ | ||
2 | algo::visit::{visitor_ctx, VisitorCtx}, | ||
3 | ast::{self, AstNode}, | ||
4 | File, | ||
5 | string_lexing::{self, CharComponentKind}, | ||
6 | yellow::{ | ||
7 | SyntaxError, | ||
8 | SyntaxErrorKind::*, | ||
9 | }, | ||
10 | }; | ||
11 | |||
12 | pub(crate) fn validate(file: &File) -> Vec<SyntaxError> { | ||
13 | let mut errors = Vec::new(); | ||
14 | for node in file.root.borrowed().descendants() { | ||
15 | let _ = visitor_ctx(&mut errors) | ||
16 | .visit::<ast::Char, _>(validate_char) | ||
17 | .accept(node); | ||
18 | } | ||
19 | errors | ||
20 | } | ||
21 | |||
22 | fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) { | ||
23 | let mut components = string_lexing::parse_char_literal(node.text()); | ||
24 | let mut len = 0; | ||
25 | for component in &mut components { | ||
26 | len += 1; | ||
27 | |||
28 | // Validate escapes | ||
29 | let text = &node.text()[component.range]; | ||
30 | let range = component.range + node.syntax().range().start(); | ||
31 | use self::CharComponentKind::*; | ||
32 | match component.kind { | ||
33 | AsciiEscape => { | ||
34 | if text.len() == 1 { | ||
35 | // Escape sequence consists only of leading `\` | ||
36 | errors.push(SyntaxError::new(EmptyAsciiEscape, range)); | ||
37 | } else { | ||
38 | let escape_code = text.chars().skip(1).next().unwrap(); | ||
39 | if !is_ascii_escape(escape_code) { | ||
40 | errors.push(SyntaxError::new(InvalidAsciiEscape, range)); | ||
41 | } | ||
42 | } | ||
43 | } | ||
44 | AsciiCodeEscape => { | ||
45 | // TODO: | ||
46 | // * First digit is octal | ||
47 | // * Second digit is hex | ||
48 | } | ||
49 | UnicodeEscape => { | ||
50 | // TODO: | ||
51 | // * Only hex digits or underscores allowed | ||
52 | // * Max 6 chars | ||
53 | // * Within allowed range (must be at most 10FFFF) | ||
54 | } | ||
55 | // Code points are always valid | ||
56 | CodePoint => (), | ||
57 | } | ||
58 | } | ||
59 | |||
60 | if !components.has_closing_quote { | ||
61 | errors.push(SyntaxError::new(UnclosedChar, node.syntax().range())); | ||
62 | } | ||
63 | |||
64 | if len == 0 { | ||
65 | errors.push(SyntaxError::new(EmptyChar, node.syntax().range())); | ||
66 | } | ||
67 | |||
68 | if len > 1 { | ||
69 | errors.push(SyntaxError::new(LongChar, node.syntax().range())); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | fn is_ascii_escape(code: char) -> bool { | ||
74 | match code { | ||
75 | '\'' | '"' | 'n' | 'r' | 't' | '0' => true, | ||
76 | _ => false, | ||
77 | } | ||
78 | } | ||
diff --git a/crates/ra_syntax/src/validation/byte.rs b/crates/ra_syntax/src/validation/byte.rs new file mode 100644 index 000000000..43c0d7edd --- /dev/null +++ b/crates/ra_syntax/src/validation/byte.rs | |||
@@ -0,0 +1,211 @@ | |||
1 | //! Validation of byte literals | ||
2 | |||
3 | use crate::{ | ||
4 | ast::{self, AstNode}, | ||
5 | string_lexing::{self, CharComponentKind}, | ||
6 | TextRange, | ||
7 | validation::char, | ||
8 | yellow::{ | ||
9 | SyntaxError, | ||
10 | SyntaxErrorKind::*, | ||
11 | }, | ||
12 | }; | ||
13 | |||
14 | pub(super) fn validate_byte_node(node: ast::Byte, errors: &mut Vec<SyntaxError>) { | ||
15 | let literal_text = node.text(); | ||
16 | let literal_range = node.syntax().range(); | ||
17 | let mut components = string_lexing::parse_byte_literal(literal_text); | ||
18 | let mut len = 0; | ||
19 | for component in &mut components { | ||
20 | len += 1; | ||
21 | let text = &literal_text[component.range]; | ||
22 | let range = component.range + literal_range.start(); | ||
23 | validate_byte_component(text, component.kind, range, errors); | ||
24 | } | ||
25 | |||
26 | if !components.has_closing_quote { | ||
27 | errors.push(SyntaxError::new(UnclosedByte, literal_range)); | ||
28 | } | ||
29 | |||
30 | if len == 0 { | ||
31 | errors.push(SyntaxError::new(EmptyByte, literal_range)); | ||
32 | } | ||
33 | |||
34 | if len > 1 { | ||
35 | errors.push(SyntaxError::new(OverlongByte, literal_range)); | ||
36 | } | ||
37 | } | ||
38 | |||
39 | pub(super) fn validate_byte_component( | ||
40 | text: &str, | ||
41 | kind: CharComponentKind, | ||
42 | range: TextRange, | ||
43 | errors: &mut Vec<SyntaxError>, | ||
44 | ) { | ||
45 | use self::CharComponentKind::*; | ||
46 | match kind { | ||
47 | AsciiEscape => validate_byte_escape(text, range, errors), | ||
48 | AsciiCodeEscape => validate_byte_code_escape(text, range, errors), | ||
49 | UnicodeEscape => errors.push(SyntaxError::new(UnicodeEscapeForbidden, range)), | ||
50 | CodePoint => { | ||
51 | let c = text | ||
52 | .chars() | ||
53 | .next() | ||
54 | .expect("Code points should be one character long"); | ||
55 | |||
56 | // These bytes must always be escaped | ||
57 | if c == '\t' || c == '\r' || c == '\n' { | ||
58 | errors.push(SyntaxError::new(UnescapedByte, range)); | ||
59 | } | ||
60 | |||
61 | // Only ASCII bytes are allowed | ||
62 | if c > 0x7F as char { | ||
63 | errors.push(SyntaxError::new(ByteOutOfRange, range)); | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | |||
69 | fn validate_byte_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { | ||
70 | if text.len() == 1 { | ||
71 | // Escape sequence consists only of leading `\` | ||
72 | errors.push(SyntaxError::new(EmptyByteEscape, range)); | ||
73 | } else { | ||
74 | let escape_code = text.chars().skip(1).next().unwrap(); | ||
75 | if !char::is_ascii_escape(escape_code) { | ||
76 | errors.push(SyntaxError::new(InvalidByteEscape, range)); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | fn validate_byte_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { | ||
82 | // A ByteCodeEscape has 4 chars, example: `\xDD` | ||
83 | if text.len() < 4 { | ||
84 | errors.push(SyntaxError::new(TooShortByteCodeEscape, range)); | ||
85 | } else { | ||
86 | assert!( | ||
87 | text.chars().count() == 4, | ||
88 | "ByteCodeEscape cannot be longer than 4 chars" | ||
89 | ); | ||
90 | |||
91 | if u8::from_str_radix(&text[2..], 16).is_err() { | ||
92 | errors.push(SyntaxError::new(MalformedByteCodeEscape, range)); | ||
93 | } | ||
94 | } | ||
95 | } | ||
96 | |||
97 | #[cfg(test)] | ||
98 | mod test { | ||
99 | use crate::SourceFileNode; | ||
100 | |||
101 | fn build_file(literal: &str) -> SourceFileNode { | ||
102 | let src = format!("const C: u8 = b'{}';", literal); | ||
103 | SourceFileNode::parse(&src) | ||
104 | } | ||
105 | |||
106 | fn assert_valid_byte(literal: &str) { | ||
107 | let file = build_file(literal); | ||
108 | assert!( | ||
109 | file.errors().len() == 0, | ||
110 | "Errors for literal '{}': {:?}", | ||
111 | literal, | ||
112 | file.errors() | ||
113 | ); | ||
114 | } | ||
115 | |||
116 | fn assert_invalid_byte(literal: &str) { | ||
117 | let file = build_file(literal); | ||
118 | assert!(file.errors().len() > 0); | ||
119 | } | ||
120 | |||
121 | #[test] | ||
122 | fn test_ansi_codepoints() { | ||
123 | for byte in 0..128 { | ||
124 | match byte { | ||
125 | b'\n' | b'\r' | b'\t' => assert_invalid_byte(&(byte as char).to_string()), | ||
126 | b'\'' | b'\\' => { /* Ignore character close and backslash */ } | ||
127 | _ => assert_valid_byte(&(byte as char).to_string()), | ||
128 | } | ||
129 | } | ||
130 | |||
131 | for byte in 128..=255u8 { | ||
132 | assert_invalid_byte(&(byte as char).to_string()); | ||
133 | } | ||
134 | } | ||
135 | |||
136 | #[test] | ||
137 | fn test_unicode_codepoints() { | ||
138 | let invalid = ["Ƒ", "バ", "メ", "﷽"]; | ||
139 | for c in &invalid { | ||
140 | assert_invalid_byte(c); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | #[test] | ||
145 | fn test_unicode_multiple_codepoints() { | ||
146 | let invalid = ["नी", "👨👨"]; | ||
147 | for c in &invalid { | ||
148 | assert_invalid_byte(c); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | #[test] | ||
153 | fn test_valid_byte_escape() { | ||
154 | let valid = [r"\'", "\"", "\\\\", "\\\"", r"\n", r"\r", r"\t", r"\0"]; | ||
155 | for c in &valid { | ||
156 | assert_valid_byte(c); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | #[test] | ||
161 | fn test_invalid_byte_escape() { | ||
162 | let invalid = [r"\a", r"\?", r"\"]; | ||
163 | for c in &invalid { | ||
164 | assert_invalid_byte(c); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | #[test] | ||
169 | fn test_valid_byte_code_escape() { | ||
170 | let valid = [r"\x00", r"\x7F", r"\x55", r"\xF0"]; | ||
171 | for c in &valid { | ||
172 | assert_valid_byte(c); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | #[test] | ||
177 | fn test_invalid_byte_code_escape() { | ||
178 | let invalid = [r"\x", r"\x7"]; | ||
179 | for c in &invalid { | ||
180 | assert_invalid_byte(c); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | #[test] | ||
185 | fn test_invalid_unicode_escape() { | ||
186 | let well_formed = [ | ||
187 | r"\u{FF}", | ||
188 | r"\u{0}", | ||
189 | r"\u{F}", | ||
190 | r"\u{10FFFF}", | ||
191 | r"\u{1_0__FF___FF_____}", | ||
192 | ]; | ||
193 | for c in &well_formed { | ||
194 | assert_invalid_byte(c); | ||
195 | } | ||
196 | |||
197 | let invalid = [ | ||
198 | r"\u", | ||
199 | r"\u{}", | ||
200 | r"\u{", | ||
201 | r"\u{FF", | ||
202 | r"\u{FFFFFF}", | ||
203 | r"\u{_F}", | ||
204 | r"\u{00FFFFF}", | ||
205 | r"\u{110000}", | ||
206 | ]; | ||
207 | for c in &invalid { | ||
208 | assert_invalid_byte(c); | ||
209 | } | ||
210 | } | ||
211 | } | ||
diff --git a/crates/ra_syntax/src/validation/byte_string.rs b/crates/ra_syntax/src/validation/byte_string.rs new file mode 100644 index 000000000..7b830e97c --- /dev/null +++ b/crates/ra_syntax/src/validation/byte_string.rs | |||
@@ -0,0 +1,178 @@ | |||
1 | use crate::{ | ||
2 | ast::{self, AstNode}, | ||
3 | string_lexing::{self, StringComponentKind}, | ||
4 | yellow::{ | ||
5 | SyntaxError, | ||
6 | SyntaxErrorKind::*, | ||
7 | }, | ||
8 | }; | ||
9 | |||
10 | use super::byte; | ||
11 | |||
12 | pub(crate) fn validate_byte_string_node(node: ast::ByteString, errors: &mut Vec<SyntaxError>) { | ||
13 | let literal_text = node.text(); | ||
14 | let literal_range = node.syntax().range(); | ||
15 | let mut components = string_lexing::parse_byte_string_literal(literal_text); | ||
16 | for component in &mut components { | ||
17 | let range = component.range + literal_range.start(); | ||
18 | |||
19 | match component.kind { | ||
20 | StringComponentKind::Char(kind) => { | ||
21 | // Chars must escape \t, \n and \r codepoints, but strings don't | ||
22 | let text = &literal_text[component.range]; | ||
23 | match text { | ||
24 | "\t" | "\n" | "\r" => { /* always valid */ } | ||
25 | _ => byte::validate_byte_component(text, kind, range, errors), | ||
26 | } | ||
27 | } | ||
28 | StringComponentKind::IgnoreNewline => { /* always valid */ } | ||
29 | } | ||
30 | } | ||
31 | |||
32 | if !components.has_closing_quote { | ||
33 | errors.push(SyntaxError::new(UnclosedString, literal_range)); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | #[cfg(test)] | ||
38 | mod test { | ||
39 | use crate::SourceFileNode; | ||
40 | |||
41 | fn build_file(literal: &str) -> SourceFileNode { | ||
42 | let src = format!(r#"const S: &'static [u8] = b"{}";"#, literal); | ||
43 | println!("Source: {}", src); | ||
44 | SourceFileNode::parse(&src) | ||
45 | } | ||
46 | |||
47 | fn assert_valid_str(literal: &str) { | ||
48 | let file = build_file(literal); | ||
49 | assert!( | ||
50 | file.errors().len() == 0, | ||
51 | "Errors for literal '{}': {:?}", | ||
52 | literal, | ||
53 | file.errors() | ||
54 | ); | ||
55 | } | ||
56 | |||
57 | fn assert_invalid_str(literal: &str) { | ||
58 | let file = build_file(literal); | ||
59 | assert!(file.errors().len() > 0); | ||
60 | } | ||
61 | |||
62 | #[test] | ||
63 | fn test_ansi_codepoints() { | ||
64 | for byte in 0..128 { | ||
65 | match byte { | ||
66 | b'\"' | b'\\' => { /* Ignore string close and backslash */ } | ||
67 | _ => assert_valid_str(&(byte as char).to_string()), | ||
68 | } | ||
69 | } | ||
70 | |||
71 | for byte in 128..=255u8 { | ||
72 | assert_invalid_str(&(byte as char).to_string()); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | #[test] | ||
77 | fn test_unicode_codepoints() { | ||
78 | let invalid = ["Ƒ", "バ", "メ", "﷽"]; | ||
79 | for c in &invalid { | ||
80 | assert_invalid_str(c); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | #[test] | ||
85 | fn test_unicode_multiple_codepoints() { | ||
86 | let invalid = ["नी", "👨👨"]; | ||
87 | for c in &invalid { | ||
88 | assert_invalid_str(c); | ||
89 | } | ||
90 | } | ||
91 | |||
92 | #[test] | ||
93 | fn test_valid_ascii_escape() { | ||
94 | let valid = [r"\'", r#"\""#, r"\\", r"\n", r"\r", r"\t", r"\0", "a", "b"]; | ||
95 | for c in &valid { | ||
96 | assert_valid_str(c); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | #[test] | ||
101 | fn test_invalid_ascii_escape() { | ||
102 | let invalid = [r"\a", r"\?", r"\"]; | ||
103 | for c in &invalid { | ||
104 | assert_invalid_str(c); | ||
105 | } | ||
106 | } | ||
107 | |||
108 | #[test] | ||
109 | fn test_valid_ascii_code_escape() { | ||
110 | let valid = [r"\x00", r"\x7F", r"\x55", r"\xF0"]; | ||
111 | for c in &valid { | ||
112 | assert_valid_str(c); | ||
113 | } | ||
114 | } | ||
115 | |||
116 | #[test] | ||
117 | fn test_invalid_ascii_code_escape() { | ||
118 | let invalid = [r"\x", r"\x7"]; | ||
119 | for c in &invalid { | ||
120 | assert_invalid_str(c); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | #[test] | ||
125 | fn test_invalid_unicode_escape() { | ||
126 | let well_formed = [ | ||
127 | r"\u{FF}", | ||
128 | r"\u{0}", | ||
129 | r"\u{F}", | ||
130 | r"\u{10FFFF}", | ||
131 | r"\u{1_0__FF___FF_____}", | ||
132 | ]; | ||
133 | for c in &well_formed { | ||
134 | assert_invalid_str(c); | ||
135 | } | ||
136 | |||
137 | let invalid = [ | ||
138 | r"\u", | ||
139 | r"\u{}", | ||
140 | r"\u{", | ||
141 | r"\u{FF", | ||
142 | r"\u{FFFFFF}", | ||
143 | r"\u{_F}", | ||
144 | r"\u{00FFFFF}", | ||
145 | r"\u{110000}", | ||
146 | ]; | ||
147 | for c in &invalid { | ||
148 | assert_invalid_str(c); | ||
149 | } | ||
150 | } | ||
151 | |||
152 | #[test] | ||
153 | fn test_mixed_invalid() { | ||
154 | assert_invalid_str( | ||
155 | r"This is the tale of a string | ||
156 | with a newline in between, some emoji (👨👨) here and there, | ||
157 | unicode escapes like this: \u{1FFBB} and weird stuff like | ||
158 | this ﷽", | ||
159 | ); | ||
160 | } | ||
161 | |||
162 | #[test] | ||
163 | fn test_mixed_valid() { | ||
164 | assert_valid_str( | ||
165 | r"This is the tale of a string | ||
166 | with a newline in between, no emoji at all, | ||
167 | nor unicode escapes or weird stuff", | ||
168 | ); | ||
169 | } | ||
170 | |||
171 | #[test] | ||
172 | fn test_ignore_newline() { | ||
173 | assert_valid_str( | ||
174 | "Hello \ | ||
175 | World", | ||
176 | ); | ||
177 | } | ||
178 | } | ||
diff --git a/crates/ra_syntax/src/validation/char.rs b/crates/ra_syntax/src/validation/char.rs new file mode 100644 index 000000000..4728c85e6 --- /dev/null +++ b/crates/ra_syntax/src/validation/char.rs | |||
@@ -0,0 +1,276 @@ | |||
1 | //! Validation of char literals | ||
2 | |||
3 | use std::u32; | ||
4 | |||
5 | use arrayvec::ArrayString; | ||
6 | |||
7 | use crate::{ | ||
8 | ast::{self, AstNode}, | ||
9 | string_lexing::{self, CharComponentKind}, | ||
10 | TextRange, | ||
11 | yellow::{ | ||
12 | SyntaxError, | ||
13 | SyntaxErrorKind::*, | ||
14 | }, | ||
15 | }; | ||
16 | |||
17 | pub(super) fn validate_char_node(node: ast::Char, errors: &mut Vec<SyntaxError>) { | ||
18 | let literal_text = node.text(); | ||
19 | let literal_range = node.syntax().range(); | ||
20 | let mut components = string_lexing::parse_char_literal(literal_text); | ||
21 | let mut len = 0; | ||
22 | for component in &mut components { | ||
23 | len += 1; | ||
24 | let text = &literal_text[component.range]; | ||
25 | let range = component.range + literal_range.start(); | ||
26 | validate_char_component(text, component.kind, range, errors); | ||
27 | } | ||
28 | |||
29 | if !components.has_closing_quote { | ||
30 | errors.push(SyntaxError::new(UnclosedChar, literal_range)); | ||
31 | } | ||
32 | |||
33 | if len == 0 { | ||
34 | errors.push(SyntaxError::new(EmptyChar, literal_range)); | ||
35 | } | ||
36 | |||
37 | if len > 1 { | ||
38 | errors.push(SyntaxError::new(OverlongChar, literal_range)); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | pub(super) fn validate_char_component( | ||
43 | text: &str, | ||
44 | kind: CharComponentKind, | ||
45 | range: TextRange, | ||
46 | errors: &mut Vec<SyntaxError>, | ||
47 | ) { | ||
48 | // Validate escapes | ||
49 | use self::CharComponentKind::*; | ||
50 | match kind { | ||
51 | AsciiEscape => validate_ascii_escape(text, range, errors), | ||
52 | AsciiCodeEscape => validate_ascii_code_escape(text, range, errors), | ||
53 | UnicodeEscape => validate_unicode_escape(text, range, errors), | ||
54 | CodePoint => { | ||
55 | // These code points must always be escaped | ||
56 | if text == "\t" || text == "\r" || text == "\n" { | ||
57 | errors.push(SyntaxError::new(UnescapedCodepoint, range)); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | |||
63 | fn validate_ascii_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { | ||
64 | if text.len() == 1 { | ||
65 | // Escape sequence consists only of leading `\` | ||
66 | errors.push(SyntaxError::new(EmptyAsciiEscape, range)); | ||
67 | } else { | ||
68 | let escape_code = text.chars().skip(1).next().unwrap(); | ||
69 | if !is_ascii_escape(escape_code) { | ||
70 | errors.push(SyntaxError::new(InvalidAsciiEscape, range)); | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | pub(super) fn is_ascii_escape(code: char) -> bool { | ||
76 | match code { | ||
77 | '\\' | '\'' | '"' | 'n' | 'r' | 't' | '0' => true, | ||
78 | _ => false, | ||
79 | } | ||
80 | } | ||
81 | |||
82 | fn validate_ascii_code_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { | ||
83 | // An AsciiCodeEscape has 4 chars, example: `\xDD` | ||
84 | if text.len() < 4 { | ||
85 | errors.push(SyntaxError::new(TooShortAsciiCodeEscape, range)); | ||
86 | } else { | ||
87 | assert!( | ||
88 | text.chars().count() == 4, | ||
89 | "AsciiCodeEscape cannot be longer than 4 chars" | ||
90 | ); | ||
91 | |||
92 | match u8::from_str_radix(&text[2..], 16) { | ||
93 | Ok(code) if code < 128 => { /* Escape code is valid */ } | ||
94 | Ok(_) => errors.push(SyntaxError::new(AsciiCodeEscapeOutOfRange, range)), | ||
95 | Err(_) => errors.push(SyntaxError::new(MalformedAsciiCodeEscape, range)), | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | |||
100 | fn validate_unicode_escape(text: &str, range: TextRange, errors: &mut Vec<SyntaxError>) { | ||
101 | assert!(&text[..2] == "\\u", "UnicodeEscape always starts with \\u"); | ||
102 | |||
103 | if text.len() == 2 { | ||
104 | // No starting `{` | ||
105 | errors.push(SyntaxError::new(MalformedUnicodeEscape, range)); | ||
106 | return; | ||
107 | } | ||
108 | |||
109 | if text.len() == 3 { | ||
110 | // Only starting `{` | ||
111 | errors.push(SyntaxError::new(UnclosedUnicodeEscape, range)); | ||
112 | return; | ||
113 | } | ||
114 | |||
115 | let mut code = ArrayString::<[_; 6]>::new(); | ||
116 | let mut closed = false; | ||
117 | for c in text[3..].chars() { | ||
118 | assert!(!closed, "no characters after escape is closed"); | ||
119 | |||
120 | if c.is_digit(16) { | ||
121 | if code.len() == 6 { | ||
122 | errors.push(SyntaxError::new(OverlongUnicodeEscape, range)); | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | code.push(c); | ||
127 | } else if c == '_' { | ||
128 | // Reject leading _ | ||
129 | if code.len() == 0 { | ||
130 | errors.push(SyntaxError::new(MalformedUnicodeEscape, range)); | ||
131 | return; | ||
132 | } | ||
133 | } else if c == '}' { | ||
134 | closed = true; | ||
135 | } else { | ||
136 | errors.push(SyntaxError::new(MalformedUnicodeEscape, range)); | ||
137 | return; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | if !closed { | ||
142 | errors.push(SyntaxError::new(UnclosedUnicodeEscape, range)) | ||
143 | } | ||
144 | |||
145 | if code.len() == 0 { | ||
146 | errors.push(SyntaxError::new(EmptyUnicodeEcape, range)); | ||
147 | return; | ||
148 | } | ||
149 | |||
150 | match u32::from_str_radix(&code, 16) { | ||
151 | Ok(code_u32) if code_u32 > 0x10FFFF => { | ||
152 | errors.push(SyntaxError::new(UnicodeEscapeOutOfRange, range)); | ||
153 | } | ||
154 | Ok(_) => { | ||
155 | // Valid escape code | ||
156 | } | ||
157 | Err(_) => { | ||
158 | errors.push(SyntaxError::new(MalformedUnicodeEscape, range)); | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | |||
163 | #[cfg(test)] | ||
164 | mod test { | ||
165 | use crate::SourceFileNode; | ||
166 | |||
167 | fn build_file(literal: &str) -> SourceFileNode { | ||
168 | let src = format!("const C: char = '{}';", literal); | ||
169 | SourceFileNode::parse(&src) | ||
170 | } | ||
171 | |||
172 | fn assert_valid_char(literal: &str) { | ||
173 | let file = build_file(literal); | ||
174 | assert!( | ||
175 | file.errors().len() == 0, | ||
176 | "Errors for literal '{}': {:?}", | ||
177 | literal, | ||
178 | file.errors() | ||
179 | ); | ||
180 | } | ||
181 | |||
182 | fn assert_invalid_char(literal: &str) { | ||
183 | let file = build_file(literal); | ||
184 | assert!(file.errors().len() > 0); | ||
185 | } | ||
186 | |||
187 | #[test] | ||
188 | fn test_ansi_codepoints() { | ||
189 | for byte in 0..=255u8 { | ||
190 | match byte { | ||
191 | b'\n' | b'\r' | b'\t' => assert_invalid_char(&(byte as char).to_string()), | ||
192 | b'\'' | b'\\' => { /* Ignore character close and backslash */ } | ||
193 | _ => assert_valid_char(&(byte as char).to_string()), | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | |||
198 | #[test] | ||
199 | fn test_unicode_codepoints() { | ||
200 | let valid = ["Ƒ", "バ", "メ", "﷽"]; | ||
201 | for c in &valid { | ||
202 | assert_valid_char(c); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | #[test] | ||
207 | fn test_unicode_multiple_codepoints() { | ||
208 | let invalid = ["नी", "👨👨"]; | ||
209 | for c in &invalid { | ||
210 | assert_invalid_char(c); | ||
211 | } | ||
212 | } | ||
213 | |||
214 | #[test] | ||
215 | fn test_valid_ascii_escape() { | ||
216 | let valid = [r"\'", "\"", "\\\\", "\\\"", r"\n", r"\r", r"\t", r"\0"]; | ||
217 | for c in &valid { | ||
218 | assert_valid_char(c); | ||
219 | } | ||
220 | } | ||
221 | |||
222 | #[test] | ||
223 | fn test_invalid_ascii_escape() { | ||
224 | let invalid = [r"\a", r"\?", r"\"]; | ||
225 | for c in &invalid { | ||
226 | assert_invalid_char(c); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | #[test] | ||
231 | fn test_valid_ascii_code_escape() { | ||
232 | let valid = [r"\x00", r"\x7F", r"\x55"]; | ||
233 | for c in &valid { | ||
234 | assert_valid_char(c); | ||
235 | } | ||
236 | } | ||
237 | |||
238 | #[test] | ||
239 | fn test_invalid_ascii_code_escape() { | ||
240 | let invalid = [r"\x", r"\x7", r"\xF0"]; | ||
241 | for c in &invalid { | ||
242 | assert_invalid_char(c); | ||
243 | } | ||
244 | } | ||
245 | |||
246 | #[test] | ||
247 | fn test_valid_unicode_escape() { | ||
248 | let valid = [ | ||
249 | r"\u{FF}", | ||
250 | r"\u{0}", | ||
251 | r"\u{F}", | ||
252 | r"\u{10FFFF}", | ||
253 | r"\u{1_0__FF___FF_____}", | ||
254 | ]; | ||
255 | for c in &valid { | ||
256 | assert_valid_char(c); | ||
257 | } | ||
258 | } | ||
259 | |||
260 | #[test] | ||
261 | fn test_invalid_unicode_escape() { | ||
262 | let invalid = [ | ||
263 | r"\u", | ||
264 | r"\u{}", | ||
265 | r"\u{", | ||
266 | r"\u{FF", | ||
267 | r"\u{FFFFFF}", | ||
268 | r"\u{_F}", | ||
269 | r"\u{00FFFFF}", | ||
270 | r"\u{110000}", | ||
271 | ]; | ||
272 | for c in &invalid { | ||
273 | assert_invalid_char(c); | ||
274 | } | ||
275 | } | ||
276 | } | ||
diff --git a/crates/ra_syntax/src/validation/mod.rs b/crates/ra_syntax/src/validation/mod.rs new file mode 100644 index 000000000..bdee8120c --- /dev/null +++ b/crates/ra_syntax/src/validation/mod.rs | |||
@@ -0,0 +1,24 @@ | |||
1 | use crate::{ | ||
2 | algo::visit::{visitor_ctx, VisitorCtx}, | ||
3 | ast, | ||
4 | SourceFileNode, | ||
5 | yellow::SyntaxError, | ||
6 | }; | ||
7 | |||
8 | mod byte; | ||
9 | mod byte_string; | ||
10 | mod char; | ||
11 | mod string; | ||
12 | |||
13 | pub(crate) fn validate(file: &SourceFileNode) -> Vec<SyntaxError> { | ||
14 | let mut errors = Vec::new(); | ||
15 | for node in file.syntax().descendants() { | ||
16 | let _ = visitor_ctx(&mut errors) | ||
17 | .visit::<ast::Byte, _>(self::byte::validate_byte_node) | ||
18 | .visit::<ast::ByteString, _>(self::byte_string::validate_byte_string_node) | ||
19 | .visit::<ast::Char, _>(self::char::validate_char_node) | ||
20 | .visit::<ast::String, _>(self::string::validate_string_node) | ||
21 | .accept(node); | ||
22 | } | ||
23 | errors | ||
24 | } | ||
diff --git a/crates/ra_syntax/src/validation/string.rs b/crates/ra_syntax/src/validation/string.rs new file mode 100644 index 000000000..089879d15 --- /dev/null +++ b/crates/ra_syntax/src/validation/string.rs | |||
@@ -0,0 +1,168 @@ | |||
1 | use crate::{ | ||
2 | ast::{self, AstNode}, | ||
3 | string_lexing::{self, StringComponentKind}, | ||
4 | yellow::{ | ||
5 | SyntaxError, | ||
6 | SyntaxErrorKind::*, | ||
7 | }, | ||
8 | }; | ||
9 | |||
10 | use super::char; | ||
11 | |||
12 | pub(crate) fn validate_string_node(node: ast::String, errors: &mut Vec<SyntaxError>) { | ||
13 | let literal_text = node.text(); | ||
14 | let literal_range = node.syntax().range(); | ||
15 | let mut components = string_lexing::parse_string_literal(literal_text); | ||
16 | for component in &mut components { | ||
17 | let range = component.range + literal_range.start(); | ||
18 | |||
19 | match component.kind { | ||
20 | StringComponentKind::Char(kind) => { | ||
21 | // Chars must escape \t, \n and \r codepoints, but strings don't | ||
22 | let text = &literal_text[component.range]; | ||
23 | match text { | ||
24 | "\t" | "\n" | "\r" => { /* always valid */ } | ||
25 | _ => char::validate_char_component(text, kind, range, errors), | ||
26 | } | ||
27 | } | ||
28 | StringComponentKind::IgnoreNewline => { /* always valid */ } | ||
29 | } | ||
30 | } | ||
31 | |||
32 | if !components.has_closing_quote { | ||
33 | errors.push(SyntaxError::new(UnclosedString, literal_range)); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | #[cfg(test)] | ||
38 | mod test { | ||
39 | use crate::SourceFileNode; | ||
40 | |||
41 | fn build_file(literal: &str) -> SourceFileNode { | ||
42 | let src = format!(r#"const S: &'static str = "{}";"#, literal); | ||
43 | println!("Source: {}", src); | ||
44 | SourceFileNode::parse(&src) | ||
45 | } | ||
46 | |||
47 | fn assert_valid_str(literal: &str) { | ||
48 | let file = build_file(literal); | ||
49 | assert!( | ||
50 | file.errors().len() == 0, | ||
51 | "Errors for literal '{}': {:?}", | ||
52 | literal, | ||
53 | file.errors() | ||
54 | ); | ||
55 | } | ||
56 | |||
57 | fn assert_invalid_str(literal: &str) { | ||
58 | let file = build_file(literal); | ||
59 | assert!(file.errors().len() > 0); | ||
60 | } | ||
61 | |||
62 | #[test] | ||
63 | fn test_ansi_codepoints() { | ||
64 | for byte in 0..=255u8 { | ||
65 | match byte { | ||
66 | b'\"' | b'\\' => { /* Ignore string close and backslash */ } | ||
67 | _ => assert_valid_str(&(byte as char).to_string()), | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | #[test] | ||
73 | fn test_unicode_codepoints() { | ||
74 | let valid = ["Ƒ", "バ", "メ", "﷽"]; | ||
75 | for c in &valid { | ||
76 | assert_valid_str(c); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | #[test] | ||
81 | fn test_unicode_multiple_codepoints() { | ||
82 | let valid = ["नी", "👨👨"]; | ||
83 | for c in &valid { | ||
84 | assert_valid_str(c); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | #[test] | ||
89 | fn test_valid_ascii_escape() { | ||
90 | let valid = [r"\'", r#"\""#, r"\\", r"\n", r"\r", r"\t", r"\0", "a", "b"]; | ||
91 | for c in &valid { | ||
92 | assert_valid_str(c); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | #[test] | ||
97 | fn test_invalid_ascii_escape() { | ||
98 | let invalid = [r"\a", r"\?", r"\"]; | ||
99 | for c in &invalid { | ||
100 | assert_invalid_str(c); | ||
101 | } | ||
102 | } | ||
103 | |||
104 | #[test] | ||
105 | fn test_valid_ascii_code_escape() { | ||
106 | let valid = [r"\x00", r"\x7F", r"\x55"]; | ||
107 | for c in &valid { | ||
108 | assert_valid_str(c); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | #[test] | ||
113 | fn test_invalid_ascii_code_escape() { | ||
114 | let invalid = [r"\x", r"\x7", r"\xF0"]; | ||
115 | for c in &invalid { | ||
116 | assert_invalid_str(c); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | #[test] | ||
121 | fn test_valid_unicode_escape() { | ||
122 | let valid = [ | ||
123 | r"\u{FF}", | ||
124 | r"\u{0}", | ||
125 | r"\u{F}", | ||
126 | r"\u{10FFFF}", | ||
127 | r"\u{1_0__FF___FF_____}", | ||
128 | ]; | ||
129 | for c in &valid { | ||
130 | assert_valid_str(c); | ||
131 | } | ||
132 | } | ||
133 | |||
134 | #[test] | ||
135 | fn test_invalid_unicode_escape() { | ||
136 | let invalid = [ | ||
137 | r"\u", | ||
138 | r"\u{}", | ||
139 | r"\u{", | ||
140 | r"\u{FF", | ||
141 | r"\u{FFFFFF}", | ||
142 | r"\u{_F}", | ||
143 | r"\u{00FFFFF}", | ||
144 | r"\u{110000}", | ||
145 | ]; | ||
146 | for c in &invalid { | ||
147 | assert_invalid_str(c); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | #[test] | ||
152 | fn test_mixed() { | ||
153 | assert_valid_str( | ||
154 | r"This is the tale of a string | ||
155 | with a newline in between, some emoji (👨👨) here and there, | ||
156 | unicode escapes like this: \u{1FFBB} and weird stuff like | ||
157 | this ﷽", | ||
158 | ); | ||
159 | } | ||
160 | |||
161 | #[test] | ||
162 | fn test_ignore_newline() { | ||
163 | assert_valid_str( | ||
164 | "Hello \ | ||
165 | World", | ||
166 | ); | ||
167 | } | ||
168 | } | ||
diff --git a/crates/ra_syntax/src/yellow/syntax_error.rs b/crates/ra_syntax/src/yellow/syntax_error.rs index f3df6bc15..c32ee650d 100644 --- a/crates/ra_syntax/src/yellow/syntax_error.rs +++ b/crates/ra_syntax/src/yellow/syntax_error.rs | |||
@@ -34,6 +34,10 @@ impl SyntaxError { | |||
34 | } | 34 | } |
35 | } | 35 | } |
36 | 36 | ||
37 | pub fn kind(&self) -> SyntaxErrorKind { | ||
38 | self.kind.clone() | ||
39 | } | ||
40 | |||
37 | pub fn location(&self) -> Location { | 41 | pub fn location(&self) -> Location { |
38 | self.location.clone() | 42 | self.location.clone() |
39 | } | 43 | } |
@@ -64,11 +68,31 @@ impl fmt::Display for SyntaxError { | |||
64 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 68 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
65 | pub enum SyntaxErrorKind { | 69 | pub enum SyntaxErrorKind { |
66 | ParseError(ParseError), | 70 | ParseError(ParseError), |
71 | UnescapedCodepoint, | ||
67 | EmptyChar, | 72 | EmptyChar, |
68 | UnclosedChar, | 73 | UnclosedChar, |
69 | LongChar, | 74 | OverlongChar, |
75 | EmptyByte, | ||
76 | UnclosedByte, | ||
77 | OverlongByte, | ||
78 | ByteOutOfRange, | ||
79 | UnescapedByte, | ||
80 | EmptyByteEscape, | ||
81 | InvalidByteEscape, | ||
82 | TooShortByteCodeEscape, | ||
83 | MalformedByteCodeEscape, | ||
84 | UnicodeEscapeForbidden, | ||
70 | EmptyAsciiEscape, | 85 | EmptyAsciiEscape, |
71 | InvalidAsciiEscape, | 86 | InvalidAsciiEscape, |
87 | TooShortAsciiCodeEscape, | ||
88 | AsciiCodeEscapeOutOfRange, | ||
89 | MalformedAsciiCodeEscape, | ||
90 | UnclosedUnicodeEscape, | ||
91 | MalformedUnicodeEscape, | ||
92 | EmptyUnicodeEcape, | ||
93 | OverlongUnicodeEscape, | ||
94 | UnicodeEscapeOutOfRange, | ||
95 | UnclosedString, | ||
72 | } | 96 | } |
73 | 97 | ||
74 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 98 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
@@ -78,11 +102,38 @@ impl fmt::Display for SyntaxErrorKind { | |||
78 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 102 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
79 | use self::SyntaxErrorKind::*; | 103 | use self::SyntaxErrorKind::*; |
80 | match self { | 104 | match self { |
105 | UnescapedCodepoint => write!(f, "This codepoint should always be escaped"), | ||
81 | EmptyAsciiEscape => write!(f, "Empty escape sequence"), | 106 | EmptyAsciiEscape => write!(f, "Empty escape sequence"), |
82 | InvalidAsciiEscape => write!(f, "Invalid escape sequence"), | 107 | InvalidAsciiEscape => write!(f, "Invalid escape sequence"), |
83 | EmptyChar => write!(f, "Empty char literal"), | 108 | EmptyChar => write!(f, "Empty char literal"), |
84 | UnclosedChar => write!(f, "Unclosed char literal"), | 109 | UnclosedChar => write!(f, "Unclosed char literal"), |
85 | LongChar => write!(f, "Char literal should be one character long"), | 110 | OverlongChar => write!(f, "Char literal should be one character long"), |
111 | EmptyByte => write!(f, "Empty byte literal"), | ||
112 | UnclosedByte => write!(f, "Unclosed byte literal"), | ||
113 | OverlongByte => write!(f, "Byte literal should be one character long"), | ||
114 | ByteOutOfRange => write!(f, "Byte should be a valid ASCII character"), | ||
115 | UnescapedByte => write!(f, "This byte should always be escaped"), | ||
116 | EmptyByteEscape => write!(f, "Empty escape sequence"), | ||
117 | InvalidByteEscape => write!(f, "Invalid escape sequence"), | ||
118 | TooShortByteCodeEscape => write!(f, "Escape sequence should have two digits"), | ||
119 | MalformedByteCodeEscape => write!(f, "Escape sequence should be a hexadecimal number"), | ||
120 | UnicodeEscapeForbidden => write!( | ||
121 | f, | ||
122 | "Unicode escapes are not allowed in byte literals or byte strings" | ||
123 | ), | ||
124 | TooShortAsciiCodeEscape => write!(f, "Escape sequence should have two digits"), | ||
125 | AsciiCodeEscapeOutOfRange => { | ||
126 | write!(f, "Escape sequence should be between \\x00 and \\x7F") | ||
127 | } | ||
128 | MalformedAsciiCodeEscape => write!(f, "Escape sequence should be a hexadecimal number"), | ||
129 | UnclosedUnicodeEscape => write!(f, "Missing `}}`"), | ||
130 | MalformedUnicodeEscape => write!(f, "Malformed unicode escape sequence"), | ||
131 | EmptyUnicodeEcape => write!(f, "Empty unicode escape sequence"), | ||
132 | OverlongUnicodeEscape => { | ||
133 | write!(f, "Unicode escape sequence should have at most 6 digits") | ||
134 | } | ||
135 | UnicodeEscapeOutOfRange => write!(f, "Unicode escape code should be at most 0x10FFFF"), | ||
136 | UnclosedString => write!(f, "Unclosed string literal"), | ||
86 | ParseError(msg) => write!(f, "{}", msg.0), | 137 | ParseError(msg) => write!(f, "{}", msg.0), |
87 | } | 138 | } |
88 | } | 139 | } |