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

38
LINES

< > BotCompany Repo | #1002729 // snlToText

JavaX fragment (include)

static S snlToText(S s) {
  ret snlToText(snlToTree(s));
}

static S snlToText(Lisp tree) {
  if (tree == null) ret "";
  tree = snlRemoveReferences(tree);
  
  if (snlToText_isJuxta(tree))
    tree = snlToText_addDots(tree);
  
  tree = snlQuestionMarksToBack(tree);
  
  S snl = snlFromTree(tree);
  new StringBuilder buf;
  L<S> drop = litlist ("[", "]", "<", ">");
  for (S t : codeTokensOnly(snlTok(snl)))
    if (!drop.contains(t)) {
      if (buf.length() != 0 && !litlist(".", "?").contains(t))
        buf.append(" ");
      buf.append(t);
    }
  ret str(buf);
}

static boolean snlToText_isJuxta(Lisp tree) {
  ret eq("*", join(asList(new HashSet<S>(codeTokensOnly(javaTok(tree.head))))));
}

static Lisp snlToText_addDots(Lisp tree) {
  Lisp t = new Lisp(tree.head);
  for (Lisp x : tree) {
    if (x.isA("<") && !x.get(0).is("?", "."))
      x = lisp("<", ".", x);
    t.add(x);
  }
  ret t;
}

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: #1002729
Snippet name: snlToText
Eternal ID of this version: #1002729/1
Text MD5: 63e0347b87b5943a6e505d441e584afc
Author: stefan
Category: eleu / nl
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-02-24 21:33:18
Source code size: 943 bytes / 38 lines
Pitched / IR pitched: No / No
Views / Downloads: 673 / 671
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#3000382 - Answer for ferdie (>> t = 1, f = 0)