Libraryless. Click here for Pure Java version (1554L/11K/36K).
1 | !747 |
2 | |
3 | m {
|
4 | p {
|
5 | S input = loadSnippet("#1001519");
|
6 | L<S> tok = javaTok(input); |
7 | |
8 | new L out; |
9 | int count = 0; |
10 | for (int i = 0; i < tok.size(); i++) {
|
11 | S t = tok.get(i); |
12 | if ((i & 1) == 1 && isOpening(t)) {
|
13 | ++count; |
14 | out.addAll(litlist(Color.green, t, Color.white)); |
15 | } else if ((i & 1) == 1 && isClosing(t)) {
|
16 | --count; |
17 | out.addAll(litlist(Color.blue, t, Color.white)); |
18 | } else |
19 | out.add(t); |
20 | } |
21 | |
22 | JTextPane textPane = showColoredText(out); |
23 | S comment = count == 0 ? "Brackets match." : "Bracket match error " + count; |
24 | addCommentToWindow(textPane, comment); |
25 | addSaveButton(textPane, "Marked opening and closing tokens", out); |
26 | } |
27 | |
28 | static boolean isOpening(S s) {
|
29 | ret litlist("<", "(", "{", "[").contains(s);
|
30 | } |
31 | |
32 | static boolean isClosing(S s) {
|
33 | ret litlist(">", ")", "}", "]").contains(s);
|
34 | } |
35 | } |
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1001525 |
| Snippet name: | Mark opening and closing tokens in JavaX source |
| Eternal ID of this version: | #1001525/1 |
| Text MD5: | 84a30db9ee2c0d8ed1d74b71185510db |
| Transpilation MD5: | 8ab05a186a7114ef68eda68b76946fad |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-10-22 18:06:48 |
| Source code size: | 937 bytes / 35 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 861 / 965 |
| Referenced in: | [show references] |