diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-26 21:41:27 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-26 21:41:27 +0000 |
commit | e40d8d40321b191ee82b8b07910f8a0898c8914c (patch) | |
tree | 7adcdf5fd1a09bdb18776e210a4686342979cbe6 /crates/ra_syntax/src/ast.rs | |
parent | 99b032b0f6b3f718ee9500655f1149dc33eac610 (diff) | |
parent | 619af1e22cb71b981fde4cedbf6ebce9b3488028 (diff) |
Merge #683
683: fix AST for if expressions r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 00c60ebf3..ab3dd1b84 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -285,13 +285,27 @@ impl LetStmt { | |||
285 | } | 285 | } |
286 | } | 286 | } |
287 | 287 | ||
288 | #[derive(Debug, Clone, PartialEq, Eq)] | ||
289 | pub enum ElseBranchFlavor<'a> { | ||
290 | Block(&'a Block), | ||
291 | IfExpr(&'a IfExpr), | ||
292 | } | ||
293 | |||
288 | impl IfExpr { | 294 | impl IfExpr { |
289 | pub fn then_branch(&self) -> Option<&Block> { | 295 | pub fn then_branch(&self) -> Option<&Block> { |
290 | self.blocks().nth(0) | 296 | self.blocks().nth(0) |
291 | } | 297 | } |
292 | pub fn else_branch(&self) -> Option<&Block> { | 298 | pub fn else_branch(&self) -> Option<ElseBranchFlavor> { |
293 | self.blocks().nth(1) | 299 | let res = match self.blocks().nth(1) { |
300 | Some(block) => ElseBranchFlavor::Block(block), | ||
301 | None => { | ||
302 | let elif: &IfExpr = child_opt(self)?; | ||
303 | ElseBranchFlavor::IfExpr(elif) | ||
304 | } | ||
305 | }; | ||
306 | Some(res) | ||
294 | } | 307 | } |
308 | |||
295 | fn blocks(&self) -> AstChildren<Block> { | 309 | fn blocks(&self) -> AstChildren<Block> { |
296 | children(self) | 310 | children(self) |
297 | } | 311 | } |