writesBackAsCode: whether a rule's expansion writes none of `tts` in the arguments of a macro other than an expression macro. Those it writes as code go into `written`.
(group: Node, tts: &HashSet<&'s str>, src: &'s str, written: &mut HashSet<&'s str>, depth: u32)
| 2183 | /// arguments of a macro other than an expression macro. Those it writes as |
| 2184 | /// code go into `written`. |
| 2185 | fn macro_writes_back_as_code<'s>(group: Node, tts: &HashSet<&'s str>, src: &'s str, written: &mut HashSet<&'s str>, depth: u32) -> bool { |
| 2186 | if depth > 32 { |
| 2187 | return false; |
| 2188 | } |
| 2189 | for i in 0..group.child_count() { |
| 2190 | let Some(t) = group.child(i) else { continue }; |
| 2191 | if t.kind() == "metavariable" { |
| 2192 | let name = macro_tok_text(t, src); |
| 2193 | if tts.contains(name) { |
| 2194 | written.insert(name); |
| 2195 | } |
| 2196 | } else if t.kind() == "token_repetition" { |
| 2197 | if !macro_writes_back_as_code(t, tts, src, written, depth + 1) { |
| 2198 | return false; |
| 2199 | } |
| 2200 | } else if t.kind() == "token_tree" { |
| 2201 | let bang = if i >= 2 { group.child(i - 1) } else { None }; |
| 2202 | let invoked = match bang { |
| 2203 | Some(b) if b.kind() == "!" => group.child(i - 2), |
| 2204 | _ => None, |
| 2205 | }; |
| 2206 | let other = match invoked { |
| 2207 | Some(n) => { |
| 2208 | (n.kind() == "identifier" || MACRO_ARG_CONTEXTUAL.contains(&n.kind())) |
| 2209 | && !RUST_EXPRESSION_MACROS.contains(¯o_tok_text(n, src)) |
| 2210 | } |
| 2211 | None => false, |
| 2212 | }; |
| 2213 | if other { |
| 2214 | if macro_uses_any(t, tts, src, depth + 1) { |
| 2215 | return false; |
| 2216 | } |
| 2217 | } else if !macro_writes_back_as_code(t, tts, src, written, depth + 1) { |
| 2218 | return false; |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | true |
| 2223 | } |
| 2224 | |
| 2225 | /// usesAny: whether any of the metavariables `tts` is written under `node`. |
| 2226 | fn macro_uses_any(node: Node, tts: &HashSet<&str>, src: &str, depth: u32) -> bool { |
no test coverage detected