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.

1  
!752
2  
3  
p {
4  
  L<S> tok = javaTok(loadSnippet("#1002166"));
5  
  
6  
  jreplace(tok, "string.Empty", quote(""));
7  
  
8  
  // classes are UPPER case!
9  
  
10  
  replaceToken(tok, "string", "String");
11  
  
12  
  // ...and have different names.
13  
  
14  
  replaceToken(tok, "Dictionary", "Map");
15  
  
16  
  // ...while methods are LOWER case.
17  
  
18  
  replaceToken(tok, "Split", "split");
19  
  replaceToken(tok, "Equals", "equals");
20  
  replaceToken(tok, "Add", "put");
21  
  replaceToken(tok, "ToLower", "toLowerCase");
22  
  
23  
  // ...and have different names.
24  
  
25  
  replaceToken(tok, "ContainsKey", "containsKey");
26  
27  
  // some syntax
28  
  replaceToken(tok, "in", ":");
29  
  replaceToken(tok, "foreach", "for");
30  
  
31  
  // split function takes a string in Java
32  
  for (int i = 1; i+6 < l(tok); i += 2)
33  
    if (eq(tok.get(i), "split") && eq(tok.get(i+2), "(") && tok.get(i+4).startsWith("'") && eq(tok.get(i+6), ")"))
34  
      tok.set(i+4, charToStringLiteral(tok.get(i+4)));
35  
      
36  
  jreplace(tok, "<id>[<id>]++;", "$1.put($3, $1.get($3)+1);");
37  
38  
  jreplace(tok, "new List", "new ArrayList");
39  
  jreplace(tok, ".Count", ".size()");
40  
  jreplace(tok, "[*]", ".get($2)");
41  
  jreplace(tok, "Uri.EscapeDataString", "urlencode");
42  
  print(join(tok));
43  
}
44  
45  
static S charToStringLiteral(S s) {
46  
  ret "\"" + s.charAt(1) + "\""; // todo: special cases
47  
}

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: 654 / 694
Referenced in: [show references]