Download Jar. Libraryless. Click here for Pure Java version (7558L/55K).
!7 abstract sclass Node { new LinkedHashSet<Node> children; toString { ret shortClassName(this) + ": " + toString2(); } abstract S toString2(); bool add(Node n) { ret children.add(n); } } sclass TextNode > Node { S text; *() {} *(S *text) {} S toString2() { ret quote(text); } } sclass TokNode > Node { L<S> tok; *() {} *(LS *tok) {} S toString2() { ret sfu(tok); } public bool equals(O o) { ret stdEq(this, o, 'tok); } public int hashCode() { ret stdHash(this, 'tok); } } sclass ObjectNode > Node { O obj; *() {} *(O *obj) {} S toString2() { ret sfu(obj); } public bool equals(O o) { ret stdEq(this, o, 'obj); } public int hashCode() { ret stdHash(this, 'obj); } } sclass OpNode > Node { S op; *() {} *(S *op) {} S toString2() { ret op; } public bool equals(O o) { ret stdEq(this, o, 'op); } public int hashCode() { ret stdHash(this, 'op); } } p-exp { S input = first(mL("Monolog examples")); TextNode root = new(input); processNode_recursive(root, 10); showFrame(jDynamicTree(root, func(Node n) -> Collection<Node> { n.children })); } svoid processNode_recursive(Node n, int depthCounter) { if (n == null || depthCounter <= 0) ret; processNode(n); for (Node child : n.children) processNode_recursive(child, depthCounter-1); } svoid processNode(Node n) { if (n instanceof TextNode) { TextNode tn = cast n; OpNode op = new("javaTokPlusCurly_dontKeep"); if (n.add(op)) op.add(TokNode(javaTokPlusCurly_dontKeep(tn.text))); } if (n instanceof TokNode) { TokNode tn = cast n; if (containsSubList(tn.tok, ll("=", "", ">"))) { OpNode op = new("splitAtDoubleArrow"); if (n.add(op)) op.add(ObjectNode(splitAtDoubleArrow(tn.tok))); } L<Int> l = indicesOfSubList(tn.tok, ll("&", "", "&")); if (nempty(l)) { OpNode op = new("split at &&"); if (n.add(op)) for (L<S> subTok : splitAroundSubListIndices(tn.tok, l, 3)) op.add(TokNode(subTok)); } } if (n instanceof ObjectNode) { ObjectNode on = cast n; O o = on.obj; if (o instanceof S) n.add(TextNode((S) o)); Collection c; if (on.obj instanceof Collection && l((c = (Collection) on.obj)) == 2) { OpNode op = new("Split Collection"); if (n.add(op)) for (O e : c) op.add(ObjectNode(e)); } } }
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: | 400 / 964 |
Version history: | 17 change(s) |
Referenced in: | #1017535 - Computation Tree Include v1 #1017536 - Flexible Computation Tree v1, shortened [OK] |