Libraryless. Click here for Pure Java version (10467L/58K).
1 | scope tok_conditionals |
2 | |
3 | // returns number of changes |
4 | static int tok_conditionals(LS tok, S keyword, S keywordEnd, IPred<S> pred, bool reTokImmediately, bool noReTok) { |
5 | int changes = 0; |
6 | if (tok instanceof IContentsIndexedList) { |
7 | int[] l = tok/IContentsIndexedList.indicesOf(keyword); |
8 | for (int j = l(l)-1; j >= 0; j--) { |
9 | int i = l[j]; |
10 | if (isIdentifier(get(tok, i+2))) { |
11 | processConditional(tok, i, keyword, keywordEnd, pred, reTokImmediately && !noReTok); |
12 | ++changes; |
13 | } |
14 | } |
15 | } else { |
16 | if (!tok.contains(keyword)) ret changes; |
17 | int i = l(tok); |
18 | while ((i = rjfind(tok, 1, i-1, keyword + " <id>")) >= 0) { |
19 | ++changes; |
20 | processConditional(tok, i, keyword, keywordEnd, pred, reTokImmediately && !noReTok); |
21 | } |
22 | } |
23 | if (changes != 0 && !reTokImmediately && !noReTok) reTok(tok); |
24 | //print(keyword + ": " + nChanges(changes)); |
25 | ret changes; |
26 | } |
27 | |
28 | svoid #processConditional(LS tok, int i, S keyword, S keywordEnd, IPred<S> pred, bool reTokImmediately) { |
29 | int j = jfind(tok, i+4, keywordEnd); |
30 | if (j < 0) j = l(tok)-1; |
31 | S name = tok.get(i+2); |
32 | bool has = pred.get(name); |
33 | //print(keyword + " " + name + " => " + has); |
34 | if (has) { |
35 | clearTokens_maybeReTok(tok, j, j+1, reTokImmediately); |
36 | clearTokens_maybeReTok(tok, i, i+3, reTokImmediately); |
37 | } else |
38 | clearTokens_maybeReTok(tok, i, j+1, reTokImmediately); // safer than before |
39 | } |
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036305 |
Snippet name: | tok_conditionals |
Eternal ID of this version: | #1036305/2 |
Text MD5: | 4b7edbb4d4d79a29ff7bd5b1b09d1202 |
Transpilation MD5: | ae0737f0d76c6e96f2944793fd1f142d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-11-15 18:17:54 |
Source code size: | 1439 bytes / 39 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 135 / 183 |
Version history: | 1 change(s) |
Referenced in: | [show references] |