MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / extract_macro_name

Function extract_macro_name

src/extraction/complexity.rs:240–257  ·  view source on GitHub ↗

Extracts the macro name from a macro invocation node (e.g. `assert!`). Looks for the first identifier child, stripping a trailing `!` if present.

(node: TsNode<'_>, source: &[u8])

Source from the content-addressed store, hash-verified

238///
239/// Looks for the first identifier child, stripping a trailing `!` if present.
240fn extract_macro_name(node: TsNode<'_>, source: &[u8]) -> Option<String> {
241 let mut cursor = node.walk();
242 if cursor.goto_first_child() {
243 loop {
244 let child = cursor.node();
245 let ck = child.kind();
246 if ck == "identifier" || ck == "scoped_identifier" {
247 if let Ok(text) = child.utf8_text(source) {
248 return Some(text.trim_end_matches('!').to_string());
249 }
250 }
251 if !cursor.goto_next_sibling() {
252 break;
253 }
254 }
255 }
256 None
257}
258
259/// Returns the text of the rightmost identifier-like child of `node`.
260fn rightmost_identifier(node: TsNode<'_>, source: &[u8]) -> String {

Callers 1

count_complexityFunction · 0.85

Calls 1

kindMethod · 0.80

Tested by

no test coverage detected