diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/make.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/make.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 287a40bee..00422ea91 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -128,6 +128,14 @@ pub fn where_clause(preds: impl Iterator<Item = ast::WherePred>) -> ast::WhereCl | |||
128 | } | 128 | } |
129 | } | 129 | } |
130 | 130 | ||
131 | pub fn if_expression(condition: &ast::Expr, statement: &str) -> ast::IfExpr { | ||
132 | return ast_from_text(&format!( | ||
133 | "fn f() {{ if !{} {{\n {}\n}}\n}}", | ||
134 | condition.syntax().text(), | ||
135 | statement | ||
136 | )); | ||
137 | } | ||
138 | |||
131 | fn ast_from_text<N: AstNode>(text: &str) -> N { | 139 | fn ast_from_text<N: AstNode>(text: &str) -> N { |
132 | let parse = SourceFile::parse(text); | 140 | let parse = SourceFile::parse(text); |
133 | let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); | 141 | let res = parse.tree().syntax().descendants().find_map(N::cast).unwrap(); |
@@ -160,6 +168,12 @@ pub mod tokens { | |||
160 | .unwrap() | 168 | .unwrap() |
161 | } | 169 | } |
162 | 170 | ||
171 | pub fn whitespace(text: &str) -> SyntaxToken { | ||
172 | assert!(text.trim().is_empty()); | ||
173 | let sf = SourceFile::parse(text).ok().unwrap(); | ||
174 | sf.syntax().first_child_or_token().unwrap().into_token().unwrap() | ||
175 | } | ||
176 | |||
163 | pub fn single_newline() -> SyntaxToken { | 177 | pub fn single_newline() -> SyntaxToken { |
164 | SOURCE_FILE | 178 | SOURCE_FILE |
165 | .tree() | 179 | .tree() |