diff options
Diffstat (limited to 'crates/syntax/src/ast/make.rs')
-rw-r--r-- | crates/syntax/src/ast/make.rs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 05a6b0b25..810c8d4c8 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -174,6 +174,11 @@ pub fn block_expr( | |||
174 | pub fn expr_unit() -> ast::Expr { | 174 | pub fn expr_unit() -> ast::Expr { |
175 | expr_from_text("()") | 175 | expr_from_text("()") |
176 | } | 176 | } |
177 | pub fn expr_literal(text: &str) -> ast::Literal { | ||
178 | assert_eq!(text.trim(), text); | ||
179 | ast_from_text(&format!("fn f() {{ let _ = {}; }}", text)) | ||
180 | } | ||
181 | |||
177 | pub fn expr_empty_block() -> ast::Expr { | 182 | pub fn expr_empty_block() -> ast::Expr { |
178 | expr_from_text("{}") | 183 | expr_from_text("{}") |
179 | } | 184 | } |
@@ -390,6 +395,7 @@ pub fn token(kind: SyntaxKind) -> SyntaxToken { | |||
390 | tokens::SOURCE_FILE | 395 | tokens::SOURCE_FILE |
391 | .tree() | 396 | .tree() |
392 | .syntax() | 397 | .syntax() |
398 | .clone_for_update() | ||
393 | .descendants_with_tokens() | 399 | .descendants_with_tokens() |
394 | .filter_map(|it| it.into_token()) | 400 | .filter_map(|it| it.into_token()) |
395 | .find(|it| it.kind() == kind) | 401 | .find(|it| it.kind() == kind) |
@@ -544,6 +550,7 @@ pub mod tokens { | |||
544 | SOURCE_FILE | 550 | SOURCE_FILE |
545 | .tree() | 551 | .tree() |
546 | .syntax() | 552 | .syntax() |
553 | .clone_for_update() | ||
547 | .descendants_with_tokens() | 554 | .descendants_with_tokens() |
548 | .filter_map(|it| it.into_token()) | 555 | .filter_map(|it| it.into_token()) |
549 | .find(|it| it.kind() == WHITESPACE && it.text() == " ") | 556 | .find(|it| it.kind() == WHITESPACE && it.text() == " ") |
@@ -569,13 +576,16 @@ pub mod tokens { | |||
569 | } | 576 | } |
570 | 577 | ||
571 | pub fn single_newline() -> SyntaxToken { | 578 | pub fn single_newline() -> SyntaxToken { |
572 | SOURCE_FILE | 579 | let res = SOURCE_FILE |
573 | .tree() | 580 | .tree() |
574 | .syntax() | 581 | .syntax() |
582 | .clone_for_update() | ||
575 | .descendants_with_tokens() | 583 | .descendants_with_tokens() |
576 | .filter_map(|it| it.into_token()) | 584 | .filter_map(|it| it.into_token()) |
577 | .find(|it| it.kind() == WHITESPACE && it.text() == "\n") | 585 | .find(|it| it.kind() == WHITESPACE && it.text() == "\n") |
578 | .unwrap() | 586 | .unwrap(); |
587 | res.detach(); | ||
588 | res | ||
579 | } | 589 | } |
580 | 590 | ||
581 | pub fn blank_line() -> SyntaxToken { | 591 | pub fn blank_line() -> SyntaxToken { |