aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r--crates/syntax/src/ast/make.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index 876659a2b..cc09b77a5 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -171,8 +171,17 @@ pub fn expr_return() -> ast::Expr {
171pub fn expr_match(expr: ast::Expr, match_arm_list: ast::MatchArmList) -> ast::Expr { 171pub fn expr_match(expr: ast::Expr, match_arm_list: ast::MatchArmList) -> ast::Expr {
172 expr_from_text(&format!("match {} {}", expr, match_arm_list)) 172 expr_from_text(&format!("match {} {}", expr, match_arm_list))
173} 173}
174pub fn expr_if(condition: ast::Condition, then_branch: ast::BlockExpr) -> ast::Expr { 174pub fn expr_if(
175 expr_from_text(&format!("if {} {}", condition, then_branch)) 175 condition: ast::Condition,
176 then_branch: ast::BlockExpr,
177 else_branch: Option<ast::ElseBranch>,
178) -> ast::Expr {
179 let else_branch = match else_branch {
180 Some(ast::ElseBranch::Block(block)) => format!("else {}", block),
181 Some(ast::ElseBranch::IfExpr(if_expr)) => format!("else {}", if_expr),
182 None => String::new(),
183 };
184 expr_from_text(&format!("if {} {} {}", condition, then_branch, else_branch))
176} 185}
177pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { 186pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr {
178 let token = token(op); 187 let token = token(op);