Download Jar. Libraryless. Click here for Pure Java version (7558L/55K).
1 | !7 |
2 | |
3 | abstract sclass Node { |
4 | new LinkedHashSet<Node> children; |
5 | |
6 | toString { ret shortClassName(this) + ": " + toString2(); } |
7 | abstract S toString2(); |
8 | |
9 | bool add(Node n) { ret children.add(n); } |
10 | } |
11 | |
12 | sclass TextNode > Node { |
13 | S text; |
14 | |
15 | *() {} |
16 | *(S *text) {} |
17 | |
18 | S toString2() { ret quote(text); } |
19 | } |
20 | |
21 | sclass TokNode > Node { |
22 | L<S> tok; |
23 | |
24 | *() {} |
25 | *(LS *tok) {} |
26 | |
27 | S toString2() { ret sfu(tok); } |
28 | |
29 | public bool equals(O o) { ret stdEq(this, o, 'tok); } |
30 | public int hashCode() { ret stdHash(this, 'tok); } |
31 | } |
32 | |
33 | sclass ObjectNode > Node { |
34 | O obj; |
35 | |
36 | *() {} |
37 | *(O *obj) {} |
38 | |
39 | S toString2() { ret sfu(obj); } |
40 | |
41 | public bool equals(O o) { ret stdEq(this, o, 'obj); } |
42 | public int hashCode() { ret stdHash(this, 'obj); } |
43 | } |
44 | |
45 | sclass OpNode > Node { |
46 | S op; |
47 | |
48 | *() {} |
49 | *(S *op) {} |
50 | |
51 | S toString2() { ret op; } |
52 | |
53 | public bool equals(O o) { ret stdEq(this, o, 'op); } |
54 | public int hashCode() { ret stdHash(this, 'op); } |
55 | } |
56 | |
57 | p-exp { |
58 | S input = first(mL("Monolog examples")); |
59 | TextNode root = new(input); |
60 | |
61 | processNode_recursive(root, 10); |
62 | |
63 | showFrame(jDynamicTree(root, func(Node n) -> Collection<Node> { n.children })); |
64 | } |
65 | |
66 | svoid processNode_recursive(Node n, int depthCounter) { |
67 | if (n == null || depthCounter <= 0) ret; |
68 | processNode(n); |
69 | for (Node child : n.children) |
70 | processNode_recursive(child, depthCounter-1); |
71 | } |
72 | |
73 | svoid processNode(Node n) { |
74 | if (n instanceof TextNode) { |
75 | TextNode tn = cast n; |
76 | |
77 | OpNode op = new("javaTokPlusCurly_dontKeep"); |
78 | if (n.add(op)) |
79 | op.add(TokNode(javaTokPlusCurly_dontKeep(tn.text))); |
80 | } |
81 | |
82 | if (n instanceof TokNode) { |
83 | TokNode tn = cast n; |
84 | if (containsSubList(tn.tok, ll("=", "", ">"))) { |
85 | OpNode op = new("splitAtDoubleArrow"); |
86 | if (n.add(op)) |
87 | op.add(ObjectNode(splitAtDoubleArrow(tn.tok))); |
88 | } |
89 | |
90 | L<Int> l = indicesOfSubList(tn.tok, ll("&", "", "&")); |
91 | if (nempty(l)) { |
92 | OpNode op = new("split at &&"); |
93 | if (n.add(op)) |
94 | for (L<S> subTok : splitAroundSubListIndices(tn.tok, l, 3)) |
95 | op.add(TokNode(subTok)); |
96 | } |
97 | } |
98 | |
99 | if (n instanceof ObjectNode) { |
100 | ObjectNode on = cast n; |
101 | O o = on.obj; |
102 | |
103 | if (o instanceof S) |
104 | n.add(TextNode((S) o)); |
105 | |
106 | Collection c; |
107 | if (on.obj instanceof Collection && l((c = (Collection) on.obj)) == 2) { |
108 | OpNode op = new("Split Collection"); |
109 | if (n.add(op)) |
110 | for (O e : c) |
111 | op.add(ObjectNode(e)); |
112 | } |
113 | } |
114 | } |
Began life as a copy of #1017531
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: | #1017532 |
Snippet name: | Flexible Computation Tree v1 [OK] |
Eternal ID of this version: | #1017532/18 |
Text MD5: | 6122932bb5925dad15c1fa50c1bdc906 |
Transpilation MD5: | 353c27b9eb5b272520eb6fd9bb476e20 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-07-26 13:50:30 |
Source code size: | 2553 bytes / 114 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 401 / 970 |
Version history: | 17 change(s) |
Referenced in: | [show references] |