sibilant 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/README.md +8 -4
  2. data/js/sibilant/.gitignore +4 -0
  3. data/js/sibilant/.travis.yml +6 -0
  4. data/js/sibilant/LICENSE +20 -0
  5. data/js/sibilant/README.md +70 -0
  6. data/js/sibilant/bin/sibilant +3 -0
  7. data/js/sibilant/cli-help +79 -0
  8. data/js/sibilant/include/functional.sibilant +57 -0
  9. data/js/sibilant/include/macros.sibilant +374 -0
  10. data/js/sibilant/include/node.sibilant +2 -0
  11. data/js/sibilant/lib/browser.js +685 -0
  12. data/js/sibilant/lib/cli.js +153 -0
  13. data/js/sibilant/lib/options.js +232 -0
  14. data/js/sibilant/lib/repl.js +78 -0
  15. data/js/sibilant/lib/sibilant.js +688 -0
  16. data/js/sibilant/misc/sibilant-mode.el +129 -0
  17. data/js/sibilant/package.json +19 -0
  18. data/js/sibilant/package.sibilant +16 -0
  19. data/js/sibilant/public/index.html +502 -0
  20. data/js/sibilant/public/javascripts/browser.js +685 -0
  21. data/js/sibilant/public/javascripts/jquery-ui.js +392 -0
  22. data/js/sibilant/public/javascripts/jquery.js +154 -0
  23. data/js/sibilant/public/javascripts/macros.sibilant +374 -0
  24. data/js/sibilant/public/javascripts/sibilant.info.sibilant +77 -0
  25. data/js/sibilant/public/sass/_mixins.sass +98 -0
  26. data/js/sibilant/public/sass/sibilant.sass +156 -0
  27. data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.eot +0 -0
  28. data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.svg +241 -0
  29. data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.ttf +0 -0
  30. data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.woff +0 -0
  31. data/js/sibilant/public/stylesheets/sibilant.css +166 -0
  32. data/js/sibilant/src/browser.sibilant +45 -0
  33. data/js/sibilant/src/cli.sibilant +93 -0
  34. data/js/sibilant/src/core.sibilant +338 -0
  35. data/js/sibilant/src/options.sibilant +65 -0
  36. data/js/sibilant/src/repl.sibilant +59 -0
  37. data/js/sibilant/src/sibilant.sibilant +78 -0
  38. data/js/sibilant/test/defvar.sibilant +5 -0
  39. data/js/sibilant/test/includeFile1.sibilant +1 -0
  40. data/js/sibilant/test/includeFile2.sibilant +1 -0
  41. data/js/sibilant/test/node.sibilant +10 -0
  42. data/js/sibilant/test/slice.sibilant +3 -0
  43. data/js/sibilant/test/test.sibilant +464 -0
  44. data/js/sibilant/test/testHelper.sibilant +80 -0
  45. data/lib/sibilant/version.rb +1 -1
  46. data/sibilant.gemspec +3 -1
  47. metadata +44 -1
@@ -0,0 +1,153 @@
1
+ var sibilant = require("./sibilant"),
2
+ path = require("path"),
3
+ options = require("../lib/options"),
4
+ fs = require("fs"),
5
+ vm = require("vm"),
6
+ context = vm.createContext();
7
+ var createContext = (function() {
8
+ context.initialized__QUERY = true;
9
+ (module)["filename"] = (process.cwd() + "/exec");
10
+ (context)["module"] = module;
11
+ (context)["require"] = require;
12
+ return (function() {
13
+ for (var key in global) (function() {
14
+ return (context)[key] = (global)[key];
15
+ })();
16
+ })();
17
+ });
18
+
19
+ var runInSandbox = (function(js, inputPath) {
20
+ // js:required inputPath:optional
21
+ if (arguments.length < 2) // if inputPath is missing
22
+ var inputPath = undefined;
23
+
24
+ (function() {
25
+ if ((!context.initialized__QUERY)) {
26
+ return createContext();
27
+ }
28
+ })();
29
+ (function() {
30
+ if (typeof(inputPath) !== 'undefined') {
31
+ (process.argv)[1] = inputPath;
32
+ (context)["__dirname"] = path.dirname(inputPath);
33
+ return (module)["filename"] = inputPath;
34
+ }
35
+ })();
36
+ return vm.runInContext(js, context, "sibilant");
37
+ });
38
+
39
+ var cli = {
40
+ v: "version",
41
+ h: "help",
42
+ unhandled: "help",
43
+ f: "file",
44
+ o: "output",
45
+ x: "execute",
46
+ e: "eval",
47
+ i: "input",
48
+ afterBreak: false,
49
+ execute: false,
50
+ unlabeled: "file"
51
+ };
52
+ cli.version = (function() {
53
+ return console.log(sibilant.versionString());
54
+ });
55
+
56
+ cli.repl = (function(args) {
57
+ // args:required
58
+ return require("../lib/repl");
59
+ });
60
+
61
+ var readStdin = (function(fn) {
62
+ // fn:required
63
+ var stdin = process.stdin,
64
+ data = "";
65
+ stdin.resume();
66
+ stdin.setEncoding("utf8");
67
+ stdin.on("data", (function(chunk) {
68
+ // chunk:required
69
+ return data = (data + chunk);
70
+ }));
71
+ return stdin.on("end", (function() {
72
+ return fn(data);
73
+ }));
74
+ });
75
+
76
+ cli.eval = (function(args, options) {
77
+ // args:required options:required
78
+ (options)["execute"] = true;
79
+ return cli.input(args, options);
80
+ });
81
+
82
+ cli.input = (function(args, options) {
83
+ // args:required options:required
84
+ var process = (function(sibilantCode) {
85
+ // sibilantCode:required
86
+ var jsCode = sibilant.translateAll(sibilantCode);
87
+ return (function() {
88
+ if (options.execute) {
89
+ return runInSandbox(jsCode);
90
+ } else {
91
+ return console.log(jsCode);
92
+ }
93
+ })();
94
+ });
95
+ ;
96
+ return (function() {
97
+ if (((args).length === 0)) {
98
+ return readStdin(process);
99
+ } else {
100
+ return process((args)[0]);
101
+ }
102
+ })();
103
+ });
104
+
105
+ cli.help = (function(args, options) {
106
+ // args:required options:required
107
+ return fs.readFile((__dirname + "/../cli-help"), { encoding: "utf8" }, (function(err, data) {
108
+ // err:required data:required
109
+ (function() {
110
+ if (err) {
111
+ throw new Error (err);
112
+ }
113
+ })();
114
+ return console.log(data);
115
+ }));
116
+ });
117
+
118
+ var cliOptions = options(cli);
119
+ var args = (cliOptions.afterBreak || [ ]);
120
+ args.unshift((process.argv)[1], "FILENAME");
121
+
122
+ (process)["argv"] = args;
123
+ (process)["ARGV"] = args;
124
+ (function() {
125
+ if (((Object.keys(cliOptions)).length === 0)) {
126
+ return cli.repl();
127
+ }
128
+ })()
129
+ var outputDir = (function() {
130
+ if (cliOptions.output) {
131
+ return (cliOptions.output)[0];
132
+ }
133
+ })();
134
+ (cliOptions.file || [ ]).forEach((function(inputFile) {
135
+ // inputFile:required
136
+ var inputPath = path.join(process.cwd(), inputFile),
137
+ translated = sibilant.translateFile(inputPath);
138
+ return (function() {
139
+ if (outputDir) {
140
+ var inputBasename = path.basename(inputPath, ".sibilant"),
141
+ outputPath = (path.join(outputDir, inputBasename) + ".js");
142
+ return fs.writeFile(outputPath, translated);
143
+ } else {
144
+ return (function() {
145
+ if (cliOptions.execute) {
146
+ return runInSandbox(translated, inputPath);
147
+ } else {
148
+ return console.log(translated);
149
+ }
150
+ })();
151
+ }
152
+ })();
153
+ }))
@@ -0,0 +1,232 @@
1
+ var bulkMap = (function(arr, fn) {
2
+ // arr:required fn:required
3
+ var index = 0,
4
+ groupSize = fn.length,
5
+ retArr = [ ];
6
+ (function() {
7
+ var __returnValue__ = undefined;
8
+ while ((index < arr.length)) {
9
+ __returnValue__ = (function() {
10
+ retArr.push(fn.apply(undefined, arr.slice(index, (index + groupSize))));
11
+ return index += groupSize;
12
+ })();
13
+ };
14
+ return __returnValue__;
15
+ })();
16
+ return retArr;
17
+ });
18
+
19
+ var inject = (function(start, items, fn) {
20
+ // start:required items:required fn:required
21
+ var value = start;
22
+ (function() {
23
+ if ((items) && (items).constructor.name === "Array") {
24
+ return items.forEach((function(item, index) {
25
+ // item:required index:required
26
+ return value = fn(value, item, index);
27
+ }));
28
+ }
29
+ })();
30
+ return value;
31
+ });
32
+
33
+ var map = (function(items, fn) {
34
+ // items:required fn:required
35
+ return inject([ ], items, (function(collector, item, index) {
36
+ // collector:required item:required index:required
37
+ collector.push(fn(item, index));
38
+ return collector;
39
+ }));
40
+ });
41
+
42
+ var select = (function(items, fn) {
43
+ // items:required fn:required
44
+ return inject([ ], items, (function(collector, item, index) {
45
+ // collector:required item:required index:required
46
+ (function() {
47
+ if (fn(item, index)) {
48
+ return collector.push(item);
49
+ }
50
+ })();
51
+ return collector;
52
+ }));
53
+ });
54
+
55
+ var detect = (function(items, fn) {
56
+ // items:required fn:required
57
+ var returnItem = undefined,
58
+ index = 0,
59
+ items = items;
60
+ return (function() {
61
+ var __returnValue__ = undefined;
62
+ while ((!((items.length === index) || returnItem))) {
63
+ __returnValue__ = (function() {
64
+ (function() {
65
+ if (fn((items)[index], index)) {
66
+ return returnItem = (items)[index];
67
+ }
68
+ })();
69
+ return ((index)++);
70
+ })();
71
+ };
72
+ return __returnValue__;
73
+ })();
74
+ });
75
+
76
+ var reject = (function(items, fn) {
77
+ // items:required fn:required
78
+ var args = [ items, fn ];
79
+ return select(items, (function() {
80
+ return (!fn.apply(undefined, arguments));
81
+ }));
82
+ });
83
+
84
+ var compact = (function(arr) {
85
+ // arr:required
86
+ return select(arr, (function(item) {
87
+ // item:required
88
+ return (!!(item));
89
+ }));
90
+ });
91
+
92
+ var flatten = (function(items) {
93
+ // items:rest
94
+ var items = Array.prototype.slice.call(arguments, 0);
95
+
96
+ return inject([ ], items, (function(collector, item) {
97
+ // collector:required item:required
98
+ return collector.concat((function() {
99
+ if ((item) && (item).constructor.name === "Array") {
100
+ return flatten.apply(undefined, item);
101
+ } else {
102
+ return item;
103
+ }
104
+ })());
105
+ }));
106
+ });
107
+
108
+
109
+ var extractOptions = (function(config, args) {
110
+ // config:required args:optional
111
+ if (arguments.length < 2) // if args is missing
112
+ var args = undefined;
113
+
114
+ var args = (args || process.argv.slice(2)),
115
+ defaultLabel = "unlabeled",
116
+ currentLabel = defaultLabel,
117
+ afterBreak = false,
118
+ config = (config || { }),
119
+ unlabeled = [ ];
120
+ var label__QUERY = (function(item) {
121
+ // item:required
122
+ return (typeof(item) === "string" && /^-/.test(item));
123
+ });
124
+ ;
125
+ var synonymLookup = (function(item) {
126
+ // item:required
127
+ var configEntry = (config)[item];
128
+ return (function() {
129
+ if (typeof(configEntry) === "string") {
130
+ return synonymLookup(configEntry);
131
+ } else {
132
+ return item;
133
+ }
134
+ })();
135
+ });
136
+ ;
137
+ var takesArgs__QUERY = (function(item) {
138
+ // item:required
139
+ return (false !== (config)[labelFor(item)]);
140
+ });
141
+ ;
142
+ defaultLabel = synonymLookup(defaultLabel);
143
+ currentLabel = defaultLabel;
144
+ var labelFor = (function(item) {
145
+ // item:required
146
+ return synonymLookup(item.replace(/^-+/, ""));
147
+ });
148
+ ;
149
+ var addValue = (function(hash, key, value) {
150
+ // hash:required key:required value:required
151
+ var currentValue = (hash)[key];
152
+ (function() {
153
+ if (typeof(currentValue) === 'undefined') {
154
+ currentValue = [ ];
155
+ return (hash)[key] = currentValue;
156
+ }
157
+ })();
158
+ return (function() {
159
+ if ((true !== value)) {
160
+ return currentValue.push(value);
161
+ }
162
+ })();
163
+ });
164
+ ;
165
+ var resetLabel = (function() {
166
+ return currentLabel = defaultLabel;
167
+ });
168
+ ;
169
+ return inject({ }, args, (function(returnHash, item, index) {
170
+ // returnHash:required item:required index:required
171
+ (function() {
172
+ if (("--" === item)) {
173
+ return afterBreak = true;
174
+ } else {
175
+ return (function() {
176
+ if (afterBreak) {
177
+ return addValue(returnHash, "afterBreak", item);
178
+ } else {
179
+ return (function() {
180
+ if (label__QUERY(item)) {
181
+ currentLabel = labelFor(item);
182
+ addValue(returnHash, currentLabel, true);
183
+ return (function() {
184
+ if ((!takesArgs__QUERY(item))) {
185
+ return resetLabel();
186
+ }
187
+ })();
188
+ } else {
189
+ addValue(returnHash, currentLabel, item);
190
+ return resetLabel();
191
+ }
192
+ })();
193
+ }
194
+ })();
195
+ }
196
+ })();
197
+ return returnHash;
198
+ }));
199
+ });
200
+
201
+ var processOptions = (function(config) {
202
+ // config:optional
203
+ if (arguments.length < 1) // if config is missing
204
+ var config = undefined;
205
+
206
+ var options = extractOptions(config);
207
+ (function() {
208
+ if (config) {
209
+ var handlePair = (function(key, value) {
210
+ // key:required value:required
211
+ var handle = (config)[key];
212
+ (function() {
213
+ if (typeof(handle) === "string") {
214
+ return handlePair(handle, value);
215
+ }
216
+ })();
217
+ return (function() {
218
+ if (typeof(handle) === 'function') {
219
+ return handle(value, options);
220
+ }
221
+ })();
222
+ });
223
+ return Object.keys(options).forEach((function(key) {
224
+ // key:required
225
+ return handlePair(key, (options)[key]);
226
+ }));
227
+ }
228
+ })();
229
+ return options;
230
+ });
231
+
232
+ (module)["exports"] = processOptions;
@@ -0,0 +1,78 @@
1
+ var input = process.openStdin(),
2
+ output = process.stdout,
3
+ vm = require("vm"),
4
+ readline = require("readline").createInterface(input, output),
5
+ sibilant = require("./sibilant"),
6
+ context = undefined,
7
+ cmdBuffer = "",
8
+ util = require("util");
9
+ var createContext = (function() {
10
+ var context = vm.createContext();
11
+ (module)["filename"] = (process.cwd() + "/exec");
12
+ (context)["module"] = module;
13
+ (context)["require"] = require;
14
+ (function() {
15
+ for (var key in global) (function() {
16
+ return (context)[key] = (global)[key];
17
+ })();
18
+ })();
19
+ return context;
20
+ });
21
+
22
+ context = createContext();
23
+ var displayPrompt = (function() {
24
+ readline.setPrompt(((function() {
25
+ if ((cmdBuffer.length > 10)) {
26
+ return ("..." + cmdBuffer.slice(-10));
27
+ } else {
28
+ return (function() {
29
+ if ((cmdBuffer.length > 0)) {
30
+ return cmdBuffer;
31
+ } else {
32
+ return "sibilant";
33
+ }
34
+ })();
35
+ }
36
+ })() + "> "));
37
+ return readline.prompt();
38
+ });
39
+
40
+ readline.on("line", (function(cmd) {
41
+ // cmd:required
42
+ var jsLine = "";
43
+ (function() {
44
+ try {
45
+ cmdBuffer = (cmdBuffer + cmd);
46
+ sibilant.tokenize(cmdBuffer).forEach((function(stmt) {
47
+ // stmt:required
48
+ return jsLine = (jsLine + sibilant.translate(stmt, "statement"));
49
+ }));
50
+ var result = vm.runInContext(jsLine, context, "sibilant-repl");
51
+ (readline.history)[0] = cmdBuffer;
52
+ (function() {
53
+ if (typeof(result) !== 'undefined') {
54
+ return output.write(("result: " + util.inspect(result) + "\n"));
55
+ }
56
+ })();
57
+ (context)["_"] = result;
58
+ return cmdBuffer = "";
59
+ } catch (e) {
60
+ return (function() {
61
+ if (e.message.match(/unexpected EOF/)) {
62
+ cmdBuffer = (cmdBuffer + " ");
63
+ return readline.history.shift();
64
+ } else {
65
+ (readline.history)[0] = cmdBuffer;
66
+ output.write((e.stack + "\n"));
67
+ return cmdBuffer = "";
68
+ }
69
+ })();
70
+ }
71
+ })();
72
+ return displayPrompt();
73
+ }));
74
+
75
+ readline.on("close", input.destroy);
76
+
77
+ displayPrompt();
78
+