1 | // split smth like "if * then *" into "if *" and "then *" |
2 | // returns null if no split |
3 | // now also for NL trees |
4 | static L<Lisp> snlSplitOps(Lisp code) { |
5 | new L<Lisp> out; |
6 | |
7 | if (code.is("[]")) { |
8 | // NL |
9 | |
10 | if ((code.size() & 1) != 0) ret null; |
11 | for (int i = 0; i < code.size(); i += 2) { |
12 | Lisp op = code.get(i), arg = code.get(i+1); |
13 | if (!op.isLeaf() || !isExtendedIdentifier(op.head)) ret null; |
14 | out.add(lisp(op + " *", nlUnbracket(arg))); |
15 | } |
16 | |
17 | ret out; |
18 | } |
19 | |
20 | S ops = code.head; |
21 | L<S> tok = codeTokensOnly(javaTok(ops)); |
22 | if ((l(tok) & 1) != 0) ret null; |
23 | for (int i = 0; i < l(tok); i += 2) { |
24 | S op = tok.get(i); |
25 | if (!isIdentifier(op) || neq("*", tok.get(i+1))) ret null; |
26 | out.add(lisp(op + " *", code.get(i/2))); |
27 | } |
28 | //print("splitOps => " + structure(out)); |
29 | ret out; |
30 | } |
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: | #1002756 |
Snippet name: | snlSplitOps |
Eternal ID of this version: | #1002756/1 |
Text MD5: | 1f0f73536ec0ab3b08c4d49b52b02087 |
Author: | stefan |
Category: | eleu / nl |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-03-03 02:17:41 |
Source code size: | 858 bytes / 30 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 709 / 892 |
Referenced in: | [show references] |