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

Function macro_parse_chain

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

parseChain: the expression that starts at `i`; returns the index past it.

(tokens: &[Node<'t>], mut i: usize, in_pattern: bool, src: &'t str, declared: &HashSet<String>, out: &mut Vec<MacroRef<'t>>)

Source from the content-addressed store, hash-verified

2327
2328/// parseChain: the expression that starts at `i`; returns the index past it.
2329fn macro_parse_chain<'t>(tokens: &[Node<'t>], mut i: usize, in_pattern: bool, src: &'t str, declared: &HashSet<String>, out: &mut Vec<MacroRef<'t>>) -> usize {
2330 stack_guard!();
2331 if !macro_starts_expr(tokens, i, src) {
2332 return i;
2333 }
2334 let start = tokens[i];
2335 let mut expr: MExpr;
2336 let mut segs: Vec<(&'t str, Node<'t>)> = Vec::new();
2337 if MACRO_ARG_LITERALS.contains(&start.kind()) {
2338 expr = MExpr::Lit;
2339 i += 1;
2340 } else if start.kind() == "token_tree" {
2341 // An array's elements are values; a pattern's (`[first, rest]`) are not.
2342 if !in_pattern && macro_group_delim(start) == "[" {
2343 macro_capture_values(&macro_group_tokens(start), true, src, out);
2344 }
2345 macro_scan_group(start, false, in_pattern, src, declared, out);
2346 expr = MExpr::Other;
2347 i += 1;
2348 } else {
2349 let leading = start.kind() == "::";
2350 if leading {
2351 i += 1;
2352 }
2353 if !macro_is_segment(tokens.get(i), src) {
2354 return i;
2355 }
2356 loop {
2357 segs.push((macro_tok_text(tokens[i], src), tokens[i]));
2358 i += 1;
2359 if tokens.get(i).map(|t| t.kind()) != Some("::") {
2360 break;
2361 }
2362 if tokens.get(i + 1).map(|t| t.kind()) == Some("<") {
2363 let Some(past) = macro_skip_angles(tokens, i + 1) else { break };
2364 i = past;
2365 if tokens.get(i).map(|t| t.kind()) == Some("::") && macro_is_segment(tokens.get(i + 1), src) {
2366 i += 1;
2367 continue;
2368 }
2369 break;
2370 }
2371 if !macro_is_segment(tokens.get(i + 1), src) {
2372 break;
2373 }
2374 i += 1;
2375 }
2376 if tokens.get(i).map(|t| t.kind()) == Some("!") && tokens.get(i + 1).map(|t| t.kind()) == Some("token_tree") {
2377 let name = segs[segs.len() - 1].0;
2378 let own = declared.contains(name) && !leading && {
2379 let texts: Vec<&str> = segs.iter().map(|s| s.0).collect();
2380 macro_is_own_path(&texts)
2381 };
2382 if RUST_EXPRESSION_MACROS.contains(&name) || own {
2383 macro_scan_macro(tokens[i + 1], name, src, declared, out);
2384 }
2385 expr = MExpr::Other;
2386 i += 2;

Callers 1

macro_scan_groupFunction · 0.85

Calls 15

macro_starts_exprFunction · 0.85
macro_group_delimFunction · 0.85
macro_capture_valuesFunction · 0.85
macro_group_tokensFunction · 0.85
macro_scan_groupFunction · 0.85
macro_is_segmentFunction · 0.85
macro_tok_textFunction · 0.85
macro_skip_anglesFunction · 0.85
macro_is_own_pathFunction · 0.85
macro_scan_macroFunction · 0.85
macro_is_nameFunction · 0.85
is_type_name_textFunction · 0.85

Tested by

no test coverage detected