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

27
LINES

< > BotCompany Repo | #1023075 // tok_optPar - "optPar int bla = 5;". also boolPar

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3305L/21K).

1  
// "optPar int bla = 5;" => "int bla = optPar bla(_, 5);"
2  
svoid tok_optPar(LS tok) {
3  
  jreplace(tok, "boolPar <id>", "optPar bool $2", tokCondition {
4  
    ret eqGetOneOf(tok, i+5, "=", ";");
5  
  });
6  
  
7  
  int i;
8  
  
9  
  while ((i = jfindOneOf(tok, "optPar <id> <id>", "optPar <id> <", "optPar <id> [")) >= 0) {
10  
    int iSemicolon = tok_findEndOfStatement(tok, i)-1;
11  
    int iEquals = indexOf_between(tok, "=", i, iSemicolon);
12  
    clearTokens(tok, i, i+2); // drop optPar
13  
    if (iEquals < 0) { // no initializer
14  
      S var = tok.get(iSemicolon-2);
15  
      S type = joinSubList(tok, i+2, iSemicolon-3);
16  
      if (eqOneOf(type, 'bool, 'boolean))
17  
        tok.set(iSemicolon, " = boolPar " + var + "(_);");
18  
      else
19  
        tok.set(iSemicolon, " = cast optPar " + var + "(_);");
20  
    } else {
21  
      S var = tok.get(iEquals-2);
22  
      tok.set(iEquals, "= optPar " + var + "(_, ");
23  
      tok.set(iSemicolon, ");");
24  
    }
25  
    reTok(tok, i, iSemicolon+1);
26  
  }
27  
}

Author comment

Began life as a copy of #1010313

download  show line numbers  debug dex  old transpilations   

Travelled to 8 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1023075
Snippet name: tok_optPar - "optPar int bla = 5;". also boolPar
Eternal ID of this version: #1023075/14
Text MD5: c066d908668177bc1c5162e63b6a99e7
Transpilation MD5: cb159cfb6e6c7f8c41bbae58c12bea2a
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-07 13:04:21
Source code size: 971 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 303 / 429
Version history: 13 change(s)
Referenced in: [show references]