MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / rust_declared_expression_macros

Function rust_declared_expression_macros

codegraph-kernel/src/rustlang.rs:2105–2122  ·  view source on GitHub ↗

rustDeclaredExpressionMacros: the macros the file declares with `macro_rules!` whose arguments are Rust code by their own rules (#3484). Every rule of every declaration of the name must bind its arguments only as `expr`, `literal`, `block` or `stmt` fragments, or as `tt` fragments it writes back as code (never drops, nor hands to another macro). The declarations are found by their keyword in the t

(root: Node, src: &str)

Source from the content-addressed store, hash-verified

2103/// writes back as code (never drops, nor hands to another macro). The
2104/// declarations are found by their keyword in the text.
2105fn rust_declared_expression_macros(root: Node, src: &str) -> HashSet<String> {
2106 let mut verdict: HashMap<&str, bool> = HashMap::new();
2107 for (at, _) in src.match_indices("macro_rules!") {
2108 let Some(keyword) = root.descendant_for_byte_range(at, at + 1) else { continue };
2109 if keyword.kind() != "macro_rules!" {
2110 continue;
2111 }
2112 let Some(def) = keyword.parent() else { continue };
2113 if def.kind() != "macro_definition" {
2114 continue;
2115 }
2116 let Some(name_node) = def.child_by_field_name("name") else { continue };
2117 let name = macro_tok_text(name_node, src);
2118 let ok = verdict.get(name) != Some(&false) && macro_declares_code_arguments(def, src);
2119 verdict.insert(name, ok);
2120 }
2121 verdict.into_iter().filter(|(_, ok)| *ok).map(|(name, _)| name.to_string()).collect()
2122}
2123
2124/// declaresCodeArguments: whether every rule of a `macro_definition` takes Rust code.
2125fn macro_declares_code_arguments(def: Node, src: &str) -> bool {

Callers 1

extractFunction · 0.85

Calls 5

macro_tok_textFunction · 0.85
mapMethod · 0.80
getMethod · 0.65
collectMethod · 0.45

Tested by

no test coverage detected