static int rfindCodeTokens(L tok, S... tokens) { ret rfindCodeTokens(tok, 1, false, tokens); } static int rfindCodeTokens(L tok, boolean ignoreCase, S... tokens) { ret rfindCodeTokens(tok, 1, ignoreCase, tokens); } static int rfindCodeTokens(L tok, int startIdx, boolean ignoreCase, S... tokens) { ret rfindCodeTokens(tok, startIdx, ignoreCase, tokens, null); } static L rfindCodeTokens_specials = litlist("*", "", "", "", "\\*"); static bool rfindCodeTokens_debug; static int rfindCodeTokens_indexed, rfindCodeTokens_unindexed; static int rfindCodeTokens_bails, rfindCodeTokens_nonbails; static int rfindCodeTokens(L tok, int startIdx, boolean ignoreCase, S[] tokens, O condition) { ret rfindCodeTokens(tok, startIdx, l(tok), ignoreCase, tokens, condition); } static int rfindCodeTokens(L tok, int startIdx, int endIndex, bool ignoreCase, S[] tokens, O condition) { if (rfindCodeTokens_debug) { if (eq(getClassName(tok), "main$IndexedList2")) rfindCodeTokens_indexed++; else rfindCodeTokens_unindexed++; } // bail out early if first token not found (works great with IndexedList) if (!rfindCodeTokens_specials.contains(tokens[0]) && !tok.contains(tokens[0] /*, startIdx << no signature in List for this, unfortunately */)) { ++rfindCodeTokens_bails; ret -1; } ++rfindCodeTokens_nonbails; outer: for (int i = min(endIndex, tok.size()-tokens.length*2) | 1; i >= startIdx; i -= 2) { for (int j = 0; j < tokens.length; j++) { S p = tokens[j], t = tok.get(i+j*2); boolean match; if (eq(p, "*")) match = true; else if (eq(p, "")) match = isQuoted(t); else if (eq(p, "")) match = isIdentifier(t); else if (eq(p, "")) match = isInteger(t); else if (eq(p, "\\*")) match = eq("*", t); else match = ignoreCase ? eqic(p, t) : eq(p, t); if (!match) continue outer; } if (condition == null || checkTokCondition(condition, tok, i-1)) // pass N index return i; } return -1; }