Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

31
LINES

< > BotCompany Repo | #1001885 // replaceKeywordBlock

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (11437L/64K).

// keyword can comprise multiple tokens now (like "p-awt"}
static L<S> replaceKeywordBlock(L<S> tok, S keyword, S beg, S end) {
  ret replaceKeywordBlock(tok, keyword, beg, end, false, null);
}

static L<S> replaceKeywordBlock(L<S> tok, S keyword, S beg, S end, O cond) {
  ret replaceKeywordBlock(tok, keyword, beg, end, false, cond);
}

static L<S> replaceKeywordBlock(L<S> tok, S keyword, S beg, S end,
  bool debug, O cond) {
  for (int n = 0; n < 1000; n++) {
    int i = jfind(tok, keyword + " {", cond);
    if (i < 0)
      break;
    int idx = findCodeTokens(tok, i, false, "{");
    int j = findEndOfBracketPart(tok, idx);
    
    if (debug) {
      print(toUpper(keyword) + " BEFORE\n" + join(subList(tok, i, j)));
      print("  THEN " + join(subList(tok, j, j+10)));
    }
    //assertEquals("}", tok.get(j-1));
    LS subList = subList(tok, i-1, idx); // N to somewhere
    tok.set(j-1, jreplaceExpandRefs(end, subList));
    replaceTokens(tok, i, idx+1, jreplaceExpandRefs(beg, subList));
    reTok(tok, i, j);
    if (debug) print(toUpper(keyword) + "\n" + join(subList(tok, i, j)) + "\n");
  }
  ret tok;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001885
Snippet name: replaceKeywordBlock
Eternal ID of this version: #1001885/8
Text MD5: be88da73a6ee78ac0fbfed3aae888ddd
Transpilation MD5: 9e97f365232108b5a2afa728ec962301
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-24 03:04:50
Source code size: 1154 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 894 / 2462
Version history: 7 change(s)
Referenced in: [show references]