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

Function macro_parse_chain

codegraph-kernel/src/rustlang.rs:2088–2241  ·  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, out: &mut Vec<MacroRef<'t>>)

Source from the content-addressed store, hash-verified

2086
2087/// parseChain: the expression that starts at `i`; returns the index past it.
2088fn macro_parse_chain<'t>(tokens: &[Node<'t>], mut i: usize, in_pattern: bool, src: &'t str, out: &mut Vec<MacroRef<'t>>) -> usize {
2089 stack_guard!();
2090 if !macro_starts_expr(tokens, i, src) {
2091 return i;
2092 }
2093 let start = tokens[i];
2094 let mut expr: MExpr;
2095 let mut segs: Vec<(&'t str, Node<'t>)> = Vec::new();
2096 if MACRO_ARG_LITERALS.contains(&start.kind()) {
2097 expr = MExpr::Lit;
2098 i += 1;
2099 } else if start.kind() == "token_tree" {
2100 macro_scan_group(start, false, in_pattern, src, out);
2101 expr = MExpr::Other;
2102 i += 1;
2103 } else {
2104 let leading = start.kind() == "::";
2105 if leading {
2106 i += 1;
2107 }
2108 if !macro_is_segment(tokens.get(i), src) {
2109 return i;
2110 }
2111 loop {
2112 segs.push((macro_tok_text(tokens[i], src), tokens[i]));
2113 i += 1;
2114 if tokens.get(i).map(|t| t.kind()) != Some("::") {
2115 break;
2116 }
2117 if tokens.get(i + 1).map(|t| t.kind()) == Some("<") {
2118 let Some(past) = macro_skip_angles(tokens, i + 1) else { break };
2119 i = past;
2120 if tokens.get(i).map(|t| t.kind()) == Some("::") && macro_is_segment(tokens.get(i + 1), src) {
2121 i += 1;
2122 continue;
2123 }
2124 break;
2125 }
2126 if !macro_is_segment(tokens.get(i + 1), src) {
2127 break;
2128 }
2129 i += 1;
2130 }
2131 if tokens.get(i).map(|t| t.kind()) == Some("!") && tokens.get(i + 1).map(|t| t.kind()) == Some("token_tree") {
2132 let name = segs[segs.len() - 1].0;
2133 if RUST_EXPRESSION_MACROS.contains(&name) {
2134 macro_scan_group(tokens[i + 1], name == "matches", false, src, out);
2135 }
2136 expr = MExpr::Other;
2137 i += 2;
2138 } else if segs.len() == 1 && !leading {
2139 let only = segs[0].0;
2140 expr = if only == "self" {
2141 MExpr::SelfE
2142 } else if macro_is_name(Some(&start), src) {
2143 MExpr::Name(only.to_string())
2144 } else {
2145 MExpr::Other

Callers 1

macro_scan_groupFunction · 0.85

Calls 15

macro_starts_exprFunction · 0.85
macro_scan_groupFunction · 0.85
macro_is_segmentFunction · 0.85
macro_tok_textFunction · 0.85
macro_skip_anglesFunction · 0.85
macro_is_nameFunction · 0.85
macro_group_delimFunction · 0.85
is_type_name_textFunction · 0.85
CallInterface · 0.85
macro_method_call_nameFunction · 0.85
pushMethod · 0.80
mapMethod · 0.80

Tested by

no test coverage detected