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.
- data/README.md +8 -4
- data/js/sibilant/.gitignore +4 -0
- data/js/sibilant/.travis.yml +6 -0
- data/js/sibilant/LICENSE +20 -0
- data/js/sibilant/README.md +70 -0
- data/js/sibilant/bin/sibilant +3 -0
- data/js/sibilant/cli-help +79 -0
- data/js/sibilant/include/functional.sibilant +57 -0
- data/js/sibilant/include/macros.sibilant +374 -0
- data/js/sibilant/include/node.sibilant +2 -0
- data/js/sibilant/lib/browser.js +685 -0
- data/js/sibilant/lib/cli.js +153 -0
- data/js/sibilant/lib/options.js +232 -0
- data/js/sibilant/lib/repl.js +78 -0
- data/js/sibilant/lib/sibilant.js +688 -0
- data/js/sibilant/misc/sibilant-mode.el +129 -0
- data/js/sibilant/package.json +19 -0
- data/js/sibilant/package.sibilant +16 -0
- data/js/sibilant/public/index.html +502 -0
- data/js/sibilant/public/javascripts/browser.js +685 -0
- data/js/sibilant/public/javascripts/jquery-ui.js +392 -0
- data/js/sibilant/public/javascripts/jquery.js +154 -0
- data/js/sibilant/public/javascripts/macros.sibilant +374 -0
- data/js/sibilant/public/javascripts/sibilant.info.sibilant +77 -0
- data/js/sibilant/public/sass/_mixins.sass +98 -0
- data/js/sibilant/public/sass/sibilant.sass +156 -0
- data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.eot +0 -0
- data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.svg +241 -0
- data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.ttf +0 -0
- data/js/sibilant/public/stylesheets/Anonymous_Pro-webfont.woff +0 -0
- data/js/sibilant/public/stylesheets/sibilant.css +166 -0
- data/js/sibilant/src/browser.sibilant +45 -0
- data/js/sibilant/src/cli.sibilant +93 -0
- data/js/sibilant/src/core.sibilant +338 -0
- data/js/sibilant/src/options.sibilant +65 -0
- data/js/sibilant/src/repl.sibilant +59 -0
- data/js/sibilant/src/sibilant.sibilant +78 -0
- data/js/sibilant/test/defvar.sibilant +5 -0
- data/js/sibilant/test/includeFile1.sibilant +1 -0
- data/js/sibilant/test/includeFile2.sibilant +1 -0
- data/js/sibilant/test/node.sibilant +10 -0
- data/js/sibilant/test/slice.sibilant +3 -0
- data/js/sibilant/test/test.sibilant +464 -0
- data/js/sibilant/test/testHelper.sibilant +80 -0
- data/lib/sibilant/version.rb +1 -1
- data/sibilant.gemspec +3 -1
- metadata +44 -1
@@ -0,0 +1,685 @@
|
|
1
|
+
(function() {
|
2
|
+
var sibilant = { };
|
3
|
+
var error = (function(str) {
|
4
|
+
// str:required
|
5
|
+
throw new Error (str);
|
6
|
+
});
|
7
|
+
;
|
8
|
+
var inspect = (function(item) {
|
9
|
+
// item:required
|
10
|
+
return (function() {
|
11
|
+
if (item.toSource) {
|
12
|
+
return item.toSource();
|
13
|
+
} else {
|
14
|
+
return item.toString();
|
15
|
+
}
|
16
|
+
})();
|
17
|
+
});
|
18
|
+
;
|
19
|
+
(window)["sibilant"] = sibilant;
|
20
|
+
var exports = { };
|
21
|
+
var bulkMap = (function(arr, fn) {
|
22
|
+
// arr:required fn:required
|
23
|
+
var index = 0,
|
24
|
+
groupSize = fn.length,
|
25
|
+
retArr = [ ];
|
26
|
+
(function() {
|
27
|
+
var __returnValue__ = undefined;
|
28
|
+
while ((index < arr.length)) {
|
29
|
+
__returnValue__ = (function() {
|
30
|
+
retArr.push(fn.apply(undefined, arr.slice(index, (index + groupSize))));
|
31
|
+
return index += groupSize;
|
32
|
+
})();
|
33
|
+
};
|
34
|
+
return __returnValue__;
|
35
|
+
})();
|
36
|
+
return retArr;
|
37
|
+
});
|
38
|
+
|
39
|
+
var inject = (function(start, items, fn) {
|
40
|
+
// start:required items:required fn:required
|
41
|
+
var value = start;
|
42
|
+
(function() {
|
43
|
+
if ((items) && (items).constructor.name === "Array") {
|
44
|
+
return items.forEach((function(item, index) {
|
45
|
+
// item:required index:required
|
46
|
+
return value = fn(value, item, index);
|
47
|
+
}));
|
48
|
+
}
|
49
|
+
})();
|
50
|
+
return value;
|
51
|
+
});
|
52
|
+
|
53
|
+
var map = (function(items, fn) {
|
54
|
+
// items:required fn:required
|
55
|
+
return inject([ ], items, (function(collector, item, index) {
|
56
|
+
// collector:required item:required index:required
|
57
|
+
collector.push(fn(item, index));
|
58
|
+
return collector;
|
59
|
+
}));
|
60
|
+
});
|
61
|
+
|
62
|
+
var select = (function(items, fn) {
|
63
|
+
// items:required fn:required
|
64
|
+
return inject([ ], items, (function(collector, item, index) {
|
65
|
+
// collector:required item:required index:required
|
66
|
+
(function() {
|
67
|
+
if (fn(item, index)) {
|
68
|
+
return collector.push(item);
|
69
|
+
}
|
70
|
+
})();
|
71
|
+
return collector;
|
72
|
+
}));
|
73
|
+
});
|
74
|
+
|
75
|
+
var detect = (function(items, fn) {
|
76
|
+
// items:required fn:required
|
77
|
+
var returnItem = undefined,
|
78
|
+
index = 0,
|
79
|
+
items = items;
|
80
|
+
return (function() {
|
81
|
+
var __returnValue__ = undefined;
|
82
|
+
while ((!((items.length === index) || returnItem))) {
|
83
|
+
__returnValue__ = (function() {
|
84
|
+
(function() {
|
85
|
+
if (fn((items)[index], index)) {
|
86
|
+
return returnItem = (items)[index];
|
87
|
+
}
|
88
|
+
})();
|
89
|
+
return ((index)++);
|
90
|
+
})();
|
91
|
+
};
|
92
|
+
return __returnValue__;
|
93
|
+
})();
|
94
|
+
});
|
95
|
+
|
96
|
+
var reject = (function(items, fn) {
|
97
|
+
// items:required fn:required
|
98
|
+
var args = [ items, fn ];
|
99
|
+
return select(items, (function() {
|
100
|
+
return (!fn.apply(undefined, arguments));
|
101
|
+
}));
|
102
|
+
});
|
103
|
+
|
104
|
+
var compact = (function(arr) {
|
105
|
+
// arr:required
|
106
|
+
return select(arr, (function(item) {
|
107
|
+
// item:required
|
108
|
+
return (!!(item));
|
109
|
+
}));
|
110
|
+
});
|
111
|
+
|
112
|
+
var flatten = (function(items) {
|
113
|
+
// items:rest
|
114
|
+
var items = Array.prototype.slice.call(arguments, 0);
|
115
|
+
|
116
|
+
return inject([ ], items, (function(collector, item) {
|
117
|
+
// collector:required item:required
|
118
|
+
return collector.concat((function() {
|
119
|
+
if ((item) && (item).constructor.name === "Array") {
|
120
|
+
return flatten.apply(undefined, item);
|
121
|
+
} else {
|
122
|
+
return item;
|
123
|
+
}
|
124
|
+
})());
|
125
|
+
}));
|
126
|
+
});
|
127
|
+
|
128
|
+
;
|
129
|
+
(sibilant)["tokens"] = { };
|
130
|
+
(sibilant.tokens)["regex"] = "(\\/(\\\\\\\/|[^\\/\\n])+\\/[glim]*)";
|
131
|
+
(sibilant.tokens)["comment"] = "(;.*)";
|
132
|
+
(sibilant.tokens)["string"] = "(\"(([^\"]|(\\\\\"))*[^\\\\])?\")";
|
133
|
+
(sibilant.tokens)["number"] = "(-?[0-9][0-9.,]*)";
|
134
|
+
(sibilant.tokens)["literal"] = "(-?[*.$a-zA-Z][*.a-zA-Z0-9-]*(\\?|!)?)";
|
135
|
+
(sibilant.tokens)["special"] = "([&']?)";
|
136
|
+
(sibilant.tokens)["otherChar"] = "([><=!\\+\\/\\*-]+)";
|
137
|
+
(sibilant.tokens)["openParen"] = "(\\()";
|
138
|
+
(sibilant.tokens)["specialOpenParen"] = "('?\\()";
|
139
|
+
(sibilant.tokens)["closeParen"] = "(\\))";
|
140
|
+
(sibilant.tokens)["alternativeParens"] = "\\{|\\[|\\}|\\]";
|
141
|
+
(sibilant.tokens)["specialLiteral"] = (sibilant.tokens.special + sibilant.tokens.literal);
|
142
|
+
(sibilant)["tokenPrecedence"] = [ "regex", "comment", "string", "number", "specialLiteral", "otherChar", "specialOpenParen", "closeParen", "alternativeParens" ];
|
143
|
+
var tokenize = sibilant.tokenize = (function(string) {
|
144
|
+
// string:required
|
145
|
+
var tokens = [ ],
|
146
|
+
parseStack = [ tokens ],
|
147
|
+
specials = [ ];
|
148
|
+
var acceptToken = (function(token) {
|
149
|
+
// token:required
|
150
|
+
return (parseStack)[0].push(token);
|
151
|
+
});
|
152
|
+
;
|
153
|
+
var increaseNesting = (function() {
|
154
|
+
var newArr = [ ];
|
155
|
+
acceptToken(newArr);
|
156
|
+
return parseStack.unshift(newArr);
|
157
|
+
});
|
158
|
+
;
|
159
|
+
var decreaseNesting = (function() {
|
160
|
+
specials.shift();
|
161
|
+
parseStack.shift();
|
162
|
+
return (function() {
|
163
|
+
if ((parseStack.length === 0)) {
|
164
|
+
throw new Error (("unbalanced parens:\n" + inspect(parseStack)));
|
165
|
+
}
|
166
|
+
})();
|
167
|
+
});
|
168
|
+
;
|
169
|
+
var handleToken = (function(token) {
|
170
|
+
// token:required
|
171
|
+
var special = (token)[0],
|
172
|
+
token = token;
|
173
|
+
(function() {
|
174
|
+
if ((special === "'")) {
|
175
|
+
token = token.slice(1);
|
176
|
+
increaseNesting();
|
177
|
+
return acceptToken("quote");
|
178
|
+
} else {
|
179
|
+
return special = false;
|
180
|
+
}
|
181
|
+
})();
|
182
|
+
specials.unshift((!!(special)));
|
183
|
+
(function() {
|
184
|
+
switch(token) {
|
185
|
+
case "(":
|
186
|
+
return increaseNesting();
|
187
|
+
|
188
|
+
case "]":
|
189
|
+
case "}":
|
190
|
+
case ")":
|
191
|
+
return decreaseNesting();
|
192
|
+
|
193
|
+
case "{":
|
194
|
+
increaseNesting();
|
195
|
+
return acceptToken("hash");
|
196
|
+
|
197
|
+
case "[":
|
198
|
+
increaseNesting();
|
199
|
+
return acceptToken("list");
|
200
|
+
|
201
|
+
default:
|
202
|
+
return (function() {
|
203
|
+
if (token.match((new RegExp(("^" + sibilant.tokens.number + "$"), undefined)))) {
|
204
|
+
return acceptToken(parseFloat(token.replace((new RegExp(",", "g")), "")));
|
205
|
+
} else {
|
206
|
+
return acceptToken(token);
|
207
|
+
}
|
208
|
+
})();
|
209
|
+
}
|
210
|
+
})();
|
211
|
+
return (function() {
|
212
|
+
if (((token !== "(") && specials.shift())) {
|
213
|
+
return decreaseNesting();
|
214
|
+
}
|
215
|
+
})();
|
216
|
+
});
|
217
|
+
;
|
218
|
+
var orderedRegexen = map(sibilant.tokenPrecedence, (function(x) {
|
219
|
+
// x:required
|
220
|
+
return (sibilant.tokens)[x];
|
221
|
+
})),
|
222
|
+
masterRegex = (new RegExp((orderedRegexen).join("|"), "g"));
|
223
|
+
string // chain
|
224
|
+
.match(masterRegex)
|
225
|
+
.forEach(handleToken)
|
226
|
+
;
|
227
|
+
(function() {
|
228
|
+
if ((parseStack.length > 1)) {
|
229
|
+
return error("unexpected EOF, probably missing a )\n", inspect((parseStack)[0]));
|
230
|
+
}
|
231
|
+
})();
|
232
|
+
return tokens;
|
233
|
+
});
|
234
|
+
var indent = (function(args) {
|
235
|
+
// args:rest
|
236
|
+
var args = Array.prototype.slice.call(arguments, 0);
|
237
|
+
|
238
|
+
return (compact(args) // chain
|
239
|
+
.join("\n")
|
240
|
+
.replace(/^/, "\n")
|
241
|
+
.replace(/\n/g, "\n ")
|
242
|
+
+ "\n");
|
243
|
+
});
|
244
|
+
|
245
|
+
var constructHash = (function(arrayOfArrays) {
|
246
|
+
// arrayOfArrays:required
|
247
|
+
return inject({ }, arrayOfArrays, (function(object, item) {
|
248
|
+
// object:required item:required
|
249
|
+
(object)[(item)[0]] = (object)[(item)[1]];
|
250
|
+
return object;
|
251
|
+
}));
|
252
|
+
});
|
253
|
+
|
254
|
+
var macros = { };
|
255
|
+
(sibilant)["macros"] = macros;
|
256
|
+
(macros)["return"] = (function(token) {
|
257
|
+
// token:required
|
258
|
+
var defaultReturn = ("return " + translate(token));
|
259
|
+
return (function() {
|
260
|
+
if ((token) && (token).constructor.name === "Array") {
|
261
|
+
return (function() {
|
262
|
+
switch((token)[0]) {
|
263
|
+
case "return":
|
264
|
+
case "throw":
|
265
|
+
case "progn":
|
266
|
+
return translate(token);
|
267
|
+
|
268
|
+
case "delete":
|
269
|
+
var deleteMacro = (macros)["delete"];
|
270
|
+
return (function() {
|
271
|
+
if ((token.length < 3)) {
|
272
|
+
return defaultReturn;
|
273
|
+
} else {
|
274
|
+
return (deleteMacro.apply(undefined, token.slice(1, -1)) + "\nreturn " + deleteMacro((token.slice(-1))[0]));
|
275
|
+
}
|
276
|
+
})();
|
277
|
+
|
278
|
+
case "setf":
|
279
|
+
return (function() {
|
280
|
+
if ((token.length < 4)) {
|
281
|
+
return defaultReturn;
|
282
|
+
} else {
|
283
|
+
return (macros.setf.apply(undefined, token.slice(1, (token.length - 2))) + "\nreturn " + macros.setf.apply(undefined, token.slice(-2)));
|
284
|
+
}
|
285
|
+
})();
|
286
|
+
|
287
|
+
case "set":
|
288
|
+
return (function() {
|
289
|
+
if ((token.length < 5)) {
|
290
|
+
return defaultReturn;
|
291
|
+
} else {
|
292
|
+
var obj = (token)[1],
|
293
|
+
nonReturnPart = token.slice(2, (token.length - 2)),
|
294
|
+
returnPart = token.slice(-2);
|
295
|
+
nonReturnPart.unshift(obj);
|
296
|
+
returnPart.unshift(obj);
|
297
|
+
return (macros.set.apply(undefined, nonReturnPart) + "\nreturn " + macros.set.apply(undefined, returnPart));
|
298
|
+
}
|
299
|
+
})();
|
300
|
+
|
301
|
+
default:
|
302
|
+
return defaultReturn;
|
303
|
+
}
|
304
|
+
})();
|
305
|
+
} else {
|
306
|
+
return defaultReturn;
|
307
|
+
}
|
308
|
+
})();
|
309
|
+
});
|
310
|
+
var asStatement = (function(string) {
|
311
|
+
// string:required
|
312
|
+
return string // chain
|
313
|
+
.toString()
|
314
|
+
.replace(/;*\s*$/, ";")
|
315
|
+
;
|
316
|
+
});
|
317
|
+
|
318
|
+
macros.statement = (function(args) {
|
319
|
+
// args:rest
|
320
|
+
var args = Array.prototype.slice.call(arguments, 0);
|
321
|
+
|
322
|
+
return (macros.call.apply(undefined, args) + ";\n");
|
323
|
+
});
|
324
|
+
|
325
|
+
macros.progn = (function(body) {
|
326
|
+
// body:rest
|
327
|
+
var body = Array.prototype.slice.call(arguments, 0);
|
328
|
+
|
329
|
+
var lastIndex = Math.max(0, (body.length - 1));
|
330
|
+
(body)[lastIndex] = [ "return", (body)[lastIndex] ];
|
331
|
+
return (map(body, (function(arg) {
|
332
|
+
// arg:required
|
333
|
+
return (asStatement(translate(arg)));
|
334
|
+
}))).join("\n");
|
335
|
+
});
|
336
|
+
|
337
|
+
macros.call = (function(fnName, args) {
|
338
|
+
// fnName:required args:rest
|
339
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
340
|
+
|
341
|
+
return (translate(fnName) + "(" + (map(args, translate)).join(", ") + ")");
|
342
|
+
});
|
343
|
+
|
344
|
+
macros.defun = (function(fnName, argsAndBody) {
|
345
|
+
// fnName:required argsAndBody:rest
|
346
|
+
var argsAndBody = Array.prototype.slice.call(arguments, 1);
|
347
|
+
|
348
|
+
var fnNameTr = translate(fnName),
|
349
|
+
start = (function() {
|
350
|
+
if (fnNameTr.match(/\./)) {
|
351
|
+
return "";
|
352
|
+
} else {
|
353
|
+
return "var ";
|
354
|
+
}
|
355
|
+
})();
|
356
|
+
return (start + fnNameTr + " = " + macros.lambda.apply(undefined, argsAndBody) + ";\n");
|
357
|
+
});
|
358
|
+
|
359
|
+
macros.defmacro = (function(name, argsAndBody) {
|
360
|
+
// name:required argsAndBody:rest
|
361
|
+
var argsAndBody = Array.prototype.slice.call(arguments, 1);
|
362
|
+
|
363
|
+
var js = macros.lambda.apply(undefined, argsAndBody),
|
364
|
+
name = translate(name);
|
365
|
+
(function() {
|
366
|
+
try {
|
367
|
+
return (macros)[name] = eval(js);
|
368
|
+
} catch (e) {
|
369
|
+
return error(("error in parsing macro " + name + ":\n" + indent(js)));
|
370
|
+
}
|
371
|
+
})();
|
372
|
+
return undefined;
|
373
|
+
});
|
374
|
+
|
375
|
+
macros.concat = (function(args) {
|
376
|
+
// args:rest
|
377
|
+
var args = Array.prototype.slice.call(arguments, 0);
|
378
|
+
|
379
|
+
return ("(" + (map(args, translate)).join(" + ") + ")");
|
380
|
+
});
|
381
|
+
|
382
|
+
var transformArgs = (function(arglist) {
|
383
|
+
// arglist:required
|
384
|
+
var last = undefined,
|
385
|
+
args = [ ];
|
386
|
+
arglist.forEach((function(arg) {
|
387
|
+
// arg:required
|
388
|
+
return (function() {
|
389
|
+
if (((arg)[0] === "&")) {
|
390
|
+
return last = arg.slice(1);
|
391
|
+
} else {
|
392
|
+
args.push([ (last || "required"), arg ]);
|
393
|
+
return last = null;
|
394
|
+
}
|
395
|
+
})();
|
396
|
+
}));
|
397
|
+
(function() {
|
398
|
+
if (last) {
|
399
|
+
return error(("unexpected argument modifier: " + last));
|
400
|
+
}
|
401
|
+
})();
|
402
|
+
return args;
|
403
|
+
});
|
404
|
+
|
405
|
+
macros.reverse = (function(arr) {
|
406
|
+
// arr:required
|
407
|
+
var reversed = [ ];
|
408
|
+
arr.forEach((function(item) {
|
409
|
+
// item:required
|
410
|
+
return reversed.unshift(item);
|
411
|
+
}));
|
412
|
+
return reversed;
|
413
|
+
});
|
414
|
+
|
415
|
+
var reverse = macros.reverse;
|
416
|
+
var buildArgsString = (function(args, rest) {
|
417
|
+
// args:required rest:required
|
418
|
+
var argsString = "",
|
419
|
+
optionalCount = 0;
|
420
|
+
args.forEach((function(arg, optionIndex) {
|
421
|
+
// arg:required optionIndex:required
|
422
|
+
return (function() {
|
423
|
+
if (((arg)[0] === "optional")) {
|
424
|
+
argsString = (argsString + "if (arguments.length < " + (args.length - optionalCount) + ")" + " // if " + translate((arg)[1]) + " is missing" + indent(("var " + map(args.slice((optionIndex + 1)), (function(arg, argIndex) {
|
425
|
+
// arg:required argIndex:required
|
426
|
+
return (translate((arg)[1]) + " = " + translate(((args)[(optionIndex + argIndex)])[1]));
|
427
|
+
})) // chain
|
428
|
+
.reverse()
|
429
|
+
.concat((translate((arg)[1]) + " = undefined"))
|
430
|
+
.join(", ")
|
431
|
+
+ ";")));
|
432
|
+
return ((optionalCount)++);
|
433
|
+
}
|
434
|
+
})();
|
435
|
+
}));
|
436
|
+
return (function() {
|
437
|
+
if (typeof(rest) !== 'undefined') {
|
438
|
+
return (argsString + "var " + translate((rest)[1]) + " = Array.prototype.slice.call(arguments, " + args.length + ");\n");
|
439
|
+
} else {
|
440
|
+
return argsString;
|
441
|
+
}
|
442
|
+
})();
|
443
|
+
});
|
444
|
+
|
445
|
+
var buildCommentString = (function(args) {
|
446
|
+
// args:required
|
447
|
+
return (function() {
|
448
|
+
if (((args).length === 0)) {
|
449
|
+
return "";
|
450
|
+
} else {
|
451
|
+
return ("// " + (map(args, (function(arg) {
|
452
|
+
// arg:required
|
453
|
+
return (translate((arg)[1]) + ":" + (arg)[0]);
|
454
|
+
}))).join(" "));
|
455
|
+
}
|
456
|
+
})();
|
457
|
+
});
|
458
|
+
|
459
|
+
// brain 'splode
|
460
|
+
macros.lambda = (function(arglist, body) {
|
461
|
+
// arglist:required body:rest
|
462
|
+
var body = Array.prototype.slice.call(arguments, 1);
|
463
|
+
|
464
|
+
var args = transformArgs(arglist),
|
465
|
+
rest = (select(args, (function(arg) {
|
466
|
+
// arg:required
|
467
|
+
return ("rest" === (arg)[0]);
|
468
|
+
})))[0],
|
469
|
+
docString = undefined;
|
470
|
+
(body)[(body.length - 1)] = [ "return", (body)[(body.length - 1)] ];
|
471
|
+
(function() {
|
472
|
+
if (((typeof((body)[0]) === "string") && (body)[0].match(/^".*"$/))) {
|
473
|
+
return docString = ("/* " + eval(body.shift()) + " */\n");
|
474
|
+
}
|
475
|
+
})();
|
476
|
+
var noRestArgs = (function() {
|
477
|
+
if (rest) {
|
478
|
+
return args.slice(0, -1);
|
479
|
+
} else {
|
480
|
+
return args;
|
481
|
+
}
|
482
|
+
})(),
|
483
|
+
argsString = buildArgsString(noRestArgs, rest),
|
484
|
+
commentString = buildCommentString(args);
|
485
|
+
return ("(function(" + (map(args, (function(arg) {
|
486
|
+
// arg:required
|
487
|
+
return translate((arg)[1]);
|
488
|
+
}))).join(", ") + ") {" + indent(commentString, docString, argsString, (map(body, (function(stmt) {
|
489
|
+
// stmt:required
|
490
|
+
var tstmt = translate(stmt);
|
491
|
+
return (tstmt + (function() {
|
492
|
+
if (((tstmt.slice(-1))[0] === ";")) {
|
493
|
+
return "";
|
494
|
+
} else {
|
495
|
+
return ";";
|
496
|
+
}
|
497
|
+
})());
|
498
|
+
}))).join("\n")) + "})");
|
499
|
+
});
|
500
|
+
|
501
|
+
macros.quote = (function(item) {
|
502
|
+
// item:required
|
503
|
+
return (function() {
|
504
|
+
if (("Array" === item.constructor.name)) {
|
505
|
+
return ("[ " + (map(item, macros.quote)).join(", ") + " ]");
|
506
|
+
} else {
|
507
|
+
return (function() {
|
508
|
+
if (("number" === typeof(item))) {
|
509
|
+
return item;
|
510
|
+
} else {
|
511
|
+
return ("\"" + literal(item) + "\"");
|
512
|
+
}
|
513
|
+
})();
|
514
|
+
}
|
515
|
+
})();
|
516
|
+
});
|
517
|
+
|
518
|
+
macros.hash = (function(pairs) {
|
519
|
+
// pairs:rest
|
520
|
+
var pairs = Array.prototype.slice.call(arguments, 0);
|
521
|
+
|
522
|
+
(function() {
|
523
|
+
if ((0 !== (pairs.length % 2))) {
|
524
|
+
return error(("odd number of key-value pairs in hash: " + inspect(pairs)));
|
525
|
+
}
|
526
|
+
})();
|
527
|
+
var pairStrings = bulkMap(pairs, (function(key, value) {
|
528
|
+
// key:required value:required
|
529
|
+
return (translate(key) + ": " + translate(value));
|
530
|
+
}));
|
531
|
+
return (function() {
|
532
|
+
if ((1 >= pairStrings.length)) {
|
533
|
+
return ("{ " + (pairStrings).join(", ") + " }");
|
534
|
+
} else {
|
535
|
+
return ("{" + indent((pairStrings).join(",\n")) + "}");
|
536
|
+
}
|
537
|
+
})();
|
538
|
+
});
|
539
|
+
|
540
|
+
var literal = (function(string) {
|
541
|
+
// string:required
|
542
|
+
return inject(string // chain
|
543
|
+
.replace(/\*/g, "_")
|
544
|
+
.replace(/\?$/, "__QUERY")
|
545
|
+
.replace(/!$/, "__BANG")
|
546
|
+
, string.match(/-(.)/g), (function(returnString, match) {
|
547
|
+
// returnString:required match:required
|
548
|
+
return returnString.replace(match, (match)[1].toUpperCase());
|
549
|
+
}));
|
550
|
+
});
|
551
|
+
|
552
|
+
var translate = (function(token, hint) {
|
553
|
+
// token:required hint:required
|
554
|
+
var hint = hint;
|
555
|
+
(function() {
|
556
|
+
if ((hint && typeof((macros)[hint]) === 'undefined')) {
|
557
|
+
return hint = undefined;
|
558
|
+
}
|
559
|
+
})();
|
560
|
+
return (function() {
|
561
|
+
if (typeof(token) !== 'undefined') {
|
562
|
+
(function() {
|
563
|
+
if (typeof(token) === "string") {
|
564
|
+
return token = token.trim();
|
565
|
+
}
|
566
|
+
})();
|
567
|
+
return (function() {
|
568
|
+
try {
|
569
|
+
return (function() {
|
570
|
+
if ((token) && (token).constructor.name === "Array") {
|
571
|
+
return (function() {
|
572
|
+
if (typeof((macros)[translate((token)[0])]) !== 'undefined') {
|
573
|
+
return (macros)[translate((token)[0])].apply(undefined, token.slice(1));
|
574
|
+
} else {
|
575
|
+
return (macros)[(hint || "call")].apply(undefined, token);
|
576
|
+
}
|
577
|
+
})();
|
578
|
+
} else {
|
579
|
+
return (function() {
|
580
|
+
if ((typeof(token) === "string" && token.match((new RegExp(("^" + sibilant.tokens.literal + "$"), undefined))))) {
|
581
|
+
return literal(token);
|
582
|
+
} else {
|
583
|
+
return (function() {
|
584
|
+
if ((typeof(token) === "string" && token.match((new RegExp("^;", undefined))))) {
|
585
|
+
return token.replace((new RegExp("^;+", undefined)), "//");
|
586
|
+
} else {
|
587
|
+
return (function() {
|
588
|
+
if ((typeof(token) === "string" && ("\"" === (token)[0] &&
|
589
|
+
"\"" === (token.slice(-1))[0]))) {
|
590
|
+
return token // chain
|
591
|
+
.split("\n")
|
592
|
+
.join("\\n\" +\n\"");
|
593
|
+
} else {
|
594
|
+
return token;
|
595
|
+
}
|
596
|
+
})();
|
597
|
+
}
|
598
|
+
})();
|
599
|
+
}
|
600
|
+
})();
|
601
|
+
}
|
602
|
+
})();
|
603
|
+
} catch (e) {
|
604
|
+
return error((e.stack + "\n" + "Encountered when attempting to process:\n" + indent(inspect(token))));
|
605
|
+
}
|
606
|
+
})();
|
607
|
+
}
|
608
|
+
})();
|
609
|
+
});
|
610
|
+
|
611
|
+
(sibilant)["translate"] = translate;
|
612
|
+
var translateAll = (function(contents) {
|
613
|
+
// contents:required
|
614
|
+
var buffer = "";
|
615
|
+
tokenize(contents).forEach((function(token) {
|
616
|
+
// token:required
|
617
|
+
var line = translate(token, "statement");
|
618
|
+
return (function() {
|
619
|
+
if (line) {
|
620
|
+
return buffer = (buffer + line + "\n");
|
621
|
+
}
|
622
|
+
})();
|
623
|
+
}));
|
624
|
+
return buffer;
|
625
|
+
});
|
626
|
+
|
627
|
+
(sibilant)["translateAll"] = translateAll;
|
628
|
+
;
|
629
|
+
return $((function() {
|
630
|
+
var sibilant = window.sibilant,
|
631
|
+
scripts = [ ];
|
632
|
+
var evalWithTryCatch = (function(js) {
|
633
|
+
// js:required
|
634
|
+
return (function() {
|
635
|
+
try {
|
636
|
+
return eval(js);
|
637
|
+
} catch (e) {
|
638
|
+
console.log(js);
|
639
|
+
throw new Error (e);
|
640
|
+
}
|
641
|
+
})();
|
642
|
+
});
|
643
|
+
;
|
644
|
+
sibilant.scriptLoaded = (function() {
|
645
|
+
var lisp = null,
|
646
|
+
js = null;
|
647
|
+
return (function() {
|
648
|
+
if ((!sibilant.loadNextScript())) {
|
649
|
+
return $("script[type=\"text/sibilant\"]:not([src])") // chain
|
650
|
+
.each((function() {
|
651
|
+
lisp = $(this) // chain
|
652
|
+
.text()
|
653
|
+
.replace(/(^\s*\/\/\<!\[CDATA\[)|(\/\/\]\]>\s*$)/g, "");
|
654
|
+
js = sibilant.translateAll(lisp);
|
655
|
+
$(this) // chain
|
656
|
+
.data("js", js)
|
657
|
+
;
|
658
|
+
return evalWithTryCatch(js);
|
659
|
+
}));
|
660
|
+
}
|
661
|
+
})();
|
662
|
+
});
|
663
|
+
;
|
664
|
+
scripts = $.makeArray($("script[type=\"text/sibilant\"][src]") // chain
|
665
|
+
.map((function() {
|
666
|
+
return this.src;
|
667
|
+
}))
|
668
|
+
);
|
669
|
+
sibilant.loadNextScript = (function() {
|
670
|
+
var nextScript = scripts.shift();
|
671
|
+
return (function() {
|
672
|
+
if (typeof(nextScript) !== 'undefined') {
|
673
|
+
$.get(nextScript, (function(data) {
|
674
|
+
// data:required
|
675
|
+
evalWithTryCatch(sibilant.translateAll(data));
|
676
|
+
return sibilant.scriptLoaded();
|
677
|
+
}));
|
678
|
+
return true;
|
679
|
+
}
|
680
|
+
})();
|
681
|
+
});
|
682
|
+
;
|
683
|
+
return sibilant.loadNextScript();
|
684
|
+
}));
|
685
|
+
})()
|