Libraryless. Click here for Pure Java version (2845L/17K).
1 | // transformer can return null or input on no change |
2 | // will not call transformer on individual words |
3 | sS lambdaMapLike gazelle_deepTransform(IF1<S> transformer, S input, O... _) { |
4 | if (transformer == null) ret input; |
5 | |
6 | // call transformer on whole input, return if change |
7 | S transformed = transformer.get(input); |
8 | if (transformed != null && transformed != input) ret transformed; |
9 | |
10 | // transformer didn't do anything, tokenize & go through parts |
11 | O tokenizer = optPar tokenizer(_, f javaTokWithBrackets); |
12 | LS tok = callTokenizer(tokenizer, input); |
13 | |
14 | bool changes; |
15 | for ping (int i = 1; i < l(tok); i += 2) { |
16 | S t = tok.get(i); |
17 | if (tok_isRoundOrCurlyBracketed(t)) { |
18 | S unBracketed = tok_deRoundOrCurlyBracket(t); |
19 | transformed = gazelle_deepTransform(transformer, unBracketed, _); |
20 | if (transformed != unBracketed) { |
21 | if (!changes) tok = cloneList(tok); // in case a caching tokenizer was used |
22 | |
23 | // enclose in brackets & replace |
24 | tok.set(i, startsWith(t, "(") ? roundOpt(transformed) : curlyOpt(transformed)); |
25 | set changes; |
26 | } |
27 | } |
28 | } |
29 | |
30 | ret changes ? join(tok) : input; |
31 | } |
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: | 285 / 416 |
Version history: | 7 change(s) |
Referenced in: | [show references] |