aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/expr_extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/expr_extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs32
1 files changed, 11 insertions, 21 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 40c8fca3b..93aa3d45f 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -1,7 +1,7 @@
1//! Various extension methods to ast Expr Nodes, which are hard to code-generate. 1//! Various extension methods to ast Expr Nodes, which are hard to code-generate.
2 2
3use crate::{ 3use crate::{
4 ast::{self, child_opt, children, AstChildren, AstNode}, 4 ast::{self, support, AstChildren, AstNode},
5 SmolStr, 5 SmolStr,
6 SyntaxKind::*, 6 SyntaxKind::*,
7 SyntaxToken, T, 7 SyntaxToken, T,
@@ -36,7 +36,7 @@ impl ast::IfExpr {
36 let res = match self.blocks().nth(1) { 36 let res = match self.blocks().nth(1) {
37 Some(block) => ElseBranch::Block(block), 37 Some(block) => ElseBranch::Block(block),
38 None => { 38 None => {
39 let elif: ast::IfExpr = child_opt(self)?; 39 let elif: ast::IfExpr = support::child(self.syntax())?;
40 ElseBranch::IfExpr(elif) 40 ElseBranch::IfExpr(elif)
41 } 41 }
42 }; 42 };
@@ -44,17 +44,7 @@ impl ast::IfExpr {
44 } 44 }
45 45
46 fn blocks(&self) -> AstChildren<ast::BlockExpr> { 46 fn blocks(&self) -> AstChildren<ast::BlockExpr> {
47 children(self) 47 support::children(self.syntax())
48 }
49}
50
51impl ast::RefExpr {
52 pub fn is_mut(&self) -> bool {
53 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
54 }
55
56 pub fn raw_token(&self) -> Option<SyntaxToken> {
57 None // FIXME: implement &raw
58 } 48 }
59} 49}
60 50
@@ -212,15 +202,15 @@ impl ast::BinExpr {
212 } 202 }
213 203
214 pub fn lhs(&self) -> Option<ast::Expr> { 204 pub fn lhs(&self) -> Option<ast::Expr> {
215 children(self).next() 205 support::children(self.syntax()).next()
216 } 206 }
217 207
218 pub fn rhs(&self) -> Option<ast::Expr> { 208 pub fn rhs(&self) -> Option<ast::Expr> {
219 children(self).nth(1) 209 support::children(self.syntax()).nth(1)
220 } 210 }
221 211
222 pub fn sub_exprs(&self) -> (Option<ast::Expr>, Option<ast::Expr>) { 212 pub fn sub_exprs(&self) -> (Option<ast::Expr>, Option<ast::Expr>) {
223 let mut children = children(self); 213 let mut children = support::children(self.syntax());
224 let first = children.next(); 214 let first = children.next();
225 let second = children.next(); 215 let second = children.next();
226 (first, second) 216 (first, second)
@@ -275,10 +265,10 @@ impl ast::RangeExpr {
275 265
276impl ast::IndexExpr { 266impl ast::IndexExpr {
277 pub fn base(&self) -> Option<ast::Expr> { 267 pub fn base(&self) -> Option<ast::Expr> {
278 children(self).next() 268 support::children(self.syntax()).next()
279 } 269 }
280 pub fn index(&self) -> Option<ast::Expr> { 270 pub fn index(&self) -> Option<ast::Expr> {
281 children(self).nth(1) 271 support::children(self.syntax()).nth(1)
282 } 272 }
283} 273}
284 274
@@ -291,11 +281,11 @@ impl ast::ArrayExpr {
291 pub fn kind(&self) -> ArrayExprKind { 281 pub fn kind(&self) -> ArrayExprKind {
292 if self.is_repeat() { 282 if self.is_repeat() {
293 ArrayExprKind::Repeat { 283 ArrayExprKind::Repeat {
294 initializer: children(self).next(), 284 initializer: support::children(self.syntax()).next(),
295 repeat: children(self).nth(1), 285 repeat: support::children(self.syntax()).nth(1),
296 } 286 }
297 } else { 287 } else {
298 ArrayExprKind::ElementList(children(self)) 288 ArrayExprKind::ElementList(support::children(self.syntax()))
299 } 289 }
300 } 290 }
301 291