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.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index b6c5de658..05a6b0b25 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -91,6 +91,10 @@ pub fn path_from_segments(
91 }) 91 })
92} 92}
93 93
94pub fn path_from_text(text: &str) -> ast::Path {
95 ast_from_text(&format!("fn main() {{ let test = {}; }}", text))
96}
97
94pub fn glob_use_tree() -> ast::UseTree { 98pub fn glob_use_tree() -> ast::UseTree {
95 ast_from_text("use *;") 99 ast_from_text("use *;")
96} 100}
@@ -218,6 +222,9 @@ pub fn expr_if(
218 }; 222 };
219 expr_from_text(&format!("if {} {} {}", condition, then_branch, else_branch)) 223 expr_from_text(&format!("if {} {} {}", condition, then_branch, else_branch))
220} 224}
225pub fn expr_for_loop(pat: ast::Pat, expr: ast::Expr, block: ast::BlockExpr) -> ast::Expr {
226 expr_from_text(&format!("for {} in {} {}", pat, expr, block))
227}
221pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { 228pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr {
222 let token = token(op); 229 let token = token(op);
223 expr_from_text(&format!("{}{}", token, expr)) 230 expr_from_text(&format!("{}{}", token, expr))