diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-03-27 10:38:31 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-03-27 10:38:31 +0000 |
commit | f9cf86475c042a41f2e3b59baf96b456e0ff521b (patch) | |
tree | 983e95c067bf9d8b81240576924cae0357d07185 /crates/ra_syntax/src/ast | |
parent | 31528620a8fca9ea79947d53b796460d0928dd95 (diff) | |
parent | cbb53cf55ca350bbcada5fc759b0119d932e879d (diff) |
Merge #3741
3741: More general ctor for ifs r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 2cc9ff153..69bacf224 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -108,7 +108,7 @@ pub fn expr_return() -> ast::Expr { | |||
108 | pub fn expr_match(expr: ast::Expr, match_arm_list: ast::MatchArmList) -> ast::Expr { | 108 | pub fn expr_match(expr: ast::Expr, match_arm_list: ast::MatchArmList) -> ast::Expr { |
109 | expr_from_text(&format!("match {} {}", expr, match_arm_list)) | 109 | expr_from_text(&format!("match {} {}", expr, match_arm_list)) |
110 | } | 110 | } |
111 | pub fn expr_if(condition: ast::Expr, then_branch: ast::BlockExpr) -> ast::Expr { | 111 | pub fn expr_if(condition: ast::Condition, then_branch: ast::BlockExpr) -> ast::Expr { |
112 | expr_from_text(&format!("if {} {}", condition, then_branch)) | 112 | expr_from_text(&format!("if {} {}", condition, then_branch)) |
113 | } | 113 | } |
114 | pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { | 114 | pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { |
@@ -123,6 +123,15 @@ pub fn try_expr_from_text(text: &str) -> Option<ast::Expr> { | |||
123 | try_ast_from_text(&format!("const C: () = {};", text)) | 123 | try_ast_from_text(&format!("const C: () = {};", text)) |
124 | } | 124 | } |
125 | 125 | ||
126 | pub fn condition(expr: ast::Expr, pattern: Option<ast::Pat>) -> ast::Condition { | ||
127 | match pattern { | ||
128 | None => ast_from_text(&format!("const _: () = while {} {{}};", expr)), | ||
129 | Some(pattern) => { | ||
130 | ast_from_text(&format!("const _: () = while {} = {} {{}};", pattern, expr)) | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
126 | pub fn bind_pat(name: ast::Name) -> ast::BindPat { | 135 | pub fn bind_pat(name: ast::Name) -> ast::BindPat { |
127 | return from_text(name.text()); | 136 | return from_text(name.text()); |
128 | 137 | ||