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

37
LINES

< > BotCompany Repo | #1002715 // snlFromTree

JavaX fragment (include)

1  
/*
2  
Binding levels:
3  
0 = lowest
4  
1 = arrows (> lowest)
5  
2 = word (> arrows)
6  
3 = juxta, idword, subword (> word)
7  
*/
8  
9  
static S snlFromTree(Lisp t) {
10  
  ret snlFromTree(t, 0, null);
11  
}
12  
13  
static S snlFromTree(Lisp t, int level, S arrow) {
14  
  if (t == null) ret "";
15  
  if (t.isEmpty()) ret t.head;
16  
  
17  
  if (t.isA("<"))
18  
    ret snlFromTree_wrap(level, eq(arrow, "<") ? 1 : 0, snlFromTree(t.get(0), 2, null) + " < "+ snlFromTree(t.get(1), 1, "<"));
19  
  if (t.isA(">"))
20  
    ret snlFromTree_wrap(level, eq(arrow, ">") ? 1 : 0,  snlFromTree(t.get(0), 2, null) + " > "+ snlFromTree(t.get(1), 1, ">"));
21  
  
22  
  // it's a juxtaposition
23  
  
24  
  new L<S> l;
25  
  int i = 0;
26  
  for (S tok : codeTokensOnly(javaTok(t.head))) {
27  
    if (eq(tok, "*") && i < t.size())
28  
      tok = snlFromTree(t.get(i++), 2, null);
29  
    l.add(tok);
30  
  }
31  
  ret snlFromTree_wrap(level, 1, join(" ", l));
32  
}
33  
34  
static S snlFromTree_wrap(int outer, int inner, S s) {
35  
  if (inner < outer) ret "[" + s + "]";
36  
  ret s;
37  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002715
Snippet name: snlFromTree
Eternal ID of this version: #1002715/1
Text MD5: 6c2cda1c4bba8140476b79db5344f0d8
Author: stefan
Category: nl bots
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-24 21:32:52
Source code size: 985 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 721 / 812
Referenced in: [show references]