Libraryless. Click here for Pure Java version (2093L/14K/47K).
!752 static class Thing { S name, type, file; } static S masterURL = "https://github.com/mcheese/cheesebase/archive/master.zip"; static File zipFile; static new MultiMap<S, Thing> map; static new MultiMap<S, S> definitions; p { zipFile = getProgramFile("master.zip"); if (!zipFile.exists()) loadMaster(); analyze(); makeBot("Cheesebase Bot."); } static void loadMaster() ctex { saveBinaryFile(zipFile, loadBinaryPage(masterURL)); print("master.zip loaded from github."); } static void analyze() { findStuff("namespace", "class", "using", "template", "struct", "union", "auto"); } synchronized answer { if (match("what is *", s, m)) { S name = m.unq(0); L<Thing> things = lookupPossiblyIgnoreCase(map, name); L<S> defs = lookupPossiblyIgnoreCase(definitions, name); if (!things.isEmpty() || !empty(defs)) { L<S> types = list(getSortedSet(things, "type")); L<S> files = list(getSortedSet(things, "file")); types = replace(types, "using", "alias"); types = replace(types, "auto", "variable"); S theTypes = isEmpty(types) ? "unknown something" : join("/", types); S a = (empty(things) ? name : things.get(0).name) + " is " + a(theTypes) + " in cheesebase. It is defined "; if (!empty(defs)) a += "as " + join("/", quoteAll(defs)) + " "; if (!empty(files)) { a += "in "; if (l(files) == 1) a += "file " + quote(files.get(0)); else if (l(files) == 2) a += "files " + quote(files.get(0)) + " and " + quote(files .get(1)); else a += quote(files.get(0)) + " and " + n(l(files)-1, " other file"); } ret a + "."; } } if (match("all things", s)) ret structure(map); if (match("cheesebase reload", s)) { loadMaster(); analyze(); ret "OK, reloaded from GitHub."; } } static void findStuff(S... keywords) { map.clear(); definitions.clear(); for (S file : listZip(zipFile)) { if (endsWithOneOf(file, ".h", ".cc")) pcall { S text = loadTextFileFromZip(zipFile, file); print("Scanning " + file); L<S> tok = javaTok(text); for (S keyword : keywords) { int i = 0; while ((i = findCodeTokens(tok, i+1, keyword, "<id>")) >= 0) { new Thing t; t.name = tok.get(i+2); t.type = keyword; t.file = dropPrefix("cheesebase-master/" , file); map.put(t.name, t); } } definitions.putAll(findInitializers(text)); } } } static L replace(L in, O a, O b) { new L l; for (O x: in) l.add(eq(x, a) ? b : x); ret l; } static S a(S s) { ret ("aeiou".contains(substr(s,0, 1)) ? "an " : "a ")+s; }
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002105 |
Snippet name: | Cheesebase Bot (knows stuff about the "cheesebase" project) |
Eternal ID of this version: | #1002105/1 |
Text MD5: | 495e8489f0f731cefaeb6ba6f5863120 |
Transpilation MD5: | 54399904d550a7bbfdd60992170b0df4 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2015-12-20 22:53:25 |
Source code size: | 2824 bytes / 102 lines |
Pitched / IR pitched: | No / Yes |
Views / Downloads: | 760 / 1737 |
Referenced in: | [show references] |