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

21
LINES

< > BotCompany Repo | #1008911 // ctxSimplifyIfs [OUTDATED]

JavaX fragment (include)

1  
static void ctxSimplifyIfs(L<S> tok) {
2  
  int i;
3  
  while ((i = jfind(tok, "if (")) >= 0) {
4  
    int iEnd = findEndOfBracketPart(tok, i+2)-1;
5  
    S cond = join(subList(tok, i+4, iEnd-1));
6  
    bool yes = ctxEvalCondition(cond);
7  
    assertEquals("{", tok.get(iEnd+2));
8  
    int iEndYes = findEndOfBlock(tok, iEnd+2)-1;
9  
    S yesCode = join(subList(tok, iEnd+4, iEndYes-1));
10  
    int j = iEndYes+2;
11  
    S noCode = "";
12  
    if (eqGet(tok, iEndYes+2, "else")) {
13  
      int iNo = iEndYes+4;
14  
      assertEquals("{", tok.get(iNo));
15  
      int iEndNo = findEndOfBlock(tok, iNo)-1;
16  
      j = iEndNo+2;
17  
      noCode = join(subList(tok, iNo+2, iEndNo-1));
18  
    }
19  
    replaceTokens_reTok(tok, i, j, yes ? yesCode : noCode);
20  
  }
21  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1008911
Snippet name: ctxSimplifyIfs [OUTDATED]
Eternal ID of this version: #1008911/6
Text MD5: 1c5a32b55859e2acdd79a907e14ff890
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-07-01 19:07:34
Source code size: 727 bytes / 21 lines
Pitched / IR pitched: No / No
Views / Downloads: 597 / 615
Version history: 5 change(s)
Referenced in: [show references]