Libraryless. Click here for Pure Java version (3599L/24K/78K).
1 | !759 |
2 | |
3 | p { |
4 | S text = loadSnippet("#1002764"); |
5 | snlCheckBrackets(text); |
6 | print("Bracket check OK"); |
7 | Lisp tree = snlToTree(text); |
8 | print("head: " + tree.head); |
9 | } |
10 | |
11 | static void snlCheckBrackets(S snl) { |
12 | L<S> tok = snlTok(snl); |
13 | new L<S> stack; |
14 | for (int i = 1; i < l(tok); i += 2) { |
15 | S t = tok.get(i); |
16 | if (eq(t, "[") || eq(t, "(")) |
17 | stack.add(t); |
18 | else if (eq(t, "]")) { |
19 | S op = popLast(stack); |
20 | if (!eq(op, "[")) |
21 | fail("bracket failure at token " + i + "/" + l(tok) + ": " + op + " vs " + join(subList(tok, i, i+9))); |
22 | } else if (eq(t, ")")) { |
23 | S op = popLast(stack); |
24 | if (!eq(op, "(")) |
25 | fail("bracket failure at token " + i + "/" + l(tok) + ": " + op + " vs " + join(subList(tok, i, i+9))); |
26 | } |
27 | } |
28 | if (!stack.isEmpty()) |
29 | print("open brackets remain: " + structure(stack)); |
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: | #1002779 |
Snippet name: | Find tests and theories |
Eternal ID of this version: | #1002779/1 |
Text MD5: | ade5bbf52538b254b55f89a946697c85 |
Transpilation MD5: | 3406af4a7594db7a82e5aaf57ea9d707 |
Author: | stefan |
Category: | eleu / snl |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2016-02-23 02:21:12 |
Source code size: | 870 bytes / 30 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 778 / 776 |
Referenced in: | [show references] |