static bool allVarNames_debug; static L<S> allVarNames(L<S> tok) { bool debug = allVarNames_debug; Map<Int, Int> bracketMap = getBracketMap(tok); new L<S> varNames; for (int i = 3; i < tok.size(); i += 2) { S t = tok.get(i); if (eqOneOf(t, "=", ";", ",")) { S v = tok.get(i-2); if (isIdentifier(v)) varNames.add(v); if (eq(t, "=")) { i = scanToEndOfInitializer(tok, bracketMap, i)+1; assertTrue(odd(i)); } } else if (eq(t, "<")) { i = findEndOfTypeArgs(tok, i)+1; if (debug) print("Skipped type args: " + struct(subList(tok, i))); } else if (eqOneOf(t, "{", "(")) i = findEndOfBracketPart(tok, i)-1; // skip function/class bodies } return varNames; } static L<S> allVarNames(S text) { ret allVarNames(javaTok(text)); }
Began life as a copy of #1001157
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005504 |
Snippet name: | allVarNames - find all variable/field declarations in a block/class |
Eternal ID of this version: | #1005504/5 |
Text MD5: | 36a512fb2957bd9031b1f9bf45ef3488 |
Author: | stefan |
Category: | javax / parsing |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2018-12-14 01:41:40 |
Source code size: | 852 bytes / 29 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 561 / 797 |
Version history: | 4 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) #1009921 - allVarNamesWithTypes - find all variable/field declarations in a block/class [dev.] |