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).

1  
// keyword can comprise multiple tokens now (like "p-awt"}
2  
static L<S> replaceKeywordBlock(L<S> tok, S keyword, S beg, S end) {
3  
  ret replaceKeywordBlock(tok, keyword, beg, end, false, null);
4  
}
5  
6  
static L<S> replaceKeywordBlock(L<S> tok, S keyword, S beg, S end, O cond) {
7  
  ret replaceKeywordBlock(tok, keyword, beg, end, false, cond);
8  
}
9  
10  
static L<S> replaceKeywordBlock(L<S> tok, S keyword, S beg, S end,
11  
  bool debug, O cond) {
12  
  for (int n = 0; n < 1000; n++) {
13  
    int i = jfind(tok, keyword + " {", cond);
14  
    if (i < 0)
15  
      break;
16  
    int idx = findCodeTokens(tok, i, false, "{");
17  
    int j = findEndOfBracketPart(tok, idx);
18  
    
19  
    if (debug) {
20  
      print(toUpper(keyword) + " BEFORE\n" + join(subList(tok, i, j)));
21  
      print("  THEN " + join(subList(tok, j, j+10)));
22  
    }
23  
    //assertEquals("}", tok.get(j-1));
24  
    LS subList = subList(tok, i-1, idx); // N to somewhere
25  
    tok.set(j-1, jreplaceExpandRefs(end, subList));
26  
    replaceTokens(tok, i, idx+1, jreplaceExpandRefs(beg, subList));
27  
    reTok(tok, i, j);
28  
    if (debug) print(toUpper(keyword) + "\n" + join(subList(tok, i, j)) + "\n");
29  
  }
30  
  ret tok;
31  
}

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: 896 / 2465
Version history: 7 change(s)
Referenced in: [show references]