From 1e9a3233f753e1e4de6a56e84e46d1811526ddd9 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 4 Mar 2020 01:13:20 +0800 Subject: Move pub function first --- crates/ra_hir_expand/src/eager.rs | 48 +++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir_expand/src/eager.rs b/crates/ra_hir_expand/src/eager.rs index b2b54ba2b..7fcdfab5a 100644 --- a/crates/ra_hir_expand/src/eager.rs +++ b/crates/ra_hir_expand/src/eager.rs @@ -29,6 +29,30 @@ use ra_parser::FragmentKind; use ra_syntax::{algo::replace_descendants, SyntaxElement, SyntaxNode}; use std::{collections::HashMap, sync::Arc}; +pub fn expand_eager_macro( + db: &impl AstDatabase, + macro_call: InFile, + def: MacroDefId, + resolver: &dyn Fn(ast::Path) -> Option, +) -> Option { + let args = macro_call.value.token_tree()?; + let parsed_args = mbe::ast_to_token_tree(&args)?.0; + let parsed_args = mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr).ok()?.0; + let result = eager_macro_recur(db, macro_call.with_value(parsed_args.syntax_node()), resolver)?; + + let subtree = to_subtree(&result)?; + + if let MacroDefKind::BuiltInEager(eager) = def.kind { + let (subtree, fragment) = eager.expand(&subtree).ok()?; + let eager = + EagerCallLoc { def, fragment, subtree: Arc::new(subtree), file_id: macro_call.file_id }; + + Some(db.intern_eager_expansion(eager)) + } else { + None + } +} + fn to_subtree(node: &SyntaxNode) -> Option { let mut subtree = mbe::syntax_node_to_token_tree(node)?.0; subtree.delimiter = None; @@ -86,27 +110,3 @@ fn eager_macro_recur( Some(original) } - -pub fn expand_eager_macro( - db: &impl AstDatabase, - macro_call: InFile, - def: MacroDefId, - resolver: &dyn Fn(ast::Path) -> Option, -) -> Option { - let args = macro_call.value.token_tree()?; - let parsed_args = mbe::ast_to_token_tree(&args)?.0; - let parsed_args = mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr).ok()?.0; - let result = eager_macro_recur(db, macro_call.with_value(parsed_args.syntax_node()), resolver)?; - - let subtree = to_subtree(&result)?; - - if let MacroDefKind::BuiltInEager(eager) = def.kind { - let (subtree, fragment) = eager.expand(&subtree).ok()?; - let eager = - EagerCallLoc { def, fragment, subtree: Arc::new(subtree), file_id: macro_call.file_id }; - - Some(db.intern_eager_expansion(eager)) - } else { - None - } -} -- cgit v1.2.3