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

1  
static new ThreadLocal<Bool> evalJava_prep_voidMagic; // set to false to avoid looking up standard function return types
2  
3  
static LS evalJava_prePrep(S code, EvalJavaPrep prep default new) {
4  
  LS tok = javaTok(trim(code));
5  
  
6  
  int idx;
7  
  while ((idx = jfind(tok, "global {")) >= 0) {
8  
    int j = findEndOfBracketPart(tok, idx+2);
9  
    prep.global.add(joinSubList(tok, idx+3, j-1));
10  
    clearTokens_reTok(tok, idx, j+1);
11  
  }
12  
  
13  
  // =1*2 as in Lua
14  
  if (eqGet(tok, 1, "=")) tok = subList(tok, 2);
15  
  
16  
  // if code is something like "sclass Bla {}", just return as is
17  
  if (tok_isStaticLevelCode(tok))
18  
    ret tok;
19  
  
20  
  if (!isFalse(evalJava_prep_voidMagic!) && tok_shouldAddReturn(tok) && eqGet(tok, 3, "(") && isIdentifier(get(tok, 1)) && isKnownVoidFunction_uncached(get(tok, 1)))
21  
    tokAppend_reTok(tok, l(tok)-2, ";");
22  
    
23  
  S name = null;
24  
  ifdef evalJava_prePrep_debug
25  
    printVars evalJava_prePrep(+tok);
26  
  endifdef
27  
  
28  
  // just a single identifier: interpret as function call
29  
  if (l(tok) == 3 && isIdentifier(name = firstToken(tok)))
30  
    tokAppend_reTok(tok, 1, "()" + (isKnownVoidFunction_uncached(name) ? ";" : ""));
31  
    
32  
  ifdef evalJava_prePrep_debug
33  
    printVars evalJava_prePrep(+name, +tok);
34  
  endifdef
35  
    
36  
  ret tok;
37  
}

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: 278 / 375
Version history: 7 change(s)
Referenced in: [show references]