diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_expand/src/eager.rs | 48 |
1 files changed, 24 insertions, 24 deletions
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; | |||
29 | use ra_syntax::{algo::replace_descendants, SyntaxElement, SyntaxNode}; | 29 | use ra_syntax::{algo::replace_descendants, SyntaxElement, SyntaxNode}; |
30 | use std::{collections::HashMap, sync::Arc}; | 30 | use std::{collections::HashMap, sync::Arc}; |
31 | 31 | ||
32 | pub fn expand_eager_macro( | ||
33 | db: &impl AstDatabase, | ||
34 | macro_call: InFile<ast::MacroCall>, | ||
35 | def: MacroDefId, | ||
36 | resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>, | ||
37 | ) -> Option<EagerMacroId> { | ||
38 | let args = macro_call.value.token_tree()?; | ||
39 | let parsed_args = mbe::ast_to_token_tree(&args)?.0; | ||
40 | let parsed_args = mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr).ok()?.0; | ||
41 | let result = eager_macro_recur(db, macro_call.with_value(parsed_args.syntax_node()), resolver)?; | ||
42 | |||
43 | let subtree = to_subtree(&result)?; | ||
44 | |||
45 | if let MacroDefKind::BuiltInEager(eager) = def.kind { | ||
46 | let (subtree, fragment) = eager.expand(&subtree).ok()?; | ||
47 | let eager = | ||
48 | EagerCallLoc { def, fragment, subtree: Arc::new(subtree), file_id: macro_call.file_id }; | ||
49 | |||
50 | Some(db.intern_eager_expansion(eager)) | ||
51 | } else { | ||
52 | None | ||
53 | } | ||
54 | } | ||
55 | |||
32 | fn to_subtree(node: &SyntaxNode) -> Option<tt::Subtree> { | 56 | fn to_subtree(node: &SyntaxNode) -> Option<tt::Subtree> { |
33 | let mut subtree = mbe::syntax_node_to_token_tree(node)?.0; | 57 | let mut subtree = mbe::syntax_node_to_token_tree(node)?.0; |
34 | subtree.delimiter = None; | 58 | subtree.delimiter = None; |
@@ -86,27 +110,3 @@ fn eager_macro_recur( | |||
86 | 110 | ||
87 | Some(original) | 111 | Some(original) |
88 | } | 112 | } |
89 | |||
90 | pub fn expand_eager_macro( | ||
91 | db: &impl AstDatabase, | ||
92 | macro_call: InFile<ast::MacroCall>, | ||
93 | def: MacroDefId, | ||
94 | resolver: &dyn Fn(ast::Path) -> Option<MacroDefId>, | ||
95 | ) -> Option<EagerMacroId> { | ||
96 | let args = macro_call.value.token_tree()?; | ||
97 | let parsed_args = mbe::ast_to_token_tree(&args)?.0; | ||
98 | let parsed_args = mbe::token_tree_to_syntax_node(&parsed_args, FragmentKind::Expr).ok()?.0; | ||
99 | let result = eager_macro_recur(db, macro_call.with_value(parsed_args.syntax_node()), resolver)?; | ||
100 | |||
101 | let subtree = to_subtree(&result)?; | ||
102 | |||
103 | if let MacroDefKind::BuiltInEager(eager) = def.kind { | ||
104 | let (subtree, fragment) = eager.expand(&subtree).ok()?; | ||
105 | let eager = | ||
106 | EagerCallLoc { def, fragment, subtree: Arc::new(subtree), file_id: macro_call.file_id }; | ||
107 | |||
108 | Some(db.intern_eager_expansion(eager)) | ||
109 | } else { | ||
110 | None | ||
111 | } | ||
112 | } | ||