Transpiled version (6246L) is out of date.
1 | svoid tok_for_unpair(LS tok) { |
2 | jreplace(tok, "for (unpair <id> <id>, <id> :", "for (unpair $4 $5, $4 $7 :"); |
3 | jreplace(tok, "for (<id> <id>, <id> : unpair", "for (unpair $3 $4, $3 $6 :"); |
4 | jreplace(tok, "for (<id> <id>, <id> <id> : unpair", "for (unpair $3 $4, $6 $7 :"); |
5 | |
6 | int i = -1; |
7 | while ((i = jfind(tok, i+1, "for (unpair <id> <id>, <id> <id> :")) >= 0) { |
8 | S type1 = tok.get(i+6), var1 = tok.get(i+8); |
9 | S type2 = tok.get(i+12), var2 = tok.get(i+14); |
10 | int iColon = indexOf(tok, ":", i); |
11 | int iClosing = findEndOfBracketPart(tok, iColon)-1; |
12 | int iCurly = iClosing+2; |
13 | tok_statementToBlock(tok, iCurly); |
14 | S pairVar = makeVar(); |
15 | replaceTokens(tok, i+4, iColon-1, tok_toNonPrimitiveTypes("Pair<" + type1 + ", " + type2 + ">") + " " + pairVar); |
16 | tok.set(iCurly, "{ " |
17 | + type1 + " " + var1 + " = pairA(" + pairVar + "); " |
18 | + type2 + " " + var2 + " = pairB(" + pairVar + "); "); |
19 | reTok(tok, i, iCurly+1); |
20 | } |
21 | |
22 | // typeless version |
23 | |
24 | i = -1; |
25 | while ((i = jfind(tok, i+1, "for (<id>, <id> : unpair")) >= 0) { |
26 | S var1 = tok.get(i+4); |
27 | S var2 = tok.get(i+8); |
28 | int iColon = indexOf(tok, ":", i); |
29 | int iClosing = findEndOfBracketPart(tok, iColon)-1; |
30 | int iCurly = iClosing+2; |
31 | tok_statementToBlock(tok, iCurly); |
32 | S pairVar = makeVar(); |
33 | replaceTokens(tok, i+4, iColon+3, "var " + pairVar + ":"); |
34 | tok.set(iCurly, "{ " |
35 | + "var " + var1 + " = pairA(" + pairVar + "); " |
36 | + "var " + var2 + " = pairB(" + pairVar + "); "); |
37 | reTok(tok, i, iCurly+1); |
38 | } |
39 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1023091 |
Snippet name: | tok_for_unpair |
Eternal ID of this version: | #1023091/22 |
Text MD5: | b713cb0f507b71b8f06dd069251b0b58 |
Author: | stefan |
Category: | javax / transpiling |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-03-12 19:50:36 |
Source code size: | 1575 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 363 / 521 |
Version history: | 21 change(s) |
Referenced in: | [show references] |