Libraryless. Click here for Pure Java version (10467L/58K).
scope tok_conditionals // returns number of changes static int tok_conditionals(LS tok, S keyword, S keywordEnd, IPred<S> pred, bool reTokImmediately, bool noReTok) { int changes = 0; if (tok instanceof IContentsIndexedList) { int[] l = tok/IContentsIndexedList.indicesOf(keyword); for (int j = l(l)-1; j >= 0; j--) { int i = l[j]; if (isIdentifier(get(tok, i+2))) { processConditional(tok, i, keyword, keywordEnd, pred, reTokImmediately && !noReTok); ++changes; } } } else { if (!tok.contains(keyword)) ret changes; int i = l(tok); while ((i = rjfind(tok, 1, i-1, keyword + " <id>")) >= 0) { ++changes; processConditional(tok, i, keyword, keywordEnd, pred, reTokImmediately && !noReTok); } } if (changes != 0 && !reTokImmediately && !noReTok) reTok(tok); //print(keyword + ": " + nChanges(changes)); ret changes; } svoid #processConditional(LS tok, int i, S keyword, S keywordEnd, IPred<S> pred, bool reTokImmediately) { int j = jfind(tok, i+4, keywordEnd); if (j < 0) j = l(tok)-1; S name = tok.get(i+2); bool has = pred.get(name); //print(keyword + " " + name + " => " + has); if (has) { clearTokens_maybeReTok(tok, j, j+1, reTokImmediately); clearTokens_maybeReTok(tok, i, i+3, reTokImmediately); } else clearTokens_maybeReTok(tok, i, j+1, reTokImmediately); // safer than before }
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: | 133 / 181 |
Version history: | 1 change(s) |
Referenced in: | [show references] |