Libraryless. Click here for Pure Java version (5458L/31K).
1 | static void tok_unpair(L<S> tok) { |
2 | if (!tok.contains("unpair")) ret; |
3 | |
4 | int i; |
5 | |
6 | while ((i = jfind(tok, "var <id>, <id> = unpair")) >= 0) { |
7 | int iUnpair = indexOf(tok, "unpair", i); |
8 | int j = findEndOfStatement(tok, iUnpair); |
9 | S var1 = tok.get(i+2); |
10 | S var2 = tok.get(i+6); |
11 | S v = makeVar(); |
12 | replaceTokens(tok, i, iUnpair+1, "var " + v + " ="); |
13 | tok.set(j-1, "; var " + var1 + " = " + v + ".a; var " + var2 + " = " + v + ".b;"); |
14 | reTok(tok, i, j); |
15 | } |
16 | |
17 | jreplace(tok, "<id> <id>, <id> = unpair", "$1 $2, $1 $4 = unpair"); |
18 | |
19 | while ((i = jfind(tok, "<id> <id>, <id> <id> = unpair")) >= 0) { |
20 | int idx = indexOf(tok, "unpair", i); |
21 | int j = findEndOfStatement(tok, idx); |
22 | S type1 = tok.get(i), var1 = tok.get(i+2); |
23 | S type2 = tok.get(i+6), var2 = tok.get(i+8); |
24 | S v = makeVar(); |
25 | //printVars(+type1, +var1, +type2, +var2); |
26 | tok.set(i+4, ";"); |
27 | tok.set(idx-2, ";"); |
28 | tok.set(idx, "Pair<" + tok_toNonPrimitiveTypes(type1) + "," + tok_toNonPrimitiveTypes(type2) + "> " + v + "="); |
29 | tok.set(j-1, "; " + var1 + " = " + v + ".a; " + var2 + " = " + v + ".b;"); |
30 | reTok(tok, i, j); |
31 | } |
32 | |
33 | while ((i = jfind(tok, "<id> <id>, <id> < <id>,<id> > <id> = unpair")) >= 0 || (i = jfind(tok, "<id> <id>, <id><<id>> <id> = unpair")) >= 0) { |
34 | print("unpair"); |
35 | int idx = indexOf(tok, "unpair", i); |
36 | int j = findEndOfStatement(tok, idx); |
37 | S type1 = tok.get(i), var1 = tok.get(i+2); |
38 | S type2 = joinSubList(tok, i+5, idx-5), var2 = tok.get(idx-4); |
39 | S v = makeVar(); |
40 | tok.set(i+4, ";"); |
41 | tok.set(idx-2, ";"); |
42 | tok.set(idx-1, ""); |
43 | tok.set(idx, "Pair<" + type1 + "," + type2 + "> " + v + "="); |
44 | tok.set(j-1, "; " + var1 + " = " + v + ".a; " + var2 + " = " + v + ".b;"); |
45 | reTok(tok, i, j); |
46 | } |
47 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1010313 |
Snippet name: | tok_unpair - "S a, S b = unpair ...;" construct |
Eternal ID of this version: | #1010313/17 |
Text MD5: | c0d54daf48a8727b802a4b8da7663d91 |
Transpilation MD5: | bf8f9b78a22109096b83e051ccae74c6 |
Author: | stefan |
Category: | javax / parsing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-01-03 01:04:28 |
Source code size: | 1820 bytes / 47 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 553 / 680 |
Version history: | 16 change(s) |
Referenced in: | [show references] |