Libraryless. Click here for Pure Java version (2845L/17K).
// transformer can return null or input on no change // will not call transformer on individual words sS lambdaMapLike gazelle_deepTransform(IF1<S> transformer, S input, O... _) { if (transformer == null) ret input; // call transformer on whole input, return if change S transformed = transformer.get(input); if (transformed != null && transformed != input) ret transformed; // transformer didn't do anything, tokenize & go through parts O tokenizer = optPar tokenizer(_, f javaTokWithBrackets); LS tok = callTokenizer(tokenizer, input); bool changes; for ping (int i = 1; i < l(tok); i += 2) { S t = tok.get(i); if (tok_isRoundOrCurlyBracketed(t)) { S unBracketed = tok_deRoundOrCurlyBracket(t); transformed = gazelle_deepTransform(transformer, unBracketed, _); if (transformed != unBracketed) { if (!changes) tok = cloneList(tok); // in case a caching tokenizer was used // enclose in brackets & replace tok.set(i, startsWith(t, "(") ? roundOpt(transformed) : curlyOpt(transformed)); set changes; } } } ret changes ? join(tok) : input; }
Began life as a copy of #1027140
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027141 |
Snippet name: | gazelle_deepTransform - call a transforming function on all inner parts of input |
Eternal ID of this version: | #1027141/8 |
Text MD5: | db3de2375183412825993b966cff00bd |
Transpilation MD5: | 65d55af3e68b9f320f89dc52e69a8959 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-02-22 18:58:01 |
Source code size: | 1178 bytes / 31 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 284 / 415 |
Version history: | 7 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1027143 - gazelle_deepReplaceFullPhrases - using map #1027176 - gazelle_deepTransform_withTrail - call a transforming function on all inner parts of input |