Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

61
LINES

< > BotCompany Repo | #1017536 // Flexible Computation Tree v1, shortened [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 1177K of libraries. Click here for Pure Java version (7637L/55K).

!7

p-exp {
  jtattoo();
  S input = first(mL("Monolog examples"));
  TextNode root = new(input);
  
  processNode_recursive(root, 10);
  
  showFrame(jDynamicTree(root, func(CTNode n) -> Collection<CTNode> { n.children }));
}

svoid processNode_recursive(CTNode n, int depthCounter) {
  if (n == null || depthCounter <= 0) ret;
  processNode(n);
  for (CTNode child : n.children)
    processNode_recursive(child, depthCounter-1);
}

svoid processNode(CTNode 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));
    }
  }
}

Author comment

Began life as a copy of #1017532

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: #1017536
Snippet name: Flexible Computation Tree v1, shortened [OK]
Eternal ID of this version: #1017536/5
Text MD5: ff6ee2949b4ab915a51b07f4d6de5d97
Transpilation MD5: 5fa2c8091db12ab8f9e6f8eb2ea59ad8
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-29 17:06:26
Source code size: 1585 bytes / 61 lines
Pitched / IR pitched: No / No
Views / Downloads: 342 / 763
Version history: 4 change(s)
Referenced in: [show references]