static void tok_listComprehensions(L<S> tok) { if (!tok.contains("[")) ret; for (int i = 1; i < l(tok); i += 2) try { continue unless eq(tok.get(i), "["); int iOp = indexOfAny(tok, i+2, "?", ":", "in", "[", "]"); if (iOp < 0) ret; if (!eqOneOf(tok.get(iOp), ":", "in")) continue; // not a list comprehension if (eqGet(tok, iOp+2, ".")) continue; // "in." (in is a variable name) Map<Int> bracketMap = getBracketMap(tok); // XXX - optimize S type = joinSubList(tok, i+2, iOp-3), id = tok.get(iOp-2); int j = scanOverExpression(tok, bracketMap, iOp+2, "|"); S exp = join(subList(tok, iOp+2, j)); j += 2; int k = scanOverExpression(tok, bracketMap, j, "]"); S where = join(subList(tok, j, k)); ++k; S code = "filter(" + exp + ", func(" + type + " " + id + ") -> Bool { " + where + " })"; replaceTokens(tok, i, k, code); reTok(tok, i, k); } on fail { print("Was processing list comprehension: " + joinSubList(tok, i, i+30) + "..."); } }
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1016767 |
Snippet name: | tok_listComprehensions |
Eternal ID of this version: | #1016767/6 |
Text MD5: | b9be9113c399ac181e57082071f19b97 |
Author: | stefan |
Category: | javax / transpiling |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-07-24 03:03:59 |
Source code size: | 1054 bytes / 26 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 414 / 448 |
Version history: | 5 change(s) |
Referenced in: | [show references] |