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

47
LINES

< > BotCompany Repo | #1031905 // tok_multiTypeArguments [replaced by tok_multiTypeArguments_v2]

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

Transpiled version (4269L) is out of date.

1  
// only one multi-type argument per declaration for now
2  
// also allows only one combo right now (File/S with newFile)
3  
// example:
4  
// sS loadTextFile(File/S file) { ... }
5  
svoid tok_multiTypeArguments(LS tok) {
6  
  int i;
7  
  while ((i = jfind(tok, "File/<id> <id>", (_tok, nIdx) ->
8  
      eqGetOneOf(_tok, nIdx+5, "S", "String"))) >= 0) {
9  
    int iOpening = lastIndexOf(tok, i, "("); // TODO: brackets
10  
    int iClosing = findEndOfBracketPart2(tok, iOpening)-1;
11  
12  
    // function name
13  
    int iName = iOpening-2;
14  
    S name = assertIdentifier(get(tok, iName));
15  
    
16  
    int iType = tok_leftScanType(tok, iName);
17  
    int iStart = tok_leftScanTypeArgsOpt(tok, iType);
18  
    iStart = leftScanModifiers(tok, iStart);
19  
    //print("Found method head: " + joinSubList(tok, iStart, iClosing+1));
20  
    int iArgEnd = i+8; // comma or closing bracket
21  
    LS _args1 = subList(tok, iOpening+1, i);
22  
    LS _args2 = subList(tok, iArgEnd+1, iClosing);
23  
    LS args1 = tok_parseArgsDeclList2(_args1);
24  
    LS args2 = tok_parseArgsDeclList2(_args2);
25  
    LS type = subList(tok, iType-1, iName);
26  
    bool isVoid = containsOneOf(codeTokens(type), javaxVoidAliases());
27  
    //printVars(+expr, +_args1, +_args2, +args1, +args2, +type, +isVoid);
28  
    
29  
    S argName = tok.get(i+6);
30  
    S mainType = tok.get(i), altType = tok.get(i+4);
31  
    S converter = "newFile";
32  
    S expr = converter + "(" + argName + ")";
33  
    
34  
    S rewrittenHead = joinSubList(tok, iStart, iOpening+1)
35  
      + joinWithComma(concatLists(
36  
          args1,
37  
          ll(altType + " " + argName),
38  
          args2)) + ")";
39  
    replaceTokens_reTok(tok, i, i+7, mainType + " " + argName);
40  
    tokPrepend_reTok(tok, iStart, rewrittenHead + " { "
41  
      + (isVoid ? "" : "return ") + name + "(" + 
42  
        joinWithComma(concatLists(
43  
          map tok_lastIdentifier(args1),
44  
          ll(expr),
45  
          map tok_lastIdentifier(args2))) + "); }\n");
46  
  }
47  
}

Author comment

Began life as a copy of #1027996

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1031905
Snippet name: tok_multiTypeArguments [replaced by tok_multiTypeArguments_v2]
Eternal ID of this version: #1031905/7
Text MD5: da67e27c87a9b32ed58dd736b1c35aa7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-17 14:27:59
Source code size: 1923 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 95 / 150
Version history: 6 change(s)
Referenced in: [show references]