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

47
LINES

< > BotCompany Repo | #1002167 // C# to JavaX Translator v2 (User Level Bot)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Transpiled version (1554L) is out of date.

!752

p {
  L<S> tok = javaTok(loadSnippet("#1002166"));
  
  jreplace(tok, "string.Empty", quote(""));
  
  // classes are UPPER case!
  
  replaceToken(tok, "string", "String");
  
  // ...and have different names.
  
  replaceToken(tok, "Dictionary", "Map");
  
  // ...while methods are LOWER case.
  
  replaceToken(tok, "Split", "split");
  replaceToken(tok, "Equals", "equals");
  replaceToken(tok, "Add", "put");
  replaceToken(tok, "ToLower", "toLowerCase");
  
  // ...and have different names.
  
  replaceToken(tok, "ContainsKey", "containsKey");

  // some syntax
  replaceToken(tok, "in", ":");
  replaceToken(tok, "foreach", "for");
  
  // split function takes a string in Java
  for (int i = 1; i+6 < l(tok); i += 2)
    if (eq(tok.get(i), "split") && eq(tok.get(i+2), "(") && tok.get(i+4).startsWith("'") && eq(tok.get(i+6), ")"))
      tok.set(i+4, charToStringLiteral(tok.get(i+4)));
      
  jreplace(tok, "<id>[<id>]++;", "$1.put($3, $1.get($3)+1);");

  jreplace(tok, "new List", "new ArrayList");
  jreplace(tok, ".Count", ".size()");
  jreplace(tok, "[*]", ".get($2)");
  jreplace(tok, "Uri.EscapeDataString", "urlencode");
  print(join(tok));
}

static S charToStringLiteral(S s) {
  ret "\"" + s.charAt(1) + "\""; // todo: special cases
}

Author comment

Began life as a copy of #1002056

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1002167
Snippet name: C# to JavaX Translator v2 (User Level Bot)
Eternal ID of this version: #1002167/1
Text MD5: da8f642abf1449e712e366b7cfaacca6
Author: stefan
Category:
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-12-23 00:45:22
Source code size: 1311 bytes / 47 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 652 / 691
Referenced in: [show references]