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 (2922L/19K).

// "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> <")) >= 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   

Travelled to 4 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz, xrpafgyirdlv

No comments. add comment

Snippet ID: #1023075
Snippet name: tok_optPar - "optPar int bla = 5;". also boolPar
Eternal ID of this version: #1023075/12
Text MD5: 37cc54edaf8f97584caaa0bc2f49233d
Transpilation MD5: 3cb6ac7a44ae569a0fee9dfb4c5f45e7
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-11 20:34:04
Source code size: 954 bytes / 27 lines
Pitched / IR pitched: No / No
Views / Downloads: 100 / 167
Version history: 11 change(s)
Referenced in: [show references]

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