aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs33
-rw-r--r--crates/ra_syntax/src/grammar.ron2
-rw-r--r--crates/ra_syntax/src/syntax_text.rs16
3 files changed, 37 insertions, 14 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)]
180pub struct AwaitExpr {
181 pub(crate) syntax: SyntaxNode,
182}
183
184impl 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
198impl 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)]
180pub struct BinExpr { 206pub struct BinExpr {
@@ -566,7 +592,7 @@ pub struct Expr {
566impl AstNode for Expr { 592impl 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 {
669impl From<FieldExpr> for Expr { 696impl 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}
699impl From<AwaitExpr> for Expr {
700 fn from(n: AwaitExpr) -> Expr { Expr { syntax: n.syntax } }
701}
672impl From<TryExpr> for Expr { 702impl 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",
diff --git a/crates/ra_syntax/src/syntax_text.rs b/crates/ra_syntax/src/syntax_text.rs
index f8ddff48e..652cb7a1e 100644
--- a/crates/ra_syntax/src/syntax_text.rs
+++ b/crates/ra_syntax/src/syntax_text.rs
@@ -57,25 +57,15 @@ impl SyntaxText {
57 } 57 }
58 } 58 }
59 59
60 pub fn push_to(&self, buf: &mut String) {
61 self.for_each_chunk(|chunk| buf.push_str(chunk))
62 }
63
64 pub fn to_string(&self) -> String {
65 let mut buf = String::new();
66 self.push_to(&mut buf);
67 buf
68 }
69
70 pub fn to_smol_string(&self) -> SmolStr { 60 pub fn to_smol_string(&self) -> SmolStr {
71 self.to_string().into() 61 self.to_string().into()
72 } 62 }
73 63
74 pub fn contains(&self, c: char) -> bool { 64 pub fn contains_char(&self, c: char) -> bool {
75 self.try_for_each_chunk(|chunk| if chunk.contains(c) { Err(()) } else { Ok(()) }).is_err() 65 self.try_for_each_chunk(|chunk| if chunk.contains(c) { Err(()) } else { Ok(()) }).is_err()
76 } 66 }
77 67
78 pub fn find(&self, c: char) -> Option<TextUnit> { 68 pub fn find_char(&self, c: char) -> Option<TextUnit> {
79 let mut acc: TextUnit = 0.into(); 69 let mut acc: TextUnit = 0.into();
80 let res = self.try_for_each_chunk(|chunk| { 70 let res = self.try_for_each_chunk(|chunk| {
81 if let Some(pos) = chunk.find(c) { 71 if let Some(pos) = chunk.find(c) {
@@ -158,7 +148,7 @@ impl fmt::Debug for SyntaxText {
158 148
159impl fmt::Display for SyntaxText { 149impl fmt::Display for SyntaxText {
160 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 150 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
161 fmt::Display::fmt(&self.to_string(), f) 151 self.try_for_each_chunk(|chunk| fmt::Display::fmt(chunk, f))
162 } 152 }
163} 153}
164 154