1 | static S tok_autoCloseBrackets(S s) { |
2 | ret join(tok_autoCloseBrackets(javaTok(s))); |
3 | } |
4 | |
5 | // modifies tok |
6 | static L<S> tok_autoCloseBrackets(L<S> tok) { |
7 | bigloop: for (int i = 1; i < l(tok); i += 2) { |
8 | if (eq(tok.get(i), ";")) { |
9 | int j, level = 0; |
10 | for (j = i-2; j >= 0; j -= 2) { |
11 | S t = tok.get(j); |
12 | if (eqOneOf(t, ";", "{")) break; |
13 | if (eq(t, "}")) break; // TODO: skip over until other end of bracket |
14 | else if (eq(t, ")")) --level; |
15 | else if (eq(t, "(")) { |
16 | if (eq(get(tok, j-2), "for")) break; |
17 | if (eq(get(tok, j-4), "for")) break; // for ping |
18 | ++level; |
19 | } |
20 | } |
21 | while (level-- > 0) { |
22 | tok.add(i++, ")"); |
23 | tok.add(i++, ""); |
24 | } |
25 | } |
26 | } |
27 | ret tok; |
28 | } |
Began life as a copy of #1006346
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1006347 |
Snippet name: | tok_autoCloseBrackets |
Eternal ID of this version: | #1006347/3 |
Text MD5: | ca804d3c60278e14b4856413479ac97e |
Author: | stefan |
Category: | javax / magic transformation |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-08-11 16:38:50 |
Source code size: | 786 bytes / 28 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 642 / 756 |
Version history: | 2 change(s) |
Referenced in: | [show references] |