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

29
LINES

< > BotCompany Repo | #723 // L<S>, O, ret and so on (translator)

JavaX translator [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (270L/3K/8K).

!636
!quicktranslator

List<String> tok = javaTok(s);

// replace <int> with <Integer>
for (int i = 1; i+4 < tok.size(); i += 2)
  if (tok.get(i).equals("<")
    && litlist(">", ",").contains(tok.get(i+4))) {
    String type = tok.get(i+2);
    if (type.equals("int")) type = "Integer";
    else if (type.equals("long")) type = "Long";
    tok.set(i+2, type);
  }
  
// O = Object, S = String, ret = return
for (int i = 1; i < tok.size(); i += 2) {
  String t = tok.get(i);
  if (t.equals("O")) t = "Object";
  if (t.equals("S")) t = "String";
  else if (t.equals("L")) t = "List";
  else if (t.equals("F")) t = "Function";
  else if (t.equals("Int")) t = "Integer";
  else if (t.equals("ret")) t = "return";
  else if (t.equals("bool") && i+2 < tok.size() && neq(tok.get(i+2), "(")) t = "boolean"; // bool -> boolean if it's not a function name
  tok.set(i, t);
}

s = join(tok);

Author comment

Began life as a copy of #1000381

download  show line numbers  debug dex  old transpilations   

Travelled to 22 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, dhtvkmknsjym, gwrvuhgaqvyk, hxnwyiuffukg, ishqpsrjomds, jlatgrcjtklg, jtubtzbbkimh, liwcxgsjrgqn, lpdgvwnxivlt, mqqgnosmbjvj, mrjhfnjfopze, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

Comments [hide]

ID Author/Program Comment Date
1110 stefan (removed a block) 2015-10-03 15:36:31
1109 stefan Warning: Possible disruptive change. 2015-10-03 15:36:19

add comment

Snippet ID: #723
Snippet name: L<S>, O, ret and so on (translator)
Eternal ID of this version: #723/1
Text MD5: 51837a72e4edf71096cc528d2cbb6fc7
Transpilation MD5: 22c7708fbd0d25c4746cfa9caabf3326
Author: stefan
Category: javax
Type: JavaX translator
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-04 17:03:56
Source code size: 908 bytes / 29 lines
Pitched / IR pitched: No / No
Views / Downloads: 870 / 19873
Referenced in: [show references]