sS gazelle_deepReplaceVars(SS map, S s, O... _) { SS map2 = mapValues roundUnlessCurlyBracketed(map); ret gazelle_deepReplaceVars_impl(map2, s, _); } sS gazelle_deepReplaceVars_impl(SS map, S s, O... _) { LS tok = javaTokWithBrackets(s); ret join(mapCodeTokens(tok, t -> { bool round = tok_isRoundBracketed(t); bool curly = tok_isCurlyBracketed(t); if (!round && !curly) ret getOrKeep(map, t); S t2 = tok_deRoundOrCurlyBracket(t); S t3 = gazelle_deepReplaceVars_impl(map, t2, _); if (t2 == t3) ret t; ret round ? roundBracket(t) : curlyBracket(t); })); }