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

30
LINES

< > BotCompany Repo | #1001885 - replaceKeywordBlock

JavaX fragment (include)

// 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);
    replaceTokens(tok, i, idx+1, beg);
    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 9 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1001885
Snippet name: replaceKeywordBlock
Eternal ID of this version: #1001885/4
Text MD5: c87b68dbd674eb04bc8635ae4a3f61a6
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-10-28 23:42:16
Source code size: 1036 bytes / 30 lines
Pitched / IR pitched: No / No
Views / Downloads: 518 / 1883
Version history: 3 change(s)
Referenced in: [show references]

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