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

25
LINES

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

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

Libraryless. Click here for Pure Java version (2339L/15K).

// "optPar int bla = 5;" => "int bla = optPar bla(_, 5);"
svoid tok_optPar(LS tok) {
  if (!tok.contains("optPar")) ret;
  
  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 3 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1023075
Snippet name: tok_optPar - "optPar int bla = 5;"
Eternal ID of this version: #1023075/9
Text MD5: bb1ebac8f39f6cb438ca1245a8693eb2
Transpilation MD5: 20670d29c69fff249b9f2c200caf1e31
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-22 13:37:29
Source code size: 877 bytes / 25 lines
Pitched / IR pitched: No / No
Views / Downloads: 61 / 106
Version history: 8 change(s)
Referenced in: [show references]

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