aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/ast/make.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index c6a7b99b7..3a588e540 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -133,6 +133,17 @@ pub fn use_(visibility: Option<ast::Visibility>, use_tree: ast::UseTree) -> ast:
133 ast_from_text(&format!("{}use {};", visibility, use_tree)) 133 ast_from_text(&format!("{}use {};", visibility, use_tree))
134} 134}
135 135
136pub fn record_expr(path: ast::Path, fields: ast::RecordExprFieldList) -> ast::RecordExpr {
137 ast_from_text(&format!("fn f() {{ {} {} }}", path, fields))
138}
139
140pub fn record_expr_field_list(
141 fields: impl IntoIterator<Item = ast::RecordExprField>,
142) -> ast::RecordExprFieldList {
143 let fields = fields.into_iter().join(", ");
144 ast_from_text(&format!("fn f() {{ S {{ {} }} }}", fields))
145}
146
136pub fn record_expr_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordExprField { 147pub fn record_expr_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordExprField {
137 return match expr { 148 return match expr {
138 Some(expr) => from_text(&format!("{}: {}", name, expr)), 149 Some(expr) => from_text(&format!("{}: {}", name, expr)),
@@ -325,6 +336,21 @@ pub fn record_pat(path: ast::Path, pats: impl IntoIterator<Item = ast::Pat>) ->
325 } 336 }
326} 337}
327 338
339pub fn record_pat_with_fields(path: ast::Path, fields: ast::RecordPatFieldList) -> ast::RecordPat {
340 ast_from_text(&format!("fn f({} {}: ()))", path, fields))
341}
342
343pub fn record_pat_field_list(
344 fields: impl IntoIterator<Item = ast::RecordPatField>,
345) -> ast::RecordPatFieldList {
346 let fields = fields.into_iter().join(", ");
347 ast_from_text(&format!("fn f(S {{ {} }}: ()))", fields))
348}
349
350pub fn record_pat_field(name_ref: ast::NameRef, pat: ast::Pat) -> ast::RecordPatField {
351 ast_from_text(&format!("fn f(S {{ {}: {} }}: ()))", name_ref, pat))
352}
353
328/// Returns a `BindPat` if the path has just one segment, a `PathPat` otherwise. 354/// Returns a `BindPat` if the path has just one segment, a `PathPat` otherwise.
329pub fn path_pat(path: ast::Path) -> ast::Pat { 355pub fn path_pat(path: ast::Path) -> ast::Pat {
330 return from_text(&path.to_string()); 356 return from_text(&path.to_string());