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

29
LINES

< > BotCompany Repo | #1006502 - tok_repeatWithSleep

JavaX fragment (include)

static bool tok_repeatWithSleep_verbose;

static L<S> tok_repeatWithSleep(L<S> tok) {
  int i;
  while ((i = jfind(tok, "repeat with sleep * {")) >= 0) {
    S seconds = tok.get(i+6); // int or id
    int idx = findCodeTokens(tok, i, false, "{");
    int j = findEndOfBracketPart(tok, idx);
    if (tok_repeatWithSleep_verbose) print("idx=" + idx + ", j=" + j);
    clearTokens(tok, i, idx+1);
    tok.set(i, "repeat { pcall {");
    tok.set(j-1, "} sleepSeconds(" + seconds + "); }");
    reTok(tok, j-1, j);
    reTok(tok, i, idx+1);
  }
  
  while ((i = jfind(tok, "repeat with ms sleep * {")) >= 0) {
    S ms = tok.get(i+8); // int or id
    int idx = findCodeTokens(tok, i, false, "{");
    int j = findEndOfBracketPart(tok, idx);
    if (tok_repeatWithSleep_verbose) print("idx=" + idx + ", j=" + j);
    clearTokens(tok, i, idx+1);
    tok.set(i, "repeat { pcall {");
    tok.set(j-1, "} sleep(" + ms + "); }");
    reTok(tok, j-1, j);
    reTok(tok, i, idx+1);
  }
  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: #1006502
Snippet name: tok_repeatWithSleep
Eternal ID of this version: #1006502/2
Text MD5: 641a78a1a806efffb526da2b223a4f01
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-02-03 05:25:06
Source code size: 1016 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 246 / 276
Version history: 1 change(s)
Referenced in: [show references]

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