diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 36 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 6 |
3 files changed, 43 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 89cb9a9f3..d3e8888bd 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -18,7 +18,8 @@ use crate::{ | |||
18 | pub use self::{ | 18 | pub use self::{ |
19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, | 19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, |
20 | extensions::{ | 20 | extensions::{ |
21 | FieldKind, PathSegmentKind, SelfParamKind, StructKind, TypeBoundKind, VisibilityKind, | 21 | FieldKind, PathSegmentKind, SelfParamKind, SlicePatComponents, StructKind, TypeBoundKind, |
22 | VisibilityKind, | ||
22 | }, | 23 | }, |
23 | generated::*, | 24 | generated::*, |
24 | tokens::*, | 25 | tokens::*, |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index cb0aee422..7dcf084de 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -1,6 +1,8 @@ | |||
1 | //! Various extension methods to ast Nodes, which are hard to code-generate. | 1 | //! Various extension methods to ast Nodes, which are hard to code-generate. |
2 | //! Extensions for various expressions live in a sibling `expr_extensions` module. | 2 | //! Extensions for various expressions live in a sibling `expr_extensions` module. |
3 | 3 | ||
4 | use itertools::Itertools; | ||
5 | |||
4 | use crate::{ | 6 | use crate::{ |
5 | ast::{self, child_opt, children, AstNode, AttrInput, SyntaxNode}, | 7 | ast::{self, child_opt, children, AstNode, AttrInput, SyntaxNode}, |
6 | SmolStr, SyntaxElement, | 8 | SmolStr, SyntaxElement, |
@@ -293,6 +295,40 @@ impl ast::BindPat { | |||
293 | } | 295 | } |
294 | } | 296 | } |
295 | 297 | ||
298 | pub struct SlicePatComponents { | ||
299 | pub prefix: Vec<ast::Pat>, | ||
300 | pub slice: Option<ast::Pat>, | ||
301 | pub suffix: Vec<ast::Pat>, | ||
302 | } | ||
303 | |||
304 | impl ast::SlicePat { | ||
305 | pub fn components(&self) -> SlicePatComponents { | ||
306 | let mut args = self.args().peekable(); | ||
307 | let prefix = args | ||
308 | .peeking_take_while(|p| match p { | ||
309 | ast::Pat::DotDotPat(_) => false, | ||
310 | ast::Pat::BindPat(bp) => match bp.pat() { | ||
311 | Some(ast::Pat::DotDotPat(_)) => false, | ||
312 | _ => true, | ||
313 | }, | ||
314 | ast::Pat::RefPat(rp) => match rp.pat() { | ||
315 | Some(ast::Pat::DotDotPat(_)) => false, | ||
316 | Some(ast::Pat::BindPat(bp)) => match bp.pat() { | ||
317 | Some(ast::Pat::DotDotPat(_)) => false, | ||
318 | _ => true, | ||
319 | }, | ||
320 | _ => true, | ||
321 | }, | ||
322 | _ => true, | ||
323 | }) | ||
324 | .collect(); | ||
325 | let slice = args.next(); | ||
326 | let suffix = args.collect(); | ||
327 | |||
328 | SlicePatComponents { prefix, slice, suffix } | ||
329 | } | ||
330 | } | ||
331 | |||
296 | impl ast::PointerType { | 332 | impl ast::PointerType { |
297 | pub fn is_mut(&self) -> bool { | 333 | pub fn is_mut(&self) -> bool { |
298 | self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) | 334 | self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 8d640642d..8eb240801 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -2117,7 +2117,11 @@ impl AstNode for SlicePat { | |||
2117 | &self.syntax | 2117 | &self.syntax |
2118 | } | 2118 | } |
2119 | } | 2119 | } |
2120 | impl SlicePat {} | 2120 | impl SlicePat { |
2121 | pub fn args(&self) -> AstChildren<Pat> { | ||
2122 | AstChildren::new(&self.syntax) | ||
2123 | } | ||
2124 | } | ||
2121 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2125 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2122 | pub struct RangePat { | 2126 | pub struct RangePat { |
2123 | pub(crate) syntax: SyntaxNode, | 2127 | pub(crate) syntax: SyntaxNode, |