From 1d129a7172bbe502182be6cc3b50b3250cb6f3a9 Mon Sep 17 00:00:00 2001 From: dragfire Date: Sun, 23 Aug 2020 14:30:07 -0600 Subject: Invert if should be smart about is_some, is_none, is_ok, is_err --- crates/syntax/src/ast/make.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'crates/syntax') 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 @@ use itertools::Itertools; use stdx::format_to; -use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxToken}; +use crate::{ast, AstNode, SourceFile, SyntaxKind, SyntaxNode, SyntaxText, SyntaxToken}; pub fn name(text: &str) -> ast::Name { ast_from_text(&format!("mod {};", text)) @@ -137,6 +137,12 @@ pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { pub fn expr_call(f: ast::Expr, arg_list: ast::ArgList) -> ast::Expr { expr_from_text(&format!("{}{}", f, arg_list)) } +pub fn expr_method_call(text: &str, caller: F) -> Option +where + F: FnOnce() -> Option, +{ + try_expr_from_text(&format!("{}.{}()", caller()?, text)) +} fn expr_from_text(text: &str) -> ast::Expr { ast_from_text(&format!("const C: () = {};", text)) } -- cgit v1.2.3