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

24
LINES

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

JavaX fragment (include)

1  
static void tok_replaceWith(L<S> tok) {
2  
  int i;
3  
  while ping ((i = jfind(tok, "replace <id> with")) >= 0) {
4  
    S token = tok.get(i+2);
5  
    int repStart = i+6;
6  
    int repEnd = repStart;
7  
    
8  
    // Find . with space or line break or EOF afterwards
9  
    while ping (repEnd < l(tok) && !(
10  
      eqGet(tok, repEnd, ".") && // end when there is a dot
11  
      (nempty(get(tok, repEnd+1)) || repEnd == l(tok)-2))) // ...and it's the end of the text OR there is a space or newline after the dot
12  
      repEnd += 2;
13  
    print("tok_replaceWith: Found " + joinSubList(tok, repStart, repEnd));
14  
    //int repEnd = smartIndexOf(tok, repStart, ".");
15  
16  
    S replacement = joinSubList(tok, repStart, repEnd-1);
17  
    clearTokens(tok, i, repEnd+1);
18  
    print("Replacing " + token + " with " + replacement + ".");
19  
    int end = findEndOfBlock(tok, repEnd)-1;
20  
    for ping (int j = repEnd+2; j < end; j += 2)
21  
      if (eq(tok.get(j), token)) tok.set(j, replacement);
22  
    reTok(tok, i, end);
23  
  }
24  
}

download  show line numbers  debug dex  old transpilations   

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

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/13
Text MD5: 4d483ca84e663fcabe218a574e7eaf15
Author: stefan
Category: javax / parsing
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-25 18:09:02
Source code size: 998 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 522 / 603
Version history: 12 change(s)
Referenced in: [show references]