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 (2899L/18K).

// 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));
    tok.set(j-1, end);
    LS subList = tok.subList(i-1, idx); // N to somewhere
    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   

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

No comments. add comment

Snippet ID: #1001885
Snippet name: replaceKeywordBlock
Eternal ID of this version: #1001885/5
Text MD5: ab1d343c4cf319fc703555fcdabc99ae
Transpilation MD5: 6637cafc9c96cdb4fa7b2236b5895c23
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-03-23 15:56:57
Source code size: 1124 bytes / 31 lines
Pitched / IR pitched: No / No
Views / Downloads: 544 / 1943
Version history: 4 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1001885 & http://1001885.tinybrain.de