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).

// "optPar int bla = 5;" => "int bla = optPar bla(_, 5);"
svoid tok_optPar(LS tok) {
  jreplace(tok, "boolPar <id>", "optPar bool $2", tokCondition {
    ret eqGetOneOf(tok, i+5, "=", ";");
  });
  
  int i;
  
  while ((i = jfindOneOf(tok, "optPar <id> <id>", "optPar <id> <", "optPar <id> [")) >= 0) {
    int iSemicolon = tok_findEndOfStatement(tok, i)-1;
    int iEquals = indexOf_between(tok, "=", i, iSemicolon);
    clearTokens(tok, i, i+2); // drop optPar
    if (iEquals < 0) { // no initializer
      S var = tok.get(iSemicolon-2);
      S type = joinSubList(tok, i+2, iSemicolon-3);
      if (eqOneOf(type, 'bool, 'boolean))
        tok.set(iSemicolon, " = boolPar " + var + "(_);");
      else
        tok.set(iSemicolon, " = cast optPar " + var + "(_);");
    } else {
      S var = tok.get(iEquals-2);
      tok.set(iEquals, "= optPar " + var + "(_, ");
      tok.set(iSemicolon, ");");
    }
    reTok(tok, i, iSemicolon+1);
  }
}

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: 379 / 520
Version history: 13 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1026760 - tok_optParLambda