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

41
LINES

< > BotCompany Repo | #1002840 // nlUnparse

JavaX fragment (include)

1  
static S nlUnparse(Lisp tree) {
2  
  ret nlUnparse(tree, true);
3  
}
4  
5  
static S nlUnparse(Lisp tree, boolean dropOuterBrackets) {
6  
  new StringBuilder buf;
7  
  nlUnparse(tree, buf, dropOuterBrackets);
8  
  ret str(buf);
9  
}
10  
11  
static void nlUnparse(Lisp tree, StringBuilder buf, boolean dropOuterBrackets) {
12  
  if (tree == null) ret;
13  
  
14  
  // special classes - Var etc.
15  
  if (tree.getClass() != Lisp.class) {
16  
    buf.append(tree);
17  
    ret;
18  
  }
19  
  
20  
  if (tree.isA("[]")) {
21  
    if (!dropOuterBrackets) buf.append("[");
22  
  } else if (tree.isA("()"))
23  
    buf.append("(");
24  
  else {
25  
    if (tree.isLeaf())
26  
      buf.append(tree.head);
27  
    else
28  
      buf.append("?? " + tree);
29  
    ret;
30  
  }
31  
  
32  
  for (int i = 0; i < tree.size(); i++) {
33  
    if (i != 0) buf.append(" ");
34  
    nlUnparse(tree.get(i), buf, false);
35  
  }
36  
  
37  
  if(tree.isA("[]")) {
38  
    if (!dropOuterBrackets) buf.append("]");
39  
  } else
40  
    buf.append(")");
41  
}

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: #1002840
Snippet name: nlUnparse
Eternal ID of this version: #1002840/1
Text MD5: fd2c2ee3d181aa6d9a8605ce3ab25e10
Author: stefan
Category: eleu / nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-03-10 01:08:35
Source code size: 926 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 668 / 836
Referenced in: [show references]