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

Function macro_parse_chain

codegraph-kernel/src/rustlang.rs:2057–2210  ·  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

2055
2056/// parseChain: the expression that starts at `i`; returns the index past it.
2057fn macro_parse_chain<'t>(tokens: &[Node<'t>], mut i: usize, in_pattern: bool, src: &'t str, out: &mut Vec<MacroRef<'t>>) -> usize {
2058 stack_guard!();
2059 if !macro_starts_expr(tokens, i, src) {
2060 return i;
2061 }
2062 let start = tokens[i];
2063 let mut expr: MExpr;
2064 let mut segs: Vec<(&'t str, Node<'t>)> = Vec::new();
2065 if MACRO_ARG_LITERALS.contains(&start.kind()) {
2066 expr = MExpr::Lit;
2067 i += 1;
2068 } else if start.kind() == "token_tree" {
2069 macro_scan_group(start, false, in_pattern, src, out);
2070 expr = MExpr::Other;
2071 i += 1;
2072 } else {
2073 let leading = start.kind() == "::";
2074 if leading {
2075 i += 1;
2076 }
2077 if !macro_is_segment(tokens.get(i), src) {
2078 return i;
2079 }
2080 loop {
2081 segs.push((macro_tok_text(tokens[i], src), tokens[i]));
2082 i += 1;
2083 if tokens.get(i).map(|t| t.kind()) != Some("::") {
2084 break;
2085 }
2086 if tokens.get(i + 1).map(|t| t.kind()) == Some("<") {
2087 let Some(past) = macro_skip_angles(tokens, i + 1) else { break };
2088 i = past;
2089 if tokens.get(i).map(|t| t.kind()) == Some("::") && macro_is_segment(tokens.get(i + 1), src) {
2090 i += 1;
2091 continue;
2092 }
2093 break;
2094 }
2095 if !macro_is_segment(tokens.get(i + 1), src) {
2096 break;
2097 }
2098 i += 1;
2099 }
2100 if tokens.get(i).map(|t| t.kind()) == Some("!") && tokens.get(i + 1).map(|t| t.kind()) == Some("token_tree") {
2101 let name = segs[segs.len() - 1].0;
2102 if RUST_EXPRESSION_MACROS.contains(&name) {
2103 macro_scan_group(tokens[i + 1], name == "matches", false, src, out);
2104 }
2105 expr = MExpr::Other;
2106 i += 2;
2107 } else if segs.len() == 1 && !leading {
2108 let only = segs[0].0;
2109 expr = if only == "self" {
2110 MExpr::SelfE
2111 } else if macro_is_name(Some(&start), src) {
2112 MExpr::Name(only.to_string())
2113 } else {
2114 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