aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-26 21:23:07 +0000
committerAleksey Kladov <[email protected]>2019-01-26 21:37:11 +0000
commit619af1e22cb71b981fde4cedbf6ebce9b3488028 (patch)
treeb99f89f6e652e7f34519ef5f4f8bfeb71694f40d /crates/ra_syntax/src/ast.rs
parent2d337c88b07b6a67b24f4bff4d72025d9ea412a5 (diff)
fix AST for if expressions
then is not always a block...
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r--crates/ra_syntax/src/ast.rs18
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)]
289pub enum ElseBranchFlavor<'a> {
290 Block(&'a Block),
291 IfExpr(&'a IfExpr),
292}
293
288impl IfExpr { 294impl 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 }