aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src
diff options
context:
space:
mode:
authordragfire <[email protected]>2020-08-23 21:30:07 +0100
committerdragfire <[email protected]>2020-08-24 05:30:34 +0100
commit1d129a7172bbe502182be6cc3b50b3250cb6f3a9 (patch)
tree7b9e694ab43ffebde2a39c4e99d5b2a6c774a005 /crates/syntax/src
parente65d48d1fb3d4d91d9dc1148a7a836ff5c9a3c87 (diff)
Invert if should be smart about is_some, is_none, is_ok, is_err
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/ast/make.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs
index d20c085aa..7958721e2 100644
--- a/crates/syntax/src/ast/make.rs
+++ b/crates/syntax/src/ast/make.rs
@@ -7,7 +7,7 @@
7use itertools::Itertools; 7use itertools::Itertools;
8use stdx::format_to; 8use stdx::format_to;
9 9
10use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken}; 10use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxText, SyntaxToken};
11 11
12pub fn name(text: &str) -> ast::Name { 12pub fn name(text: &str) -> ast::Name {
13 ast_from_text(&format!("mod {};", text)) 13 ast_from_text(&format!("mod {};", text))
@@ -137,6 +137,12 @@ pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr {
137pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr { 137pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr {
138 expr_from_text(&format!("{}{}", f, arg_list)) 138 expr_from_text(&format!("{}{}", f, arg_list))
139} 139}
140pub fn expr_method_call<F>(text: &str, caller: F) -> Option<ast::Expr>
141where
142 F: FnOnce() -> Option<SyntaxText>,
143{
144 try_expr_from_text(&format!("{}.{}()", caller()?, text))
145}
140fn expr_from_text(text: &str) -> ast::Expr { 146fn expr_from_text(text: &str) -> ast::Expr {
141 ast_from_text(&format!("const C: () = {};", text)) 147 ast_from_text(&format!("const C: () = {};", text))
142} 148}