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

37
LINES

< > BotCompany Repo | #1033000 // evalJava_prePrep

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

Libraryless. Click here for Pure Java version (7612L/45K).

static new ThreadLocal<Bool> evalJava_prep_voidMagic; // set to false to avoid looking up standard function return types

static LS evalJava_prePrep(S code, EvalJavaPrep prep default new) {
  LS tok = javaTok(trim(code));
  
  int idx;
  while ((idx = jfind(tok, "global {")) >= 0) {
    int j = findEndOfBracketPart(tok, idx+2);
    prep.global.add(joinSubList(tok, idx+3, j-1));
    clearTokens_reTok(tok, idx, j+1);
  }
  
  // =1*2 as in Lua
  if (eqGet(tok, 1, "=")) tok = subList(tok, 2);
  
  // if code is something like "sclass Bla {}", just return as is
  if (tok_isStaticLevelCode(tok))
    ret tok;
  
  if (!isFalse(evalJava_prep_voidMagic!) && tok_shouldAddReturn(tok) && eqGet(tok, 3, "(") && isIdentifier(get(tok, 1)) && isKnownVoidFunction_uncached(get(tok, 1)))
    tokAppend_reTok(tok, l(tok)-2, ";");
    
  S name = null;
  ifdef evalJava_prePrep_debug
    printVars evalJava_prePrep(+tok);
  endifdef
  
  // just a single identifier: interpret as function call
  if (l(tok) == 3 && isIdentifier(name = firstToken(tok)))
    tokAppend_reTok(tok, 1, "()" + (isKnownVoidFunction_uncached(name) ? ";" : ""));
    
  ifdef evalJava_prePrep_debug
    printVars evalJava_prePrep(+name, +tok);
  endifdef
    
  ret tok;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033000
Snippet name: evalJava_prePrep
Eternal ID of this version: #1033000/8
Text MD5: d9bd911819bec9169f2ce211e3854f4e
Transpilation MD5: 0b98792ab0306c030c4da376244f1d69
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-11 09:31:41
Source code size: 1277 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 276 / 373
Version history: 7 change(s)
Referenced in: [show references]