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

73
LINES

< > BotCompany Repo | #1017599 // Computation tree for parsing with OpNode results [dev.]

JavaX source code (desktop) - run with: x30.jar

Download Jar.

1  
!7
2  
3  
srecord IfThen(Exp in, Exp out) {}
4  
sclass Exp {}
5  
srecord And(Exp a, Exp b) extends Exp {}
6  
srecord Sentence(S text) extends Exp {}
7  
8  
p-exp {
9  
  jtattoo();
10  
  S input = first(mL("Monolog examples"));
11  
  TextNode root = new(input);
12  
  
13  
  processNode_recursive(root, 10);
14  
15  
  showFrame(jDynamicTree(root, func(CTNode n) -> Collection<CTNode> { n.children }));
16  
}
17  
18  
svoid processNode_recursive(CTNode n, int depthCounter) {
19  
  if (n == null || depthCounter <= 0) ret;
20  
  processNode(n);
21  
  for (CTNode child : n.children)
22  
    processNode_recursive(child, depthCounter-1);
23  
  
24  
  makeResults(n);
25  
}
26  
27  
svoid makeResults(CTNode n) {
28  
  if (!n instanceof OpNode) ret;
29  
  for (TokNode child : instancesOf(TokNode, n.children))
30  
}
31  
32  
svoid processNode(CTNode n) {
33  
  if (n instanceof TextNode) {
34  
    TextNode tn = cast n;
35  
    
36  
    OpNode op = new("javaTokPlusCurly_dontKeep");
37  
    if (n.add(op))
38  
      op.add(TokNode(javaTokPlusCurly_dontKeep(tn.text)));
39  
  }
40  
  
41  
  if (n instanceof TokNode) {
42  
    TokNode tn = cast n;
43  
    if (containsSubList(tn.tok, ll("=", "", ">"))) {
44  
      OpNode op = new("splitAtDoubleArrow");
45  
      if (n.add(op))
46  
        op.add(ObjectNode(splitAtDoubleArrow(tn.tok)));
47  
    }
48  
    
49  
    L<Int> l = indicesOfSubList(tn.tok, ll("&", "", "&"));
50  
    if (nempty(l)) {
51  
      OpNode op = new("split at &&");
52  
      if (n.add(op))
53  
        for (L<S> subTok : splitAroundSubListIndices(tn.tok, l, 3))
54  
          op.add(TokNode(subTok));
55  
    }
56  
  }
57  
  
58  
  if (n instanceof ObjectNode) {
59  
    ObjectNode on = cast n;
60  
    O o = on.obj;
61  
    
62  
    if (o instanceof S)
63  
      n.add(TextNode((S) o));
64  
    
65  
    Collection c;
66  
    if (on.obj instanceof Collection && l((c = (Collection) on.obj)) == 2) {
67  
      OpNode op = new("Split Collection");
68  
      if (n.add(op))
69  
        for (O e : c)
70  
          op.add(ObjectNode(e));
71  
    }
72  
  }
73  
}

Author comment

Began life as a copy of #1017536

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: #1017599
Snippet name: Computation tree for parsing with OpNode results [dev.]
Eternal ID of this version: #1017599/1
Text MD5: 26f71f3a7137f4b83eb28cc285e4aa1e
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:05:41
Source code size: 1870 bytes / 73 lines
Pitched / IR pitched: No / No
Views / Downloads: 382 / 565
Referenced in: [show references]