Libraryless. Click here for Pure Java version (1741L/12K/38K).
!752 p { S src = loadSnippet("#1002128"); // original as dictated through google voice recognition src = executeReplacements(loadSnippet("#1002129"), src, false); // correct dictation errors src = strings(src); src = executeReplacements(loadSnippet("#1002131"), src, true); // translate to CODE (JavaX) print(); print(src); createTempProgram(src, "WTF Bot (translated from dictation)"); } static S executeReplacements(S rep, S src, boolean withNewlines) { L<S> tok = javaTok(src); L<S> lines = toLinesFullTrim(rep); for (S line : lines) { L<S> tokl = javaTok(line); int i = tokl.indexOf("="); S in, out; if (i >= 0) { in = trim(join(tokl.subList(0, i))); out = trim(join(subList(tokl, i+1))); } else if (l(tokl) != 5) { print("bad line, ignoring: " + quote(line)); continue; } else { in = unquote(tokl.get(1)); out = unquote(tokl.get(3)); } print(format("Replacing: * with *", in, out)); jreplace(tok, in, withNewlines ? out + "\n" : out, true, true); } ret join(tok); } static S strings(S src) { L<S> tok = javaTok(src); for (int n = 0; n < 10000; n++) { int i = findCodeTokens(tok, true, "string", "begin"); if (i < 0) break; clearAllTokens(tok.subList(i, i+4)); // code to N tok.set(i, "\""); } for (int n = 0; n < 10000; n++) { int i = findCodeTokens(tok, true, "string", "end"); if (i < 0) break; clearAllTokens(tok.subList(i-1, i+3)); // N to code tok.set(i, "\""); } ret join(tok); }
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: | #1002134 |
Snippet name: | Translate WTF Bot |
Eternal ID of this version: | #1002134/1 |
Text MD5: | 08d19d474a26f71423a5bb17a6e5bdf9 |
Transpilation MD5: | 3dc168c2e01304457bb2159f3232eccf |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-12-21 20:17:34 |
Source code size: | 1595 bytes / 54 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 660 / 737 |
Referenced in: | [show references] |