aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorAndrey Tkachenko <[email protected]>2019-06-06 12:36:16 +0100
committerAndrey Tkachenko <[email protected]>2019-06-06 12:43:26 +0100
commit281c9eeaff8eac4e666089f80f67cf684e1d001b (patch)
treed5d315543cfc7aa47db24aafec3b98df3754ddb3 /crates/ra_syntax/src/ast
parentb79e6294a68fd41f0a3dbd9eb907dfe99646d77e (diff)
[#1083] Try block syntax
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs37
-rw-r--r--crates/ra_syntax/src/ast/traits.rs6
2 files changed, 43 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index e73fe22e9..1d888e709 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -713,6 +713,7 @@ pub enum ExprKind<'a> {
713 MethodCallExpr(&'a MethodCallExpr), 713 MethodCallExpr(&'a MethodCallExpr),
714 FieldExpr(&'a FieldExpr), 714 FieldExpr(&'a FieldExpr),
715 TryExpr(&'a TryExpr), 715 TryExpr(&'a TryExpr),
716 TryBlockExpr(&'a TryBlockExpr),
716 CastExpr(&'a CastExpr), 717 CastExpr(&'a CastExpr),
717 RefExpr(&'a RefExpr), 718 RefExpr(&'a RefExpr),
718 PrefixExpr(&'a PrefixExpr), 719 PrefixExpr(&'a PrefixExpr),
@@ -826,6 +827,11 @@ impl<'a> From<&'a TryExpr> for &'a Expr {
826 Expr::cast(&n.syntax).unwrap() 827 Expr::cast(&n.syntax).unwrap()
827 } 828 }
828} 829}
830impl<'a> From<&'a TryBlockExpr> for &'a Expr {
831 fn from(n: &'a TryBlockExpr) -> &'a Expr {
832 Expr::cast(&n.syntax).unwrap()
833 }
834}
829impl<'a> From<&'a CastExpr> for &'a Expr { 835impl<'a> From<&'a CastExpr> for &'a Expr {
830 fn from(n: &'a CastExpr) -> &'a Expr { 836 fn from(n: &'a CastExpr) -> &'a Expr {
831 Expr::cast(&n.syntax).unwrap() 837 Expr::cast(&n.syntax).unwrap()
@@ -887,6 +893,7 @@ impl AstNode for Expr {
887 | METHOD_CALL_EXPR 893 | METHOD_CALL_EXPR
888 | FIELD_EXPR 894 | FIELD_EXPR
889 | TRY_EXPR 895 | TRY_EXPR
896 | TRY_BLOCK_EXPR
890 | CAST_EXPR 897 | CAST_EXPR
891 | REF_EXPR 898 | REF_EXPR
892 | PREFIX_EXPR 899 | PREFIX_EXPR
@@ -929,6 +936,7 @@ impl Expr {
929 METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()), 936 METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(&self.syntax).unwrap()),
930 FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()), 937 FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(&self.syntax).unwrap()),
931 TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()), 938 TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(&self.syntax).unwrap()),
939 TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(&self.syntax).unwrap()),
932 CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()), 940 CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(&self.syntax).unwrap()),
933 REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()), 941 REF_EXPR => ExprKind::RefExpr(RefExpr::cast(&self.syntax).unwrap()),
934 PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()), 942 PREFIX_EXPR => ExprKind::PrefixExpr(PrefixExpr::cast(&self.syntax).unwrap()),
@@ -3672,6 +3680,35 @@ impl TraitDef {
3672 } 3680 }
3673} 3681}
3674 3682
3683// TryBlockExpr
3684#[derive(Debug, PartialEq, Eq, Hash)]
3685#[repr(transparent)]
3686pub struct TryBlockExpr {
3687 pub(crate) syntax: SyntaxNode,
3688}
3689unsafe impl TransparentNewType for TryBlockExpr {
3690 type Repr = rowan::SyntaxNode;
3691}
3692
3693impl AstNode for TryBlockExpr {
3694 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
3695 match syntax.kind() {
3696 TRY_BLOCK_EXPR => Some(TryBlockExpr::from_repr(syntax.into_repr())),
3697 _ => None,
3698 }
3699 }
3700 fn syntax(&self) -> &SyntaxNode { &self.syntax }
3701}
3702
3703impl ToOwned for TryBlockExpr {
3704 type Owned = TreeArc<TryBlockExpr>;
3705 fn to_owned(&self) -> TreeArc<TryBlockExpr> { TreeArc::cast(self.syntax.to_owned()) }
3706}
3707
3708
3709impl ast::TryBlockBodyOwner for TryBlockExpr {}
3710impl TryBlockExpr {}
3711
3675// TryExpr 3712// TryExpr
3676#[derive(Debug, PartialEq, Eq, Hash)] 3713#[derive(Debug, PartialEq, Eq, Hash)]
3677#[repr(transparent)] 3714#[repr(transparent)]
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index 1c90cf148..433485400 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -33,6 +33,12 @@ pub trait LoopBodyOwner: AstNode {
33 } 33 }
34} 34}
35 35
36pub trait TryBlockBodyOwner: AstNode {
37 fn try_body(&self) -> Option<&ast::Block> {
38 child_opt(self)
39 }
40}
41
36pub trait ArgListOwner: AstNode { 42pub trait ArgListOwner: AstNode {
37 fn arg_list(&self) -> Option<&ast::ArgList> { 43 fn arg_list(&self) -> Option<&ast::ArgList> {
38 child_opt(self) 44 child_opt(self)