diff options
Diffstat (limited to 'crates/ra_syntax/src')
24 files changed, 0 insertions, 9859 deletions
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs deleted file mode 100644 index 26b3c813a..000000000 --- a/crates/ra_syntax/src/algo.rs +++ /dev/null | |||
@@ -1,406 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use std::{ | ||
4 | fmt, | ||
5 | ops::{self, RangeInclusive}, | ||
6 | }; | ||
7 | |||
8 | use itertools::Itertools; | ||
9 | use ra_text_edit::TextEditBuilder; | ||
10 | use rustc_hash::FxHashMap; | ||
11 | |||
12 | use crate::{ | ||
13 | AstNode, Direction, NodeOrToken, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxNodePtr, | ||
14 | SyntaxToken, TextRange, TextSize, | ||
15 | }; | ||
16 | |||
17 | /// Returns ancestors of the node at the offset, sorted by length. This should | ||
18 | /// do the right thing at an edge, e.g. when searching for expressions at `{ | ||
19 | /// <|>foo }` we will get the name reference instead of the whole block, which | ||
20 | /// we would get if we just did `find_token_at_offset(...).flat_map(|t| | ||
21 | /// t.parent().ancestors())`. | ||
22 | pub fn ancestors_at_offset( | ||
23 | node: &SyntaxNode, | ||
24 | offset: TextSize, | ||
25 | ) -> impl Iterator<Item = SyntaxNode> { | ||
26 | node.token_at_offset(offset) | ||
27 | .map(|token| token.parent().ancestors()) | ||
28 | .kmerge_by(|node1, node2| node1.text_range().len() < node2.text_range().len()) | ||
29 | } | ||
30 | |||
31 | /// Finds a node of specific Ast type at offset. Note that this is slightly | ||
32 | /// imprecise: if the cursor is strictly between two nodes of the desired type, | ||
33 | /// as in | ||
34 | /// | ||
35 | /// ```no-run | ||
36 | /// struct Foo {}|struct Bar; | ||
37 | /// ``` | ||
38 | /// | ||
39 | /// then the shorter node will be silently preferred. | ||
40 | pub fn find_node_at_offset<N: AstNode>(syntax: &SyntaxNode, offset: TextSize) -> Option<N> { | ||
41 | ancestors_at_offset(syntax, offset).find_map(N::cast) | ||
42 | } | ||
43 | |||
44 | pub fn find_node_at_range<N: AstNode>(syntax: &SyntaxNode, range: TextRange) -> Option<N> { | ||
45 | find_covering_element(syntax, range).ancestors().find_map(N::cast) | ||
46 | } | ||
47 | |||
48 | /// Skip to next non `trivia` token | ||
49 | pub fn skip_trivia_token(mut token: SyntaxToken, direction: Direction) -> Option<SyntaxToken> { | ||
50 | while token.kind().is_trivia() { | ||
51 | token = match direction { | ||
52 | Direction::Next => token.next_token()?, | ||
53 | Direction::Prev => token.prev_token()?, | ||
54 | } | ||
55 | } | ||
56 | Some(token) | ||
57 | } | ||
58 | |||
59 | /// Finds the first sibling in the given direction which is not `trivia` | ||
60 | pub fn non_trivia_sibling(element: SyntaxElement, direction: Direction) -> Option<SyntaxElement> { | ||
61 | return match element { | ||
62 | NodeOrToken::Node(node) => node.siblings_with_tokens(direction).skip(1).find(not_trivia), | ||
63 | NodeOrToken::Token(token) => token.siblings_with_tokens(direction).skip(1).find(not_trivia), | ||
64 | }; | ||
65 | |||
66 | fn not_trivia(element: &SyntaxElement) -> bool { | ||
67 | match element { | ||
68 | NodeOrToken::Node(_) => true, | ||
69 | NodeOrToken::Token(token) => !token.kind().is_trivia(), | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | |||
74 | pub fn find_covering_element(root: &SyntaxNode, range: TextRange) -> SyntaxElement { | ||
75 | root.covering_element(range) | ||
76 | } | ||
77 | |||
78 | pub fn least_common_ancestor(u: &SyntaxNode, v: &SyntaxNode) -> Option<SyntaxNode> { | ||
79 | if u == v { | ||
80 | return Some(u.clone()); | ||
81 | } | ||
82 | |||
83 | let u_depth = u.ancestors().count(); | ||
84 | let v_depth = v.ancestors().count(); | ||
85 | let keep = u_depth.min(v_depth); | ||
86 | |||
87 | let u_candidates = u.ancestors().skip(u_depth - keep); | ||
88 | let v_canidates = v.ancestors().skip(v_depth - keep); | ||
89 | let (res, _) = u_candidates.zip(v_canidates).find(|(x, y)| x == y)?; | ||
90 | Some(res) | ||
91 | } | ||
92 | |||
93 | pub fn neighbor<T: AstNode>(me: &T, direction: Direction) -> Option<T> { | ||
94 | me.syntax().siblings(direction).skip(1).find_map(T::cast) | ||
95 | } | ||
96 | |||
97 | pub fn has_errors(node: &SyntaxNode) -> bool { | ||
98 | node.children().any(|it| it.kind() == SyntaxKind::ERROR) | ||
99 | } | ||
100 | |||
101 | #[derive(Debug, PartialEq, Eq, Clone, Copy)] | ||
102 | pub enum InsertPosition<T> { | ||
103 | First, | ||
104 | Last, | ||
105 | Before(T), | ||
106 | After(T), | ||
107 | } | ||
108 | |||
109 | pub struct TreeDiff { | ||
110 | replacements: FxHashMap<SyntaxElement, SyntaxElement>, | ||
111 | } | ||
112 | |||
113 | impl TreeDiff { | ||
114 | pub fn into_text_edit(&self, builder: &mut TextEditBuilder) { | ||
115 | for (from, to) in self.replacements.iter() { | ||
116 | builder.replace(from.text_range(), to.to_string()) | ||
117 | } | ||
118 | } | ||
119 | |||
120 | pub fn is_empty(&self) -> bool { | ||
121 | self.replacements.is_empty() | ||
122 | } | ||
123 | } | ||
124 | |||
125 | /// Finds minimal the diff, which, applied to `from`, will result in `to`. | ||
126 | /// | ||
127 | /// Specifically, returns a map whose keys are descendants of `from` and values | ||
128 | /// are descendants of `to`, such that `replace_descendants(from, map) == to`. | ||
129 | /// | ||
130 | /// A trivial solution is a singleton map `{ from: to }`, but this function | ||
131 | /// tries to find a more fine-grained diff. | ||
132 | pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff { | ||
133 | let mut buf = FxHashMap::default(); | ||
134 | // FIXME: this is both horrible inefficient and gives larger than | ||
135 | // necessary diff. I bet there's a cool algorithm to diff trees properly. | ||
136 | go(&mut buf, from.clone().into(), to.clone().into()); | ||
137 | return TreeDiff { replacements: buf }; | ||
138 | |||
139 | fn go( | ||
140 | buf: &mut FxHashMap<SyntaxElement, SyntaxElement>, | ||
141 | lhs: SyntaxElement, | ||
142 | rhs: SyntaxElement, | ||
143 | ) { | ||
144 | if lhs.kind() == rhs.kind() | ||
145 | && lhs.text_range().len() == rhs.text_range().len() | ||
146 | && match (&lhs, &rhs) { | ||
147 | (NodeOrToken::Node(lhs), NodeOrToken::Node(rhs)) => { | ||
148 | lhs.green() == rhs.green() || lhs.text() == rhs.text() | ||
149 | } | ||
150 | (NodeOrToken::Token(lhs), NodeOrToken::Token(rhs)) => lhs.text() == rhs.text(), | ||
151 | _ => false, | ||
152 | } | ||
153 | { | ||
154 | return; | ||
155 | } | ||
156 | if let (Some(lhs), Some(rhs)) = (lhs.as_node(), rhs.as_node()) { | ||
157 | if lhs.children_with_tokens().count() == rhs.children_with_tokens().count() { | ||
158 | for (lhs, rhs) in lhs.children_with_tokens().zip(rhs.children_with_tokens()) { | ||
159 | go(buf, lhs, rhs) | ||
160 | } | ||
161 | return; | ||
162 | } | ||
163 | } | ||
164 | buf.insert(lhs, rhs); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | /// Adds specified children (tokens or nodes) to the current node at the | ||
169 | /// specific position. | ||
170 | /// | ||
171 | /// This is a type-unsafe low-level editing API, if you need to use it, | ||
172 | /// prefer to create a type-safe abstraction on top of it instead. | ||
173 | pub fn insert_children( | ||
174 | parent: &SyntaxNode, | ||
175 | position: InsertPosition<SyntaxElement>, | ||
176 | to_insert: impl IntoIterator<Item = SyntaxElement>, | ||
177 | ) -> SyntaxNode { | ||
178 | let mut to_insert = to_insert.into_iter(); | ||
179 | _insert_children(parent, position, &mut to_insert) | ||
180 | } | ||
181 | |||
182 | fn _insert_children( | ||
183 | parent: &SyntaxNode, | ||
184 | position: InsertPosition<SyntaxElement>, | ||
185 | to_insert: &mut dyn Iterator<Item = SyntaxElement>, | ||
186 | ) -> SyntaxNode { | ||
187 | let mut delta = TextSize::default(); | ||
188 | let to_insert = to_insert.map(|element| { | ||
189 | delta += element.text_range().len(); | ||
190 | to_green_element(element) | ||
191 | }); | ||
192 | |||
193 | let mut old_children = parent.green().children().map(|it| match it { | ||
194 | NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()), | ||
195 | NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()), | ||
196 | }); | ||
197 | |||
198 | let new_children = match &position { | ||
199 | InsertPosition::First => to_insert.chain(old_children).collect::<Vec<_>>(), | ||
200 | InsertPosition::Last => old_children.chain(to_insert).collect::<Vec<_>>(), | ||
201 | InsertPosition::Before(anchor) | InsertPosition::After(anchor) => { | ||
202 | let take_anchor = if let InsertPosition::After(_) = position { 1 } else { 0 }; | ||
203 | let split_at = position_of_child(parent, anchor.clone()) + take_anchor; | ||
204 | let before = old_children.by_ref().take(split_at).collect::<Vec<_>>(); | ||
205 | before.into_iter().chain(to_insert).chain(old_children).collect::<Vec<_>>() | ||
206 | } | ||
207 | }; | ||
208 | |||
209 | with_children(parent, new_children) | ||
210 | } | ||
211 | |||
212 | /// Replaces all nodes in `to_delete` with nodes from `to_insert` | ||
213 | /// | ||
214 | /// This is a type-unsafe low-level editing API, if you need to use it, | ||
215 | /// prefer to create a type-safe abstraction on top of it instead. | ||
216 | pub fn replace_children( | ||
217 | parent: &SyntaxNode, | ||
218 | to_delete: RangeInclusive<SyntaxElement>, | ||
219 | to_insert: impl IntoIterator<Item = SyntaxElement>, | ||
220 | ) -> SyntaxNode { | ||
221 | let mut to_insert = to_insert.into_iter(); | ||
222 | _replace_children(parent, to_delete, &mut to_insert) | ||
223 | } | ||
224 | |||
225 | fn _replace_children( | ||
226 | parent: &SyntaxNode, | ||
227 | to_delete: RangeInclusive<SyntaxElement>, | ||
228 | to_insert: &mut dyn Iterator<Item = SyntaxElement>, | ||
229 | ) -> SyntaxNode { | ||
230 | let start = position_of_child(parent, to_delete.start().clone()); | ||
231 | let end = position_of_child(parent, to_delete.end().clone()); | ||
232 | let mut old_children = parent.green().children().map(|it| match it { | ||
233 | NodeOrToken::Token(it) => NodeOrToken::Token(it.clone()), | ||
234 | NodeOrToken::Node(it) => NodeOrToken::Node(it.clone()), | ||
235 | }); | ||
236 | |||
237 | let before = old_children.by_ref().take(start).collect::<Vec<_>>(); | ||
238 | let new_children = before | ||
239 | .into_iter() | ||
240 | .chain(to_insert.map(to_green_element)) | ||
241 | .chain(old_children.skip(end + 1 - start)) | ||
242 | .collect::<Vec<_>>(); | ||
243 | with_children(parent, new_children) | ||
244 | } | ||
245 | |||
246 | #[derive(Default)] | ||
247 | pub struct SyntaxRewriter<'a> { | ||
248 | f: Option<Box<dyn Fn(&SyntaxElement) -> Option<SyntaxElement> + 'a>>, | ||
249 | //FIXME: add debug_assertions that all elements are in fact from the same file. | ||
250 | replacements: FxHashMap<SyntaxElement, Replacement>, | ||
251 | } | ||
252 | |||
253 | impl fmt::Debug for SyntaxRewriter<'_> { | ||
254 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
255 | f.debug_struct("SyntaxRewriter").field("replacements", &self.replacements).finish() | ||
256 | } | ||
257 | } | ||
258 | |||
259 | impl<'a> SyntaxRewriter<'a> { | ||
260 | pub fn from_fn(f: impl Fn(&SyntaxElement) -> Option<SyntaxElement> + 'a) -> SyntaxRewriter<'a> { | ||
261 | SyntaxRewriter { f: Some(Box::new(f)), replacements: FxHashMap::default() } | ||
262 | } | ||
263 | pub fn delete<T: Clone + Into<SyntaxElement>>(&mut self, what: &T) { | ||
264 | let what = what.clone().into(); | ||
265 | let replacement = Replacement::Delete; | ||
266 | self.replacements.insert(what, replacement); | ||
267 | } | ||
268 | pub fn replace<T: Clone + Into<SyntaxElement>>(&mut self, what: &T, with: &T) { | ||
269 | let what = what.clone().into(); | ||
270 | let replacement = Replacement::Single(with.clone().into()); | ||
271 | self.replacements.insert(what, replacement); | ||
272 | } | ||
273 | pub fn replace_with_many<T: Clone + Into<SyntaxElement>>( | ||
274 | &mut self, | ||
275 | what: &T, | ||
276 | with: Vec<SyntaxElement>, | ||
277 | ) { | ||
278 | let what = what.clone().into(); | ||
279 | let replacement = Replacement::Many(with); | ||
280 | self.replacements.insert(what, replacement); | ||
281 | } | ||
282 | pub fn replace_ast<T: AstNode>(&mut self, what: &T, with: &T) { | ||
283 | self.replace(what.syntax(), with.syntax()) | ||
284 | } | ||
285 | |||
286 | pub fn rewrite(&self, node: &SyntaxNode) -> SyntaxNode { | ||
287 | if self.f.is_none() && self.replacements.is_empty() { | ||
288 | return node.clone(); | ||
289 | } | ||
290 | self.rewrite_children(node) | ||
291 | } | ||
292 | |||
293 | pub fn rewrite_ast<N: AstNode>(self, node: &N) -> N { | ||
294 | N::cast(self.rewrite(node.syntax())).unwrap() | ||
295 | } | ||
296 | |||
297 | /// Returns a node that encompasses all replacements to be done by this rewriter. | ||
298 | /// | ||
299 | /// Passing the returned node to `rewrite` will apply all replacements queued up in `self`. | ||
300 | /// | ||
301 | /// Returns `None` when there are no replacements. | ||
302 | pub fn rewrite_root(&self) -> Option<SyntaxNode> { | ||
303 | assert!(self.f.is_none()); | ||
304 | self.replacements | ||
305 | .keys() | ||
306 | .map(|element| match element { | ||
307 | SyntaxElement::Node(it) => it.clone(), | ||
308 | SyntaxElement::Token(it) => it.parent(), | ||
309 | }) | ||
310 | // If we only have one replacement, we must return its parent node, since `rewrite` does | ||
311 | // not replace the node passed to it. | ||
312 | .map(|it| it.parent().unwrap_or(it)) | ||
313 | .fold1(|a, b| least_common_ancestor(&a, &b).unwrap()) | ||
314 | } | ||
315 | |||
316 | fn replacement(&self, element: &SyntaxElement) -> Option<Replacement> { | ||
317 | if let Some(f) = &self.f { | ||
318 | assert!(self.replacements.is_empty()); | ||
319 | return f(element).map(Replacement::Single); | ||
320 | } | ||
321 | self.replacements.get(element).cloned() | ||
322 | } | ||
323 | |||
324 | fn rewrite_children(&self, node: &SyntaxNode) -> SyntaxNode { | ||
325 | // FIXME: this could be made much faster. | ||
326 | let mut new_children = Vec::new(); | ||
327 | for child in node.children_with_tokens() { | ||
328 | self.rewrite_self(&mut new_children, &child); | ||
329 | } | ||
330 | with_children(node, new_children) | ||
331 | } | ||
332 | |||
333 | fn rewrite_self( | ||
334 | &self, | ||
335 | acc: &mut Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>, | ||
336 | element: &SyntaxElement, | ||
337 | ) { | ||
338 | if let Some(replacement) = self.replacement(&element) { | ||
339 | match replacement { | ||
340 | Replacement::Single(NodeOrToken::Node(it)) => { | ||
341 | acc.push(NodeOrToken::Node(it.green().clone())) | ||
342 | } | ||
343 | Replacement::Single(NodeOrToken::Token(it)) => { | ||
344 | acc.push(NodeOrToken::Token(it.green().clone())) | ||
345 | } | ||
346 | Replacement::Many(replacements) => { | ||
347 | acc.extend(replacements.iter().map(|it| match it { | ||
348 | NodeOrToken::Node(it) => NodeOrToken::Node(it.green().clone()), | ||
349 | NodeOrToken::Token(it) => NodeOrToken::Token(it.green().clone()), | ||
350 | })) | ||
351 | } | ||
352 | Replacement::Delete => (), | ||
353 | }; | ||
354 | return; | ||
355 | } | ||
356 | let res = match element { | ||
357 | NodeOrToken::Token(it) => NodeOrToken::Token(it.green().clone()), | ||
358 | NodeOrToken::Node(it) => NodeOrToken::Node(self.rewrite_children(it).green().clone()), | ||
359 | }; | ||
360 | acc.push(res) | ||
361 | } | ||
362 | } | ||
363 | |||
364 | impl ops::AddAssign for SyntaxRewriter<'_> { | ||
365 | fn add_assign(&mut self, rhs: SyntaxRewriter) { | ||
366 | assert!(rhs.f.is_none()); | ||
367 | self.replacements.extend(rhs.replacements) | ||
368 | } | ||
369 | } | ||
370 | |||
371 | #[derive(Clone, Debug)] | ||
372 | enum Replacement { | ||
373 | Delete, | ||
374 | Single(SyntaxElement), | ||
375 | Many(Vec<SyntaxElement>), | ||
376 | } | ||
377 | |||
378 | fn with_children( | ||
379 | parent: &SyntaxNode, | ||
380 | new_children: Vec<NodeOrToken<rowan::GreenNode, rowan::GreenToken>>, | ||
381 | ) -> SyntaxNode { | ||
382 | let len = new_children.iter().map(|it| it.text_len()).sum::<TextSize>(); | ||
383 | let new_node = rowan::GreenNode::new(rowan::SyntaxKind(parent.kind() as u16), new_children); | ||
384 | let new_root_node = parent.replace_with(new_node); | ||
385 | let new_root_node = SyntaxNode::new_root(new_root_node); | ||
386 | |||
387 | // FIXME: use a more elegant way to re-fetch the node (#1185), make | ||
388 | // `range` private afterwards | ||
389 | let mut ptr = SyntaxNodePtr::new(parent); | ||
390 | ptr.range = TextRange::at(ptr.range.start(), len); | ||
391 | ptr.to_node(&new_root_node) | ||
392 | } | ||
393 | |||
394 | fn position_of_child(parent: &SyntaxNode, child: SyntaxElement) -> usize { | ||
395 | parent | ||
396 | .children_with_tokens() | ||
397 | .position(|it| it == child) | ||
398 | .expect("element is not a child of current element") | ||
399 | } | ||
400 | |||
401 | fn to_green_element(element: SyntaxElement) -> NodeOrToken<rowan::GreenNode, rowan::GreenToken> { | ||
402 | match element { | ||
403 | NodeOrToken::Node(it) => it.green().clone().into(), | ||
404 | NodeOrToken::Token(it) => it.green().clone().into(), | ||
405 | } | ||
406 | } | ||
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs deleted file mode 100644 index fd426ece9..000000000 --- a/crates/ra_syntax/src/ast.rs +++ /dev/null | |||
@@ -1,331 +0,0 @@ | |||
1 | //! Abstract Syntax Tree, layered on top of untyped `SyntaxNode`s | ||
2 | |||
3 | mod generated; | ||
4 | mod traits; | ||
5 | mod token_ext; | ||
6 | mod node_ext; | ||
7 | mod expr_ext; | ||
8 | pub mod edit; | ||
9 | pub mod make; | ||
10 | |||
11 | use std::marker::PhantomData; | ||
12 | |||
13 | use crate::{ | ||
14 | syntax_node::{SyntaxNode, SyntaxNodeChildren, SyntaxToken}, | ||
15 | SmolStr, SyntaxKind, | ||
16 | }; | ||
17 | |||
18 | pub use self::{ | ||
19 | expr_ext::{ArrayExprKind, BinOp, Effect, ElseBranch, LiteralKind, PrefixOp, RangeOp}, | ||
20 | generated::{nodes::*, tokens::*}, | ||
21 | node_ext::{ | ||
22 | AttrKind, FieldKind, NameOrNameRef, PathSegmentKind, SelfParamKind, SlicePatComponents, | ||
23 | StructKind, TypeBoundKind, VisibilityKind, | ||
24 | }, | ||
25 | token_ext::*, | ||
26 | traits::*, | ||
27 | }; | ||
28 | |||
29 | /// The main trait to go from untyped `SyntaxNode` to a typed ast. The | ||
30 | /// conversion itself has zero runtime cost: ast and syntax nodes have exactly | ||
31 | /// the same representation: a pointer to the tree root and a pointer to the | ||
32 | /// node itself. | ||
33 | pub trait AstNode { | ||
34 | fn can_cast(kind: SyntaxKind) -> bool | ||
35 | where | ||
36 | Self: Sized; | ||
37 | |||
38 | fn cast(syntax: SyntaxNode) -> Option<Self> | ||
39 | where | ||
40 | Self: Sized; | ||
41 | |||
42 | fn syntax(&self) -> &SyntaxNode; | ||
43 | } | ||
44 | |||
45 | /// Like `AstNode`, but wraps tokens rather than interior nodes. | ||
46 | pub trait AstToken { | ||
47 | fn can_cast(token: SyntaxKind) -> bool | ||
48 | where | ||
49 | Self: Sized; | ||
50 | |||
51 | fn cast(syntax: SyntaxToken) -> Option<Self> | ||
52 | where | ||
53 | Self: Sized; | ||
54 | |||
55 | fn syntax(&self) -> &SyntaxToken; | ||
56 | |||
57 | fn text(&self) -> &SmolStr { | ||
58 | self.syntax().text() | ||
59 | } | ||
60 | } | ||
61 | |||
62 | /// An iterator over `SyntaxNode` children of a particular AST type. | ||
63 | #[derive(Debug, Clone)] | ||
64 | pub struct AstChildren<N> { | ||
65 | inner: SyntaxNodeChildren, | ||
66 | ph: PhantomData<N>, | ||
67 | } | ||
68 | |||
69 | impl<N> AstChildren<N> { | ||
70 | fn new(parent: &SyntaxNode) -> Self { | ||
71 | AstChildren { inner: parent.children(), ph: PhantomData } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | impl<N: AstNode> Iterator for AstChildren<N> { | ||
76 | type Item = N; | ||
77 | fn next(&mut self) -> Option<N> { | ||
78 | self.inner.find_map(N::cast) | ||
79 | } | ||
80 | } | ||
81 | |||
82 | mod support { | ||
83 | use super::{AstChildren, AstNode, SyntaxKind, SyntaxNode, SyntaxToken}; | ||
84 | |||
85 | pub(super) fn child<N: AstNode>(parent: &SyntaxNode) -> Option<N> { | ||
86 | parent.children().find_map(N::cast) | ||
87 | } | ||
88 | |||
89 | pub(super) fn children<N: AstNode>(parent: &SyntaxNode) -> AstChildren<N> { | ||
90 | AstChildren::new(parent) | ||
91 | } | ||
92 | |||
93 | pub(super) fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option<SyntaxToken> { | ||
94 | parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind) | ||
95 | } | ||
96 | } | ||
97 | |||
98 | #[test] | ||
99 | fn assert_ast_is_object_safe() { | ||
100 | fn _f(_: &dyn AstNode, _: &dyn NameOwner) {} | ||
101 | } | ||
102 | |||
103 | #[test] | ||
104 | fn test_doc_comment_none() { | ||
105 | let file = SourceFile::parse( | ||
106 | r#" | ||
107 | // non-doc | ||
108 | mod foo {} | ||
109 | "#, | ||
110 | ) | ||
111 | .ok() | ||
112 | .unwrap(); | ||
113 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
114 | assert!(module.doc_comment_text().is_none()); | ||
115 | } | ||
116 | |||
117 | #[test] | ||
118 | fn test_doc_comment_of_items() { | ||
119 | let file = SourceFile::parse( | ||
120 | r#" | ||
121 | //! doc | ||
122 | // non-doc | ||
123 | mod foo {} | ||
124 | "#, | ||
125 | ) | ||
126 | .ok() | ||
127 | .unwrap(); | ||
128 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
129 | assert_eq!("doc", module.doc_comment_text().unwrap()); | ||
130 | } | ||
131 | |||
132 | #[test] | ||
133 | fn test_doc_comment_of_statics() { | ||
134 | let file = SourceFile::parse( | ||
135 | r#" | ||
136 | /// Number of levels | ||
137 | static LEVELS: i32 = 0; | ||
138 | "#, | ||
139 | ) | ||
140 | .ok() | ||
141 | .unwrap(); | ||
142 | let st = file.syntax().descendants().find_map(Static::cast).unwrap(); | ||
143 | assert_eq!("Number of levels", st.doc_comment_text().unwrap()); | ||
144 | } | ||
145 | |||
146 | #[test] | ||
147 | fn test_doc_comment_preserves_indents() { | ||
148 | let file = SourceFile::parse( | ||
149 | r#" | ||
150 | /// doc1 | ||
151 | /// ``` | ||
152 | /// fn foo() { | ||
153 | /// // ... | ||
154 | /// } | ||
155 | /// ``` | ||
156 | mod foo {} | ||
157 | "#, | ||
158 | ) | ||
159 | .ok() | ||
160 | .unwrap(); | ||
161 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
162 | assert_eq!("doc1\n```\nfn foo() {\n // ...\n}\n```", module.doc_comment_text().unwrap()); | ||
163 | } | ||
164 | |||
165 | #[test] | ||
166 | fn test_doc_comment_preserves_newlines() { | ||
167 | let file = SourceFile::parse( | ||
168 | r#" | ||
169 | /// this | ||
170 | /// is | ||
171 | /// mod | ||
172 | /// foo | ||
173 | mod foo {} | ||
174 | "#, | ||
175 | ) | ||
176 | .ok() | ||
177 | .unwrap(); | ||
178 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
179 | assert_eq!("this\nis\nmod\nfoo", module.doc_comment_text().unwrap()); | ||
180 | } | ||
181 | |||
182 | #[test] | ||
183 | fn test_doc_comment_single_line_block_strips_suffix() { | ||
184 | let file = SourceFile::parse( | ||
185 | r#" | ||
186 | /** this is mod foo*/ | ||
187 | mod foo {} | ||
188 | "#, | ||
189 | ) | ||
190 | .ok() | ||
191 | .unwrap(); | ||
192 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
193 | assert_eq!("this is mod foo", module.doc_comment_text().unwrap()); | ||
194 | } | ||
195 | |||
196 | #[test] | ||
197 | fn test_doc_comment_single_line_block_strips_suffix_whitespace() { | ||
198 | let file = SourceFile::parse( | ||
199 | r#" | ||
200 | /** this is mod foo */ | ||
201 | mod foo {} | ||
202 | "#, | ||
203 | ) | ||
204 | .ok() | ||
205 | .unwrap(); | ||
206 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
207 | assert_eq!("this is mod foo ", module.doc_comment_text().unwrap()); | ||
208 | } | ||
209 | |||
210 | #[test] | ||
211 | fn test_doc_comment_multi_line_block_strips_suffix() { | ||
212 | let file = SourceFile::parse( | ||
213 | r#" | ||
214 | /** | ||
215 | this | ||
216 | is | ||
217 | mod foo | ||
218 | */ | ||
219 | mod foo {} | ||
220 | "#, | ||
221 | ) | ||
222 | .ok() | ||
223 | .unwrap(); | ||
224 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
225 | assert_eq!( | ||
226 | " this\n is\n mod foo\n ", | ||
227 | module.doc_comment_text().unwrap() | ||
228 | ); | ||
229 | } | ||
230 | |||
231 | #[test] | ||
232 | fn test_comments_preserve_trailing_whitespace() { | ||
233 | let file = SourceFile::parse( | ||
234 | "\n/// Representation of a Realm. \n/// In the specification these are called Realm Records.\nstruct Realm {}", | ||
235 | ) | ||
236 | .ok() | ||
237 | .unwrap(); | ||
238 | let def = file.syntax().descendants().find_map(Struct::cast).unwrap(); | ||
239 | assert_eq!( | ||
240 | "Representation of a Realm. \nIn the specification these are called Realm Records.", | ||
241 | def.doc_comment_text().unwrap() | ||
242 | ); | ||
243 | } | ||
244 | |||
245 | #[test] | ||
246 | fn test_four_slash_line_comment() { | ||
247 | let file = SourceFile::parse( | ||
248 | r#" | ||
249 | //// too many slashes to be a doc comment | ||
250 | /// doc comment | ||
251 | mod foo {} | ||
252 | "#, | ||
253 | ) | ||
254 | .ok() | ||
255 | .unwrap(); | ||
256 | let module = file.syntax().descendants().find_map(Module::cast).unwrap(); | ||
257 | assert_eq!("doc comment", module.doc_comment_text().unwrap()); | ||
258 | } | ||
259 | |||
260 | #[test] | ||
261 | fn test_where_predicates() { | ||
262 | fn assert_bound(text: &str, bound: Option<TypeBound>) { | ||
263 | assert_eq!(text, bound.unwrap().syntax().text().to_string()); | ||
264 | } | ||
265 | |||
266 | let file = SourceFile::parse( | ||
267 | r#" | ||
268 | fn foo() | ||
269 | where | ||
270 | T: Clone + Copy + Debug + 'static, | ||
271 | 'a: 'b + 'c, | ||
272 | Iterator::Item: 'a + Debug, | ||
273 | Iterator::Item: Debug + 'a, | ||
274 | <T as Iterator>::Item: Debug + 'a, | ||
275 | for<'a> F: Fn(&'a str) | ||
276 | {} | ||
277 | "#, | ||
278 | ) | ||
279 | .ok() | ||
280 | .unwrap(); | ||
281 | let where_clause = file.syntax().descendants().find_map(WhereClause::cast).unwrap(); | ||
282 | |||
283 | let mut predicates = where_clause.predicates(); | ||
284 | |||
285 | let pred = predicates.next().unwrap(); | ||
286 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | ||
287 | |||
288 | assert!(pred.for_token().is_none()); | ||
289 | assert!(pred.generic_param_list().is_none()); | ||
290 | assert_eq!("T", pred.type_ref().unwrap().syntax().text().to_string()); | ||
291 | assert_bound("Clone", bounds.next()); | ||
292 | assert_bound("Copy", bounds.next()); | ||
293 | assert_bound("Debug", bounds.next()); | ||
294 | assert_bound("'static", bounds.next()); | ||
295 | |||
296 | let pred = predicates.next().unwrap(); | ||
297 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | ||
298 | |||
299 | assert_eq!("'a", pred.lifetime_token().unwrap().text()); | ||
300 | |||
301 | assert_bound("'b", bounds.next()); | ||
302 | assert_bound("'c", bounds.next()); | ||
303 | |||
304 | let pred = predicates.next().unwrap(); | ||
305 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | ||
306 | |||
307 | assert_eq!("Iterator::Item", pred.type_ref().unwrap().syntax().text().to_string()); | ||
308 | assert_bound("'a", bounds.next()); | ||
309 | |||
310 | let pred = predicates.next().unwrap(); | ||
311 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | ||
312 | |||
313 | assert_eq!("Iterator::Item", pred.type_ref().unwrap().syntax().text().to_string()); | ||
314 | assert_bound("Debug", bounds.next()); | ||
315 | assert_bound("'a", bounds.next()); | ||
316 | |||
317 | let pred = predicates.next().unwrap(); | ||
318 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | ||
319 | |||
320 | assert_eq!("<T as Iterator>::Item", pred.type_ref().unwrap().syntax().text().to_string()); | ||
321 | assert_bound("Debug", bounds.next()); | ||
322 | assert_bound("'a", bounds.next()); | ||
323 | |||
324 | let pred = predicates.next().unwrap(); | ||
325 | let mut bounds = pred.type_bound_list().unwrap().bounds(); | ||
326 | |||
327 | assert!(pred.for_token().is_some()); | ||
328 | assert_eq!("<'a>", pred.generic_param_list().unwrap().syntax().text().to_string()); | ||
329 | assert_eq!("F", pred.type_ref().unwrap().syntax().text().to_string()); | ||
330 | assert_bound("Fn(&'a str)", bounds.next()); | ||
331 | } | ||
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs deleted file mode 100644 index 8d3e42f25..000000000 --- a/crates/ra_syntax/src/ast/edit.rs +++ /dev/null | |||
@@ -1,642 +0,0 @@ | |||
1 | //! This module contains functions for editing syntax trees. As the trees are | ||
2 | //! immutable, all function here return a fresh copy of the tree, instead of | ||
3 | //! doing an in-place modification. | ||
4 | use std::{ | ||
5 | fmt, iter, | ||
6 | ops::{self, RangeInclusive}, | ||
7 | }; | ||
8 | |||
9 | use arrayvec::ArrayVec; | ||
10 | |||
11 | use crate::{ | ||
12 | algo::{self, neighbor, SyntaxRewriter}, | ||
13 | ast::{ | ||
14 | self, | ||
15 | make::{self, tokens}, | ||
16 | AstNode, TypeBoundsOwner, | ||
17 | }, | ||
18 | AstToken, Direction, InsertPosition, SmolStr, SyntaxElement, SyntaxKind, | ||
19 | SyntaxKind::{ATTR, COMMENT, WHITESPACE}, | ||
20 | SyntaxNode, SyntaxToken, T, | ||
21 | }; | ||
22 | |||
23 | impl ast::BinExpr { | ||
24 | #[must_use] | ||
25 | pub fn replace_op(&self, op: SyntaxKind) -> Option<ast::BinExpr> { | ||
26 | let op_node: SyntaxElement = self.op_details()?.0.into(); | ||
27 | let to_insert: Option<SyntaxElement> = Some(make::token(op).into()); | ||
28 | Some(self.replace_children(single_node(op_node), to_insert)) | ||
29 | } | ||
30 | } | ||
31 | |||
32 | impl ast::Fn { | ||
33 | #[must_use] | ||
34 | pub fn with_body(&self, body: ast::BlockExpr) -> ast::Fn { | ||
35 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); | ||
36 | let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { | ||
37 | old_body.syntax().clone().into() | ||
38 | } else if let Some(semi) = self.semicolon_token() { | ||
39 | to_insert.push(make::tokens::single_space().into()); | ||
40 | semi.into() | ||
41 | } else { | ||
42 | to_insert.push(make::tokens::single_space().into()); | ||
43 | to_insert.push(body.syntax().clone().into()); | ||
44 | return self.insert_children(InsertPosition::Last, to_insert); | ||
45 | }; | ||
46 | to_insert.push(body.syntax().clone().into()); | ||
47 | self.replace_children(single_node(old_body_or_semi), to_insert) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | fn make_multiline<N>(node: N) -> N | ||
52 | where | ||
53 | N: AstNode + Clone, | ||
54 | { | ||
55 | let l_curly = match node.syntax().children_with_tokens().find(|it| it.kind() == T!['{']) { | ||
56 | Some(it) => it, | ||
57 | None => return node, | ||
58 | }; | ||
59 | let sibling = match l_curly.next_sibling_or_token() { | ||
60 | Some(it) => it, | ||
61 | None => return node, | ||
62 | }; | ||
63 | let existing_ws = match sibling.as_token() { | ||
64 | None => None, | ||
65 | Some(tok) if tok.kind() != WHITESPACE => None, | ||
66 | Some(ws) => { | ||
67 | if ws.text().contains('\n') { | ||
68 | return node; | ||
69 | } | ||
70 | Some(ws.clone()) | ||
71 | } | ||
72 | }; | ||
73 | |||
74 | let indent = leading_indent(node.syntax()).unwrap_or_default(); | ||
75 | let ws = tokens::WsBuilder::new(&format!("\n{}", indent)); | ||
76 | let to_insert = iter::once(ws.ws().into()); | ||
77 | match existing_ws { | ||
78 | None => node.insert_children(InsertPosition::After(l_curly), to_insert), | ||
79 | Some(ws) => node.replace_children(single_node(ws), to_insert), | ||
80 | } | ||
81 | } | ||
82 | |||
83 | impl ast::AssocItemList { | ||
84 | #[must_use] | ||
85 | pub fn append_items( | ||
86 | &self, | ||
87 | items: impl IntoIterator<Item = ast::AssocItem>, | ||
88 | ) -> ast::AssocItemList { | ||
89 | let mut res = self.clone(); | ||
90 | if !self.syntax().text().contains_char('\n') { | ||
91 | res = make_multiline(res); | ||
92 | } | ||
93 | items.into_iter().for_each(|it| res = res.append_item(it)); | ||
94 | res | ||
95 | } | ||
96 | |||
97 | #[must_use] | ||
98 | pub fn append_item(&self, item: ast::AssocItem) -> ast::AssocItemList { | ||
99 | let (indent, position) = match self.assoc_items().last() { | ||
100 | Some(it) => ( | ||
101 | leading_indent(it.syntax()).unwrap_or_default().to_string(), | ||
102 | InsertPosition::After(it.syntax().clone().into()), | ||
103 | ), | ||
104 | None => match self.l_curly_token() { | ||
105 | Some(it) => ( | ||
106 | " ".to_string() + &leading_indent(self.syntax()).unwrap_or_default(), | ||
107 | InsertPosition::After(it.into()), | ||
108 | ), | ||
109 | None => return self.clone(), | ||
110 | }, | ||
111 | }; | ||
112 | let ws = tokens::WsBuilder::new(&format!("\n{}", indent)); | ||
113 | let to_insert: ArrayVec<[SyntaxElement; 2]> = | ||
114 | [ws.ws().into(), item.syntax().clone().into()].into(); | ||
115 | self.insert_children(position, to_insert) | ||
116 | } | ||
117 | } | ||
118 | |||
119 | impl ast::RecordExprFieldList { | ||
120 | #[must_use] | ||
121 | pub fn append_field(&self, field: &ast::RecordExprField) -> ast::RecordExprFieldList { | ||
122 | self.insert_field(InsertPosition::Last, field) | ||
123 | } | ||
124 | |||
125 | #[must_use] | ||
126 | pub fn insert_field( | ||
127 | &self, | ||
128 | position: InsertPosition<&'_ ast::RecordExprField>, | ||
129 | field: &ast::RecordExprField, | ||
130 | ) -> ast::RecordExprFieldList { | ||
131 | let is_multiline = self.syntax().text().contains_char('\n'); | ||
132 | let ws; | ||
133 | let space = if is_multiline { | ||
134 | ws = tokens::WsBuilder::new(&format!( | ||
135 | "\n{} ", | ||
136 | leading_indent(self.syntax()).unwrap_or_default() | ||
137 | )); | ||
138 | ws.ws() | ||
139 | } else { | ||
140 | tokens::single_space() | ||
141 | }; | ||
142 | |||
143 | let mut to_insert: ArrayVec<[SyntaxElement; 4]> = ArrayVec::new(); | ||
144 | to_insert.push(space.into()); | ||
145 | to_insert.push(field.syntax().clone().into()); | ||
146 | to_insert.push(make::token(T![,]).into()); | ||
147 | |||
148 | macro_rules! after_l_curly { | ||
149 | () => {{ | ||
150 | let anchor = match self.l_curly_token() { | ||
151 | Some(it) => it.into(), | ||
152 | None => return self.clone(), | ||
153 | }; | ||
154 | InsertPosition::After(anchor) | ||
155 | }}; | ||
156 | } | ||
157 | |||
158 | macro_rules! after_field { | ||
159 | ($anchor:expr) => { | ||
160 | if let Some(comma) = $anchor | ||
161 | .syntax() | ||
162 | .siblings_with_tokens(Direction::Next) | ||
163 | .find(|it| it.kind() == T![,]) | ||
164 | { | ||
165 | InsertPosition::After(comma) | ||
166 | } else { | ||
167 | to_insert.insert(0, make::token(T![,]).into()); | ||
168 | InsertPosition::After($anchor.syntax().clone().into()) | ||
169 | } | ||
170 | }; | ||
171 | }; | ||
172 | |||
173 | let position = match position { | ||
174 | InsertPosition::First => after_l_curly!(), | ||
175 | InsertPosition::Last => { | ||
176 | if !is_multiline { | ||
177 | // don't insert comma before curly | ||
178 | to_insert.pop(); | ||
179 | } | ||
180 | match self.fields().last() { | ||
181 | Some(it) => after_field!(it), | ||
182 | None => after_l_curly!(), | ||
183 | } | ||
184 | } | ||
185 | InsertPosition::Before(anchor) => { | ||
186 | InsertPosition::Before(anchor.syntax().clone().into()) | ||
187 | } | ||
188 | InsertPosition::After(anchor) => after_field!(anchor), | ||
189 | }; | ||
190 | |||
191 | self.insert_children(position, to_insert) | ||
192 | } | ||
193 | } | ||
194 | |||
195 | impl ast::TypeAlias { | ||
196 | #[must_use] | ||
197 | pub fn remove_bounds(&self) -> ast::TypeAlias { | ||
198 | let colon = match self.colon_token() { | ||
199 | Some(it) => it, | ||
200 | None => return self.clone(), | ||
201 | }; | ||
202 | let end = match self.type_bound_list() { | ||
203 | Some(it) => it.syntax().clone().into(), | ||
204 | None => colon.clone().into(), | ||
205 | }; | ||
206 | self.replace_children(colon.into()..=end, iter::empty()) | ||
207 | } | ||
208 | } | ||
209 | |||
210 | impl ast::TypeParam { | ||
211 | #[must_use] | ||
212 | pub fn remove_bounds(&self) -> ast::TypeParam { | ||
213 | let colon = match self.colon_token() { | ||
214 | Some(it) => it, | ||
215 | None => return self.clone(), | ||
216 | }; | ||
217 | let end = match self.type_bound_list() { | ||
218 | Some(it) => it.syntax().clone().into(), | ||
219 | None => colon.clone().into(), | ||
220 | }; | ||
221 | self.replace_children(colon.into()..=end, iter::empty()) | ||
222 | } | ||
223 | } | ||
224 | |||
225 | impl ast::Path { | ||
226 | #[must_use] | ||
227 | pub fn with_segment(&self, segment: ast::PathSegment) -> ast::Path { | ||
228 | if let Some(old) = self.segment() { | ||
229 | return self.replace_children( | ||
230 | single_node(old.syntax().clone()), | ||
231 | iter::once(segment.syntax().clone().into()), | ||
232 | ); | ||
233 | } | ||
234 | self.clone() | ||
235 | } | ||
236 | } | ||
237 | |||
238 | impl ast::PathSegment { | ||
239 | #[must_use] | ||
240 | pub fn with_type_args(&self, type_args: ast::TypeArgList) -> ast::PathSegment { | ||
241 | self._with_type_args(type_args, false) | ||
242 | } | ||
243 | |||
244 | #[must_use] | ||
245 | pub fn with_turbo_fish(&self, type_args: ast::TypeArgList) -> ast::PathSegment { | ||
246 | self._with_type_args(type_args, true) | ||
247 | } | ||
248 | |||
249 | fn _with_type_args(&self, type_args: ast::TypeArgList, turbo: bool) -> ast::PathSegment { | ||
250 | if let Some(old) = self.type_arg_list() { | ||
251 | return self.replace_children( | ||
252 | single_node(old.syntax().clone()), | ||
253 | iter::once(type_args.syntax().clone().into()), | ||
254 | ); | ||
255 | } | ||
256 | let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); | ||
257 | if turbo { | ||
258 | to_insert.push(make::token(T![::]).into()); | ||
259 | } | ||
260 | to_insert.push(type_args.syntax().clone().into()); | ||
261 | self.insert_children(InsertPosition::Last, to_insert) | ||
262 | } | ||
263 | } | ||
264 | |||
265 | impl ast::Use { | ||
266 | #[must_use] | ||
267 | pub fn with_use_tree(&self, use_tree: ast::UseTree) -> ast::Use { | ||
268 | if let Some(old) = self.use_tree() { | ||
269 | return self.replace_descendant(old, use_tree); | ||
270 | } | ||
271 | self.clone() | ||
272 | } | ||
273 | |||
274 | pub fn remove(&self) -> SyntaxRewriter<'static> { | ||
275 | let mut res = SyntaxRewriter::default(); | ||
276 | res.delete(self.syntax()); | ||
277 | let next_ws = self | ||
278 | .syntax() | ||
279 | .next_sibling_or_token() | ||
280 | .and_then(|it| it.into_token()) | ||
281 | .and_then(ast::Whitespace::cast); | ||
282 | if let Some(next_ws) = next_ws { | ||
283 | let ws_text = next_ws.syntax().text(); | ||
284 | if ws_text.starts_with('\n') { | ||
285 | let rest = &ws_text[1..]; | ||
286 | if rest.is_empty() { | ||
287 | res.delete(next_ws.syntax()) | ||
288 | } else { | ||
289 | res.replace(next_ws.syntax(), &make::tokens::whitespace(rest)); | ||
290 | } | ||
291 | } | ||
292 | } | ||
293 | res | ||
294 | } | ||
295 | } | ||
296 | |||
297 | impl ast::UseTree { | ||
298 | #[must_use] | ||
299 | pub fn with_path(&self, path: ast::Path) -> ast::UseTree { | ||
300 | if let Some(old) = self.path() { | ||
301 | return self.replace_descendant(old, path); | ||
302 | } | ||
303 | self.clone() | ||
304 | } | ||
305 | |||
306 | #[must_use] | ||
307 | pub fn with_use_tree_list(&self, use_tree_list: ast::UseTreeList) -> ast::UseTree { | ||
308 | if let Some(old) = self.use_tree_list() { | ||
309 | return self.replace_descendant(old, use_tree_list); | ||
310 | } | ||
311 | self.clone() | ||
312 | } | ||
313 | |||
314 | #[must_use] | ||
315 | pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree { | ||
316 | let suffix = match split_path_prefix(&prefix) { | ||
317 | Some(it) => it, | ||
318 | None => return self.clone(), | ||
319 | }; | ||
320 | let use_tree = make::use_tree( | ||
321 | suffix, | ||
322 | self.use_tree_list(), | ||
323 | self.rename(), | ||
324 | self.star_token().is_some(), | ||
325 | ); | ||
326 | let nested = make::use_tree_list(iter::once(use_tree)); | ||
327 | return make::use_tree(prefix.clone(), Some(nested), None, false); | ||
328 | |||
329 | fn split_path_prefix(prefix: &ast::Path) -> Option<ast::Path> { | ||
330 | let parent = prefix.parent_path()?; | ||
331 | let segment = parent.segment()?; | ||
332 | if algo::has_errors(segment.syntax()) { | ||
333 | return None; | ||
334 | } | ||
335 | let mut res = make::path_unqualified(segment); | ||
336 | for p in iter::successors(parent.parent_path(), |it| it.parent_path()) { | ||
337 | res = make::path_qualified(res, p.segment()?); | ||
338 | } | ||
339 | Some(res) | ||
340 | } | ||
341 | } | ||
342 | |||
343 | pub fn remove(&self) -> SyntaxRewriter<'static> { | ||
344 | let mut res = SyntaxRewriter::default(); | ||
345 | res.delete(self.syntax()); | ||
346 | for &dir in [Direction::Next, Direction::Prev].iter() { | ||
347 | if let Some(nb) = neighbor(self, dir) { | ||
348 | self.syntax() | ||
349 | .siblings_with_tokens(dir) | ||
350 | .skip(1) | ||
351 | .take_while(|it| it.as_node() != Some(nb.syntax())) | ||
352 | .for_each(|el| res.delete(&el)); | ||
353 | return res; | ||
354 | } | ||
355 | } | ||
356 | res | ||
357 | } | ||
358 | } | ||
359 | |||
360 | impl ast::MatchArmList { | ||
361 | #[must_use] | ||
362 | pub fn append_arms(&self, items: impl IntoIterator<Item = ast::MatchArm>) -> ast::MatchArmList { | ||
363 | let mut res = self.clone(); | ||
364 | res = res.strip_if_only_whitespace(); | ||
365 | if !res.syntax().text().contains_char('\n') { | ||
366 | res = make_multiline(res); | ||
367 | } | ||
368 | items.into_iter().for_each(|it| res = res.append_arm(it)); | ||
369 | res | ||
370 | } | ||
371 | |||
372 | fn strip_if_only_whitespace(&self) -> ast::MatchArmList { | ||
373 | let mut iter = self.syntax().children_with_tokens().skip_while(|it| it.kind() != T!['{']); | ||
374 | iter.next(); // Eat the curly | ||
375 | let mut inner = iter.take_while(|it| it.kind() != T!['}']); | ||
376 | if !inner.clone().all(|it| it.kind() == WHITESPACE) { | ||
377 | return self.clone(); | ||
378 | } | ||
379 | let start = match inner.next() { | ||
380 | Some(s) => s, | ||
381 | None => return self.clone(), | ||
382 | }; | ||
383 | let end = match inner.last() { | ||
384 | Some(s) => s, | ||
385 | None => start.clone(), | ||
386 | }; | ||
387 | self.replace_children(start..=end, &mut iter::empty()) | ||
388 | } | ||
389 | |||
390 | #[must_use] | ||
391 | pub fn remove_placeholder(&self) -> ast::MatchArmList { | ||
392 | let placeholder = | ||
393 | self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::PlaceholderPat(_)))); | ||
394 | if let Some(placeholder) = placeholder { | ||
395 | self.remove_arm(&placeholder) | ||
396 | } else { | ||
397 | self.clone() | ||
398 | } | ||
399 | } | ||
400 | |||
401 | #[must_use] | ||
402 | fn remove_arm(&self, arm: &ast::MatchArm) -> ast::MatchArmList { | ||
403 | let start = arm.syntax().clone(); | ||
404 | let end = if let Some(comma) = start | ||
405 | .siblings_with_tokens(Direction::Next) | ||
406 | .skip(1) | ||
407 | .skip_while(|it| it.kind().is_trivia()) | ||
408 | .next() | ||
409 | .filter(|it| it.kind() == T![,]) | ||
410 | { | ||
411 | comma | ||
412 | } else { | ||
413 | start.clone().into() | ||
414 | }; | ||
415 | self.replace_children(start.into()..=end, None) | ||
416 | } | ||
417 | |||
418 | #[must_use] | ||
419 | pub fn append_arm(&self, item: ast::MatchArm) -> ast::MatchArmList { | ||
420 | let r_curly = match self.syntax().children_with_tokens().find(|it| it.kind() == T!['}']) { | ||
421 | Some(t) => t, | ||
422 | None => return self.clone(), | ||
423 | }; | ||
424 | let position = InsertPosition::Before(r_curly.into()); | ||
425 | let arm_ws = tokens::WsBuilder::new(" "); | ||
426 | let match_indent = &leading_indent(self.syntax()).unwrap_or_default(); | ||
427 | let match_ws = tokens::WsBuilder::new(&format!("\n{}", match_indent)); | ||
428 | let to_insert: ArrayVec<[SyntaxElement; 3]> = | ||
429 | [arm_ws.ws().into(), item.syntax().clone().into(), match_ws.ws().into()].into(); | ||
430 | self.insert_children(position, to_insert) | ||
431 | } | ||
432 | } | ||
433 | |||
434 | #[must_use] | ||
435 | pub fn remove_attrs_and_docs<N: ast::AttrsOwner>(node: &N) -> N { | ||
436 | N::cast(remove_attrs_and_docs_inner(node.syntax().clone())).unwrap() | ||
437 | } | ||
438 | |||
439 | fn remove_attrs_and_docs_inner(mut node: SyntaxNode) -> SyntaxNode { | ||
440 | while let Some(start) = | ||
441 | node.children_with_tokens().find(|it| it.kind() == ATTR || it.kind() == COMMENT) | ||
442 | { | ||
443 | let end = match &start.next_sibling_or_token() { | ||
444 | Some(el) if el.kind() == WHITESPACE => el.clone(), | ||
445 | Some(_) | None => start.clone(), | ||
446 | }; | ||
447 | node = algo::replace_children(&node, start..=end, &mut iter::empty()); | ||
448 | } | ||
449 | node | ||
450 | } | ||
451 | |||
452 | #[derive(Debug, Clone, Copy)] | ||
453 | pub struct IndentLevel(pub u8); | ||
454 | |||
455 | impl From<u8> for IndentLevel { | ||
456 | fn from(level: u8) -> IndentLevel { | ||
457 | IndentLevel(level) | ||
458 | } | ||
459 | } | ||
460 | |||
461 | impl fmt::Display for IndentLevel { | ||
462 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
463 | let spaces = " "; | ||
464 | let buf; | ||
465 | let len = self.0 as usize * 4; | ||
466 | let indent = if len <= spaces.len() { | ||
467 | &spaces[..len] | ||
468 | } else { | ||
469 | buf = iter::repeat(' ').take(len).collect::<String>(); | ||
470 | &buf | ||
471 | }; | ||
472 | fmt::Display::fmt(indent, f) | ||
473 | } | ||
474 | } | ||
475 | |||
476 | impl ops::Add<u8> for IndentLevel { | ||
477 | type Output = IndentLevel; | ||
478 | fn add(self, rhs: u8) -> IndentLevel { | ||
479 | IndentLevel(self.0 + rhs) | ||
480 | } | ||
481 | } | ||
482 | |||
483 | impl IndentLevel { | ||
484 | pub fn from_node(node: &SyntaxNode) -> IndentLevel { | ||
485 | let first_token = match node.first_token() { | ||
486 | Some(it) => it, | ||
487 | None => return IndentLevel(0), | ||
488 | }; | ||
489 | for ws in prev_tokens(first_token).filter_map(ast::Whitespace::cast) { | ||
490 | let text = ws.syntax().text(); | ||
491 | if let Some(pos) = text.rfind('\n') { | ||
492 | let level = text[pos + 1..].chars().count() / 4; | ||
493 | return IndentLevel(level as u8); | ||
494 | } | ||
495 | } | ||
496 | IndentLevel(0) | ||
497 | } | ||
498 | |||
499 | /// XXX: this intentionally doesn't change the indent of the very first token. | ||
500 | /// Ie, in something like | ||
501 | /// ``` | ||
502 | /// fn foo() { | ||
503 | /// 92 | ||
504 | /// } | ||
505 | /// ``` | ||
506 | /// if you indent the block, the `{` token would stay put. | ||
507 | fn increase_indent(self, node: SyntaxNode) -> SyntaxNode { | ||
508 | let mut rewriter = SyntaxRewriter::default(); | ||
509 | node.descendants_with_tokens() | ||
510 | .filter_map(|el| el.into_token()) | ||
511 | .filter_map(ast::Whitespace::cast) | ||
512 | .filter(|ws| { | ||
513 | let text = ws.syntax().text(); | ||
514 | text.contains('\n') | ||
515 | }) | ||
516 | .for_each(|ws| { | ||
517 | let new_ws = make::tokens::whitespace(&format!("{}{}", ws.syntax(), self,)); | ||
518 | rewriter.replace(ws.syntax(), &new_ws) | ||
519 | }); | ||
520 | rewriter.rewrite(&node) | ||
521 | } | ||
522 | |||
523 | fn decrease_indent(self, node: SyntaxNode) -> SyntaxNode { | ||
524 | let mut rewriter = SyntaxRewriter::default(); | ||
525 | node.descendants_with_tokens() | ||
526 | .filter_map(|el| el.into_token()) | ||
527 | .filter_map(ast::Whitespace::cast) | ||
528 | .filter(|ws| { | ||
529 | let text = ws.syntax().text(); | ||
530 | text.contains('\n') | ||
531 | }) | ||
532 | .for_each(|ws| { | ||
533 | let new_ws = make::tokens::whitespace( | ||
534 | &ws.syntax().text().replace(&format!("\n{}", self), "\n"), | ||
535 | ); | ||
536 | rewriter.replace(ws.syntax(), &new_ws) | ||
537 | }); | ||
538 | rewriter.rewrite(&node) | ||
539 | } | ||
540 | } | ||
541 | |||
542 | // FIXME: replace usages with IndentLevel above | ||
543 | fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> { | ||
544 | for token in prev_tokens(node.first_token()?) { | ||
545 | if let Some(ws) = ast::Whitespace::cast(token.clone()) { | ||
546 | let ws_text = ws.text(); | ||
547 | if let Some(pos) = ws_text.rfind('\n') { | ||
548 | return Some(ws_text[pos + 1..].into()); | ||
549 | } | ||
550 | } | ||
551 | if token.text().contains('\n') { | ||
552 | break; | ||
553 | } | ||
554 | } | ||
555 | None | ||
556 | } | ||
557 | |||
558 | fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> { | ||
559 | iter::successors(Some(token), |token| token.prev_token()) | ||
560 | } | ||
561 | |||
562 | pub trait AstNodeEdit: AstNode + Clone + Sized { | ||
563 | #[must_use] | ||
564 | fn insert_children( | ||
565 | &self, | ||
566 | position: InsertPosition<SyntaxElement>, | ||
567 | to_insert: impl IntoIterator<Item = SyntaxElement>, | ||
568 | ) -> Self { | ||
569 | let new_syntax = algo::insert_children(self.syntax(), position, to_insert); | ||
570 | Self::cast(new_syntax).unwrap() | ||
571 | } | ||
572 | |||
573 | #[must_use] | ||
574 | fn replace_children( | ||
575 | &self, | ||
576 | to_replace: RangeInclusive<SyntaxElement>, | ||
577 | to_insert: impl IntoIterator<Item = SyntaxElement>, | ||
578 | ) -> Self { | ||
579 | let new_syntax = algo::replace_children(self.syntax(), to_replace, to_insert); | ||
580 | Self::cast(new_syntax).unwrap() | ||
581 | } | ||
582 | |||
583 | #[must_use] | ||
584 | fn replace_descendant<D: AstNode>(&self, old: D, new: D) -> Self { | ||
585 | self.replace_descendants(iter::once((old, new))) | ||
586 | } | ||
587 | |||
588 | #[must_use] | ||
589 | fn replace_descendants<D: AstNode>( | ||
590 | &self, | ||
591 | replacement_map: impl IntoIterator<Item = (D, D)>, | ||
592 | ) -> Self { | ||
593 | let mut rewriter = SyntaxRewriter::default(); | ||
594 | for (from, to) in replacement_map { | ||
595 | rewriter.replace(from.syntax(), to.syntax()) | ||
596 | } | ||
597 | rewriter.rewrite_ast(self) | ||
598 | } | ||
599 | #[must_use] | ||
600 | fn indent(&self, level: IndentLevel) -> Self { | ||
601 | Self::cast(level.increase_indent(self.syntax().clone())).unwrap() | ||
602 | } | ||
603 | #[must_use] | ||
604 | fn dedent(&self, level: IndentLevel) -> Self { | ||
605 | Self::cast(level.decrease_indent(self.syntax().clone())).unwrap() | ||
606 | } | ||
607 | #[must_use] | ||
608 | fn reset_indent(&self) -> Self { | ||
609 | let level = IndentLevel::from_node(self.syntax()); | ||
610 | self.dedent(level) | ||
611 | } | ||
612 | } | ||
613 | |||
614 | impl<N: AstNode + Clone> AstNodeEdit for N {} | ||
615 | |||
616 | fn single_node(element: impl Into<SyntaxElement>) -> RangeInclusive<SyntaxElement> { | ||
617 | let element = element.into(); | ||
618 | element.clone()..=element | ||
619 | } | ||
620 | |||
621 | #[test] | ||
622 | fn test_increase_indent() { | ||
623 | let arm_list = { | ||
624 | let arm = make::match_arm(iter::once(make::placeholder_pat().into()), make::expr_unit()); | ||
625 | make::match_arm_list(vec![arm.clone(), arm]) | ||
626 | }; | ||
627 | assert_eq!( | ||
628 | arm_list.syntax().to_string(), | ||
629 | "{ | ||
630 | _ => (), | ||
631 | _ => (), | ||
632 | }" | ||
633 | ); | ||
634 | let indented = arm_list.indent(IndentLevel(2)); | ||
635 | assert_eq!( | ||
636 | indented.syntax().to_string(), | ||
637 | "{ | ||
638 | _ => (), | ||
639 | _ => (), | ||
640 | }" | ||
641 | ); | ||
642 | } | ||
diff --git a/crates/ra_syntax/src/ast/expr_ext.rs b/crates/ra_syntax/src/ast/expr_ext.rs deleted file mode 100644 index f5ba87223..000000000 --- a/crates/ra_syntax/src/ast/expr_ext.rs +++ /dev/null | |||
@@ -1,418 +0,0 @@ | |||
1 | //! Various extension methods to ast Expr Nodes, which are hard to code-generate. | ||
2 | |||
3 | use crate::{ | ||
4 | ast::{self, support, AstChildren, AstNode}, | ||
5 | SmolStr, | ||
6 | SyntaxKind::*, | ||
7 | SyntaxToken, T, | ||
8 | }; | ||
9 | |||
10 | impl ast::AttrsOwner for ast::Expr {} | ||
11 | |||
12 | impl ast::Expr { | ||
13 | pub fn is_block_like(&self) -> bool { | ||
14 | match self { | ||
15 | ast::Expr::IfExpr(_) | ||
16 | | ast::Expr::LoopExpr(_) | ||
17 | | ast::Expr::ForExpr(_) | ||
18 | | ast::Expr::WhileExpr(_) | ||
19 | | ast::Expr::BlockExpr(_) | ||
20 | | ast::Expr::MatchExpr(_) | ||
21 | | ast::Expr::EffectExpr(_) => true, | ||
22 | _ => false, | ||
23 | } | ||
24 | } | ||
25 | } | ||
26 | |||
27 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
28 | pub enum ElseBranch { | ||
29 | Block(ast::BlockExpr), | ||
30 | IfExpr(ast::IfExpr), | ||
31 | } | ||
32 | |||
33 | impl ast::IfExpr { | ||
34 | pub fn then_branch(&self) -> Option<ast::BlockExpr> { | ||
35 | self.blocks().next() | ||
36 | } | ||
37 | pub fn else_branch(&self) -> Option<ElseBranch> { | ||
38 | let res = match self.blocks().nth(1) { | ||
39 | Some(block) => ElseBranch::Block(block), | ||
40 | None => { | ||
41 | let elif: ast::IfExpr = support::child(self.syntax())?; | ||
42 | ElseBranch::IfExpr(elif) | ||
43 | } | ||
44 | }; | ||
45 | Some(res) | ||
46 | } | ||
47 | |||
48 | pub fn blocks(&self) -> AstChildren<ast::BlockExpr> { | ||
49 | support::children(self.syntax()) | ||
50 | } | ||
51 | } | ||
52 | |||
53 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | ||
54 | pub enum PrefixOp { | ||
55 | /// The `*` operator for dereferencing | ||
56 | Deref, | ||
57 | /// The `!` operator for logical inversion | ||
58 | Not, | ||
59 | /// The `-` operator for negation | ||
60 | Neg, | ||
61 | } | ||
62 | |||
63 | impl ast::PrefixExpr { | ||
64 | pub fn op_kind(&self) -> Option<PrefixOp> { | ||
65 | match self.op_token()?.kind() { | ||
66 | T![*] => Some(PrefixOp::Deref), | ||
67 | T![!] => Some(PrefixOp::Not), | ||
68 | T![-] => Some(PrefixOp::Neg), | ||
69 | _ => None, | ||
70 | } | ||
71 | } | ||
72 | |||
73 | pub fn op_token(&self) -> Option<SyntaxToken> { | ||
74 | self.syntax().first_child_or_token()?.into_token() | ||
75 | } | ||
76 | } | ||
77 | |||
78 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | ||
79 | pub enum BinOp { | ||
80 | /// The `||` operator for boolean OR | ||
81 | BooleanOr, | ||
82 | /// The `&&` operator for boolean AND | ||
83 | BooleanAnd, | ||
84 | /// The `==` operator for equality testing | ||
85 | EqualityTest, | ||
86 | /// The `!=` operator for equality testing | ||
87 | NegatedEqualityTest, | ||
88 | /// The `<=` operator for lesser-equal testing | ||
89 | LesserEqualTest, | ||
90 | /// The `>=` operator for greater-equal testing | ||
91 | GreaterEqualTest, | ||
92 | /// The `<` operator for comparison | ||
93 | LesserTest, | ||
94 | /// The `>` operator for comparison | ||
95 | GreaterTest, | ||
96 | /// The `+` operator for addition | ||
97 | Addition, | ||
98 | /// The `*` operator for multiplication | ||
99 | Multiplication, | ||
100 | /// The `-` operator for subtraction | ||
101 | Subtraction, | ||
102 | /// The `/` operator for division | ||
103 | Division, | ||
104 | /// The `%` operator for remainder after division | ||
105 | Remainder, | ||
106 | /// The `<<` operator for left shift | ||
107 | LeftShift, | ||
108 | /// The `>>` operator for right shift | ||
109 | RightShift, | ||
110 | /// The `^` operator for bitwise XOR | ||
111 | BitwiseXor, | ||
112 | /// The `|` operator for bitwise OR | ||
113 | BitwiseOr, | ||
114 | /// The `&` operator for bitwise AND | ||
115 | BitwiseAnd, | ||
116 | /// The `=` operator for assignment | ||
117 | Assignment, | ||
118 | /// The `+=` operator for assignment after addition | ||
119 | AddAssign, | ||
120 | /// The `/=` operator for assignment after division | ||
121 | DivAssign, | ||
122 | /// The `*=` operator for assignment after multiplication | ||
123 | MulAssign, | ||
124 | /// The `%=` operator for assignment after remainders | ||
125 | RemAssign, | ||
126 | /// The `>>=` operator for assignment after shifting right | ||
127 | ShrAssign, | ||
128 | /// The `<<=` operator for assignment after shifting left | ||
129 | ShlAssign, | ||
130 | /// The `-=` operator for assignment after subtraction | ||
131 | SubAssign, | ||
132 | /// The `|=` operator for assignment after bitwise OR | ||
133 | BitOrAssign, | ||
134 | /// The `&=` operator for assignment after bitwise AND | ||
135 | BitAndAssign, | ||
136 | /// The `^=` operator for assignment after bitwise XOR | ||
137 | BitXorAssign, | ||
138 | } | ||
139 | |||
140 | impl BinOp { | ||
141 | pub fn is_assignment(self) -> bool { | ||
142 | match self { | ||
143 | BinOp::Assignment | ||
144 | | BinOp::AddAssign | ||
145 | | BinOp::DivAssign | ||
146 | | BinOp::MulAssign | ||
147 | | BinOp::RemAssign | ||
148 | | BinOp::ShrAssign | ||
149 | | BinOp::ShlAssign | ||
150 | | BinOp::SubAssign | ||
151 | | BinOp::BitOrAssign | ||
152 | | BinOp::BitAndAssign | ||
153 | | BinOp::BitXorAssign => true, | ||
154 | _ => false, | ||
155 | } | ||
156 | } | ||
157 | } | ||
158 | |||
159 | impl ast::BinExpr { | ||
160 | pub fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { | ||
161 | self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| { | ||
162 | let bin_op = match c.kind() { | ||
163 | T![||] => BinOp::BooleanOr, | ||
164 | T![&&] => BinOp::BooleanAnd, | ||
165 | T![==] => BinOp::EqualityTest, | ||
166 | T![!=] => BinOp::NegatedEqualityTest, | ||
167 | T![<=] => BinOp::LesserEqualTest, | ||
168 | T![>=] => BinOp::GreaterEqualTest, | ||
169 | T![<] => BinOp::LesserTest, | ||
170 | T![>] => BinOp::GreaterTest, | ||
171 | T![+] => BinOp::Addition, | ||
172 | T![*] => BinOp::Multiplication, | ||
173 | T![-] => BinOp::Subtraction, | ||
174 | T![/] => BinOp::Division, | ||
175 | T![%] => BinOp::Remainder, | ||
176 | T![<<] => BinOp::LeftShift, | ||
177 | T![>>] => BinOp::RightShift, | ||
178 | T![^] => BinOp::BitwiseXor, | ||
179 | T![|] => BinOp::BitwiseOr, | ||
180 | T![&] => BinOp::BitwiseAnd, | ||
181 | T![=] => BinOp::Assignment, | ||
182 | T![+=] => BinOp::AddAssign, | ||
183 | T![/=] => BinOp::DivAssign, | ||
184 | T![*=] => BinOp::MulAssign, | ||
185 | T![%=] => BinOp::RemAssign, | ||
186 | T![>>=] => BinOp::ShrAssign, | ||
187 | T![<<=] => BinOp::ShlAssign, | ||
188 | T![-=] => BinOp::SubAssign, | ||
189 | T![|=] => BinOp::BitOrAssign, | ||
190 | T![&=] => BinOp::BitAndAssign, | ||
191 | T![^=] => BinOp::BitXorAssign, | ||
192 | _ => return None, | ||
193 | }; | ||
194 | Some((c, bin_op)) | ||
195 | }) | ||
196 | } | ||
197 | |||
198 | pub fn op_kind(&self) -> Option<BinOp> { | ||
199 | self.op_details().map(|t| t.1) | ||
200 | } | ||
201 | |||
202 | pub fn op_token(&self) -> Option<SyntaxToken> { | ||
203 | self.op_details().map(|t| t.0) | ||
204 | } | ||
205 | |||
206 | pub fn lhs(&self) -> Option<ast::Expr> { | ||
207 | support::children(self.syntax()).next() | ||
208 | } | ||
209 | |||
210 | pub fn rhs(&self) -> Option<ast::Expr> { | ||
211 | support::children(self.syntax()).nth(1) | ||
212 | } | ||
213 | |||
214 | pub fn sub_exprs(&self) -> (Option<ast::Expr>, Option<ast::Expr>) { | ||
215 | let mut children = support::children(self.syntax()); | ||
216 | let first = children.next(); | ||
217 | let second = children.next(); | ||
218 | (first, second) | ||
219 | } | ||
220 | } | ||
221 | |||
222 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | ||
223 | pub enum RangeOp { | ||
224 | /// `..` | ||
225 | Exclusive, | ||
226 | /// `..=` | ||
227 | Inclusive, | ||
228 | } | ||
229 | |||
230 | impl ast::RangeExpr { | ||
231 | fn op_details(&self) -> Option<(usize, SyntaxToken, RangeOp)> { | ||
232 | self.syntax().children_with_tokens().enumerate().find_map(|(ix, child)| { | ||
233 | let token = child.into_token()?; | ||
234 | let bin_op = match token.kind() { | ||
235 | T![..] => RangeOp::Exclusive, | ||
236 | T![..=] => RangeOp::Inclusive, | ||
237 | _ => return None, | ||
238 | }; | ||
239 | Some((ix, token, bin_op)) | ||
240 | }) | ||
241 | } | ||
242 | |||
243 | pub fn op_kind(&self) -> Option<RangeOp> { | ||
244 | self.op_details().map(|t| t.2) | ||
245 | } | ||
246 | |||
247 | pub fn op_token(&self) -> Option<SyntaxToken> { | ||
248 | self.op_details().map(|t| t.1) | ||
249 | } | ||
250 | |||
251 | pub fn start(&self) -> Option<ast::Expr> { | ||
252 | let op_ix = self.op_details()?.0; | ||
253 | self.syntax() | ||
254 | .children_with_tokens() | ||
255 | .take(op_ix) | ||
256 | .find_map(|it| ast::Expr::cast(it.into_node()?)) | ||
257 | } | ||
258 | |||
259 | pub fn end(&self) -> Option<ast::Expr> { | ||
260 | let op_ix = self.op_details()?.0; | ||
261 | self.syntax() | ||
262 | .children_with_tokens() | ||
263 | .skip(op_ix + 1) | ||
264 | .find_map(|it| ast::Expr::cast(it.into_node()?)) | ||
265 | } | ||
266 | } | ||
267 | |||
268 | impl ast::IndexExpr { | ||
269 | pub fn base(&self) -> Option<ast::Expr> { | ||
270 | support::children(self.syntax()).next() | ||
271 | } | ||
272 | pub fn index(&self) -> Option<ast::Expr> { | ||
273 | support::children(self.syntax()).nth(1) | ||
274 | } | ||
275 | } | ||
276 | |||
277 | pub enum ArrayExprKind { | ||
278 | Repeat { initializer: Option<ast::Expr>, repeat: Option<ast::Expr> }, | ||
279 | ElementList(AstChildren<ast::Expr>), | ||
280 | } | ||
281 | |||
282 | impl ast::ArrayExpr { | ||
283 | pub fn kind(&self) -> ArrayExprKind { | ||
284 | if self.is_repeat() { | ||
285 | ArrayExprKind::Repeat { | ||
286 | initializer: support::children(self.syntax()).next(), | ||
287 | repeat: support::children(self.syntax()).nth(1), | ||
288 | } | ||
289 | } else { | ||
290 | ArrayExprKind::ElementList(support::children(self.syntax())) | ||
291 | } | ||
292 | } | ||
293 | |||
294 | fn is_repeat(&self) -> bool { | ||
295 | self.syntax().children_with_tokens().any(|it| it.kind() == T![;]) | ||
296 | } | ||
297 | } | ||
298 | |||
299 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
300 | pub enum LiteralKind { | ||
301 | String, | ||
302 | ByteString, | ||
303 | Char, | ||
304 | Byte, | ||
305 | IntNumber { suffix: Option<SmolStr> }, | ||
306 | FloatNumber { suffix: Option<SmolStr> }, | ||
307 | Bool(bool), | ||
308 | } | ||
309 | |||
310 | impl ast::Literal { | ||
311 | pub fn token(&self) -> SyntaxToken { | ||
312 | self.syntax() | ||
313 | .children_with_tokens() | ||
314 | .find(|e| e.kind() != ATTR && !e.kind().is_trivia()) | ||
315 | .and_then(|e| e.into_token()) | ||
316 | .unwrap() | ||
317 | } | ||
318 | |||
319 | fn find_suffix(text: &str, possible_suffixes: &[&str]) -> Option<SmolStr> { | ||
320 | possible_suffixes | ||
321 | .iter() | ||
322 | .find(|&suffix| text.ends_with(suffix)) | ||
323 | .map(|&suffix| SmolStr::new(suffix)) | ||
324 | } | ||
325 | |||
326 | pub fn kind(&self) -> LiteralKind { | ||
327 | const INT_SUFFIXES: [&str; 12] = [ | ||
328 | "u64", "u32", "u16", "u8", "usize", "isize", "i64", "i32", "i16", "i8", "u128", "i128", | ||
329 | ]; | ||
330 | const FLOAT_SUFFIXES: [&str; 2] = ["f32", "f64"]; | ||
331 | |||
332 | let token = self.token(); | ||
333 | |||
334 | match token.kind() { | ||
335 | INT_NUMBER => { | ||
336 | // FYI: there was a bug here previously, thus the if statement below is necessary. | ||
337 | // The lexer treats e.g. `1f64` as an integer literal. See | ||
338 | // https://github.com/rust-analyzer/rust-analyzer/issues/1592 | ||
339 | // and the comments on the linked PR. | ||
340 | |||
341 | let text = token.text(); | ||
342 | if let suffix @ Some(_) = Self::find_suffix(&text, &FLOAT_SUFFIXES) { | ||
343 | LiteralKind::FloatNumber { suffix } | ||
344 | } else { | ||
345 | LiteralKind::IntNumber { suffix: Self::find_suffix(&text, &INT_SUFFIXES) } | ||
346 | } | ||
347 | } | ||
348 | FLOAT_NUMBER => { | ||
349 | let text = token.text(); | ||
350 | LiteralKind::FloatNumber { suffix: Self::find_suffix(&text, &FLOAT_SUFFIXES) } | ||
351 | } | ||
352 | STRING | RAW_STRING => LiteralKind::String, | ||
353 | T![true] => LiteralKind::Bool(true), | ||
354 | T![false] => LiteralKind::Bool(false), | ||
355 | BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString, | ||
356 | CHAR => LiteralKind::Char, | ||
357 | BYTE => LiteralKind::Byte, | ||
358 | _ => unreachable!(), | ||
359 | } | ||
360 | } | ||
361 | } | ||
362 | |||
363 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
364 | pub enum Effect { | ||
365 | Async(SyntaxToken), | ||
366 | Unsafe(SyntaxToken), | ||
367 | Try(SyntaxToken), | ||
368 | // Very much not an effect, but we stuff it into this node anyway | ||
369 | Label(ast::Label), | ||
370 | } | ||
371 | |||
372 | impl ast::EffectExpr { | ||
373 | pub fn effect(&self) -> Effect { | ||
374 | if let Some(token) = self.async_token() { | ||
375 | return Effect::Async(token); | ||
376 | } | ||
377 | if let Some(token) = self.unsafe_token() { | ||
378 | return Effect::Unsafe(token); | ||
379 | } | ||
380 | if let Some(token) = self.try_token() { | ||
381 | return Effect::Try(token); | ||
382 | } | ||
383 | if let Some(label) = self.label() { | ||
384 | return Effect::Label(label); | ||
385 | } | ||
386 | unreachable!("ast::EffectExpr without Effect") | ||
387 | } | ||
388 | } | ||
389 | |||
390 | impl ast::BlockExpr { | ||
391 | /// false if the block is an intrinsic part of the syntax and can't be | ||
392 | /// replaced with arbitrary expression. | ||
393 | /// | ||
394 | /// ```not_rust | ||
395 | /// fn foo() { not_stand_alone } | ||
396 | /// const FOO: () = { stand_alone }; | ||
397 | /// ``` | ||
398 | pub fn is_standalone(&self) -> bool { | ||
399 | let parent = match self.syntax().parent() { | ||
400 | Some(it) => it, | ||
401 | None => return true, | ||
402 | }; | ||
403 | !matches!(parent.kind(), FN | IF_EXPR | WHILE_EXPR | LOOP_EXPR | EFFECT_EXPR) | ||
404 | } | ||
405 | } | ||
406 | |||
407 | #[test] | ||
408 | fn test_literal_with_attr() { | ||
409 | let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#); | ||
410 | let lit = parse.tree().syntax().descendants().find_map(ast::Literal::cast).unwrap(); | ||
411 | assert_eq!(lit.token().text(), r#""Hello""#); | ||
412 | } | ||
413 | |||
414 | impl ast::RecordExprField { | ||
415 | pub fn parent_record_lit(&self) -> ast::RecordExpr { | ||
416 | self.syntax().ancestors().find_map(ast::RecordExpr::cast).unwrap() | ||
417 | } | ||
418 | } | ||
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs deleted file mode 100644 index f5199e09f..000000000 --- a/crates/ra_syntax/src/ast/generated.rs +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | //! This file is actually hand-written, but the submodules are indeed generated. | ||
2 | |||
3 | #[rustfmt::skip] | ||
4 | pub(super) mod nodes; | ||
5 | #[rustfmt::skip] | ||
6 | pub(super) mod tokens; | ||
diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs deleted file mode 100644 index 4306efe13..000000000 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ /dev/null | |||
@@ -1,4071 +0,0 @@ | |||
1 | //! Generated file, do not edit by hand, see `xtask/src/codegen` | ||
2 | |||
3 | use crate::{ | ||
4 | ast::{self, support, AstChildren, AstNode}, | ||
5 | SyntaxKind::{self, *}, | ||
6 | SyntaxNode, SyntaxToken, T, | ||
7 | }; | ||
8 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
9 | pub struct SourceFile { | ||
10 | pub(crate) syntax: SyntaxNode, | ||
11 | } | ||
12 | impl ast::AttrsOwner for SourceFile {} | ||
13 | impl ast::ModuleItemOwner for SourceFile {} | ||
14 | impl SourceFile { | ||
15 | pub fn shebang_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![shebang]) } | ||
16 | } | ||
17 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
18 | pub struct Attr { | ||
19 | pub(crate) syntax: SyntaxNode, | ||
20 | } | ||
21 | impl Attr { | ||
22 | pub fn pound_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![#]) } | ||
23 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
24 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
25 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
26 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
27 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | ||
28 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
29 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
30 | } | ||
31 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
32 | pub struct Const { | ||
33 | pub(crate) syntax: SyntaxNode, | ||
34 | } | ||
35 | impl ast::AttrsOwner for Const {} | ||
36 | impl ast::NameOwner for Const {} | ||
37 | impl ast::VisibilityOwner for Const {} | ||
38 | impl Const { | ||
39 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
40 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
41 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | ||
42 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
43 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
44 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
45 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
46 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
47 | } | ||
48 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
49 | pub struct Enum { | ||
50 | pub(crate) syntax: SyntaxNode, | ||
51 | } | ||
52 | impl ast::AttrsOwner for Enum {} | ||
53 | impl ast::NameOwner for Enum {} | ||
54 | impl ast::VisibilityOwner for Enum {} | ||
55 | impl ast::GenericParamsOwner for Enum {} | ||
56 | impl Enum { | ||
57 | pub fn enum_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![enum]) } | ||
58 | pub fn variant_list(&self) -> Option<VariantList> { support::child(&self.syntax) } | ||
59 | } | ||
60 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
61 | pub struct ExternBlock { | ||
62 | pub(crate) syntax: SyntaxNode, | ||
63 | } | ||
64 | impl ast::AttrsOwner for ExternBlock {} | ||
65 | impl ExternBlock { | ||
66 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | ||
67 | pub fn extern_item_list(&self) -> Option<ExternItemList> { support::child(&self.syntax) } | ||
68 | } | ||
69 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
70 | pub struct ExternCrate { | ||
71 | pub(crate) syntax: SyntaxNode, | ||
72 | } | ||
73 | impl ast::AttrsOwner for ExternCrate {} | ||
74 | impl ast::VisibilityOwner for ExternCrate {} | ||
75 | impl ExternCrate { | ||
76 | pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } | ||
77 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | ||
78 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
79 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
80 | pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) } | ||
81 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
82 | } | ||
83 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
84 | pub struct Fn { | ||
85 | pub(crate) syntax: SyntaxNode, | ||
86 | } | ||
87 | impl ast::AttrsOwner for Fn {} | ||
88 | impl ast::NameOwner for Fn {} | ||
89 | impl ast::VisibilityOwner for Fn {} | ||
90 | impl ast::GenericParamsOwner for Fn {} | ||
91 | impl Fn { | ||
92 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
93 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | ||
94 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
95 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
96 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | ||
97 | pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) } | ||
98 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | ||
99 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | ||
100 | pub fn body(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | ||
101 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
102 | } | ||
103 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
104 | pub struct Impl { | ||
105 | pub(crate) syntax: SyntaxNode, | ||
106 | } | ||
107 | impl ast::AttrsOwner for Impl {} | ||
108 | impl ast::VisibilityOwner for Impl {} | ||
109 | impl ast::GenericParamsOwner for Impl {} | ||
110 | impl Impl { | ||
111 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
112 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
113 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | ||
114 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
115 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
116 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
117 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | ||
118 | pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) } | ||
119 | } | ||
120 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
121 | pub struct MacroCall { | ||
122 | pub(crate) syntax: SyntaxNode, | ||
123 | } | ||
124 | impl ast::AttrsOwner for MacroCall {} | ||
125 | impl ast::NameOwner for MacroCall {} | ||
126 | impl MacroCall { | ||
127 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
128 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
129 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
130 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
131 | } | ||
132 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
133 | pub struct Module { | ||
134 | pub(crate) syntax: SyntaxNode, | ||
135 | } | ||
136 | impl ast::AttrsOwner for Module {} | ||
137 | impl ast::NameOwner for Module {} | ||
138 | impl ast::VisibilityOwner for Module {} | ||
139 | impl Module { | ||
140 | pub fn mod_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mod]) } | ||
141 | pub fn item_list(&self) -> Option<ItemList> { support::child(&self.syntax) } | ||
142 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
143 | } | ||
144 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
145 | pub struct Static { | ||
146 | pub(crate) syntax: SyntaxNode, | ||
147 | } | ||
148 | impl ast::AttrsOwner for Static {} | ||
149 | impl ast::NameOwner for Static {} | ||
150 | impl ast::VisibilityOwner for Static {} | ||
151 | impl Static { | ||
152 | pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } | ||
153 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
154 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
155 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
156 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
157 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
158 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
159 | } | ||
160 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
161 | pub struct Struct { | ||
162 | pub(crate) syntax: SyntaxNode, | ||
163 | } | ||
164 | impl ast::AttrsOwner for Struct {} | ||
165 | impl ast::NameOwner for Struct {} | ||
166 | impl ast::VisibilityOwner for Struct {} | ||
167 | impl ast::GenericParamsOwner for Struct {} | ||
168 | impl Struct { | ||
169 | pub fn struct_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![struct]) } | ||
170 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
171 | pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) } | ||
172 | } | ||
173 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
174 | pub struct Trait { | ||
175 | pub(crate) syntax: SyntaxNode, | ||
176 | } | ||
177 | impl ast::AttrsOwner for Trait {} | ||
178 | impl ast::NameOwner for Trait {} | ||
179 | impl ast::VisibilityOwner for Trait {} | ||
180 | impl ast::GenericParamsOwner for Trait {} | ||
181 | impl ast::TypeBoundsOwner for Trait {} | ||
182 | impl Trait { | ||
183 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
184 | pub fn auto_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![auto]) } | ||
185 | pub fn trait_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![trait]) } | ||
186 | pub fn assoc_item_list(&self) -> Option<AssocItemList> { support::child(&self.syntax) } | ||
187 | } | ||
188 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
189 | pub struct TypeAlias { | ||
190 | pub(crate) syntax: SyntaxNode, | ||
191 | } | ||
192 | impl ast::AttrsOwner for TypeAlias {} | ||
193 | impl ast::NameOwner for TypeAlias {} | ||
194 | impl ast::VisibilityOwner for TypeAlias {} | ||
195 | impl ast::GenericParamsOwner for TypeAlias {} | ||
196 | impl ast::TypeBoundsOwner for TypeAlias {} | ||
197 | impl TypeAlias { | ||
198 | pub fn default_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![default]) } | ||
199 | pub fn type_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![type]) } | ||
200 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
201 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
202 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
203 | } | ||
204 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
205 | pub struct Union { | ||
206 | pub(crate) syntax: SyntaxNode, | ||
207 | } | ||
208 | impl ast::AttrsOwner for Union {} | ||
209 | impl ast::NameOwner for Union {} | ||
210 | impl ast::VisibilityOwner for Union {} | ||
211 | impl ast::GenericParamsOwner for Union {} | ||
212 | impl Union { | ||
213 | pub fn union_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![union]) } | ||
214 | pub fn record_field_list(&self) -> Option<RecordFieldList> { support::child(&self.syntax) } | ||
215 | } | ||
216 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
217 | pub struct Use { | ||
218 | pub(crate) syntax: SyntaxNode, | ||
219 | } | ||
220 | impl ast::AttrsOwner for Use {} | ||
221 | impl ast::VisibilityOwner for Use {} | ||
222 | impl Use { | ||
223 | pub fn use_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![use]) } | ||
224 | pub fn use_tree(&self) -> Option<UseTree> { support::child(&self.syntax) } | ||
225 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
226 | } | ||
227 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
228 | pub struct Visibility { | ||
229 | pub(crate) syntax: SyntaxNode, | ||
230 | } | ||
231 | impl Visibility { | ||
232 | pub fn pub_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![pub]) } | ||
233 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
234 | pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) } | ||
235 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
236 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | ||
237 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | ||
238 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
239 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
240 | } | ||
241 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
242 | pub struct Name { | ||
243 | pub(crate) syntax: SyntaxNode, | ||
244 | } | ||
245 | impl Name { | ||
246 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | ||
247 | } | ||
248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
249 | pub struct ItemList { | ||
250 | pub(crate) syntax: SyntaxNode, | ||
251 | } | ||
252 | impl ast::AttrsOwner for ItemList {} | ||
253 | impl ast::ModuleItemOwner for ItemList {} | ||
254 | impl ItemList { | ||
255 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
256 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
257 | } | ||
258 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
259 | pub struct NameRef { | ||
260 | pub(crate) syntax: SyntaxNode, | ||
261 | } | ||
262 | impl NameRef { | ||
263 | pub fn ident_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ident]) } | ||
264 | } | ||
265 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
266 | pub struct Rename { | ||
267 | pub(crate) syntax: SyntaxNode, | ||
268 | } | ||
269 | impl ast::NameOwner for Rename {} | ||
270 | impl Rename { | ||
271 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | ||
272 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | ||
273 | } | ||
274 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
275 | pub struct UseTree { | ||
276 | pub(crate) syntax: SyntaxNode, | ||
277 | } | ||
278 | impl UseTree { | ||
279 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
280 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
281 | pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } | ||
282 | pub fn use_tree_list(&self) -> Option<UseTreeList> { support::child(&self.syntax) } | ||
283 | pub fn rename(&self) -> Option<Rename> { support::child(&self.syntax) } | ||
284 | } | ||
285 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
286 | pub struct Path { | ||
287 | pub(crate) syntax: SyntaxNode, | ||
288 | } | ||
289 | impl Path { | ||
290 | pub fn qualifier(&self) -> Option<Path> { support::child(&self.syntax) } | ||
291 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
292 | pub fn segment(&self) -> Option<PathSegment> { support::child(&self.syntax) } | ||
293 | } | ||
294 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
295 | pub struct UseTreeList { | ||
296 | pub(crate) syntax: SyntaxNode, | ||
297 | } | ||
298 | impl UseTreeList { | ||
299 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
300 | pub fn use_trees(&self) -> AstChildren<UseTree> { support::children(&self.syntax) } | ||
301 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
302 | } | ||
303 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
304 | pub struct Abi { | ||
305 | pub(crate) syntax: SyntaxNode, | ||
306 | } | ||
307 | impl Abi { | ||
308 | pub fn extern_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![extern]) } | ||
309 | } | ||
310 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
311 | pub struct GenericParamList { | ||
312 | pub(crate) syntax: SyntaxNode, | ||
313 | } | ||
314 | impl GenericParamList { | ||
315 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | ||
316 | pub fn generic_params(&self) -> AstChildren<GenericParam> { support::children(&self.syntax) } | ||
317 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
318 | } | ||
319 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
320 | pub struct ParamList { | ||
321 | pub(crate) syntax: SyntaxNode, | ||
322 | } | ||
323 | impl ParamList { | ||
324 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
325 | pub fn self_param(&self) -> Option<SelfParam> { support::child(&self.syntax) } | ||
326 | pub fn comma_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![,]) } | ||
327 | pub fn params(&self) -> AstChildren<Param> { support::children(&self.syntax) } | ||
328 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
329 | } | ||
330 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
331 | pub struct RetType { | ||
332 | pub(crate) syntax: SyntaxNode, | ||
333 | } | ||
334 | impl RetType { | ||
335 | pub fn thin_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![->]) } | ||
336 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
337 | } | ||
338 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
339 | pub struct WhereClause { | ||
340 | pub(crate) syntax: SyntaxNode, | ||
341 | } | ||
342 | impl WhereClause { | ||
343 | pub fn where_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![where]) } | ||
344 | pub fn predicates(&self) -> AstChildren<WherePred> { support::children(&self.syntax) } | ||
345 | } | ||
346 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
347 | pub struct BlockExpr { | ||
348 | pub(crate) syntax: SyntaxNode, | ||
349 | } | ||
350 | impl ast::AttrsOwner for BlockExpr {} | ||
351 | impl ast::ModuleItemOwner for BlockExpr {} | ||
352 | impl BlockExpr { | ||
353 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } | ||
354 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
355 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | ||
356 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
357 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
358 | } | ||
359 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
360 | pub struct SelfParam { | ||
361 | pub(crate) syntax: SyntaxNode, | ||
362 | } | ||
363 | impl ast::AttrsOwner for SelfParam {} | ||
364 | impl SelfParam { | ||
365 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } | ||
366 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
367 | support::token(&self.syntax, T![lifetime]) | ||
368 | } | ||
369 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
370 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
371 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
372 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
373 | } | ||
374 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
375 | pub struct Param { | ||
376 | pub(crate) syntax: SyntaxNode, | ||
377 | } | ||
378 | impl ast::AttrsOwner for Param {} | ||
379 | impl Param { | ||
380 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
381 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
382 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
383 | pub fn dotdotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![...]) } | ||
384 | } | ||
385 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
386 | pub struct TypeBoundList { | ||
387 | pub(crate) syntax: SyntaxNode, | ||
388 | } | ||
389 | impl TypeBoundList { | ||
390 | pub fn bounds(&self) -> AstChildren<TypeBound> { support::children(&self.syntax) } | ||
391 | } | ||
392 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
393 | pub struct RecordFieldList { | ||
394 | pub(crate) syntax: SyntaxNode, | ||
395 | } | ||
396 | impl RecordFieldList { | ||
397 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
398 | pub fn fields(&self) -> AstChildren<RecordField> { support::children(&self.syntax) } | ||
399 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
400 | } | ||
401 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
402 | pub struct TupleFieldList { | ||
403 | pub(crate) syntax: SyntaxNode, | ||
404 | } | ||
405 | impl TupleFieldList { | ||
406 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
407 | pub fn fields(&self) -> AstChildren<TupleField> { support::children(&self.syntax) } | ||
408 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
409 | } | ||
410 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
411 | pub struct RecordField { | ||
412 | pub(crate) syntax: SyntaxNode, | ||
413 | } | ||
414 | impl ast::AttrsOwner for RecordField {} | ||
415 | impl ast::NameOwner for RecordField {} | ||
416 | impl ast::VisibilityOwner for RecordField {} | ||
417 | impl RecordField { | ||
418 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
419 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
420 | } | ||
421 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
422 | pub struct TupleField { | ||
423 | pub(crate) syntax: SyntaxNode, | ||
424 | } | ||
425 | impl ast::AttrsOwner for TupleField {} | ||
426 | impl ast::VisibilityOwner for TupleField {} | ||
427 | impl TupleField { | ||
428 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
429 | } | ||
430 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
431 | pub struct VariantList { | ||
432 | pub(crate) syntax: SyntaxNode, | ||
433 | } | ||
434 | impl VariantList { | ||
435 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
436 | pub fn variants(&self) -> AstChildren<Variant> { support::children(&self.syntax) } | ||
437 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
438 | } | ||
439 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
440 | pub struct Variant { | ||
441 | pub(crate) syntax: SyntaxNode, | ||
442 | } | ||
443 | impl ast::AttrsOwner for Variant {} | ||
444 | impl ast::NameOwner for Variant {} | ||
445 | impl ast::VisibilityOwner for Variant {} | ||
446 | impl Variant { | ||
447 | pub fn field_list(&self) -> Option<FieldList> { support::child(&self.syntax) } | ||
448 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
449 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
450 | } | ||
451 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
452 | pub struct AssocItemList { | ||
453 | pub(crate) syntax: SyntaxNode, | ||
454 | } | ||
455 | impl ast::AttrsOwner for AssocItemList {} | ||
456 | impl AssocItemList { | ||
457 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
458 | pub fn assoc_items(&self) -> AstChildren<AssocItem> { support::children(&self.syntax) } | ||
459 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
460 | } | ||
461 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
462 | pub struct ExternItemList { | ||
463 | pub(crate) syntax: SyntaxNode, | ||
464 | } | ||
465 | impl ast::AttrsOwner for ExternItemList {} | ||
466 | impl ExternItemList { | ||
467 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
468 | pub fn extern_items(&self) -> AstChildren<ExternItem> { support::children(&self.syntax) } | ||
469 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
470 | } | ||
471 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
472 | pub struct LifetimeParam { | ||
473 | pub(crate) syntax: SyntaxNode, | ||
474 | } | ||
475 | impl ast::AttrsOwner for LifetimeParam {} | ||
476 | impl LifetimeParam { | ||
477 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
478 | support::token(&self.syntax, T![lifetime]) | ||
479 | } | ||
480 | } | ||
481 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
482 | pub struct TypeParam { | ||
483 | pub(crate) syntax: SyntaxNode, | ||
484 | } | ||
485 | impl ast::AttrsOwner for TypeParam {} | ||
486 | impl ast::NameOwner for TypeParam {} | ||
487 | impl ast::TypeBoundsOwner for TypeParam {} | ||
488 | impl TypeParam { | ||
489 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
490 | pub fn default_type(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
491 | } | ||
492 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
493 | pub struct ConstParam { | ||
494 | pub(crate) syntax: SyntaxNode, | ||
495 | } | ||
496 | impl ast::AttrsOwner for ConstParam {} | ||
497 | impl ast::NameOwner for ConstParam {} | ||
498 | impl ConstParam { | ||
499 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
500 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
501 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
502 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
503 | pub fn default_val(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
504 | } | ||
505 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
506 | pub struct Literal { | ||
507 | pub(crate) syntax: SyntaxNode, | ||
508 | } | ||
509 | impl Literal {} | ||
510 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
511 | pub struct TokenTree { | ||
512 | pub(crate) syntax: SyntaxNode, | ||
513 | } | ||
514 | impl TokenTree { | ||
515 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
516 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
517 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
518 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
519 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
520 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
521 | } | ||
522 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
523 | pub struct ParenType { | ||
524 | pub(crate) syntax: SyntaxNode, | ||
525 | } | ||
526 | impl ParenType { | ||
527 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
528 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
529 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
530 | } | ||
531 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
532 | pub struct TupleType { | ||
533 | pub(crate) syntax: SyntaxNode, | ||
534 | } | ||
535 | impl TupleType { | ||
536 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
537 | pub fn fields(&self) -> AstChildren<TypeRef> { support::children(&self.syntax) } | ||
538 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
539 | } | ||
540 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
541 | pub struct NeverType { | ||
542 | pub(crate) syntax: SyntaxNode, | ||
543 | } | ||
544 | impl NeverType { | ||
545 | pub fn excl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![!]) } | ||
546 | } | ||
547 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
548 | pub struct PathType { | ||
549 | pub(crate) syntax: SyntaxNode, | ||
550 | } | ||
551 | impl PathType { | ||
552 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
553 | } | ||
554 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
555 | pub struct PointerType { | ||
556 | pub(crate) syntax: SyntaxNode, | ||
557 | } | ||
558 | impl PointerType { | ||
559 | pub fn star_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![*]) } | ||
560 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
561 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
562 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
563 | } | ||
564 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
565 | pub struct ArrayType { | ||
566 | pub(crate) syntax: SyntaxNode, | ||
567 | } | ||
568 | impl ArrayType { | ||
569 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
570 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
571 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
572 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
573 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
574 | } | ||
575 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
576 | pub struct SliceType { | ||
577 | pub(crate) syntax: SyntaxNode, | ||
578 | } | ||
579 | impl SliceType { | ||
580 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
581 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
582 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
583 | } | ||
584 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
585 | pub struct ReferenceType { | ||
586 | pub(crate) syntax: SyntaxNode, | ||
587 | } | ||
588 | impl ReferenceType { | ||
589 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } | ||
590 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
591 | support::token(&self.syntax, T![lifetime]) | ||
592 | } | ||
593 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
594 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
595 | } | ||
596 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
597 | pub struct PlaceholderType { | ||
598 | pub(crate) syntax: SyntaxNode, | ||
599 | } | ||
600 | impl PlaceholderType { | ||
601 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | ||
602 | } | ||
603 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
604 | pub struct FnPointerType { | ||
605 | pub(crate) syntax: SyntaxNode, | ||
606 | } | ||
607 | impl FnPointerType { | ||
608 | pub fn abi(&self) -> Option<Abi> { support::child(&self.syntax) } | ||
609 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
610 | pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) } | ||
611 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | ||
612 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | ||
613 | } | ||
614 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
615 | pub struct ForType { | ||
616 | pub(crate) syntax: SyntaxNode, | ||
617 | } | ||
618 | impl ForType { | ||
619 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | ||
620 | pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) } | ||
621 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
622 | } | ||
623 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
624 | pub struct ImplTraitType { | ||
625 | pub(crate) syntax: SyntaxNode, | ||
626 | } | ||
627 | impl ImplTraitType { | ||
628 | pub fn impl_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![impl]) } | ||
629 | pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) } | ||
630 | } | ||
631 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
632 | pub struct DynTraitType { | ||
633 | pub(crate) syntax: SyntaxNode, | ||
634 | } | ||
635 | impl DynTraitType { | ||
636 | pub fn dyn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![dyn]) } | ||
637 | pub fn type_bound_list(&self) -> Option<TypeBoundList> { support::child(&self.syntax) } | ||
638 | } | ||
639 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
640 | pub struct TupleExpr { | ||
641 | pub(crate) syntax: SyntaxNode, | ||
642 | } | ||
643 | impl ast::AttrsOwner for TupleExpr {} | ||
644 | impl TupleExpr { | ||
645 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
646 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | ||
647 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
648 | } | ||
649 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
650 | pub struct ArrayExpr { | ||
651 | pub(crate) syntax: SyntaxNode, | ||
652 | } | ||
653 | impl ast::AttrsOwner for ArrayExpr {} | ||
654 | impl ArrayExpr { | ||
655 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
656 | pub fn exprs(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | ||
657 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
658 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
659 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
660 | } | ||
661 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
662 | pub struct ParenExpr { | ||
663 | pub(crate) syntax: SyntaxNode, | ||
664 | } | ||
665 | impl ast::AttrsOwner for ParenExpr {} | ||
666 | impl ParenExpr { | ||
667 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
668 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
669 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
670 | } | ||
671 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
672 | pub struct PathExpr { | ||
673 | pub(crate) syntax: SyntaxNode, | ||
674 | } | ||
675 | impl PathExpr { | ||
676 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
677 | } | ||
678 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
679 | pub struct LambdaExpr { | ||
680 | pub(crate) syntax: SyntaxNode, | ||
681 | } | ||
682 | impl ast::AttrsOwner for LambdaExpr {} | ||
683 | impl LambdaExpr { | ||
684 | pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) } | ||
685 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | ||
686 | pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) } | ||
687 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | ||
688 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | ||
689 | pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
690 | } | ||
691 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
692 | pub struct IfExpr { | ||
693 | pub(crate) syntax: SyntaxNode, | ||
694 | } | ||
695 | impl ast::AttrsOwner for IfExpr {} | ||
696 | impl IfExpr { | ||
697 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | ||
698 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | ||
699 | } | ||
700 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
701 | pub struct Condition { | ||
702 | pub(crate) syntax: SyntaxNode, | ||
703 | } | ||
704 | impl Condition { | ||
705 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } | ||
706 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
707 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
708 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
709 | } | ||
710 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
711 | pub struct EffectExpr { | ||
712 | pub(crate) syntax: SyntaxNode, | ||
713 | } | ||
714 | impl ast::AttrsOwner for EffectExpr {} | ||
715 | impl EffectExpr { | ||
716 | pub fn label(&self) -> Option<Label> { support::child(&self.syntax) } | ||
717 | pub fn try_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![try]) } | ||
718 | pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) } | ||
719 | pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) } | ||
720 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | ||
721 | } | ||
722 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
723 | pub struct Label { | ||
724 | pub(crate) syntax: SyntaxNode, | ||
725 | } | ||
726 | impl Label { | ||
727 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
728 | support::token(&self.syntax, T![lifetime]) | ||
729 | } | ||
730 | } | ||
731 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
732 | pub struct LoopExpr { | ||
733 | pub(crate) syntax: SyntaxNode, | ||
734 | } | ||
735 | impl ast::AttrsOwner for LoopExpr {} | ||
736 | impl ast::LoopBodyOwner for LoopExpr {} | ||
737 | impl LoopExpr { | ||
738 | pub fn loop_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![loop]) } | ||
739 | } | ||
740 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
741 | pub struct ForExpr { | ||
742 | pub(crate) syntax: SyntaxNode, | ||
743 | } | ||
744 | impl ast::AttrsOwner for ForExpr {} | ||
745 | impl ast::LoopBodyOwner for ForExpr {} | ||
746 | impl ForExpr { | ||
747 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | ||
748 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
749 | pub fn in_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![in]) } | ||
750 | pub fn iterable(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
751 | } | ||
752 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
753 | pub struct WhileExpr { | ||
754 | pub(crate) syntax: SyntaxNode, | ||
755 | } | ||
756 | impl ast::AttrsOwner for WhileExpr {} | ||
757 | impl ast::LoopBodyOwner for WhileExpr {} | ||
758 | impl WhileExpr { | ||
759 | pub fn while_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![while]) } | ||
760 | pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } | ||
761 | } | ||
762 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
763 | pub struct ContinueExpr { | ||
764 | pub(crate) syntax: SyntaxNode, | ||
765 | } | ||
766 | impl ast::AttrsOwner for ContinueExpr {} | ||
767 | impl ContinueExpr { | ||
768 | pub fn continue_token(&self) -> Option<SyntaxToken> { | ||
769 | support::token(&self.syntax, T![continue]) | ||
770 | } | ||
771 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
772 | support::token(&self.syntax, T![lifetime]) | ||
773 | } | ||
774 | } | ||
775 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
776 | pub struct BreakExpr { | ||
777 | pub(crate) syntax: SyntaxNode, | ||
778 | } | ||
779 | impl ast::AttrsOwner for BreakExpr {} | ||
780 | impl BreakExpr { | ||
781 | pub fn break_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![break]) } | ||
782 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
783 | support::token(&self.syntax, T![lifetime]) | ||
784 | } | ||
785 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
786 | } | ||
787 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
788 | pub struct ReturnExpr { | ||
789 | pub(crate) syntax: SyntaxNode, | ||
790 | } | ||
791 | impl ast::AttrsOwner for ReturnExpr {} | ||
792 | impl ReturnExpr { | ||
793 | pub fn return_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![return]) } | ||
794 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
795 | } | ||
796 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
797 | pub struct CallExpr { | ||
798 | pub(crate) syntax: SyntaxNode, | ||
799 | } | ||
800 | impl ast::AttrsOwner for CallExpr {} | ||
801 | impl ast::ArgListOwner for CallExpr {} | ||
802 | impl CallExpr { | ||
803 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
804 | } | ||
805 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
806 | pub struct ArgList { | ||
807 | pub(crate) syntax: SyntaxNode, | ||
808 | } | ||
809 | impl ArgList { | ||
810 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
811 | pub fn args(&self) -> AstChildren<Expr> { support::children(&self.syntax) } | ||
812 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
813 | } | ||
814 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
815 | pub struct MethodCallExpr { | ||
816 | pub(crate) syntax: SyntaxNode, | ||
817 | } | ||
818 | impl ast::AttrsOwner for MethodCallExpr {} | ||
819 | impl ast::ArgListOwner for MethodCallExpr {} | ||
820 | impl MethodCallExpr { | ||
821 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
822 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | ||
823 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
824 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } | ||
825 | } | ||
826 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
827 | pub struct TypeArgList { | ||
828 | pub(crate) syntax: SyntaxNode, | ||
829 | } | ||
830 | impl TypeArgList { | ||
831 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
832 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | ||
833 | pub fn type_args(&self) -> AstChildren<TypeArg> { support::children(&self.syntax) } | ||
834 | pub fn lifetime_args(&self) -> AstChildren<LifetimeArg> { support::children(&self.syntax) } | ||
835 | pub fn assoc_type_args(&self) -> AstChildren<AssocTypeArg> { support::children(&self.syntax) } | ||
836 | pub fn const_args(&self) -> AstChildren<ConstArg> { support::children(&self.syntax) } | ||
837 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
838 | } | ||
839 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
840 | pub struct FieldExpr { | ||
841 | pub(crate) syntax: SyntaxNode, | ||
842 | } | ||
843 | impl ast::AttrsOwner for FieldExpr {} | ||
844 | impl FieldExpr { | ||
845 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
846 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | ||
847 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
848 | } | ||
849 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
850 | pub struct IndexExpr { | ||
851 | pub(crate) syntax: SyntaxNode, | ||
852 | } | ||
853 | impl ast::AttrsOwner for IndexExpr {} | ||
854 | impl IndexExpr { | ||
855 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
856 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
857 | } | ||
858 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
859 | pub struct AwaitExpr { | ||
860 | pub(crate) syntax: SyntaxNode, | ||
861 | } | ||
862 | impl ast::AttrsOwner for AwaitExpr {} | ||
863 | impl AwaitExpr { | ||
864 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
865 | pub fn dot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![.]) } | ||
866 | pub fn await_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![await]) } | ||
867 | } | ||
868 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
869 | pub struct TryExpr { | ||
870 | pub(crate) syntax: SyntaxNode, | ||
871 | } | ||
872 | impl ast::AttrsOwner for TryExpr {} | ||
873 | impl TryExpr { | ||
874 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
875 | pub fn question_mark_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![?]) } | ||
876 | } | ||
877 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
878 | pub struct CastExpr { | ||
879 | pub(crate) syntax: SyntaxNode, | ||
880 | } | ||
881 | impl ast::AttrsOwner for CastExpr {} | ||
882 | impl CastExpr { | ||
883 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
884 | pub fn as_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![as]) } | ||
885 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
886 | } | ||
887 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
888 | pub struct RefExpr { | ||
889 | pub(crate) syntax: SyntaxNode, | ||
890 | } | ||
891 | impl ast::AttrsOwner for RefExpr {} | ||
892 | impl RefExpr { | ||
893 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } | ||
894 | pub fn raw_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![raw]) } | ||
895 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
896 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
897 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
898 | } | ||
899 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
900 | pub struct PrefixExpr { | ||
901 | pub(crate) syntax: SyntaxNode, | ||
902 | } | ||
903 | impl ast::AttrsOwner for PrefixExpr {} | ||
904 | impl PrefixExpr { | ||
905 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
906 | } | ||
907 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
908 | pub struct BoxExpr { | ||
909 | pub(crate) syntax: SyntaxNode, | ||
910 | } | ||
911 | impl ast::AttrsOwner for BoxExpr {} | ||
912 | impl BoxExpr { | ||
913 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | ||
914 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
915 | } | ||
916 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
917 | pub struct RangeExpr { | ||
918 | pub(crate) syntax: SyntaxNode, | ||
919 | } | ||
920 | impl ast::AttrsOwner for RangeExpr {} | ||
921 | impl RangeExpr {} | ||
922 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
923 | pub struct BinExpr { | ||
924 | pub(crate) syntax: SyntaxNode, | ||
925 | } | ||
926 | impl ast::AttrsOwner for BinExpr {} | ||
927 | impl BinExpr {} | ||
928 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
929 | pub struct MatchExpr { | ||
930 | pub(crate) syntax: SyntaxNode, | ||
931 | } | ||
932 | impl ast::AttrsOwner for MatchExpr {} | ||
933 | impl MatchExpr { | ||
934 | pub fn match_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![match]) } | ||
935 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
936 | pub fn match_arm_list(&self) -> Option<MatchArmList> { support::child(&self.syntax) } | ||
937 | } | ||
938 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
939 | pub struct MatchArmList { | ||
940 | pub(crate) syntax: SyntaxNode, | ||
941 | } | ||
942 | impl MatchArmList { | ||
943 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
944 | pub fn arms(&self) -> AstChildren<MatchArm> { support::children(&self.syntax) } | ||
945 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
946 | } | ||
947 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
948 | pub struct MatchArm { | ||
949 | pub(crate) syntax: SyntaxNode, | ||
950 | } | ||
951 | impl ast::AttrsOwner for MatchArm {} | ||
952 | impl MatchArm { | ||
953 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
954 | pub fn guard(&self) -> Option<MatchGuard> { support::child(&self.syntax) } | ||
955 | pub fn fat_arrow_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=>]) } | ||
956 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
957 | } | ||
958 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
959 | pub struct MatchGuard { | ||
960 | pub(crate) syntax: SyntaxNode, | ||
961 | } | ||
962 | impl MatchGuard { | ||
963 | pub fn if_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![if]) } | ||
964 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
965 | } | ||
966 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
967 | pub struct RecordExpr { | ||
968 | pub(crate) syntax: SyntaxNode, | ||
969 | } | ||
970 | impl RecordExpr { | ||
971 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
972 | pub fn record_expr_field_list(&self) -> Option<RecordExprFieldList> { | ||
973 | support::child(&self.syntax) | ||
974 | } | ||
975 | } | ||
976 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
977 | pub struct RecordExprFieldList { | ||
978 | pub(crate) syntax: SyntaxNode, | ||
979 | } | ||
980 | impl RecordExprFieldList { | ||
981 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
982 | pub fn fields(&self) -> AstChildren<RecordExprField> { support::children(&self.syntax) } | ||
983 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | ||
984 | pub fn spread(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
985 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
986 | } | ||
987 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
988 | pub struct RecordExprField { | ||
989 | pub(crate) syntax: SyntaxNode, | ||
990 | } | ||
991 | impl ast::AttrsOwner for RecordExprField {} | ||
992 | impl RecordExprField { | ||
993 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
994 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
995 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
996 | } | ||
997 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
998 | pub struct OrPat { | ||
999 | pub(crate) syntax: SyntaxNode, | ||
1000 | } | ||
1001 | impl OrPat { | ||
1002 | pub fn pats(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | ||
1003 | } | ||
1004 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1005 | pub struct ParenPat { | ||
1006 | pub(crate) syntax: SyntaxNode, | ||
1007 | } | ||
1008 | impl ParenPat { | ||
1009 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
1010 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
1011 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
1012 | } | ||
1013 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1014 | pub struct RefPat { | ||
1015 | pub(crate) syntax: SyntaxNode, | ||
1016 | } | ||
1017 | impl RefPat { | ||
1018 | pub fn amp_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![&]) } | ||
1019 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
1020 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
1021 | } | ||
1022 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1023 | pub struct BoxPat { | ||
1024 | pub(crate) syntax: SyntaxNode, | ||
1025 | } | ||
1026 | impl BoxPat { | ||
1027 | pub fn box_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![box]) } | ||
1028 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1029 | } | ||
1030 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1031 | pub struct BindPat { | ||
1032 | pub(crate) syntax: SyntaxNode, | ||
1033 | } | ||
1034 | impl ast::AttrsOwner for BindPat {} | ||
1035 | impl ast::NameOwner for BindPat {} | ||
1036 | impl BindPat { | ||
1037 | pub fn ref_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![ref]) } | ||
1038 | pub fn mut_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![mut]) } | ||
1039 | pub fn at_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![@]) } | ||
1040 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
1041 | } | ||
1042 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1043 | pub struct PlaceholderPat { | ||
1044 | pub(crate) syntax: SyntaxNode, | ||
1045 | } | ||
1046 | impl PlaceholderPat { | ||
1047 | pub fn underscore_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![_]) } | ||
1048 | } | ||
1049 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1050 | pub struct DotDotPat { | ||
1051 | pub(crate) syntax: SyntaxNode, | ||
1052 | } | ||
1053 | impl DotDotPat { | ||
1054 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | ||
1055 | } | ||
1056 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1057 | pub struct PathPat { | ||
1058 | pub(crate) syntax: SyntaxNode, | ||
1059 | } | ||
1060 | impl PathPat { | ||
1061 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1062 | } | ||
1063 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1064 | pub struct SlicePat { | ||
1065 | pub(crate) syntax: SyntaxNode, | ||
1066 | } | ||
1067 | impl SlicePat { | ||
1068 | pub fn l_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['[']) } | ||
1069 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | ||
1070 | pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } | ||
1071 | } | ||
1072 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1073 | pub struct RangePat { | ||
1074 | pub(crate) syntax: SyntaxNode, | ||
1075 | } | ||
1076 | impl RangePat { | ||
1077 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | ||
1078 | pub fn dotdoteq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..=]) } | ||
1079 | } | ||
1080 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1081 | pub struct LiteralPat { | ||
1082 | pub(crate) syntax: SyntaxNode, | ||
1083 | } | ||
1084 | impl LiteralPat { | ||
1085 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | ||
1086 | } | ||
1087 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1088 | pub struct MacroPat { | ||
1089 | pub(crate) syntax: SyntaxNode, | ||
1090 | } | ||
1091 | impl MacroPat { | ||
1092 | pub fn macro_call(&self) -> Option<MacroCall> { support::child(&self.syntax) } | ||
1093 | } | ||
1094 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1095 | pub struct RecordPat { | ||
1096 | pub(crate) syntax: SyntaxNode, | ||
1097 | } | ||
1098 | impl RecordPat { | ||
1099 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1100 | pub fn record_field_pat_list(&self) -> Option<RecordFieldPatList> { | ||
1101 | support::child(&self.syntax) | ||
1102 | } | ||
1103 | } | ||
1104 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1105 | pub struct RecordFieldPatList { | ||
1106 | pub(crate) syntax: SyntaxNode, | ||
1107 | } | ||
1108 | impl RecordFieldPatList { | ||
1109 | pub fn l_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['{']) } | ||
1110 | pub fn record_field_pats(&self) -> AstChildren<RecordFieldPat> { | ||
1111 | support::children(&self.syntax) | ||
1112 | } | ||
1113 | pub fn bind_pats(&self) -> AstChildren<BindPat> { support::children(&self.syntax) } | ||
1114 | pub fn dotdot_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![..]) } | ||
1115 | pub fn r_curly_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['}']) } | ||
1116 | } | ||
1117 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1118 | pub struct RecordFieldPat { | ||
1119 | pub(crate) syntax: SyntaxNode, | ||
1120 | } | ||
1121 | impl ast::AttrsOwner for RecordFieldPat {} | ||
1122 | impl RecordFieldPat { | ||
1123 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
1124 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
1125 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
1126 | } | ||
1127 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1128 | pub struct TupleStructPat { | ||
1129 | pub(crate) syntax: SyntaxNode, | ||
1130 | } | ||
1131 | impl TupleStructPat { | ||
1132 | pub fn path(&self) -> Option<Path> { support::child(&self.syntax) } | ||
1133 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
1134 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | ||
1135 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
1136 | } | ||
1137 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1138 | pub struct TuplePat { | ||
1139 | pub(crate) syntax: SyntaxNode, | ||
1140 | } | ||
1141 | impl TuplePat { | ||
1142 | pub fn l_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T!['(']) } | ||
1143 | pub fn args(&self) -> AstChildren<Pat> { support::children(&self.syntax) } | ||
1144 | pub fn r_paren_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![')']) } | ||
1145 | } | ||
1146 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1147 | pub struct MacroDef { | ||
1148 | pub(crate) syntax: SyntaxNode, | ||
1149 | } | ||
1150 | impl ast::NameOwner for MacroDef {} | ||
1151 | impl MacroDef { | ||
1152 | pub fn token_tree(&self) -> Option<TokenTree> { support::child(&self.syntax) } | ||
1153 | } | ||
1154 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1155 | pub struct MacroItems { | ||
1156 | pub(crate) syntax: SyntaxNode, | ||
1157 | } | ||
1158 | impl ast::ModuleItemOwner for MacroItems {} | ||
1159 | impl MacroItems {} | ||
1160 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1161 | pub struct MacroStmts { | ||
1162 | pub(crate) syntax: SyntaxNode, | ||
1163 | } | ||
1164 | impl MacroStmts { | ||
1165 | pub fn statements(&self) -> AstChildren<Stmt> { support::children(&self.syntax) } | ||
1166 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
1167 | } | ||
1168 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1169 | pub struct TypeBound { | ||
1170 | pub(crate) syntax: SyntaxNode, | ||
1171 | } | ||
1172 | impl TypeBound { | ||
1173 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
1174 | support::token(&self.syntax, T![lifetime]) | ||
1175 | } | ||
1176 | pub fn const_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![const]) } | ||
1177 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
1178 | } | ||
1179 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1180 | pub struct WherePred { | ||
1181 | pub(crate) syntax: SyntaxNode, | ||
1182 | } | ||
1183 | impl ast::TypeBoundsOwner for WherePred {} | ||
1184 | impl WherePred { | ||
1185 | pub fn for_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![for]) } | ||
1186 | pub fn generic_param_list(&self) -> Option<GenericParamList> { support::child(&self.syntax) } | ||
1187 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
1188 | support::token(&self.syntax, T![lifetime]) | ||
1189 | } | ||
1190 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
1191 | } | ||
1192 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1193 | pub struct ExprStmt { | ||
1194 | pub(crate) syntax: SyntaxNode, | ||
1195 | } | ||
1196 | impl ast::AttrsOwner for ExprStmt {} | ||
1197 | impl ExprStmt { | ||
1198 | pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
1199 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
1200 | } | ||
1201 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1202 | pub struct LetStmt { | ||
1203 | pub(crate) syntax: SyntaxNode, | ||
1204 | } | ||
1205 | impl ast::AttrsOwner for LetStmt {} | ||
1206 | impl LetStmt { | ||
1207 | pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) } | ||
1208 | pub fn pat(&self) -> Option<Pat> { support::child(&self.syntax) } | ||
1209 | pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } | ||
1210 | pub fn ty(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
1211 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
1212 | pub fn initializer(&self) -> Option<Expr> { support::child(&self.syntax) } | ||
1213 | pub fn semicolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![;]) } | ||
1214 | } | ||
1215 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1216 | pub struct PathSegment { | ||
1217 | pub(crate) syntax: SyntaxNode, | ||
1218 | } | ||
1219 | impl PathSegment { | ||
1220 | pub fn coloncolon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![::]) } | ||
1221 | pub fn crate_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![crate]) } | ||
1222 | pub fn self_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![self]) } | ||
1223 | pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) } | ||
1224 | pub fn l_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![<]) } | ||
1225 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
1226 | pub fn type_arg_list(&self) -> Option<TypeArgList> { support::child(&self.syntax) } | ||
1227 | pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) } | ||
1228 | pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) } | ||
1229 | pub fn path_type(&self) -> Option<PathType> { support::child(&self.syntax) } | ||
1230 | pub fn r_angle_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![>]) } | ||
1231 | } | ||
1232 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1233 | pub struct TypeArg { | ||
1234 | pub(crate) syntax: SyntaxNode, | ||
1235 | } | ||
1236 | impl TypeArg { | ||
1237 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
1238 | } | ||
1239 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1240 | pub struct LifetimeArg { | ||
1241 | pub(crate) syntax: SyntaxNode, | ||
1242 | } | ||
1243 | impl LifetimeArg { | ||
1244 | pub fn lifetime_token(&self) -> Option<SyntaxToken> { | ||
1245 | support::token(&self.syntax, T![lifetime]) | ||
1246 | } | ||
1247 | } | ||
1248 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1249 | pub struct AssocTypeArg { | ||
1250 | pub(crate) syntax: SyntaxNode, | ||
1251 | } | ||
1252 | impl ast::TypeBoundsOwner for AssocTypeArg {} | ||
1253 | impl AssocTypeArg { | ||
1254 | pub fn name_ref(&self) -> Option<NameRef> { support::child(&self.syntax) } | ||
1255 | pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } | ||
1256 | pub fn type_ref(&self) -> Option<TypeRef> { support::child(&self.syntax) } | ||
1257 | } | ||
1258 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1259 | pub struct ConstArg { | ||
1260 | pub(crate) syntax: SyntaxNode, | ||
1261 | } | ||
1262 | impl ConstArg { | ||
1263 | pub fn literal(&self) -> Option<Literal> { support::child(&self.syntax) } | ||
1264 | pub fn block_expr(&self) -> Option<BlockExpr> { support::child(&self.syntax) } | ||
1265 | } | ||
1266 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1267 | pub enum Item { | ||
1268 | Const(Const), | ||
1269 | Enum(Enum), | ||
1270 | ExternBlock(ExternBlock), | ||
1271 | ExternCrate(ExternCrate), | ||
1272 | Fn(Fn), | ||
1273 | Impl(Impl), | ||
1274 | MacroCall(MacroCall), | ||
1275 | Module(Module), | ||
1276 | Static(Static), | ||
1277 | Struct(Struct), | ||
1278 | Trait(Trait), | ||
1279 | TypeAlias(TypeAlias), | ||
1280 | Union(Union), | ||
1281 | Use(Use), | ||
1282 | } | ||
1283 | impl ast::AttrsOwner for Item {} | ||
1284 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1285 | pub enum TypeRef { | ||
1286 | ParenType(ParenType), | ||
1287 | TupleType(TupleType), | ||
1288 | NeverType(NeverType), | ||
1289 | PathType(PathType), | ||
1290 | PointerType(PointerType), | ||
1291 | ArrayType(ArrayType), | ||
1292 | SliceType(SliceType), | ||
1293 | ReferenceType(ReferenceType), | ||
1294 | PlaceholderType(PlaceholderType), | ||
1295 | FnPointerType(FnPointerType), | ||
1296 | ForType(ForType), | ||
1297 | ImplTraitType(ImplTraitType), | ||
1298 | DynTraitType(DynTraitType), | ||
1299 | } | ||
1300 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1301 | pub enum Pat { | ||
1302 | OrPat(OrPat), | ||
1303 | ParenPat(ParenPat), | ||
1304 | RefPat(RefPat), | ||
1305 | BoxPat(BoxPat), | ||
1306 | BindPat(BindPat), | ||
1307 | PlaceholderPat(PlaceholderPat), | ||
1308 | DotDotPat(DotDotPat), | ||
1309 | PathPat(PathPat), | ||
1310 | RecordPat(RecordPat), | ||
1311 | TupleStructPat(TupleStructPat), | ||
1312 | TuplePat(TuplePat), | ||
1313 | SlicePat(SlicePat), | ||
1314 | RangePat(RangePat), | ||
1315 | LiteralPat(LiteralPat), | ||
1316 | MacroPat(MacroPat), | ||
1317 | } | ||
1318 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1319 | pub enum FieldList { | ||
1320 | RecordFieldList(RecordFieldList), | ||
1321 | TupleFieldList(TupleFieldList), | ||
1322 | } | ||
1323 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1324 | pub enum Expr { | ||
1325 | TupleExpr(TupleExpr), | ||
1326 | ArrayExpr(ArrayExpr), | ||
1327 | ParenExpr(ParenExpr), | ||
1328 | PathExpr(PathExpr), | ||
1329 | LambdaExpr(LambdaExpr), | ||
1330 | IfExpr(IfExpr), | ||
1331 | LoopExpr(LoopExpr), | ||
1332 | ForExpr(ForExpr), | ||
1333 | WhileExpr(WhileExpr), | ||
1334 | ContinueExpr(ContinueExpr), | ||
1335 | BreakExpr(BreakExpr), | ||
1336 | Label(Label), | ||
1337 | BlockExpr(BlockExpr), | ||
1338 | ReturnExpr(ReturnExpr), | ||
1339 | MatchExpr(MatchExpr), | ||
1340 | RecordExpr(RecordExpr), | ||
1341 | CallExpr(CallExpr), | ||
1342 | IndexExpr(IndexExpr), | ||
1343 | MethodCallExpr(MethodCallExpr), | ||
1344 | FieldExpr(FieldExpr), | ||
1345 | AwaitExpr(AwaitExpr), | ||
1346 | TryExpr(TryExpr), | ||
1347 | EffectExpr(EffectExpr), | ||
1348 | CastExpr(CastExpr), | ||
1349 | RefExpr(RefExpr), | ||
1350 | PrefixExpr(PrefixExpr), | ||
1351 | RangeExpr(RangeExpr), | ||
1352 | BinExpr(BinExpr), | ||
1353 | Literal(Literal), | ||
1354 | MacroCall(MacroCall), | ||
1355 | BoxExpr(BoxExpr), | ||
1356 | } | ||
1357 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1358 | pub enum AssocItem { | ||
1359 | Fn(Fn), | ||
1360 | TypeAlias(TypeAlias), | ||
1361 | Const(Const), | ||
1362 | MacroCall(MacroCall), | ||
1363 | } | ||
1364 | impl ast::AttrsOwner for AssocItem {} | ||
1365 | impl ast::NameOwner for AssocItem {} | ||
1366 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1367 | pub enum ExternItem { | ||
1368 | Fn(Fn), | ||
1369 | Static(Static), | ||
1370 | MacroCall(MacroCall), | ||
1371 | } | ||
1372 | impl ast::AttrsOwner for ExternItem {} | ||
1373 | impl ast::NameOwner for ExternItem {} | ||
1374 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1375 | pub enum GenericParam { | ||
1376 | LifetimeParam(LifetimeParam), | ||
1377 | TypeParam(TypeParam), | ||
1378 | ConstParam(ConstParam), | ||
1379 | } | ||
1380 | impl ast::AttrsOwner for GenericParam {} | ||
1381 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1382 | pub enum Stmt { | ||
1383 | LetStmt(LetStmt), | ||
1384 | ExprStmt(ExprStmt), | ||
1385 | } | ||
1386 | impl ast::AttrsOwner for Stmt {} | ||
1387 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
1388 | pub enum AdtDef { | ||
1389 | Struct(Struct), | ||
1390 | Enum(Enum), | ||
1391 | Union(Union), | ||
1392 | } | ||
1393 | impl ast::AttrsOwner for AdtDef {} | ||
1394 | impl ast::GenericParamsOwner for AdtDef {} | ||
1395 | impl ast::NameOwner for AdtDef {} | ||
1396 | impl ast::VisibilityOwner for AdtDef {} | ||
1397 | impl AstNode for SourceFile { | ||
1398 | fn can_cast(kind: SyntaxKind) -> bool { kind == SOURCE_FILE } | ||
1399 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1400 | if Self::can_cast(syntax.kind()) { | ||
1401 | Some(Self { syntax }) | ||
1402 | } else { | ||
1403 | None | ||
1404 | } | ||
1405 | } | ||
1406 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1407 | } | ||
1408 | impl AstNode for Attr { | ||
1409 | fn can_cast(kind: SyntaxKind) -> bool { kind == ATTR } | ||
1410 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1411 | if Self::can_cast(syntax.kind()) { | ||
1412 | Some(Self { syntax }) | ||
1413 | } else { | ||
1414 | None | ||
1415 | } | ||
1416 | } | ||
1417 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1418 | } | ||
1419 | impl AstNode for Const { | ||
1420 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST } | ||
1421 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1422 | if Self::can_cast(syntax.kind()) { | ||
1423 | Some(Self { syntax }) | ||
1424 | } else { | ||
1425 | None | ||
1426 | } | ||
1427 | } | ||
1428 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1429 | } | ||
1430 | impl AstNode for Enum { | ||
1431 | fn can_cast(kind: SyntaxKind) -> bool { kind == ENUM } | ||
1432 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1433 | if Self::can_cast(syntax.kind()) { | ||
1434 | Some(Self { syntax }) | ||
1435 | } else { | ||
1436 | None | ||
1437 | } | ||
1438 | } | ||
1439 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1440 | } | ||
1441 | impl AstNode for ExternBlock { | ||
1442 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_BLOCK } | ||
1443 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1444 | if Self::can_cast(syntax.kind()) { | ||
1445 | Some(Self { syntax }) | ||
1446 | } else { | ||
1447 | None | ||
1448 | } | ||
1449 | } | ||
1450 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1451 | } | ||
1452 | impl AstNode for ExternCrate { | ||
1453 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_CRATE } | ||
1454 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1455 | if Self::can_cast(syntax.kind()) { | ||
1456 | Some(Self { syntax }) | ||
1457 | } else { | ||
1458 | None | ||
1459 | } | ||
1460 | } | ||
1461 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1462 | } | ||
1463 | impl AstNode for Fn { | ||
1464 | fn can_cast(kind: SyntaxKind) -> bool { kind == FN } | ||
1465 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1466 | if Self::can_cast(syntax.kind()) { | ||
1467 | Some(Self { syntax }) | ||
1468 | } else { | ||
1469 | None | ||
1470 | } | ||
1471 | } | ||
1472 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1473 | } | ||
1474 | impl AstNode for Impl { | ||
1475 | fn can_cast(kind: SyntaxKind) -> bool { kind == IMPL } | ||
1476 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1477 | if Self::can_cast(syntax.kind()) { | ||
1478 | Some(Self { syntax }) | ||
1479 | } else { | ||
1480 | None | ||
1481 | } | ||
1482 | } | ||
1483 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1484 | } | ||
1485 | impl AstNode for MacroCall { | ||
1486 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_CALL } | ||
1487 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1488 | if Self::can_cast(syntax.kind()) { | ||
1489 | Some(Self { syntax }) | ||
1490 | } else { | ||
1491 | None | ||
1492 | } | ||
1493 | } | ||
1494 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1495 | } | ||
1496 | impl AstNode for Module { | ||
1497 | fn can_cast(kind: SyntaxKind) -> bool { kind == MODULE } | ||
1498 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1499 | if Self::can_cast(syntax.kind()) { | ||
1500 | Some(Self { syntax }) | ||
1501 | } else { | ||
1502 | None | ||
1503 | } | ||
1504 | } | ||
1505 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1506 | } | ||
1507 | impl AstNode for Static { | ||
1508 | fn can_cast(kind: SyntaxKind) -> bool { kind == STATIC } | ||
1509 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1510 | if Self::can_cast(syntax.kind()) { | ||
1511 | Some(Self { syntax }) | ||
1512 | } else { | ||
1513 | None | ||
1514 | } | ||
1515 | } | ||
1516 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1517 | } | ||
1518 | impl AstNode for Struct { | ||
1519 | fn can_cast(kind: SyntaxKind) -> bool { kind == STRUCT } | ||
1520 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1521 | if Self::can_cast(syntax.kind()) { | ||
1522 | Some(Self { syntax }) | ||
1523 | } else { | ||
1524 | None | ||
1525 | } | ||
1526 | } | ||
1527 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1528 | } | ||
1529 | impl AstNode for Trait { | ||
1530 | fn can_cast(kind: SyntaxKind) -> bool { kind == TRAIT } | ||
1531 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1532 | if Self::can_cast(syntax.kind()) { | ||
1533 | Some(Self { syntax }) | ||
1534 | } else { | ||
1535 | None | ||
1536 | } | ||
1537 | } | ||
1538 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1539 | } | ||
1540 | impl AstNode for TypeAlias { | ||
1541 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ALIAS } | ||
1542 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1543 | if Self::can_cast(syntax.kind()) { | ||
1544 | Some(Self { syntax }) | ||
1545 | } else { | ||
1546 | None | ||
1547 | } | ||
1548 | } | ||
1549 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1550 | } | ||
1551 | impl AstNode for Union { | ||
1552 | fn can_cast(kind: SyntaxKind) -> bool { kind == UNION } | ||
1553 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1554 | if Self::can_cast(syntax.kind()) { | ||
1555 | Some(Self { syntax }) | ||
1556 | } else { | ||
1557 | None | ||
1558 | } | ||
1559 | } | ||
1560 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1561 | } | ||
1562 | impl AstNode for Use { | ||
1563 | fn can_cast(kind: SyntaxKind) -> bool { kind == USE } | ||
1564 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1565 | if Self::can_cast(syntax.kind()) { | ||
1566 | Some(Self { syntax }) | ||
1567 | } else { | ||
1568 | None | ||
1569 | } | ||
1570 | } | ||
1571 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1572 | } | ||
1573 | impl AstNode for Visibility { | ||
1574 | fn can_cast(kind: SyntaxKind) -> bool { kind == VISIBILITY } | ||
1575 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1576 | if Self::can_cast(syntax.kind()) { | ||
1577 | Some(Self { syntax }) | ||
1578 | } else { | ||
1579 | None | ||
1580 | } | ||
1581 | } | ||
1582 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1583 | } | ||
1584 | impl AstNode for Name { | ||
1585 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME } | ||
1586 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1587 | if Self::can_cast(syntax.kind()) { | ||
1588 | Some(Self { syntax }) | ||
1589 | } else { | ||
1590 | None | ||
1591 | } | ||
1592 | } | ||
1593 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1594 | } | ||
1595 | impl AstNode for ItemList { | ||
1596 | fn can_cast(kind: SyntaxKind) -> bool { kind == ITEM_LIST } | ||
1597 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1598 | if Self::can_cast(syntax.kind()) { | ||
1599 | Some(Self { syntax }) | ||
1600 | } else { | ||
1601 | None | ||
1602 | } | ||
1603 | } | ||
1604 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1605 | } | ||
1606 | impl AstNode for NameRef { | ||
1607 | fn can_cast(kind: SyntaxKind) -> bool { kind == NAME_REF } | ||
1608 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1609 | if Self::can_cast(syntax.kind()) { | ||
1610 | Some(Self { syntax }) | ||
1611 | } else { | ||
1612 | None | ||
1613 | } | ||
1614 | } | ||
1615 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1616 | } | ||
1617 | impl AstNode for Rename { | ||
1618 | fn can_cast(kind: SyntaxKind) -> bool { kind == RENAME } | ||
1619 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1620 | if Self::can_cast(syntax.kind()) { | ||
1621 | Some(Self { syntax }) | ||
1622 | } else { | ||
1623 | None | ||
1624 | } | ||
1625 | } | ||
1626 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1627 | } | ||
1628 | impl AstNode for UseTree { | ||
1629 | fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE } | ||
1630 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1631 | if Self::can_cast(syntax.kind()) { | ||
1632 | Some(Self { syntax }) | ||
1633 | } else { | ||
1634 | None | ||
1635 | } | ||
1636 | } | ||
1637 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1638 | } | ||
1639 | impl AstNode for Path { | ||
1640 | fn can_cast(kind: SyntaxKind) -> bool { kind == PATH } | ||
1641 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1642 | if Self::can_cast(syntax.kind()) { | ||
1643 | Some(Self { syntax }) | ||
1644 | } else { | ||
1645 | None | ||
1646 | } | ||
1647 | } | ||
1648 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1649 | } | ||
1650 | impl AstNode for UseTreeList { | ||
1651 | fn can_cast(kind: SyntaxKind) -> bool { kind == USE_TREE_LIST } | ||
1652 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1653 | if Self::can_cast(syntax.kind()) { | ||
1654 | Some(Self { syntax }) | ||
1655 | } else { | ||
1656 | None | ||
1657 | } | ||
1658 | } | ||
1659 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1660 | } | ||
1661 | impl AstNode for Abi { | ||
1662 | fn can_cast(kind: SyntaxKind) -> bool { kind == ABI } | ||
1663 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1664 | if Self::can_cast(syntax.kind()) { | ||
1665 | Some(Self { syntax }) | ||
1666 | } else { | ||
1667 | None | ||
1668 | } | ||
1669 | } | ||
1670 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1671 | } | ||
1672 | impl AstNode for GenericParamList { | ||
1673 | fn can_cast(kind: SyntaxKind) -> bool { kind == GENERIC_PARAM_LIST } | ||
1674 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1675 | if Self::can_cast(syntax.kind()) { | ||
1676 | Some(Self { syntax }) | ||
1677 | } else { | ||
1678 | None | ||
1679 | } | ||
1680 | } | ||
1681 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1682 | } | ||
1683 | impl AstNode for ParamList { | ||
1684 | fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM_LIST } | ||
1685 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1686 | if Self::can_cast(syntax.kind()) { | ||
1687 | Some(Self { syntax }) | ||
1688 | } else { | ||
1689 | None | ||
1690 | } | ||
1691 | } | ||
1692 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1693 | } | ||
1694 | impl AstNode for RetType { | ||
1695 | fn can_cast(kind: SyntaxKind) -> bool { kind == RET_TYPE } | ||
1696 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1697 | if Self::can_cast(syntax.kind()) { | ||
1698 | Some(Self { syntax }) | ||
1699 | } else { | ||
1700 | None | ||
1701 | } | ||
1702 | } | ||
1703 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1704 | } | ||
1705 | impl AstNode for WhereClause { | ||
1706 | fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_CLAUSE } | ||
1707 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1708 | if Self::can_cast(syntax.kind()) { | ||
1709 | Some(Self { syntax }) | ||
1710 | } else { | ||
1711 | None | ||
1712 | } | ||
1713 | } | ||
1714 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1715 | } | ||
1716 | impl AstNode for BlockExpr { | ||
1717 | fn can_cast(kind: SyntaxKind) -> bool { kind == BLOCK_EXPR } | ||
1718 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1719 | if Self::can_cast(syntax.kind()) { | ||
1720 | Some(Self { syntax }) | ||
1721 | } else { | ||
1722 | None | ||
1723 | } | ||
1724 | } | ||
1725 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1726 | } | ||
1727 | impl AstNode for SelfParam { | ||
1728 | fn can_cast(kind: SyntaxKind) -> bool { kind == SELF_PARAM } | ||
1729 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1730 | if Self::can_cast(syntax.kind()) { | ||
1731 | Some(Self { syntax }) | ||
1732 | } else { | ||
1733 | None | ||
1734 | } | ||
1735 | } | ||
1736 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1737 | } | ||
1738 | impl AstNode for Param { | ||
1739 | fn can_cast(kind: SyntaxKind) -> bool { kind == PARAM } | ||
1740 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1741 | if Self::can_cast(syntax.kind()) { | ||
1742 | Some(Self { syntax }) | ||
1743 | } else { | ||
1744 | None | ||
1745 | } | ||
1746 | } | ||
1747 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1748 | } | ||
1749 | impl AstNode for TypeBoundList { | ||
1750 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND_LIST } | ||
1751 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1752 | if Self::can_cast(syntax.kind()) { | ||
1753 | Some(Self { syntax }) | ||
1754 | } else { | ||
1755 | None | ||
1756 | } | ||
1757 | } | ||
1758 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1759 | } | ||
1760 | impl AstNode for RecordFieldList { | ||
1761 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_LIST } | ||
1762 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1763 | if Self::can_cast(syntax.kind()) { | ||
1764 | Some(Self { syntax }) | ||
1765 | } else { | ||
1766 | None | ||
1767 | } | ||
1768 | } | ||
1769 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1770 | } | ||
1771 | impl AstNode for TupleFieldList { | ||
1772 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD_LIST } | ||
1773 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1774 | if Self::can_cast(syntax.kind()) { | ||
1775 | Some(Self { syntax }) | ||
1776 | } else { | ||
1777 | None | ||
1778 | } | ||
1779 | } | ||
1780 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1781 | } | ||
1782 | impl AstNode for RecordField { | ||
1783 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD } | ||
1784 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1785 | if Self::can_cast(syntax.kind()) { | ||
1786 | Some(Self { syntax }) | ||
1787 | } else { | ||
1788 | None | ||
1789 | } | ||
1790 | } | ||
1791 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1792 | } | ||
1793 | impl AstNode for TupleField { | ||
1794 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_FIELD } | ||
1795 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1796 | if Self::can_cast(syntax.kind()) { | ||
1797 | Some(Self { syntax }) | ||
1798 | } else { | ||
1799 | None | ||
1800 | } | ||
1801 | } | ||
1802 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1803 | } | ||
1804 | impl AstNode for VariantList { | ||
1805 | fn can_cast(kind: SyntaxKind) -> bool { kind == VARIANT_LIST } | ||
1806 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1807 | if Self::can_cast(syntax.kind()) { | ||
1808 | Some(Self { syntax }) | ||
1809 | } else { | ||
1810 | None | ||
1811 | } | ||
1812 | } | ||
1813 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1814 | } | ||
1815 | impl AstNode for Variant { | ||
1816 | fn can_cast(kind: SyntaxKind) -> bool { kind == VARIANT } | ||
1817 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1818 | if Self::can_cast(syntax.kind()) { | ||
1819 | Some(Self { syntax }) | ||
1820 | } else { | ||
1821 | None | ||
1822 | } | ||
1823 | } | ||
1824 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1825 | } | ||
1826 | impl AstNode for AssocItemList { | ||
1827 | fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_ITEM_LIST } | ||
1828 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1829 | if Self::can_cast(syntax.kind()) { | ||
1830 | Some(Self { syntax }) | ||
1831 | } else { | ||
1832 | None | ||
1833 | } | ||
1834 | } | ||
1835 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1836 | } | ||
1837 | impl AstNode for ExternItemList { | ||
1838 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXTERN_ITEM_LIST } | ||
1839 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1840 | if Self::can_cast(syntax.kind()) { | ||
1841 | Some(Self { syntax }) | ||
1842 | } else { | ||
1843 | None | ||
1844 | } | ||
1845 | } | ||
1846 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1847 | } | ||
1848 | impl AstNode for LifetimeParam { | ||
1849 | fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_PARAM } | ||
1850 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1851 | if Self::can_cast(syntax.kind()) { | ||
1852 | Some(Self { syntax }) | ||
1853 | } else { | ||
1854 | None | ||
1855 | } | ||
1856 | } | ||
1857 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1858 | } | ||
1859 | impl AstNode for TypeParam { | ||
1860 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_PARAM } | ||
1861 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1862 | if Self::can_cast(syntax.kind()) { | ||
1863 | Some(Self { syntax }) | ||
1864 | } else { | ||
1865 | None | ||
1866 | } | ||
1867 | } | ||
1868 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1869 | } | ||
1870 | impl AstNode for ConstParam { | ||
1871 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_PARAM } | ||
1872 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1873 | if Self::can_cast(syntax.kind()) { | ||
1874 | Some(Self { syntax }) | ||
1875 | } else { | ||
1876 | None | ||
1877 | } | ||
1878 | } | ||
1879 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1880 | } | ||
1881 | impl AstNode for Literal { | ||
1882 | fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL } | ||
1883 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1884 | if Self::can_cast(syntax.kind()) { | ||
1885 | Some(Self { syntax }) | ||
1886 | } else { | ||
1887 | None | ||
1888 | } | ||
1889 | } | ||
1890 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1891 | } | ||
1892 | impl AstNode for TokenTree { | ||
1893 | fn can_cast(kind: SyntaxKind) -> bool { kind == TOKEN_TREE } | ||
1894 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1895 | if Self::can_cast(syntax.kind()) { | ||
1896 | Some(Self { syntax }) | ||
1897 | } else { | ||
1898 | None | ||
1899 | } | ||
1900 | } | ||
1901 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1902 | } | ||
1903 | impl AstNode for ParenType { | ||
1904 | fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_TYPE } | ||
1905 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1906 | if Self::can_cast(syntax.kind()) { | ||
1907 | Some(Self { syntax }) | ||
1908 | } else { | ||
1909 | None | ||
1910 | } | ||
1911 | } | ||
1912 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1913 | } | ||
1914 | impl AstNode for TupleType { | ||
1915 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_TYPE } | ||
1916 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1917 | if Self::can_cast(syntax.kind()) { | ||
1918 | Some(Self { syntax }) | ||
1919 | } else { | ||
1920 | None | ||
1921 | } | ||
1922 | } | ||
1923 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1924 | } | ||
1925 | impl AstNode for NeverType { | ||
1926 | fn can_cast(kind: SyntaxKind) -> bool { kind == NEVER_TYPE } | ||
1927 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1928 | if Self::can_cast(syntax.kind()) { | ||
1929 | Some(Self { syntax }) | ||
1930 | } else { | ||
1931 | None | ||
1932 | } | ||
1933 | } | ||
1934 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1935 | } | ||
1936 | impl AstNode for PathType { | ||
1937 | fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_TYPE } | ||
1938 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1939 | if Self::can_cast(syntax.kind()) { | ||
1940 | Some(Self { syntax }) | ||
1941 | } else { | ||
1942 | None | ||
1943 | } | ||
1944 | } | ||
1945 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1946 | } | ||
1947 | impl AstNode for PointerType { | ||
1948 | fn can_cast(kind: SyntaxKind) -> bool { kind == POINTER_TYPE } | ||
1949 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1950 | if Self::can_cast(syntax.kind()) { | ||
1951 | Some(Self { syntax }) | ||
1952 | } else { | ||
1953 | None | ||
1954 | } | ||
1955 | } | ||
1956 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1957 | } | ||
1958 | impl AstNode for ArrayType { | ||
1959 | fn can_cast(kind: SyntaxKind) -> bool { kind == ARRAY_TYPE } | ||
1960 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1961 | if Self::can_cast(syntax.kind()) { | ||
1962 | Some(Self { syntax }) | ||
1963 | } else { | ||
1964 | None | ||
1965 | } | ||
1966 | } | ||
1967 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1968 | } | ||
1969 | impl AstNode for SliceType { | ||
1970 | fn can_cast(kind: SyntaxKind) -> bool { kind == SLICE_TYPE } | ||
1971 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1972 | if Self::can_cast(syntax.kind()) { | ||
1973 | Some(Self { syntax }) | ||
1974 | } else { | ||
1975 | None | ||
1976 | } | ||
1977 | } | ||
1978 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1979 | } | ||
1980 | impl AstNode for ReferenceType { | ||
1981 | fn can_cast(kind: SyntaxKind) -> bool { kind == REFERENCE_TYPE } | ||
1982 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1983 | if Self::can_cast(syntax.kind()) { | ||
1984 | Some(Self { syntax }) | ||
1985 | } else { | ||
1986 | None | ||
1987 | } | ||
1988 | } | ||
1989 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
1990 | } | ||
1991 | impl AstNode for PlaceholderType { | ||
1992 | fn can_cast(kind: SyntaxKind) -> bool { kind == PLACEHOLDER_TYPE } | ||
1993 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
1994 | if Self::can_cast(syntax.kind()) { | ||
1995 | Some(Self { syntax }) | ||
1996 | } else { | ||
1997 | None | ||
1998 | } | ||
1999 | } | ||
2000 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2001 | } | ||
2002 | impl AstNode for FnPointerType { | ||
2003 | fn can_cast(kind: SyntaxKind) -> bool { kind == FN_POINTER_TYPE } | ||
2004 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2005 | if Self::can_cast(syntax.kind()) { | ||
2006 | Some(Self { syntax }) | ||
2007 | } else { | ||
2008 | None | ||
2009 | } | ||
2010 | } | ||
2011 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2012 | } | ||
2013 | impl AstNode for ForType { | ||
2014 | fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_TYPE } | ||
2015 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2016 | if Self::can_cast(syntax.kind()) { | ||
2017 | Some(Self { syntax }) | ||
2018 | } else { | ||
2019 | None | ||
2020 | } | ||
2021 | } | ||
2022 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2023 | } | ||
2024 | impl AstNode for ImplTraitType { | ||
2025 | fn can_cast(kind: SyntaxKind) -> bool { kind == IMPL_TRAIT_TYPE } | ||
2026 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2027 | if Self::can_cast(syntax.kind()) { | ||
2028 | Some(Self { syntax }) | ||
2029 | } else { | ||
2030 | None | ||
2031 | } | ||
2032 | } | ||
2033 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2034 | } | ||
2035 | impl AstNode for DynTraitType { | ||
2036 | fn can_cast(kind: SyntaxKind) -> bool { kind == DYN_TRAIT_TYPE } | ||
2037 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2038 | if Self::can_cast(syntax.kind()) { | ||
2039 | Some(Self { syntax }) | ||
2040 | } else { | ||
2041 | None | ||
2042 | } | ||
2043 | } | ||
2044 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2045 | } | ||
2046 | impl AstNode for TupleExpr { | ||
2047 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_EXPR } | ||
2048 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2049 | if Self::can_cast(syntax.kind()) { | ||
2050 | Some(Self { syntax }) | ||
2051 | } else { | ||
2052 | None | ||
2053 | } | ||
2054 | } | ||
2055 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2056 | } | ||
2057 | impl AstNode for ArrayExpr { | ||
2058 | fn can_cast(kind: SyntaxKind) -> bool { kind == ARRAY_EXPR } | ||
2059 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2060 | if Self::can_cast(syntax.kind()) { | ||
2061 | Some(Self { syntax }) | ||
2062 | } else { | ||
2063 | None | ||
2064 | } | ||
2065 | } | ||
2066 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2067 | } | ||
2068 | impl AstNode for ParenExpr { | ||
2069 | fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_EXPR } | ||
2070 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2071 | if Self::can_cast(syntax.kind()) { | ||
2072 | Some(Self { syntax }) | ||
2073 | } else { | ||
2074 | None | ||
2075 | } | ||
2076 | } | ||
2077 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2078 | } | ||
2079 | impl AstNode for PathExpr { | ||
2080 | fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_EXPR } | ||
2081 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2082 | if Self::can_cast(syntax.kind()) { | ||
2083 | Some(Self { syntax }) | ||
2084 | } else { | ||
2085 | None | ||
2086 | } | ||
2087 | } | ||
2088 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2089 | } | ||
2090 | impl AstNode for LambdaExpr { | ||
2091 | fn can_cast(kind: SyntaxKind) -> bool { kind == LAMBDA_EXPR } | ||
2092 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2093 | if Self::can_cast(syntax.kind()) { | ||
2094 | Some(Self { syntax }) | ||
2095 | } else { | ||
2096 | None | ||
2097 | } | ||
2098 | } | ||
2099 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2100 | } | ||
2101 | impl AstNode for IfExpr { | ||
2102 | fn can_cast(kind: SyntaxKind) -> bool { kind == IF_EXPR } | ||
2103 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2104 | if Self::can_cast(syntax.kind()) { | ||
2105 | Some(Self { syntax }) | ||
2106 | } else { | ||
2107 | None | ||
2108 | } | ||
2109 | } | ||
2110 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2111 | } | ||
2112 | impl AstNode for Condition { | ||
2113 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONDITION } | ||
2114 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2115 | if Self::can_cast(syntax.kind()) { | ||
2116 | Some(Self { syntax }) | ||
2117 | } else { | ||
2118 | None | ||
2119 | } | ||
2120 | } | ||
2121 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2122 | } | ||
2123 | impl AstNode for EffectExpr { | ||
2124 | fn can_cast(kind: SyntaxKind) -> bool { kind == EFFECT_EXPR } | ||
2125 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2126 | if Self::can_cast(syntax.kind()) { | ||
2127 | Some(Self { syntax }) | ||
2128 | } else { | ||
2129 | None | ||
2130 | } | ||
2131 | } | ||
2132 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2133 | } | ||
2134 | impl AstNode for Label { | ||
2135 | fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL } | ||
2136 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2137 | if Self::can_cast(syntax.kind()) { | ||
2138 | Some(Self { syntax }) | ||
2139 | } else { | ||
2140 | None | ||
2141 | } | ||
2142 | } | ||
2143 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2144 | } | ||
2145 | impl AstNode for LoopExpr { | ||
2146 | fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } | ||
2147 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2148 | if Self::can_cast(syntax.kind()) { | ||
2149 | Some(Self { syntax }) | ||
2150 | } else { | ||
2151 | None | ||
2152 | } | ||
2153 | } | ||
2154 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2155 | } | ||
2156 | impl AstNode for ForExpr { | ||
2157 | fn can_cast(kind: SyntaxKind) -> bool { kind == FOR_EXPR } | ||
2158 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2159 | if Self::can_cast(syntax.kind()) { | ||
2160 | Some(Self { syntax }) | ||
2161 | } else { | ||
2162 | None | ||
2163 | } | ||
2164 | } | ||
2165 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2166 | } | ||
2167 | impl AstNode for WhileExpr { | ||
2168 | fn can_cast(kind: SyntaxKind) -> bool { kind == WHILE_EXPR } | ||
2169 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2170 | if Self::can_cast(syntax.kind()) { | ||
2171 | Some(Self { syntax }) | ||
2172 | } else { | ||
2173 | None | ||
2174 | } | ||
2175 | } | ||
2176 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2177 | } | ||
2178 | impl AstNode for ContinueExpr { | ||
2179 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONTINUE_EXPR } | ||
2180 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2181 | if Self::can_cast(syntax.kind()) { | ||
2182 | Some(Self { syntax }) | ||
2183 | } else { | ||
2184 | None | ||
2185 | } | ||
2186 | } | ||
2187 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2188 | } | ||
2189 | impl AstNode for BreakExpr { | ||
2190 | fn can_cast(kind: SyntaxKind) -> bool { kind == BREAK_EXPR } | ||
2191 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2192 | if Self::can_cast(syntax.kind()) { | ||
2193 | Some(Self { syntax }) | ||
2194 | } else { | ||
2195 | None | ||
2196 | } | ||
2197 | } | ||
2198 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2199 | } | ||
2200 | impl AstNode for ReturnExpr { | ||
2201 | fn can_cast(kind: SyntaxKind) -> bool { kind == RETURN_EXPR } | ||
2202 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2203 | if Self::can_cast(syntax.kind()) { | ||
2204 | Some(Self { syntax }) | ||
2205 | } else { | ||
2206 | None | ||
2207 | } | ||
2208 | } | ||
2209 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2210 | } | ||
2211 | impl AstNode for CallExpr { | ||
2212 | fn can_cast(kind: SyntaxKind) -> bool { kind == CALL_EXPR } | ||
2213 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2214 | if Self::can_cast(syntax.kind()) { | ||
2215 | Some(Self { syntax }) | ||
2216 | } else { | ||
2217 | None | ||
2218 | } | ||
2219 | } | ||
2220 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2221 | } | ||
2222 | impl AstNode for ArgList { | ||
2223 | fn can_cast(kind: SyntaxKind) -> bool { kind == ARG_LIST } | ||
2224 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2225 | if Self::can_cast(syntax.kind()) { | ||
2226 | Some(Self { syntax }) | ||
2227 | } else { | ||
2228 | None | ||
2229 | } | ||
2230 | } | ||
2231 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2232 | } | ||
2233 | impl AstNode for MethodCallExpr { | ||
2234 | fn can_cast(kind: SyntaxKind) -> bool { kind == METHOD_CALL_EXPR } | ||
2235 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2236 | if Self::can_cast(syntax.kind()) { | ||
2237 | Some(Self { syntax }) | ||
2238 | } else { | ||
2239 | None | ||
2240 | } | ||
2241 | } | ||
2242 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2243 | } | ||
2244 | impl AstNode for TypeArgList { | ||
2245 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG_LIST } | ||
2246 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2247 | if Self::can_cast(syntax.kind()) { | ||
2248 | Some(Self { syntax }) | ||
2249 | } else { | ||
2250 | None | ||
2251 | } | ||
2252 | } | ||
2253 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2254 | } | ||
2255 | impl AstNode for FieldExpr { | ||
2256 | fn can_cast(kind: SyntaxKind) -> bool { kind == FIELD_EXPR } | ||
2257 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2258 | if Self::can_cast(syntax.kind()) { | ||
2259 | Some(Self { syntax }) | ||
2260 | } else { | ||
2261 | None | ||
2262 | } | ||
2263 | } | ||
2264 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2265 | } | ||
2266 | impl AstNode for IndexExpr { | ||
2267 | fn can_cast(kind: SyntaxKind) -> bool { kind == INDEX_EXPR } | ||
2268 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2269 | if Self::can_cast(syntax.kind()) { | ||
2270 | Some(Self { syntax }) | ||
2271 | } else { | ||
2272 | None | ||
2273 | } | ||
2274 | } | ||
2275 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2276 | } | ||
2277 | impl AstNode for AwaitExpr { | ||
2278 | fn can_cast(kind: SyntaxKind) -> bool { kind == AWAIT_EXPR } | ||
2279 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2280 | if Self::can_cast(syntax.kind()) { | ||
2281 | Some(Self { syntax }) | ||
2282 | } else { | ||
2283 | None | ||
2284 | } | ||
2285 | } | ||
2286 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2287 | } | ||
2288 | impl AstNode for TryExpr { | ||
2289 | fn can_cast(kind: SyntaxKind) -> bool { kind == TRY_EXPR } | ||
2290 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2291 | if Self::can_cast(syntax.kind()) { | ||
2292 | Some(Self { syntax }) | ||
2293 | } else { | ||
2294 | None | ||
2295 | } | ||
2296 | } | ||
2297 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2298 | } | ||
2299 | impl AstNode for CastExpr { | ||
2300 | fn can_cast(kind: SyntaxKind) -> bool { kind == CAST_EXPR } | ||
2301 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2302 | if Self::can_cast(syntax.kind()) { | ||
2303 | Some(Self { syntax }) | ||
2304 | } else { | ||
2305 | None | ||
2306 | } | ||
2307 | } | ||
2308 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2309 | } | ||
2310 | impl AstNode for RefExpr { | ||
2311 | fn can_cast(kind: SyntaxKind) -> bool { kind == REF_EXPR } | ||
2312 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2313 | if Self::can_cast(syntax.kind()) { | ||
2314 | Some(Self { syntax }) | ||
2315 | } else { | ||
2316 | None | ||
2317 | } | ||
2318 | } | ||
2319 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2320 | } | ||
2321 | impl AstNode for PrefixExpr { | ||
2322 | fn can_cast(kind: SyntaxKind) -> bool { kind == PREFIX_EXPR } | ||
2323 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2324 | if Self::can_cast(syntax.kind()) { | ||
2325 | Some(Self { syntax }) | ||
2326 | } else { | ||
2327 | None | ||
2328 | } | ||
2329 | } | ||
2330 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2331 | } | ||
2332 | impl AstNode for BoxExpr { | ||
2333 | fn can_cast(kind: SyntaxKind) -> bool { kind == BOX_EXPR } | ||
2334 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2335 | if Self::can_cast(syntax.kind()) { | ||
2336 | Some(Self { syntax }) | ||
2337 | } else { | ||
2338 | None | ||
2339 | } | ||
2340 | } | ||
2341 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2342 | } | ||
2343 | impl AstNode for RangeExpr { | ||
2344 | fn can_cast(kind: SyntaxKind) -> bool { kind == RANGE_EXPR } | ||
2345 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2346 | if Self::can_cast(syntax.kind()) { | ||
2347 | Some(Self { syntax }) | ||
2348 | } else { | ||
2349 | None | ||
2350 | } | ||
2351 | } | ||
2352 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2353 | } | ||
2354 | impl AstNode for BinExpr { | ||
2355 | fn can_cast(kind: SyntaxKind) -> bool { kind == BIN_EXPR } | ||
2356 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2357 | if Self::can_cast(syntax.kind()) { | ||
2358 | Some(Self { syntax }) | ||
2359 | } else { | ||
2360 | None | ||
2361 | } | ||
2362 | } | ||
2363 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2364 | } | ||
2365 | impl AstNode for MatchExpr { | ||
2366 | fn can_cast(kind: SyntaxKind) -> bool { kind == MATCH_EXPR } | ||
2367 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2368 | if Self::can_cast(syntax.kind()) { | ||
2369 | Some(Self { syntax }) | ||
2370 | } else { | ||
2371 | None | ||
2372 | } | ||
2373 | } | ||
2374 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2375 | } | ||
2376 | impl AstNode for MatchArmList { | ||
2377 | fn can_cast(kind: SyntaxKind) -> bool { kind == MATCH_ARM_LIST } | ||
2378 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2379 | if Self::can_cast(syntax.kind()) { | ||
2380 | Some(Self { syntax }) | ||
2381 | } else { | ||
2382 | None | ||
2383 | } | ||
2384 | } | ||
2385 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2386 | } | ||
2387 | impl AstNode for MatchArm { | ||
2388 | fn can_cast(kind: SyntaxKind) -> bool { kind == MATCH_ARM } | ||
2389 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2390 | if Self::can_cast(syntax.kind()) { | ||
2391 | Some(Self { syntax }) | ||
2392 | } else { | ||
2393 | None | ||
2394 | } | ||
2395 | } | ||
2396 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2397 | } | ||
2398 | impl AstNode for MatchGuard { | ||
2399 | fn can_cast(kind: SyntaxKind) -> bool { kind == MATCH_GUARD } | ||
2400 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2401 | if Self::can_cast(syntax.kind()) { | ||
2402 | Some(Self { syntax }) | ||
2403 | } else { | ||
2404 | None | ||
2405 | } | ||
2406 | } | ||
2407 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2408 | } | ||
2409 | impl AstNode for RecordExpr { | ||
2410 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR } | ||
2411 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2412 | if Self::can_cast(syntax.kind()) { | ||
2413 | Some(Self { syntax }) | ||
2414 | } else { | ||
2415 | None | ||
2416 | } | ||
2417 | } | ||
2418 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2419 | } | ||
2420 | impl AstNode for RecordExprFieldList { | ||
2421 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST } | ||
2422 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2423 | if Self::can_cast(syntax.kind()) { | ||
2424 | Some(Self { syntax }) | ||
2425 | } else { | ||
2426 | None | ||
2427 | } | ||
2428 | } | ||
2429 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2430 | } | ||
2431 | impl AstNode for RecordExprField { | ||
2432 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD } | ||
2433 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2434 | if Self::can_cast(syntax.kind()) { | ||
2435 | Some(Self { syntax }) | ||
2436 | } else { | ||
2437 | None | ||
2438 | } | ||
2439 | } | ||
2440 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2441 | } | ||
2442 | impl AstNode for OrPat { | ||
2443 | fn can_cast(kind: SyntaxKind) -> bool { kind == OR_PAT } | ||
2444 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2445 | if Self::can_cast(syntax.kind()) { | ||
2446 | Some(Self { syntax }) | ||
2447 | } else { | ||
2448 | None | ||
2449 | } | ||
2450 | } | ||
2451 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2452 | } | ||
2453 | impl AstNode for ParenPat { | ||
2454 | fn can_cast(kind: SyntaxKind) -> bool { kind == PAREN_PAT } | ||
2455 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2456 | if Self::can_cast(syntax.kind()) { | ||
2457 | Some(Self { syntax }) | ||
2458 | } else { | ||
2459 | None | ||
2460 | } | ||
2461 | } | ||
2462 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2463 | } | ||
2464 | impl AstNode for RefPat { | ||
2465 | fn can_cast(kind: SyntaxKind) -> bool { kind == REF_PAT } | ||
2466 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2467 | if Self::can_cast(syntax.kind()) { | ||
2468 | Some(Self { syntax }) | ||
2469 | } else { | ||
2470 | None | ||
2471 | } | ||
2472 | } | ||
2473 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2474 | } | ||
2475 | impl AstNode for BoxPat { | ||
2476 | fn can_cast(kind: SyntaxKind) -> bool { kind == BOX_PAT } | ||
2477 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2478 | if Self::can_cast(syntax.kind()) { | ||
2479 | Some(Self { syntax }) | ||
2480 | } else { | ||
2481 | None | ||
2482 | } | ||
2483 | } | ||
2484 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2485 | } | ||
2486 | impl AstNode for BindPat { | ||
2487 | fn can_cast(kind: SyntaxKind) -> bool { kind == BIND_PAT } | ||
2488 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2489 | if Self::can_cast(syntax.kind()) { | ||
2490 | Some(Self { syntax }) | ||
2491 | } else { | ||
2492 | None | ||
2493 | } | ||
2494 | } | ||
2495 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2496 | } | ||
2497 | impl AstNode for PlaceholderPat { | ||
2498 | fn can_cast(kind: SyntaxKind) -> bool { kind == PLACEHOLDER_PAT } | ||
2499 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2500 | if Self::can_cast(syntax.kind()) { | ||
2501 | Some(Self { syntax }) | ||
2502 | } else { | ||
2503 | None | ||
2504 | } | ||
2505 | } | ||
2506 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2507 | } | ||
2508 | impl AstNode for DotDotPat { | ||
2509 | fn can_cast(kind: SyntaxKind) -> bool { kind == DOT_DOT_PAT } | ||
2510 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2511 | if Self::can_cast(syntax.kind()) { | ||
2512 | Some(Self { syntax }) | ||
2513 | } else { | ||
2514 | None | ||
2515 | } | ||
2516 | } | ||
2517 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2518 | } | ||
2519 | impl AstNode for PathPat { | ||
2520 | fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_PAT } | ||
2521 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2522 | if Self::can_cast(syntax.kind()) { | ||
2523 | Some(Self { syntax }) | ||
2524 | } else { | ||
2525 | None | ||
2526 | } | ||
2527 | } | ||
2528 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2529 | } | ||
2530 | impl AstNode for SlicePat { | ||
2531 | fn can_cast(kind: SyntaxKind) -> bool { kind == SLICE_PAT } | ||
2532 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2533 | if Self::can_cast(syntax.kind()) { | ||
2534 | Some(Self { syntax }) | ||
2535 | } else { | ||
2536 | None | ||
2537 | } | ||
2538 | } | ||
2539 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2540 | } | ||
2541 | impl AstNode for RangePat { | ||
2542 | fn can_cast(kind: SyntaxKind) -> bool { kind == RANGE_PAT } | ||
2543 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2544 | if Self::can_cast(syntax.kind()) { | ||
2545 | Some(Self { syntax }) | ||
2546 | } else { | ||
2547 | None | ||
2548 | } | ||
2549 | } | ||
2550 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2551 | } | ||
2552 | impl AstNode for LiteralPat { | ||
2553 | fn can_cast(kind: SyntaxKind) -> bool { kind == LITERAL_PAT } | ||
2554 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2555 | if Self::can_cast(syntax.kind()) { | ||
2556 | Some(Self { syntax }) | ||
2557 | } else { | ||
2558 | None | ||
2559 | } | ||
2560 | } | ||
2561 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2562 | } | ||
2563 | impl AstNode for MacroPat { | ||
2564 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_PAT } | ||
2565 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2566 | if Self::can_cast(syntax.kind()) { | ||
2567 | Some(Self { syntax }) | ||
2568 | } else { | ||
2569 | None | ||
2570 | } | ||
2571 | } | ||
2572 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2573 | } | ||
2574 | impl AstNode for RecordPat { | ||
2575 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_PAT } | ||
2576 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2577 | if Self::can_cast(syntax.kind()) { | ||
2578 | Some(Self { syntax }) | ||
2579 | } else { | ||
2580 | None | ||
2581 | } | ||
2582 | } | ||
2583 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2584 | } | ||
2585 | impl AstNode for RecordFieldPatList { | ||
2586 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT_LIST } | ||
2587 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2588 | if Self::can_cast(syntax.kind()) { | ||
2589 | Some(Self { syntax }) | ||
2590 | } else { | ||
2591 | None | ||
2592 | } | ||
2593 | } | ||
2594 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2595 | } | ||
2596 | impl AstNode for RecordFieldPat { | ||
2597 | fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_FIELD_PAT } | ||
2598 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2599 | if Self::can_cast(syntax.kind()) { | ||
2600 | Some(Self { syntax }) | ||
2601 | } else { | ||
2602 | None | ||
2603 | } | ||
2604 | } | ||
2605 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2606 | } | ||
2607 | impl AstNode for TupleStructPat { | ||
2608 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_STRUCT_PAT } | ||
2609 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2610 | if Self::can_cast(syntax.kind()) { | ||
2611 | Some(Self { syntax }) | ||
2612 | } else { | ||
2613 | None | ||
2614 | } | ||
2615 | } | ||
2616 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2617 | } | ||
2618 | impl AstNode for TuplePat { | ||
2619 | fn can_cast(kind: SyntaxKind) -> bool { kind == TUPLE_PAT } | ||
2620 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2621 | if Self::can_cast(syntax.kind()) { | ||
2622 | Some(Self { syntax }) | ||
2623 | } else { | ||
2624 | None | ||
2625 | } | ||
2626 | } | ||
2627 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2628 | } | ||
2629 | impl AstNode for MacroDef { | ||
2630 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_DEF } | ||
2631 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2632 | if Self::can_cast(syntax.kind()) { | ||
2633 | Some(Self { syntax }) | ||
2634 | } else { | ||
2635 | None | ||
2636 | } | ||
2637 | } | ||
2638 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2639 | } | ||
2640 | impl AstNode for MacroItems { | ||
2641 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_ITEMS } | ||
2642 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2643 | if Self::can_cast(syntax.kind()) { | ||
2644 | Some(Self { syntax }) | ||
2645 | } else { | ||
2646 | None | ||
2647 | } | ||
2648 | } | ||
2649 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2650 | } | ||
2651 | impl AstNode for MacroStmts { | ||
2652 | fn can_cast(kind: SyntaxKind) -> bool { kind == MACRO_STMTS } | ||
2653 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2654 | if Self::can_cast(syntax.kind()) { | ||
2655 | Some(Self { syntax }) | ||
2656 | } else { | ||
2657 | None | ||
2658 | } | ||
2659 | } | ||
2660 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2661 | } | ||
2662 | impl AstNode for TypeBound { | ||
2663 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_BOUND } | ||
2664 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2665 | if Self::can_cast(syntax.kind()) { | ||
2666 | Some(Self { syntax }) | ||
2667 | } else { | ||
2668 | None | ||
2669 | } | ||
2670 | } | ||
2671 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2672 | } | ||
2673 | impl AstNode for WherePred { | ||
2674 | fn can_cast(kind: SyntaxKind) -> bool { kind == WHERE_PRED } | ||
2675 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2676 | if Self::can_cast(syntax.kind()) { | ||
2677 | Some(Self { syntax }) | ||
2678 | } else { | ||
2679 | None | ||
2680 | } | ||
2681 | } | ||
2682 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2683 | } | ||
2684 | impl AstNode for ExprStmt { | ||
2685 | fn can_cast(kind: SyntaxKind) -> bool { kind == EXPR_STMT } | ||
2686 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2687 | if Self::can_cast(syntax.kind()) { | ||
2688 | Some(Self { syntax }) | ||
2689 | } else { | ||
2690 | None | ||
2691 | } | ||
2692 | } | ||
2693 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2694 | } | ||
2695 | impl AstNode for LetStmt { | ||
2696 | fn can_cast(kind: SyntaxKind) -> bool { kind == LET_STMT } | ||
2697 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2698 | if Self::can_cast(syntax.kind()) { | ||
2699 | Some(Self { syntax }) | ||
2700 | } else { | ||
2701 | None | ||
2702 | } | ||
2703 | } | ||
2704 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2705 | } | ||
2706 | impl AstNode for PathSegment { | ||
2707 | fn can_cast(kind: SyntaxKind) -> bool { kind == PATH_SEGMENT } | ||
2708 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2709 | if Self::can_cast(syntax.kind()) { | ||
2710 | Some(Self { syntax }) | ||
2711 | } else { | ||
2712 | None | ||
2713 | } | ||
2714 | } | ||
2715 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2716 | } | ||
2717 | impl AstNode for TypeArg { | ||
2718 | fn can_cast(kind: SyntaxKind) -> bool { kind == TYPE_ARG } | ||
2719 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2720 | if Self::can_cast(syntax.kind()) { | ||
2721 | Some(Self { syntax }) | ||
2722 | } else { | ||
2723 | None | ||
2724 | } | ||
2725 | } | ||
2726 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2727 | } | ||
2728 | impl AstNode for LifetimeArg { | ||
2729 | fn can_cast(kind: SyntaxKind) -> bool { kind == LIFETIME_ARG } | ||
2730 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2731 | if Self::can_cast(syntax.kind()) { | ||
2732 | Some(Self { syntax }) | ||
2733 | } else { | ||
2734 | None | ||
2735 | } | ||
2736 | } | ||
2737 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2738 | } | ||
2739 | impl AstNode for AssocTypeArg { | ||
2740 | fn can_cast(kind: SyntaxKind) -> bool { kind == ASSOC_TYPE_ARG } | ||
2741 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2742 | if Self::can_cast(syntax.kind()) { | ||
2743 | Some(Self { syntax }) | ||
2744 | } else { | ||
2745 | None | ||
2746 | } | ||
2747 | } | ||
2748 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2749 | } | ||
2750 | impl AstNode for ConstArg { | ||
2751 | fn can_cast(kind: SyntaxKind) -> bool { kind == CONST_ARG } | ||
2752 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2753 | if Self::can_cast(syntax.kind()) { | ||
2754 | Some(Self { syntax }) | ||
2755 | } else { | ||
2756 | None | ||
2757 | } | ||
2758 | } | ||
2759 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
2760 | } | ||
2761 | impl From<Const> for Item { | ||
2762 | fn from(node: Const) -> Item { Item::Const(node) } | ||
2763 | } | ||
2764 | impl From<Enum> for Item { | ||
2765 | fn from(node: Enum) -> Item { Item::Enum(node) } | ||
2766 | } | ||
2767 | impl From<ExternBlock> for Item { | ||
2768 | fn from(node: ExternBlock) -> Item { Item::ExternBlock(node) } | ||
2769 | } | ||
2770 | impl From<ExternCrate> for Item { | ||
2771 | fn from(node: ExternCrate) -> Item { Item::ExternCrate(node) } | ||
2772 | } | ||
2773 | impl From<Fn> for Item { | ||
2774 | fn from(node: Fn) -> Item { Item::Fn(node) } | ||
2775 | } | ||
2776 | impl From<Impl> for Item { | ||
2777 | fn from(node: Impl) -> Item { Item::Impl(node) } | ||
2778 | } | ||
2779 | impl From<MacroCall> for Item { | ||
2780 | fn from(node: MacroCall) -> Item { Item::MacroCall(node) } | ||
2781 | } | ||
2782 | impl From<Module> for Item { | ||
2783 | fn from(node: Module) -> Item { Item::Module(node) } | ||
2784 | } | ||
2785 | impl From<Static> for Item { | ||
2786 | fn from(node: Static) -> Item { Item::Static(node) } | ||
2787 | } | ||
2788 | impl From<Struct> for Item { | ||
2789 | fn from(node: Struct) -> Item { Item::Struct(node) } | ||
2790 | } | ||
2791 | impl From<Trait> for Item { | ||
2792 | fn from(node: Trait) -> Item { Item::Trait(node) } | ||
2793 | } | ||
2794 | impl From<TypeAlias> for Item { | ||
2795 | fn from(node: TypeAlias) -> Item { Item::TypeAlias(node) } | ||
2796 | } | ||
2797 | impl From<Union> for Item { | ||
2798 | fn from(node: Union) -> Item { Item::Union(node) } | ||
2799 | } | ||
2800 | impl From<Use> for Item { | ||
2801 | fn from(node: Use) -> Item { Item::Use(node) } | ||
2802 | } | ||
2803 | impl AstNode for Item { | ||
2804 | fn can_cast(kind: SyntaxKind) -> bool { | ||
2805 | match kind { | ||
2806 | CONST | ENUM | EXTERN_BLOCK | EXTERN_CRATE | FN | IMPL | MACRO_CALL | MODULE | ||
2807 | | STATIC | STRUCT | TRAIT | TYPE_ALIAS | UNION | USE => true, | ||
2808 | _ => false, | ||
2809 | } | ||
2810 | } | ||
2811 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2812 | let res = match syntax.kind() { | ||
2813 | CONST => Item::Const(Const { syntax }), | ||
2814 | ENUM => Item::Enum(Enum { syntax }), | ||
2815 | EXTERN_BLOCK => Item::ExternBlock(ExternBlock { syntax }), | ||
2816 | EXTERN_CRATE => Item::ExternCrate(ExternCrate { syntax }), | ||
2817 | FN => Item::Fn(Fn { syntax }), | ||
2818 | IMPL => Item::Impl(Impl { syntax }), | ||
2819 | MACRO_CALL => Item::MacroCall(MacroCall { syntax }), | ||
2820 | MODULE => Item::Module(Module { syntax }), | ||
2821 | STATIC => Item::Static(Static { syntax }), | ||
2822 | STRUCT => Item::Struct(Struct { syntax }), | ||
2823 | TRAIT => Item::Trait(Trait { syntax }), | ||
2824 | TYPE_ALIAS => Item::TypeAlias(TypeAlias { syntax }), | ||
2825 | UNION => Item::Union(Union { syntax }), | ||
2826 | USE => Item::Use(Use { syntax }), | ||
2827 | _ => return None, | ||
2828 | }; | ||
2829 | Some(res) | ||
2830 | } | ||
2831 | fn syntax(&self) -> &SyntaxNode { | ||
2832 | match self { | ||
2833 | Item::Const(it) => &it.syntax, | ||
2834 | Item::Enum(it) => &it.syntax, | ||
2835 | Item::ExternBlock(it) => &it.syntax, | ||
2836 | Item::ExternCrate(it) => &it.syntax, | ||
2837 | Item::Fn(it) => &it.syntax, | ||
2838 | Item::Impl(it) => &it.syntax, | ||
2839 | Item::MacroCall(it) => &it.syntax, | ||
2840 | Item::Module(it) => &it.syntax, | ||
2841 | Item::Static(it) => &it.syntax, | ||
2842 | Item::Struct(it) => &it.syntax, | ||
2843 | Item::Trait(it) => &it.syntax, | ||
2844 | Item::TypeAlias(it) => &it.syntax, | ||
2845 | Item::Union(it) => &it.syntax, | ||
2846 | Item::Use(it) => &it.syntax, | ||
2847 | } | ||
2848 | } | ||
2849 | } | ||
2850 | impl From<ParenType> for TypeRef { | ||
2851 | fn from(node: ParenType) -> TypeRef { TypeRef::ParenType(node) } | ||
2852 | } | ||
2853 | impl From<TupleType> for TypeRef { | ||
2854 | fn from(node: TupleType) -> TypeRef { TypeRef::TupleType(node) } | ||
2855 | } | ||
2856 | impl From<NeverType> for TypeRef { | ||
2857 | fn from(node: NeverType) -> TypeRef { TypeRef::NeverType(node) } | ||
2858 | } | ||
2859 | impl From<PathType> for TypeRef { | ||
2860 | fn from(node: PathType) -> TypeRef { TypeRef::PathType(node) } | ||
2861 | } | ||
2862 | impl From<PointerType> for TypeRef { | ||
2863 | fn from(node: PointerType) -> TypeRef { TypeRef::PointerType(node) } | ||
2864 | } | ||
2865 | impl From<ArrayType> for TypeRef { | ||
2866 | fn from(node: ArrayType) -> TypeRef { TypeRef::ArrayType(node) } | ||
2867 | } | ||
2868 | impl From<SliceType> for TypeRef { | ||
2869 | fn from(node: SliceType) -> TypeRef { TypeRef::SliceType(node) } | ||
2870 | } | ||
2871 | impl From<ReferenceType> for TypeRef { | ||
2872 | fn from(node: ReferenceType) -> TypeRef { TypeRef::ReferenceType(node) } | ||
2873 | } | ||
2874 | impl From<PlaceholderType> for TypeRef { | ||
2875 | fn from(node: PlaceholderType) -> TypeRef { TypeRef::PlaceholderType(node) } | ||
2876 | } | ||
2877 | impl From<FnPointerType> for TypeRef { | ||
2878 | fn from(node: FnPointerType) -> TypeRef { TypeRef::FnPointerType(node) } | ||
2879 | } | ||
2880 | impl From<ForType> for TypeRef { | ||
2881 | fn from(node: ForType) -> TypeRef { TypeRef::ForType(node) } | ||
2882 | } | ||
2883 | impl From<ImplTraitType> for TypeRef { | ||
2884 | fn from(node: ImplTraitType) -> TypeRef { TypeRef::ImplTraitType(node) } | ||
2885 | } | ||
2886 | impl From<DynTraitType> for TypeRef { | ||
2887 | fn from(node: DynTraitType) -> TypeRef { TypeRef::DynTraitType(node) } | ||
2888 | } | ||
2889 | impl AstNode for TypeRef { | ||
2890 | fn can_cast(kind: SyntaxKind) -> bool { | ||
2891 | match kind { | ||
2892 | PAREN_TYPE | TUPLE_TYPE | NEVER_TYPE | PATH_TYPE | POINTER_TYPE | ARRAY_TYPE | ||
2893 | | SLICE_TYPE | REFERENCE_TYPE | PLACEHOLDER_TYPE | FN_POINTER_TYPE | FOR_TYPE | ||
2894 | | IMPL_TRAIT_TYPE | DYN_TRAIT_TYPE => true, | ||
2895 | _ => false, | ||
2896 | } | ||
2897 | } | ||
2898 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2899 | let res = match syntax.kind() { | ||
2900 | PAREN_TYPE => TypeRef::ParenType(ParenType { syntax }), | ||
2901 | TUPLE_TYPE => TypeRef::TupleType(TupleType { syntax }), | ||
2902 | NEVER_TYPE => TypeRef::NeverType(NeverType { syntax }), | ||
2903 | PATH_TYPE => TypeRef::PathType(PathType { syntax }), | ||
2904 | POINTER_TYPE => TypeRef::PointerType(PointerType { syntax }), | ||
2905 | ARRAY_TYPE => TypeRef::ArrayType(ArrayType { syntax }), | ||
2906 | SLICE_TYPE => TypeRef::SliceType(SliceType { syntax }), | ||
2907 | REFERENCE_TYPE => TypeRef::ReferenceType(ReferenceType { syntax }), | ||
2908 | PLACEHOLDER_TYPE => TypeRef::PlaceholderType(PlaceholderType { syntax }), | ||
2909 | FN_POINTER_TYPE => TypeRef::FnPointerType(FnPointerType { syntax }), | ||
2910 | FOR_TYPE => TypeRef::ForType(ForType { syntax }), | ||
2911 | IMPL_TRAIT_TYPE => TypeRef::ImplTraitType(ImplTraitType { syntax }), | ||
2912 | DYN_TRAIT_TYPE => TypeRef::DynTraitType(DynTraitType { syntax }), | ||
2913 | _ => return None, | ||
2914 | }; | ||
2915 | Some(res) | ||
2916 | } | ||
2917 | fn syntax(&self) -> &SyntaxNode { | ||
2918 | match self { | ||
2919 | TypeRef::ParenType(it) => &it.syntax, | ||
2920 | TypeRef::TupleType(it) => &it.syntax, | ||
2921 | TypeRef::NeverType(it) => &it.syntax, | ||
2922 | TypeRef::PathType(it) => &it.syntax, | ||
2923 | TypeRef::PointerType(it) => &it.syntax, | ||
2924 | TypeRef::ArrayType(it) => &it.syntax, | ||
2925 | TypeRef::SliceType(it) => &it.syntax, | ||
2926 | TypeRef::ReferenceType(it) => &it.syntax, | ||
2927 | TypeRef::PlaceholderType(it) => &it.syntax, | ||
2928 | TypeRef::FnPointerType(it) => &it.syntax, | ||
2929 | TypeRef::ForType(it) => &it.syntax, | ||
2930 | TypeRef::ImplTraitType(it) => &it.syntax, | ||
2931 | TypeRef::DynTraitType(it) => &it.syntax, | ||
2932 | } | ||
2933 | } | ||
2934 | } | ||
2935 | impl From<OrPat> for Pat { | ||
2936 | fn from(node: OrPat) -> Pat { Pat::OrPat(node) } | ||
2937 | } | ||
2938 | impl From<ParenPat> for Pat { | ||
2939 | fn from(node: ParenPat) -> Pat { Pat::ParenPat(node) } | ||
2940 | } | ||
2941 | impl From<RefPat> for Pat { | ||
2942 | fn from(node: RefPat) -> Pat { Pat::RefPat(node) } | ||
2943 | } | ||
2944 | impl From<BoxPat> for Pat { | ||
2945 | fn from(node: BoxPat) -> Pat { Pat::BoxPat(node) } | ||
2946 | } | ||
2947 | impl From<BindPat> for Pat { | ||
2948 | fn from(node: BindPat) -> Pat { Pat::BindPat(node) } | ||
2949 | } | ||
2950 | impl From<PlaceholderPat> for Pat { | ||
2951 | fn from(node: PlaceholderPat) -> Pat { Pat::PlaceholderPat(node) } | ||
2952 | } | ||
2953 | impl From<DotDotPat> for Pat { | ||
2954 | fn from(node: DotDotPat) -> Pat { Pat::DotDotPat(node) } | ||
2955 | } | ||
2956 | impl From<PathPat> for Pat { | ||
2957 | fn from(node: PathPat) -> Pat { Pat::PathPat(node) } | ||
2958 | } | ||
2959 | impl From<RecordPat> for Pat { | ||
2960 | fn from(node: RecordPat) -> Pat { Pat::RecordPat(node) } | ||
2961 | } | ||
2962 | impl From<TupleStructPat> for Pat { | ||
2963 | fn from(node: TupleStructPat) -> Pat { Pat::TupleStructPat(node) } | ||
2964 | } | ||
2965 | impl From<TuplePat> for Pat { | ||
2966 | fn from(node: TuplePat) -> Pat { Pat::TuplePat(node) } | ||
2967 | } | ||
2968 | impl From<SlicePat> for Pat { | ||
2969 | fn from(node: SlicePat) -> Pat { Pat::SlicePat(node) } | ||
2970 | } | ||
2971 | impl From<RangePat> for Pat { | ||
2972 | fn from(node: RangePat) -> Pat { Pat::RangePat(node) } | ||
2973 | } | ||
2974 | impl From<LiteralPat> for Pat { | ||
2975 | fn from(node: LiteralPat) -> Pat { Pat::LiteralPat(node) } | ||
2976 | } | ||
2977 | impl From<MacroPat> for Pat { | ||
2978 | fn from(node: MacroPat) -> Pat { Pat::MacroPat(node) } | ||
2979 | } | ||
2980 | impl AstNode for Pat { | ||
2981 | fn can_cast(kind: SyntaxKind) -> bool { | ||
2982 | match kind { | ||
2983 | OR_PAT | PAREN_PAT | REF_PAT | BOX_PAT | BIND_PAT | PLACEHOLDER_PAT | DOT_DOT_PAT | ||
2984 | | PATH_PAT | RECORD_PAT | TUPLE_STRUCT_PAT | TUPLE_PAT | SLICE_PAT | RANGE_PAT | ||
2985 | | LITERAL_PAT | MACRO_PAT => true, | ||
2986 | _ => false, | ||
2987 | } | ||
2988 | } | ||
2989 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
2990 | let res = match syntax.kind() { | ||
2991 | OR_PAT => Pat::OrPat(OrPat { syntax }), | ||
2992 | PAREN_PAT => Pat::ParenPat(ParenPat { syntax }), | ||
2993 | REF_PAT => Pat::RefPat(RefPat { syntax }), | ||
2994 | BOX_PAT => Pat::BoxPat(BoxPat { syntax }), | ||
2995 | BIND_PAT => Pat::BindPat(BindPat { syntax }), | ||
2996 | PLACEHOLDER_PAT => Pat::PlaceholderPat(PlaceholderPat { syntax }), | ||
2997 | DOT_DOT_PAT => Pat::DotDotPat(DotDotPat { syntax }), | ||
2998 | PATH_PAT => Pat::PathPat(PathPat { syntax }), | ||
2999 | RECORD_PAT => Pat::RecordPat(RecordPat { syntax }), | ||
3000 | TUPLE_STRUCT_PAT => Pat::TupleStructPat(TupleStructPat { syntax }), | ||
3001 | TUPLE_PAT => Pat::TuplePat(TuplePat { syntax }), | ||
3002 | SLICE_PAT => Pat::SlicePat(SlicePat { syntax }), | ||
3003 | RANGE_PAT => Pat::RangePat(RangePat { syntax }), | ||
3004 | LITERAL_PAT => Pat::LiteralPat(LiteralPat { syntax }), | ||
3005 | MACRO_PAT => Pat::MacroPat(MacroPat { syntax }), | ||
3006 | _ => return None, | ||
3007 | }; | ||
3008 | Some(res) | ||
3009 | } | ||
3010 | fn syntax(&self) -> &SyntaxNode { | ||
3011 | match self { | ||
3012 | Pat::OrPat(it) => &it.syntax, | ||
3013 | Pat::ParenPat(it) => &it.syntax, | ||
3014 | Pat::RefPat(it) => &it.syntax, | ||
3015 | Pat::BoxPat(it) => &it.syntax, | ||
3016 | Pat::BindPat(it) => &it.syntax, | ||
3017 | Pat::PlaceholderPat(it) => &it.syntax, | ||
3018 | Pat::DotDotPat(it) => &it.syntax, | ||
3019 | Pat::PathPat(it) => &it.syntax, | ||
3020 | Pat::RecordPat(it) => &it.syntax, | ||
3021 | Pat::TupleStructPat(it) => &it.syntax, | ||
3022 | Pat::TuplePat(it) => &it.syntax, | ||
3023 | Pat::SlicePat(it) => &it.syntax, | ||
3024 | Pat::RangePat(it) => &it.syntax, | ||
3025 | Pat::LiteralPat(it) => &it.syntax, | ||
3026 | Pat::MacroPat(it) => &it.syntax, | ||
3027 | } | ||
3028 | } | ||
3029 | } | ||
3030 | impl From<RecordFieldList> for FieldList { | ||
3031 | fn from(node: RecordFieldList) -> FieldList { FieldList::RecordFieldList(node) } | ||
3032 | } | ||
3033 | impl From<TupleFieldList> for FieldList { | ||
3034 | fn from(node: TupleFieldList) -> FieldList { FieldList::TupleFieldList(node) } | ||
3035 | } | ||
3036 | impl AstNode for FieldList { | ||
3037 | fn can_cast(kind: SyntaxKind) -> bool { | ||
3038 | match kind { | ||
3039 | RECORD_FIELD_LIST | TUPLE_FIELD_LIST => true, | ||
3040 | _ => false, | ||
3041 | } | ||
3042 | } | ||
3043 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
3044 | let res = match syntax.kind() { | ||
3045 | RECORD_FIELD_LIST => FieldList::RecordFieldList(RecordFieldList { syntax }), | ||
3046 | TUPLE_FIELD_LIST => FieldList::TupleFieldList(TupleFieldList { syntax }), | ||
3047 | _ => return None, | ||
3048 | }; | ||
3049 | Some(res) | ||
3050 | } | ||
3051 | fn syntax(&self) -> &SyntaxNode { | ||
3052 | match self { | ||
3053 | FieldList::RecordFieldList(it) => &it.syntax, | ||
3054 | FieldList::TupleFieldList(it) => &it.syntax, | ||
3055 | } | ||
3056 | } | ||
3057 | } | ||
3058 | impl From<TupleExpr> for Expr { | ||
3059 | fn from(node: TupleExpr) -> Expr { Expr::TupleExpr(node) } | ||
3060 | } | ||
3061 | impl From<ArrayExpr> for Expr { | ||
3062 | fn from(node: ArrayExpr) -> Expr { Expr::ArrayExpr(node) } | ||
3063 | } | ||
3064 | impl From<ParenExpr> for Expr { | ||
3065 | fn from(node: ParenExpr) -> Expr { Expr::ParenExpr(node) } | ||
3066 | } | ||
3067 | impl From<PathExpr> for Expr { | ||
3068 | fn from(node: PathExpr) -> Expr { Expr::PathExpr(node) } | ||
3069 | } | ||
3070 | impl From<LambdaExpr> for Expr { | ||
3071 | fn from(node: LambdaExpr) -> Expr { Expr::LambdaExpr(node) } | ||
3072 | } | ||
3073 | impl From<IfExpr> for Expr { | ||
3074 | fn from(node: IfExpr) -> Expr { Expr::IfExpr(node) } | ||
3075 | } | ||
3076 | impl From<LoopExpr> for Expr { | ||
3077 | fn from(node: LoopExpr) -> Expr { Expr::LoopExpr(node) } | ||
3078 | } | ||
3079 | impl From<ForExpr> for Expr { | ||
3080 | fn from(node: ForExpr) -> Expr { Expr::ForExpr(node) } | ||
3081 | } | ||
3082 | impl From<WhileExpr> for Expr { | ||
3083 | fn from(node: WhileExpr) -> Expr { Expr::WhileExpr(node) } | ||
3084 | } | ||
3085 | impl From<ContinueExpr> for Expr { | ||
3086 | fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } | ||
3087 | } | ||
3088 | impl From<BreakExpr> for Expr { | ||
3089 | fn from(node: BreakExpr) -> Expr { Expr::BreakExpr(node) } | ||
3090 | } | ||
3091 | impl From<Label> for Expr { | ||
3092 | fn from(node: Label) -> Expr { Expr::Label(node) } | ||
3093 | } | ||
3094 | impl From<BlockExpr> for Expr { | ||
3095 | fn from(node: BlockExpr) -> Expr { Expr::BlockExpr(node) } | ||
3096 | } | ||
3097 | impl From<ReturnExpr> for Expr { | ||
3098 | fn from(node: ReturnExpr) -> Expr { Expr::ReturnExpr(node) } | ||
3099 | } | ||
3100 | impl From<MatchExpr> for Expr { | ||
3101 | fn from(node: MatchExpr) -> Expr { Expr::MatchExpr(node) } | ||
3102 | } | ||
3103 | impl From<RecordExpr> for Expr { | ||
3104 | fn from(node: RecordExpr) -> Expr { Expr::RecordExpr(node) } | ||
3105 | } | ||
3106 | impl From<CallExpr> for Expr { | ||
3107 | fn from(node: CallExpr) -> Expr { Expr::CallExpr(node) } | ||
3108 | } | ||
3109 | impl From<IndexExpr> for Expr { | ||
3110 | fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } | ||
3111 | } | ||
3112 | impl From<MethodCallExpr> for Expr { | ||
3113 | fn from(node: MethodCallExpr) -> Expr { Expr::MethodCallExpr(node) } | ||
3114 | } | ||
3115 | impl From<FieldExpr> for Expr { | ||
3116 | fn from(node: FieldExpr) -> Expr { Expr::FieldExpr(node) } | ||
3117 | } | ||
3118 | impl From<AwaitExpr> for Expr { | ||
3119 | fn from(node: AwaitExpr) -> Expr { Expr::AwaitExpr(node) } | ||
3120 | } | ||
3121 | impl From<TryExpr> for Expr { | ||
3122 | fn from(node: TryExpr) -> Expr { Expr::TryExpr(node) } | ||
3123 | } | ||
3124 | impl From<EffectExpr> for Expr { | ||
3125 | fn from(node: EffectExpr) -> Expr { Expr::EffectExpr(node) } | ||
3126 | } | ||
3127 | impl From<CastExpr> for Expr { | ||
3128 | fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } | ||
3129 | } | ||
3130 | impl From<RefExpr> for Expr { | ||
3131 | fn from(node: RefExpr) -> Expr { Expr::RefExpr(node) } | ||
3132 | } | ||
3133 | impl From<PrefixExpr> for Expr { | ||
3134 | fn from(node: PrefixExpr) -> Expr { Expr::PrefixExpr(node) } | ||
3135 | } | ||
3136 | impl From<RangeExpr> for Expr { | ||
3137 | fn from(node: RangeExpr) -> Expr { Expr::RangeExpr(node) } | ||
3138 | } | ||
3139 | impl From<BinExpr> for Expr { | ||
3140 | fn from(node: BinExpr) -> Expr { Expr::BinExpr(node) } | ||
3141 | } | ||
3142 | impl From<Literal> for Expr { | ||
3143 | fn from(node: Literal) -> Expr { Expr::Literal(node) } | ||
3144 | } | ||
3145 | impl From<MacroCall> for Expr { | ||
3146 | fn from(node: MacroCall) -> Expr { Expr::MacroCall(node) } | ||
3147 | } | ||
3148 | impl From<BoxExpr> for Expr { | ||
3149 | fn from(node: BoxExpr) -> Expr { Expr::BoxExpr(node) } | ||
3150 | } | ||
3151 | impl AstNode for Expr { | ||
3152 | fn can_cast(kind: SyntaxKind) -> bool { | ||
3153 | match kind { | ||
3154 | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | ||
3155 | | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | ||
3156 | | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | RECORD_EXPR | CALL_EXPR | INDEX_EXPR | ||
3157 | | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | EFFECT_EXPR | CAST_EXPR | ||
3158 | | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL | BOX_EXPR => { | ||
3159 | true | ||
3160 | } | ||
3161 | _ => false, | ||
3162 | } | ||
3163 | } | ||
3164 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||