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

22
LINES

< > BotCompany Repo | #1013759 - tok_replaceWith - process "replace * with *." statements; applies to current block only

JavaX fragment (include)

static void tok_replaceWith(L<S> tok) {
  int i;
  while ((i = jfind(tok, "replace <id> with")) >= 0) {
    S token = tok.get(i+2);
    int repStart = i+6;
    int repEnd = repStart;
    
    // Find . with space or line break or EOF afterwards
    while (!(eqGet(tok, repEnd, ".") &&
      (nempty(get(tok, repEnd+1)) || repEnd == l(tok)-2)))
      repEnd += 2;
    //int repEnd = smartIndexOf(tok, repStart, ".");
    
    S replacement = joinSubList(tok, repStart, repEnd-1);
    clearTokens(tok, i, repEnd+1);
    print("Replacing " + token + " with " + replacement + ".");
    int end = findEndOfBlock(tok, repEnd)-1;
    for (int j = repEnd+2; j < end; j += 2)
      if (eq(tok.get(j), token)) tok.set(j, replacement);
    reTok(tok, i, end);
  }
}

download  show line numbers  debug dex   

Travelled to 10 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1013759
Snippet name: tok_replaceWith - process "replace * with *." statements; applies to current block only
Eternal ID of this version: #1013759/10
Text MD5: 0b16d0d67e8fb532fcb030bf6b9fcd55
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-08-24 14:01:32
Source code size: 777 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 186 / 214
Version history: 9 change(s)
Referenced in: [show references]

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