diff options
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/ast/make.rs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 2cf436e7a..b1578820f 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -110,8 +110,16 @@ pub fn record_expr_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::Re | |||
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | pub fn record_field(name: ast::NameRef, ty: ast::Type) -> ast::RecordField { | 113 | pub fn record_field( |
114 | ast_from_text(&format!("struct S {{ {}: {}, }}", name, ty)) | 114 | visibility: Option<ast::Visibility>, |
115 | name: ast::Name, | ||
116 | ty: ast::Type, | ||
117 | ) -> ast::RecordField { | ||
118 | let visibility = match visibility { | ||
119 | None => String::new(), | ||
120 | Some(it) => format!("{} ", it), | ||
121 | }; | ||
122 | ast_from_text(&format!("struct S {{ {}{}: {}, }}", visibility, name, ty)) | ||
115 | } | 123 | } |
116 | 124 | ||
117 | pub fn block_expr( | 125 | pub fn block_expr( |
@@ -360,6 +368,13 @@ pub fn tuple_field_list(fields: impl IntoIterator<Item = ast::TupleField>) -> as | |||
360 | ast_from_text(&format!("struct f({});", fields)) | 368 | ast_from_text(&format!("struct f({});", fields)) |
361 | } | 369 | } |
362 | 370 | ||
371 | pub fn record_field_list( | ||
372 | fields: impl IntoIterator<Item = ast::RecordField>, | ||
373 | ) -> ast::RecordFieldList { | ||
374 | let fields = fields.into_iter().join(", "); | ||
375 | ast_from_text(&format!("struct f {{ {} }}", fields)) | ||
376 | } | ||
377 | |||
363 | pub fn tuple_field(visibility: Option<ast::Visibility>, ty: ast::Type) -> ast::TupleField { | 378 | pub fn tuple_field(visibility: Option<ast::Visibility>, ty: ast::Type) -> ast::TupleField { |
364 | let visibility = match visibility { | 379 | let visibility = match visibility { |
365 | None => String::new(), | 380 | None => String::new(), |
@@ -368,6 +383,14 @@ pub fn tuple_field(visibility: Option<ast::Visibility>, ty: ast::Type) -> ast::T | |||
368 | ast_from_text(&format!("struct f({}{});", visibility, ty)) | 383 | ast_from_text(&format!("struct f({}{});", visibility, ty)) |
369 | } | 384 | } |
370 | 385 | ||
386 | pub fn variant(name: ast::Name, field_list: Option<ast::FieldList>) -> ast::Variant { | ||
387 | let field_list = match field_list { | ||
388 | None => String::new(), | ||
389 | Some(it) => format!("{}", it), | ||
390 | }; | ||
391 | ast_from_text(&format!("enum f {{ {}{} }}", name, field_list)) | ||
392 | } | ||
393 | |||
371 | pub fn fn_( | 394 | pub fn fn_( |
372 | visibility: Option<ast::Visibility>, | 395 | visibility: Option<ast::Visibility>, |
373 | fn_name: ast::Name, | 396 | fn_name: ast::Name, |