diff options
author | Unreal Hoang <[email protected]> | 2019-07-20 11:35:49 +0100 |
---|---|---|
committer | Unreal Hoang <[email protected]> | 2019-07-20 11:35:49 +0100 |
commit | 5ac9f5cdc7a88dcb9545d2e150780c8edee83b06 (patch) | |
tree | 7893e33a7b7cf986b14d60fd1cf50c03d2403a24 /crates | |
parent | 2830d1376b05794c7bf1467fe52ad3bc0eb4ca41 (diff) |
add await expr to ast
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/expr.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 33 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 2 |
4 files changed, 45 insertions, 1 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 66cb9633b..7e3e0a07d 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs | |||
@@ -220,6 +220,9 @@ pub enum Expr { | |||
220 | expr: ExprId, | 220 | expr: ExprId, |
221 | name: Name, | 221 | name: Name, |
222 | }, | 222 | }, |
223 | Await { | ||
224 | expr: ExprId, | ||
225 | }, | ||
223 | Try { | 226 | Try { |
224 | expr: ExprId, | 227 | expr: ExprId, |
225 | }, | 228 | }, |
@@ -359,6 +362,7 @@ impl Expr { | |||
359 | f(*rhs); | 362 | f(*rhs); |
360 | } | 363 | } |
361 | Expr::Field { expr, .. } | 364 | Expr::Field { expr, .. } |
365 | | Expr::Await { expr } | ||
362 | | Expr::Try { expr } | 366 | | Expr::Try { expr } |
363 | | Expr::Cast { expr, .. } | 367 | | Expr::Cast { expr, .. } |
364 | | Expr::Ref { expr, .. } | 368 | | Expr::Ref { expr, .. } |
@@ -729,6 +733,10 @@ where | |||
729 | }; | 733 | }; |
730 | self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) | 734 | self.alloc_expr(Expr::Field { expr, name }, syntax_ptr) |
731 | } | 735 | } |
736 | ast::ExprKind::AwaitExpr(e) => { | ||
737 | let expr = self.collect_expr_opt(e.expr()); | ||
738 | self.alloc_expr(Expr::Await { expr }, syntax_ptr) | ||
739 | } | ||
732 | ast::ExprKind::TryExpr(e) => { | 740 | ast::ExprKind::TryExpr(e) => { |
733 | let expr = self.collect_expr_opt(e.expr()); | 741 | let expr = self.collect_expr_opt(e.expr()); |
734 | self.alloc_expr(Expr::Try { expr }, syntax_ptr) | 742 | self.alloc_expr(Expr::Try { expr }, syntax_ptr) |
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 0e030576d..6eae595a9 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -1114,6 +1114,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
1114 | .unwrap_or(Ty::Unknown); | 1114 | .unwrap_or(Ty::Unknown); |
1115 | self.insert_type_vars(ty) | 1115 | self.insert_type_vars(ty) |
1116 | } | 1116 | } |
1117 | Expr::Await { .. } => { | ||
1118 | Ty::Unknown | ||
1119 | } | ||
1117 | Expr::Try { expr } => { | 1120 | Expr::Try { expr } => { |
1118 | let inner_ty = self.infer_expr(*expr, &Expectation::none()); | 1121 | let inner_ty = self.infer_expr(*expr, &Expectation::none()); |
1119 | let ty = match self.resolve_ops_try_ok() { | 1122 | let ty = match self.resolve_ops_try_ok() { |
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 99fcdbd9a..da8cf4ae8 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -175,6 +175,32 @@ impl Attr { | |||
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | // AwaitExpr | ||
179 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
180 | pub struct AwaitExpr { | ||
181 | pub(crate) syntax: SyntaxNode, | ||
182 | } | ||
183 | |||
184 | impl AstNode for AwaitExpr { | ||
185 | fn can_cast(kind: SyntaxKind) -> bool { | ||
186 | match kind { | ||
187 | AWAIT_EXPR => true, | ||
188 | _ => false, | ||
189 | } | ||
190 | } | ||
191 | fn cast(syntax: SyntaxNode) -> Option<Self> { | ||
192 | if Self::can_cast(syntax.kind()) { Some(AwaitExpr { syntax }) } else { None } | ||
193 | } | ||
194 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
195 | } | ||
196 | |||
197 | |||
198 | impl AwaitExpr { | ||
199 | pub fn expr(&self) -> Option<Expr> { | ||
200 | super::child_opt(self) | ||
201 | } | ||
202 | } | ||
203 | |||
178 | // BinExpr | 204 | // BinExpr |
179 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 205 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
180 | pub struct BinExpr { | 206 | pub struct BinExpr { |
@@ -566,7 +592,7 @@ pub struct Expr { | |||
566 | impl AstNode for Expr { | 592 | impl AstNode for Expr { |
567 | fn can_cast(kind: SyntaxKind) -> bool { | 593 | fn can_cast(kind: SyntaxKind) -> bool { |
568 | match kind { | 594 | match kind { |
569 | | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true, | 595 | | TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true, |
570 | _ => false, | 596 | _ => false, |
571 | } | 597 | } |
572 | } | 598 | } |
@@ -599,6 +625,7 @@ pub enum ExprKind { | |||
599 | IndexExpr(IndexExpr), | 625 | IndexExpr(IndexExpr), |
600 | MethodCallExpr(MethodCallExpr), | 626 | MethodCallExpr(MethodCallExpr), |
601 | FieldExpr(FieldExpr), | 627 | FieldExpr(FieldExpr), |
628 | AwaitExpr(AwaitExpr), | ||
602 | TryExpr(TryExpr), | 629 | TryExpr(TryExpr), |
603 | TryBlockExpr(TryBlockExpr), | 630 | TryBlockExpr(TryBlockExpr), |
604 | CastExpr(CastExpr), | 631 | CastExpr(CastExpr), |
@@ -669,6 +696,9 @@ impl From<MethodCallExpr> for Expr { | |||
669 | impl From<FieldExpr> for Expr { | 696 | impl From<FieldExpr> for Expr { |
670 | fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } } | 697 | fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } } |
671 | } | 698 | } |
699 | impl From<AwaitExpr> for Expr { | ||
700 | fn from(n: AwaitExpr) -> Expr { Expr { syntax: n.syntax } } | ||
701 | } | ||
672 | impl From<TryExpr> for Expr { | 702 | impl From<TryExpr> for Expr { |
673 | fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } } | 703 | fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } } |
674 | } | 704 | } |
@@ -719,6 +749,7 @@ impl Expr { | |||
719 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(self.syntax.clone()).unwrap()), | 749 | INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(self.syntax.clone()).unwrap()), |
720 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(self.syntax.clone()).unwrap()), | 750 | METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(self.syntax.clone()).unwrap()), |
721 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(self.syntax.clone()).unwrap()), | 751 | FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(self.syntax.clone()).unwrap()), |
752 | AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr::cast(self.syntax.clone()).unwrap()), | ||
722 | TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(self.syntax.clone()).unwrap()), | 753 | TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(self.syntax.clone()).unwrap()), |
723 | TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(self.syntax.clone()).unwrap()), | 754 | TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(self.syntax.clone()).unwrap()), |
724 | CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(self.syntax.clone()).unwrap()), | 755 | CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(self.syntax.clone()).unwrap()), |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 55494239e..817dedfbf 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -477,6 +477,7 @@ Grammar( | |||
477 | ), | 477 | ), |
478 | "IndexExpr": (), | 478 | "IndexExpr": (), |
479 | "FieldExpr": (options: ["Expr", "NameRef"]), | 479 | "FieldExpr": (options: ["Expr", "NameRef"]), |
480 | "AwaitExpr": (options: ["Expr"]), | ||
480 | "TryExpr": (options: ["Expr"]), | 481 | "TryExpr": (options: ["Expr"]), |
481 | "CastExpr": (options: ["Expr", "TypeRef"]), | 482 | "CastExpr": (options: ["Expr", "TypeRef"]), |
482 | "RefExpr": (options: ["Expr"]), | 483 | "RefExpr": (options: ["Expr"]), |
@@ -508,6 +509,7 @@ Grammar( | |||
508 | "IndexExpr", | 509 | "IndexExpr", |
509 | "MethodCallExpr", | 510 | "MethodCallExpr", |
510 | "FieldExpr", | 511 | "FieldExpr", |
512 | "AwaitExpr", | ||
511 | "TryExpr", | 513 | "TryExpr", |
512 | "TryBlockExpr", | 514 | "TryBlockExpr", |
513 | "CastExpr", | 515 | "CastExpr", |