diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 18 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 44 |
2 files changed, 60 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 00c60ebf3..ab3dd1b84 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -285,13 +285,27 @@ impl LetStmt { | |||
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
289 | pub enum ElseBranchFlavor<'a> { | ||
290 | Block(&'a Block), | ||
291 | IfExpr(&'a IfExpr), | ||
292 | } | ||
293 | |||
288 | impl IfExpr { | 294 | impl IfExpr { |
289 | pub fn then_branch(&self) -> Option<&Block> { | 295 | pub fn then_branch(&self) -> Option<&Block> { |
290 | self.blocks().nth(0) | 296 | self.blocks().nth(0) |
291 | } | 297 | } |
292 | pub fn else_branch(&self) -> Option<&Block> { | 298 | pub fn else_branch(&self) -> Option<ElseBranchFlavor> { |
293 | self.blocks().nth(1) | 299 | let res = match self.blocks().nth(1) { |
300 | Some(block) => ElseBranchFlavor::Block(block), | ||
301 | None => { | ||
302 | let elif: &IfExpr = child_opt(self)?; | ||
303 | ElseBranchFlavor::IfExpr(elif) | ||
304 | } | ||
305 | }; | ||
306 | Some(res) | ||
294 | } | 307 | } |
308 | |||
295 | fn blocks(&self) -> AstChildren<Block> { | 309 | fn blocks(&self) -> AstChildren<Block> { |
296 | children(self) | 310 | children(self) |
297 | } | 311 | } |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 3ace6533c..4f8723ae7 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -660,6 +660,50 @@ impl ToOwned for DynTraitType { | |||
660 | 660 | ||
661 | impl DynTraitType {} | 661 | impl DynTraitType {} |
662 | 662 | ||
663 | // ElseBranch | ||
664 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
665 | #[repr(transparent)] | ||
666 | pub struct ElseBranch { | ||
667 | pub(crate) syntax: SyntaxNode, | ||
668 | } | ||
669 | unsafe impl TransparentNewType for ElseBranch { | ||
670 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
671 | } | ||
672 | |||
673 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
674 | pub enum ElseBranchKind<'a> { | ||
675 | Block(&'a Block), | ||
676 | IfExpr(&'a IfExpr), | ||
677 | } | ||
678 | |||
679 | impl AstNode for ElseBranch { | ||
680 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
681 | match syntax.kind() { | ||
682 | | BLOCK | ||
683 | | IF_EXPR => Some(ElseBranch::from_repr(syntax.into_repr())), | ||
684 | _ => None, | ||
685 | } | ||
686 | } | ||
687 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
688 | } | ||
689 | |||
690 | impl ToOwned for ElseBranch { | ||
691 | type Owned = TreeArc<ElseBranch>; | ||
692 | fn to_owned(&self) -> TreeArc<ElseBranch> { TreeArc::cast(self.syntax.to_owned()) } | ||
693 | } | ||
694 | |||
695 | impl ElseBranch { | ||
696 | pub fn kind(&self) -> ElseBranchKind { | ||
697 | match self.syntax.kind() { | ||
698 | BLOCK => ElseBranchKind::Block(Block::cast(&self.syntax).unwrap()), | ||
699 | IF_EXPR => ElseBranchKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()), | ||
700 | _ => unreachable!(), | ||
701 | } | ||
702 | } | ||
703 | } | ||
704 | |||
705 | impl ElseBranch {} | ||
706 | |||
663 | // EnumDef | 707 | // EnumDef |
664 | #[derive(Debug, PartialEq, Eq, Hash)] | 708 | #[derive(Debug, PartialEq, Eq, Hash)] |
665 | #[repr(transparent)] | 709 | #[repr(transparent)] |