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/ra_syntax/src | |
parent | 2830d1376b05794c7bf1467fe52ad3bc0eb4ca41 (diff) |
add await expr to ast
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 33 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 2 |
2 files changed, 34 insertions, 1 deletions
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", |