diff options
author | Aleksey Kladov <[email protected]> | 2019-07-18 17:23:05 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-07-19 11:16:24 +0100 |
commit | d402974aa0af6de290245a9d2a69a5d56c4fa610 (patch) | |
tree | df4a0e38e548f9f74592e00a2c5a7d37bab3c4c2 /crates/ra_syntax/src/ast/expr_extensions.rs | |
parent | 58d4983ba5745975446d60f2886d96f8d2adf0f2 (diff) |
migrate ra_syntax to the new rowan API
Diffstat (limited to 'crates/ra_syntax/src/ast/expr_extensions.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/expr_extensions.rs | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 4355e3587..ca1773908 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs | |||
@@ -8,20 +8,20 @@ use crate::{ | |||
8 | }; | 8 | }; |
9 | 9 | ||
10 | #[derive(Debug, Clone, PartialEq, Eq)] | 10 | #[derive(Debug, Clone, PartialEq, Eq)] |
11 | pub enum ElseBranch<'a> { | 11 | pub enum ElseBranch { |
12 | Block(&'a ast::Block), | 12 | Block(ast::Block), |
13 | IfExpr(&'a ast::IfExpr), | 13 | IfExpr(ast::IfExpr), |
14 | } | 14 | } |
15 | 15 | ||
16 | impl ast::IfExpr { | 16 | impl ast::IfExpr { |
17 | pub fn then_branch(&self) -> Option<&ast::Block> { | 17 | pub fn then_branch(&self) -> Option<ast::Block> { |
18 | self.blocks().nth(0) | 18 | self.blocks().nth(0) |
19 | } | 19 | } |
20 | pub fn else_branch(&self) -> Option<ElseBranch> { | 20 | pub fn else_branch(&self) -> Option<ElseBranch> { |
21 | let res = match self.blocks().nth(1) { | 21 | let res = match self.blocks().nth(1) { |
22 | Some(block) => ElseBranch::Block(block), | 22 | Some(block) => ElseBranch::Block(block), |
23 | None => { | 23 | None => { |
24 | let elif: &ast::IfExpr = child_opt(self)?; | 24 | let elif: ast::IfExpr = child_opt(self)?; |
25 | ElseBranch::IfExpr(elif) | 25 | ElseBranch::IfExpr(elif) |
26 | } | 26 | } |
27 | }; | 27 | }; |
@@ -60,7 +60,7 @@ impl ast::PrefixExpr { | |||
60 | } | 60 | } |
61 | 61 | ||
62 | pub fn op_token(&self) -> Option<SyntaxToken> { | 62 | pub fn op_token(&self) -> Option<SyntaxToken> { |
63 | self.syntax().first_child_or_token()?.as_token() | 63 | self.syntax().first_child_or_token()?.as_token().cloned() |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
@@ -132,7 +132,7 @@ pub enum BinOp { | |||
132 | 132 | ||
133 | impl ast::BinExpr { | 133 | impl ast::BinExpr { |
134 | fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { | 134 | fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { |
135 | self.syntax().children_with_tokens().filter_map(|it| it.as_token()).find_map(|c| { | 135 | self.syntax().children_with_tokens().filter_map(|it| it.as_token().cloned()).find_map(|c| { |
136 | match c.kind() { | 136 | match c.kind() { |
137 | T![||] => Some((c, BinOp::BooleanOr)), | 137 | T![||] => Some((c, BinOp::BooleanOr)), |
138 | T![&&] => Some((c, BinOp::BooleanAnd)), | 138 | T![&&] => Some((c, BinOp::BooleanAnd)), |
@@ -178,15 +178,15 @@ impl ast::BinExpr { | |||
178 | self.op_details().map(|t| t.0) | 178 | self.op_details().map(|t| t.0) |
179 | } | 179 | } |
180 | 180 | ||
181 | pub fn lhs(&self) -> Option<&ast::Expr> { | 181 | pub fn lhs(&self) -> Option<ast::Expr> { |
182 | children(self).nth(0) | 182 | children(self).nth(0) |
183 | } | 183 | } |
184 | 184 | ||
185 | pub fn rhs(&self) -> Option<&ast::Expr> { | 185 | pub fn rhs(&self) -> Option<ast::Expr> { |
186 | children(self).nth(1) | 186 | children(self).nth(1) |
187 | } | 187 | } |
188 | 188 | ||
189 | pub fn sub_exprs(&self) -> (Option<&ast::Expr>, Option<&ast::Expr>) { | 189 | pub fn sub_exprs(&self) -> (Option<ast::Expr>, Option<ast::Expr>) { |
190 | let mut children = children(self); | 190 | let mut children = children(self); |
191 | let first = children.next(); | 191 | let first = children.next(); |
192 | let second = children.next(); | 192 | let second = children.next(); |
@@ -194,9 +194,9 @@ impl ast::BinExpr { | |||
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | pub enum ArrayExprKind<'a> { | 197 | pub enum ArrayExprKind { |
198 | Repeat { initializer: Option<&'a ast::Expr>, repeat: Option<&'a ast::Expr> }, | 198 | Repeat { initializer: Option<ast::Expr>, repeat: Option<ast::Expr> }, |
199 | ElementList(AstChildren<'a, ast::Expr>), | 199 | ElementList(AstChildren<ast::Expr>), |
200 | } | 200 | } |
201 | 201 | ||
202 | impl ast::ArrayExpr { | 202 | impl ast::ArrayExpr { |
@@ -275,12 +275,12 @@ impl ast::Literal { | |||
275 | #[test] | 275 | #[test] |
276 | fn test_literal_with_attr() { | 276 | fn test_literal_with_attr() { |
277 | let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#); | 277 | let parse = ast::SourceFile::parse(r#"const _: &str = { #[attr] "Hello" };"#); |
278 | let lit = parse.tree.syntax().descendants().find_map(ast::Literal::cast).unwrap(); | 278 | let lit = parse.tree().syntax().descendants().find_map(ast::Literal::cast).unwrap(); |
279 | assert_eq!(lit.token().text(), r#""Hello""#); | 279 | assert_eq!(lit.token().text(), r#""Hello""#); |
280 | } | 280 | } |
281 | 281 | ||
282 | impl ast::NamedField { | 282 | impl ast::NamedField { |
283 | pub fn parent_struct_lit(&self) -> &ast::StructLit { | 283 | pub fn parent_struct_lit(&self) -> ast::StructLit { |
284 | self.syntax().ancestors().find_map(ast::StructLit::cast).unwrap() | 284 | self.syntax().ancestors().find_map(ast::StructLit::cast).unwrap() |
285 | } | 285 | } |
286 | } | 286 | } |