diff options
Diffstat (limited to 'crates/syntax/src/ast/make.rs')
-rw-r--r-- | crates/syntax/src/ast/make.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index c2c938ad1..25e8a359d 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -294,6 +294,21 @@ pub fn param_list(pats: impl IntoIterator<Item = ast::Param>) -> ast::ParamList | |||
294 | ast_from_text(&format!("fn f({}) {{ }}", args)) | 294 | ast_from_text(&format!("fn f({}) {{ }}", args)) |
295 | } | 295 | } |
296 | 296 | ||
297 | pub fn generic_param(name: String, ty: Option<ast::TypeBoundList>) -> ast::GenericParam { | ||
298 | let bound = match ty { | ||
299 | Some(it) => format!(": {}", it), | ||
300 | None => String::new(), | ||
301 | }; | ||
302 | ast_from_text(&format!("fn f<{}{}>() {{ }}", name, bound)) | ||
303 | } | ||
304 | |||
305 | pub fn generic_param_list( | ||
306 | pats: impl IntoIterator<Item = ast::GenericParam>, | ||
307 | ) -> ast::GenericParamList { | ||
308 | let args = pats.into_iter().join(", "); | ||
309 | ast_from_text(&format!("fn f<{}>() {{ }}", args)) | ||
310 | } | ||
311 | |||
297 | pub fn visibility_pub_crate() -> ast::Visibility { | 312 | pub fn visibility_pub_crate() -> ast::Visibility { |
298 | ast_from_text("pub(crate) struct S") | 313 | ast_from_text("pub(crate) struct S") |
299 | } | 314 | } |
@@ -339,7 +354,7 @@ pub mod tokens { | |||
339 | use crate::{ast, AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken}; | 354 | use crate::{ast, AstNode, Parse, SourceFile, SyntaxKind::*, SyntaxToken}; |
340 | 355 | ||
341 | pub(super) static SOURCE_FILE: Lazy<Parse<SourceFile>> = | 356 | pub(super) static SOURCE_FILE: Lazy<Parse<SourceFile>> = |
342 | Lazy::new(|| SourceFile::parse("const C: <()>::Item = (1 != 1, 2 == 2, !true)\n;")); | 357 | Lazy::new(|| SourceFile::parse("const C: <()>::Item = (1 != 1, 2 == 2, !true)\n;\n\n")); |
343 | 358 | ||
344 | pub fn single_space() -> SyntaxToken { | 359 | pub fn single_space() -> SyntaxToken { |
345 | SOURCE_FILE | 360 | SOURCE_FILE |
@@ -379,6 +394,16 @@ pub mod tokens { | |||
379 | .unwrap() | 394 | .unwrap() |
380 | } | 395 | } |
381 | 396 | ||
397 | pub fn blank_line() -> SyntaxToken { | ||
398 | SOURCE_FILE | ||
399 | .tree() | ||
400 | .syntax() | ||
401 | .descendants_with_tokens() | ||
402 | .filter_map(|it| it.into_token()) | ||
403 | .find(|it| it.kind() == WHITESPACE && it.text().as_str() == "\n\n") | ||
404 | .unwrap() | ||
405 | } | ||
406 | |||
382 | pub struct WsBuilder(SourceFile); | 407 | pub struct WsBuilder(SourceFile); |
383 | 408 | ||
384 | impl WsBuilder { | 409 | impl WsBuilder { |