Libraryless. Click here for Pure Java version (1741L/12K/38K).
1 | !752 |
2 | |
3 | p { |
4 | S src = loadSnippet("#1002128"); // original as dictated through google voice recognition |
5 | src = executeReplacements(loadSnippet("#1002129"), src, false); // correct dictation errors |
6 | src = strings(src); |
7 | src = executeReplacements(loadSnippet("#1002131"), src, true); // translate to CODE (JavaX) |
8 | print(); |
9 | print(src); |
10 | createTempProgram(src, "WTF Bot (translated from dictation)"); |
11 | } |
12 | |
13 | static S executeReplacements(S rep, S src, boolean withNewlines) { |
14 | L<S> tok = javaTok(src); |
15 | L<S> lines = toLinesFullTrim(rep); |
16 | for (S line : lines) { |
17 | L<S> tokl = javaTok(line); |
18 | int i = tokl.indexOf("="); |
19 | S in, out; |
20 | if (i >= 0) { |
21 | in = trim(join(tokl.subList(0, i))); |
22 | out = trim(join(subList(tokl, i+1))); |
23 | } else if (l(tokl) != 5) { |
24 | print("bad line, ignoring: " + quote(line)); |
25 | continue; |
26 | } else { |
27 | in = unquote(tokl.get(1)); |
28 | out = unquote(tokl.get(3)); |
29 | } |
30 | print(format("Replacing: * with *", in, out)); |
31 | jreplace(tok, in, withNewlines ? out + "\n" : out, true, true); |
32 | } |
33 | ret join(tok); |
34 | } |
35 | |
36 | static S strings(S src) { |
37 | L<S> tok = javaTok(src); |
38 | |
39 | for (int n = 0; n < 10000; n++) { |
40 | int i = findCodeTokens(tok, true, "string", "begin"); |
41 | if (i < 0) break; |
42 | clearAllTokens(tok.subList(i, i+4)); // code to N |
43 | tok.set(i, "\""); |
44 | } |
45 | |
46 | for (int n = 0; n < 10000; n++) { |
47 | int i = findCodeTokens(tok, true, "string", "end"); |
48 | if (i < 0) break; |
49 | clearAllTokens(tok.subList(i-1, i+3)); // N to code |
50 | tok.set(i, "\""); |
51 | } |
52 | |
53 | ret join(tok); |
54 | } |
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: | 661 / 740 |
Referenced in: | [show references] |