Download Jar. Libraryless. Click here for Pure Java version (7319L/51K).
1 | !7 |
2 | |
3 | static void tok_recordDecls(L<S> tok) { |
4 | int i; |
5 | bool re = false; |
6 | while ((i = jfind(tok, "record <id>(")) >= 0) { |
7 | int argsFrom = i+6, argsTo = findCodeTokens(tok, i, false, ")"); |
8 | int idx = findCodeTokens(tok, argsTo, false, "{"); |
9 | int j = findEndOfBracketPart(tok, idx); |
10 | S name = tok.get(i+2); |
11 | bool noEq = eq(get(tok, i-2), "noeq"); |
12 | if (noEq) tok.set(i-2, ""); |
13 | bool noToString = eq(get(tok, i-2), "noToString"); |
14 | if (noToString) tok.set(i-2, ""); |
15 | |
16 | new StringBuilder buf; |
17 | |
18 | L<S> tArgs = subList(tok, argsFrom-1, argsTo); |
19 | L<Pair<S>> args = tok_typesAndNamesOfParams(tArgs); |
20 | L<S> contents = subList(tok, idx+1, j); |
21 | |
22 | for (Pair<S> p : args) |
23 | buf.append("\n " + jreplace(p.a, "...", "[]") + " " + p.b + ";"); |
24 | |
25 | buf.append("\n *() {}"); |
26 | buf.append("\n *(" + joinWithComma(map(args, func(Pair<S> p) -> S { |
27 | dropPrefix("new ", p.a) + " *" + p.b })) + ") {}"); |
28 | |
29 | if (!noToString && !(jfind(contents, "toString {") >= 0 || jfind(contents, "toString()") >= 0)) |
30 | buf.append("\n toString { ret " |
31 | + quote(name + "(") |
32 | + " + " |
33 | + join([[ + ", " + ]], secondOfPairs(args)) |
34 | + " + \")\"; }"); |
35 | |
36 | if (!noEq) { |
37 | //buf.append("\n [stdEq]"); |
38 | buf.append(tok_genEqualsAndHashCode(name, args)); |
39 | } |
40 | |
41 | tok.set(idx, "{" + buf); |
42 | tok.set(i, "class"); |
43 | clearTokens(tok, argsFrom-2, argsTo+1); |
44 | reTok(tok, i, idx+1); |
45 | tok_addFieldOrder(tok, i); |
46 | set re; |
47 | } |
48 | if (re) reTok(tok); |
49 | } |
50 | |
51 | static bool allVarNames_debug = true; |
52 | |
53 | static L<S> allVarNames(L<S> tok) { |
54 | print(join(tok)); |
55 | bool debug = allVarNames_debug; |
56 | Map<Int, Int> bracketMap = getBracketMap(tok); |
57 | new L<S> varNames; |
58 | for (int i = 3; i < tok.size(); i += 2) { |
59 | S t = tok.get(i); |
60 | print("Got token: " + t); |
61 | if (eqOneOf(t, "=", ";", ",")) { |
62 | S v = tok.get(i-2); |
63 | if (isIdentifier(v)) |
64 | varNames.add(v); |
65 | if (eq(t, "=")) { |
66 | i = scanToEndOfInitializer(tok, bracketMap, i)+1; |
67 | assertTrue(odd(i)); |
68 | } |
69 | } else if (eq(t, "<")) { |
70 | i = findEndOfTypeArgs(tok, i)+1; |
71 | if (debug) |
72 | print("Skipped type args: " + struct(subList(tok, i))); |
73 | } else if (eqOneOf(t, "{", "(")) { |
74 | int j = findEndOfBracketPart(tok, i)-1; // skip function/class bodies |
75 | if (debug) print("Skipping body " + (j-i)/2); |
76 | i = j; |
77 | } |
78 | } |
79 | return varNames; |
80 | } |
81 | |
82 | p-exp { |
83 | LS tok = javaTok([[record Definition(S word, S definition) {}]]); |
84 | tok_recordDecls(tok); |
85 | print(join(tok)); |
86 | assertTrue(join(tok).contains([[_fieldOrder = "word definition"]])); |
87 | print("OK"); |
88 | } |
download show line numbers debug dex old transpilations
Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1020318 |
Snippet name: | Record Declaration Bug [fixed] |
Eternal ID of this version: | #1020318/8 |
Text MD5: | e7ea6e35637e23084dc796e66c036936 |
Transpilation MD5: | 41cde6c94b065aec540e7559eb19a93a |
Author: | stefan |
Category: | javax / transpiling |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-12-14 01:48:15 |
Source code size: | 2720 bytes / 88 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 388 / 957 |
Version history: | 7 change(s) |
Referenced in: | [show references] |