sibilant 0.0.2 → 0.0.3

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.
@@ -1,12 +1,10 @@
1
1
  (function() {
2
2
  var sibilant = { };
3
3
  var error = (function(str) {
4
- // str:required
5
4
  throw new Error (str);
6
5
  });
7
6
  ;
8
7
  var inspect = (function(item) {
9
- // item:required
10
8
  return (function() {
11
9
  if (item.toSource) {
12
10
  return item.toSource();
@@ -19,7 +17,6 @@
19
17
  (window)["sibilant"] = sibilant;
20
18
  var exports = { };
21
19
  var bulkMap = (function(arr, fn) {
22
- // arr:required fn:required
23
20
  var index = 0,
24
21
  groupSize = fn.length,
25
22
  retArr = [ ];
@@ -37,12 +34,10 @@
37
34
  });
38
35
 
39
36
  var inject = (function(start, items, fn) {
40
- // start:required items:required fn:required
41
37
  var value = start;
42
38
  (function() {
43
39
  if ((items) && (items).constructor.name === "Array") {
44
40
  return items.forEach((function(item, index) {
45
- // item:required index:required
46
41
  return value = fn(value, item, index);
47
42
  }));
48
43
  }
@@ -51,18 +46,14 @@
51
46
  });
52
47
 
53
48
  var map = (function(items, fn) {
54
- // items:required fn:required
55
49
  return inject([ ], items, (function(collector, item, index) {
56
- // collector:required item:required index:required
57
50
  collector.push(fn(item, index));
58
51
  return collector;
59
52
  }));
60
53
  });
61
54
 
62
55
  var select = (function(items, fn) {
63
- // items:required fn:required
64
56
  return inject([ ], items, (function(collector, item, index) {
65
- // collector:required item:required index:required
66
57
  (function() {
67
58
  if (fn(item, index)) {
68
59
  return collector.push(item);
@@ -73,7 +64,6 @@
73
64
  });
74
65
 
75
66
  var detect = (function(items, fn) {
76
- // items:required fn:required
77
67
  var returnItem = undefined,
78
68
  index = 0,
79
69
  items = items;
@@ -94,7 +84,6 @@
94
84
  });
95
85
 
96
86
  var reject = (function(items, fn) {
97
- // items:required fn:required
98
87
  var args = [ items, fn ];
99
88
  return select(items, (function() {
100
89
  return (!fn.apply(undefined, arguments));
@@ -102,19 +91,15 @@
102
91
  });
103
92
 
104
93
  var compact = (function(arr) {
105
- // arr:required
106
94
  return select(arr, (function(item) {
107
- // item:required
108
95
  return (!!(item));
109
96
  }));
110
97
  });
111
98
 
112
99
  var flatten = (function(items) {
113
- // items:rest
114
100
  var items = Array.prototype.slice.call(arguments, 0);
115
101
 
116
102
  return inject([ ], items, (function(collector, item) {
117
- // collector:required item:required
118
103
  return collector.concat((function() {
119
104
  if ((item) && (item).constructor.name === "Array") {
120
105
  return flatten.apply(undefined, item);
@@ -141,12 +126,10 @@
141
126
  (sibilant.tokens)["specialLiteral"] = (sibilant.tokens.special + sibilant.tokens.literal);
142
127
  (sibilant)["tokenPrecedence"] = [ "regex", "comment", "string", "number", "specialLiteral", "otherChar", "specialOpenParen", "closeParen", "alternativeParens" ];
143
128
  var tokenize = sibilant.tokenize = (function(string) {
144
- // string:required
145
129
  var tokens = [ ],
146
130
  parseStack = [ tokens ],
147
131
  specials = [ ];
148
132
  var acceptToken = (function(token) {
149
- // token:required
150
133
  return (parseStack)[0].push(token);
151
134
  });
152
135
  ;
@@ -167,7 +150,6 @@
167
150
  });
168
151
  ;
169
152
  var handleToken = (function(token) {
170
- // token:required
171
153
  var special = (token)[0],
172
154
  token = token;
173
155
  (function() {
@@ -216,11 +198,10 @@
216
198
  });
217
199
  ;
218
200
  var orderedRegexen = map(sibilant.tokenPrecedence, (function(x) {
219
- // x:required
220
201
  return (sibilant.tokens)[x];
221
202
  })),
222
203
  masterRegex = (new RegExp((orderedRegexen).join("|"), "g"));
223
- string // chain
204
+ string
224
205
  .match(masterRegex)
225
206
  .forEach(handleToken)
226
207
  ;
@@ -232,10 +213,9 @@
232
213
  return tokens;
233
214
  });
234
215
  var indent = (function(args) {
235
- // args:rest
236
216
  var args = Array.prototype.slice.call(arguments, 0);
237
217
 
238
- return (compact(args) // chain
218
+ return (compact(args)
239
219
  .join("\n")
240
220
  .replace(/^/, "\n")
241
221
  .replace(/\n/g, "\n ")
@@ -243,9 +223,7 @@
243
223
  });
244
224
 
245
225
  var constructHash = (function(arrayOfArrays) {
246
- // arrayOfArrays:required
247
226
  return inject({ }, arrayOfArrays, (function(object, item) {
248
- // object:required item:required
249
227
  (object)[(item)[0]] = (object)[(item)[1]];
250
228
  return object;
251
229
  }));
@@ -254,7 +232,6 @@
254
232
  var macros = { };
255
233
  (sibilant)["macros"] = macros;
256
234
  (macros)["return"] = (function(token) {
257
- // token:required
258
235
  var defaultReturn = ("return " + translate(token));
259
236
  return (function() {
260
237
  if ((token) && (token).constructor.name === "Array") {
@@ -308,41 +285,39 @@
308
285
  })();
309
286
  });
310
287
  var asStatement = (function(string) {
311
- // string:required
312
- return string // chain
288
+ return string
313
289
  .toString()
314
290
  .replace(/;*\s*$/, ";")
315
291
  ;
316
292
  });
317
293
 
318
294
  macros.statement = (function(args) {
319
- // args:rest
320
295
  var args = Array.prototype.slice.call(arguments, 0);
321
296
 
322
297
  return (macros.call.apply(undefined, args) + ";\n");
323
298
  });
324
299
 
325
300
  macros.progn = (function(body) {
326
- // body:rest
327
301
  var body = Array.prototype.slice.call(arguments, 0);
328
302
 
329
303
  var lastIndex = Math.max(0, (body.length - 1));
330
304
  (body)[lastIndex] = [ "return", (body)[lastIndex] ];
331
305
  return (map(body, (function(arg) {
332
- // arg:required
333
306
  return (asStatement(translate(arg)));
334
307
  }))).join("\n");
335
308
  });
336
309
 
310
+ macros.emptyList = (function() {
311
+ return "null";
312
+ });
313
+
337
314
  macros.call = (function(fnName, args) {
338
- // fnName:required args:rest
339
315
  var args = Array.prototype.slice.call(arguments, 1);
340
316
 
341
317
  return (translate(fnName) + "(" + (map(args, translate)).join(", ") + ")");
342
318
  });
343
319
 
344
320
  macros.defun = (function(fnName, argsAndBody) {
345
- // fnName:required argsAndBody:rest
346
321
  var argsAndBody = Array.prototype.slice.call(arguments, 1);
347
322
 
348
323
  var fnNameTr = translate(fnName),
@@ -357,7 +332,6 @@
357
332
  });
358
333
 
359
334
  macros.defmacro = (function(name, argsAndBody) {
360
- // name:required argsAndBody:rest
361
335
  var argsAndBody = Array.prototype.slice.call(arguments, 1);
362
336
 
363
337
  var js = macros.lambda.apply(undefined, argsAndBody),
@@ -373,18 +347,15 @@
373
347
  });
374
348
 
375
349
  macros.concat = (function(args) {
376
- // args:rest
377
350
  var args = Array.prototype.slice.call(arguments, 0);
378
351
 
379
352
  return ("(" + (map(args, translate)).join(" + ") + ")");
380
353
  });
381
354
 
382
355
  var transformArgs = (function(arglist) {
383
- // arglist:required
384
356
  var last = undefined,
385
357
  args = [ ];
386
358
  arglist.forEach((function(arg) {
387
- // arg:required
388
359
  return (function() {
389
360
  if (((arg)[0] === "&")) {
390
361
  return last = arg.slice(1);
@@ -403,10 +374,8 @@
403
374
  });
404
375
 
405
376
  macros.reverse = (function(arr) {
406
- // arr:required
407
377
  var reversed = [ ];
408
378
  arr.forEach((function(item) {
409
- // item:required
410
379
  return reversed.unshift(item);
411
380
  }));
412
381
  return reversed;
@@ -414,17 +383,14 @@
414
383
 
415
384
  var reverse = macros.reverse;
416
385
  var buildArgsString = (function(args, rest) {
417
- // args:required rest:required
418
386
  var argsString = "",
419
387
  optionalCount = 0;
420
388
  args.forEach((function(arg, optionIndex) {
421
- // arg:required optionIndex:required
422
389
  return (function() {
423
390
  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
391
+ argsString = (argsString + "if (arguments.length < " + (args.length - optionalCount) + ")" + indent(("var " + map(args.slice((optionIndex + 1)), (function(arg, argIndex) {
426
392
  return (translate((arg)[1]) + " = " + translate(((args)[(optionIndex + argIndex)])[1]));
427
- })) // chain
393
+ }))
428
394
  .reverse()
429
395
  .concat((translate((arg)[1]) + " = undefined"))
430
396
  .join(", ")
@@ -442,28 +408,11 @@
442
408
  })();
443
409
  });
444
410
 
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
411
  macros.lambda = (function(arglist, body) {
461
- // arglist:required body:rest
462
412
  var body = Array.prototype.slice.call(arguments, 1);
463
413
 
464
414
  var args = transformArgs(arglist),
465
415
  rest = (select(args, (function(arg) {
466
- // arg:required
467
416
  return ("rest" === (arg)[0]);
468
417
  })))[0],
469
418
  docString = undefined;
@@ -480,13 +429,10 @@
480
429
  return args;
481
430
  }
482
431
  })(),
483
- argsString = buildArgsString(noRestArgs, rest),
484
- commentString = buildCommentString(args);
432
+ argsString = buildArgsString(noRestArgs, rest);
485
433
  return ("(function(" + (map(args, (function(arg) {
486
- // arg:required
487
434
  return translate((arg)[1]);
488
- }))).join(", ") + ") {" + indent(commentString, docString, argsString, (map(body, (function(stmt) {
489
- // stmt:required
435
+ }))).join(", ") + ") {" + indent(docString, argsString, (map(body, (function(stmt) {
490
436
  var tstmt = translate(stmt);
491
437
  return (tstmt + (function() {
492
438
  if (((tstmt.slice(-1))[0] === ";")) {
@@ -499,7 +445,6 @@
499
445
  });
500
446
 
501
447
  macros.quote = (function(item) {
502
- // item:required
503
448
  return (function() {
504
449
  if (("Array" === item.constructor.name)) {
505
450
  return ("[ " + (map(item, macros.quote)).join(", ") + " ]");
@@ -516,7 +461,6 @@
516
461
  });
517
462
 
518
463
  macros.hash = (function(pairs) {
519
- // pairs:rest
520
464
  var pairs = Array.prototype.slice.call(arguments, 0);
521
465
 
522
466
  (function() {
@@ -525,7 +469,6 @@
525
469
  }
526
470
  })();
527
471
  var pairStrings = bulkMap(pairs, (function(key, value) {
528
- // key:required value:required
529
472
  return (translate(key) + ": " + translate(value));
530
473
  }));
531
474
  return (function() {
@@ -538,19 +481,57 @@
538
481
  });
539
482
 
540
483
  var literal = (function(string) {
541
- // string:required
542
- return inject(string // chain
484
+ return inject(string
543
485
  .replace(/\*/g, "_")
544
486
  .replace(/\?$/, "__QUERY")
545
487
  .replace(/!$/, "__BANG")
546
488
  , string.match(/-(.)/g), (function(returnString, match) {
547
- // returnString:required match:required
548
489
  return returnString.replace(match, (match)[1].toUpperCase());
549
490
  }));
550
491
  });
551
492
 
493
+ var translateListToken = (function(token, hint) {
494
+ return (function() {
495
+ if (((token).length === 0)) {
496
+ return macros.emptyList();
497
+ } else {
498
+ return (function() {
499
+ if (typeof((macros)[translate((token)[0])]) !== 'undefined') {
500
+ return (macros)[translate((token)[0])].apply(undefined, token.slice(1));
501
+ } else {
502
+ return (macros)[(hint || "call")].apply(undefined, token);
503
+ }
504
+ })();
505
+ }
506
+ })();
507
+ });
508
+
509
+ var translateStringToken = (function(token, hint) {
510
+ return (function() {
511
+ if (token.match((new RegExp(("^" + sibilant.tokens.literal + "$"), undefined)))) {
512
+ return literal(token);
513
+ } else {
514
+ return (function() {
515
+ if (token.match((new RegExp("^;", undefined)))) {
516
+ return token.replace((new RegExp("^;+", undefined)), "//");
517
+ } else {
518
+ return (function() {
519
+ if (("\"" === (token)[0] &&
520
+ "\"" === (token.slice(-1))[0])) {
521
+ return token
522
+ .split("\n")
523
+ .join("\\n\" +\n\"");
524
+ } else {
525
+ return token;
526
+ }
527
+ })();
528
+ }
529
+ })();
530
+ }
531
+ })();
532
+ });
533
+
552
534
  var translate = (function(token, hint) {
553
- // token:required hint:required
554
535
  var hint = hint;
555
536
  (function() {
556
537
  if ((hint && typeof((macros)[hint]) === 'undefined')) {
@@ -568,34 +549,13 @@
568
549
  try {
569
550
  return (function() {
570
551
  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
- })();
552
+ return translateListToken(token, hint);
578
553
  } else {
579
554
  return (function() {
580
- if ((typeof(token) === "string" && token.match((new RegExp(("^" + sibilant.tokens.literal + "$"), undefined))))) {
581
- return literal(token);
555
+ if (typeof(token) === "string") {
556
+ return translateStringToken(token, hint);
582
557
  } 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
- })();
558
+ return token;
599
559
  }
600
560
  })();
601
561
  }
@@ -610,10 +570,8 @@
610
570
 
611
571
  (sibilant)["translate"] = translate;
612
572
  var translateAll = (function(contents) {
613
- // contents:required
614
573
  var buffer = "";
615
574
  tokenize(contents).forEach((function(token) {
616
- // token:required
617
575
  var line = translate(token, "statement");
618
576
  return (function() {
619
577
  if (line) {
@@ -630,7 +588,6 @@
630
588
  var sibilant = window.sibilant,
631
589
  scripts = [ ];
632
590
  var evalWithTryCatch = (function(js) {
633
- // js:required
634
591
  return (function() {
635
592
  try {
636
593
  return eval(js);
@@ -646,13 +603,13 @@
646
603
  js = null;
647
604
  return (function() {
648
605
  if ((!sibilant.loadNextScript())) {
649
- return $("script[type=\"text/sibilant\"]:not([src])") // chain
606
+ return $("script[type=\"text/sibilant\"]:not([src])")
650
607
  .each((function() {
651
- lisp = $(this) // chain
608
+ lisp = $(this)
652
609
  .text()
653
610
  .replace(/(^\s*\/\/\<!\[CDATA\[)|(\/\/\]\]>\s*$)/g, "");
654
611
  js = sibilant.translateAll(lisp);
655
- $(this) // chain
612
+ $(this)
656
613
  .data("js", js)
657
614
  ;
658
615
  return evalWithTryCatch(js);
@@ -661,7 +618,7 @@
661
618
  })();
662
619
  });
663
620
  ;
664
- scripts = $.makeArray($("script[type=\"text/sibilant\"][src]") // chain
621
+ scripts = $.makeArray($("script[type=\"text/sibilant\"][src]")
665
622
  .map((function() {
666
623
  return this.src;
667
624
  }))
@@ -671,7 +628,6 @@
671
628
  return (function() {
672
629
  if (typeof(nextScript) !== 'undefined') {
673
630
  $.get(nextScript, (function(data) {
674
- // data:required
675
631
  evalWithTryCatch(sibilant.translateAll(data));
676
632
  return sibilant.scriptLoaded();
677
633
  }));
@@ -228,7 +228,7 @@
228
228
  (concat "(!!(" (translate expr) "))"))
229
229
 
230
230
  (defmacro chain (object &rest calls)
231
- (concat (translate object) " // chain"
231
+ (concat (translate object)
232
232
  (indent (join "\n"
233
233
  (map calls
234
234
  (lambda (call, index)
@@ -237,6 +237,11 @@
237
237
  (concat "." (translate method)
238
238
  "(" (join ", " (map args translate)) ")")))))))
239
239
 
240
+ (defmacro chainable (&rest names)
241
+ (each (name) names
242
+ (macros.defmacro name ['target "&rest" 'calls]
243
+ ['apply 'macros.chain ['cons ['macros.call ['quote name] 'target] 'calls]])))
244
+
240
245
  (defmacro try (tryblock catchblock)
241
246
  (concat
242
247
  "(function() {"
@@ -150,6 +150,8 @@
150
150
  (map body (lambda (arg)
151
151
  (concat (as-statement (translate arg)))))))
152
152
 
153
+ (defun macros.empty-list () 'null)
154
+
153
155
  (defun macros.call (fn-name &rest args)
154
156
  (concat (translate fn-name)
155
157
  "(" (join ", " (map args translate)) ")"))
@@ -206,7 +208,6 @@
206
208
  args-string
207
209
  "if (arguments.length < "
208
210
  (- args.length optional-count) ")"
209
- " // if " (translate (second arg)) " is missing"
210
211
  (indent
211
212
  (concat "var "
212
213
  (chain
@@ -229,15 +230,6 @@
229
230
  args.length ");\n")
230
231
  args-string))
231
232
 
232
- (defun build-comment-string (args)
233
- (if (empty? args) ""
234
- (concat "// "
235
- (join " "
236
- (map args
237
- (lambda (arg)
238
- (concat (translate (second arg)) ":" (first arg))))))))
239
-
240
- ;; brain 'splode
241
233
  (defun macros.lambda (arglist &rest body)
242
234
  (defvar args (transform-args arglist)
243
235
  rest (first (select args
@@ -254,13 +246,12 @@
254
246
  (concat "/* " (eval (body.shift)) " */\n")))
255
247
 
256
248
  (defvar no-rest-args (if rest (args.slice 0 -1) args)
257
- args-string (build-args-string no-rest-args rest)
258
- comment-string (build-comment-string args))
249
+ args-string (build-args-string no-rest-args rest))
259
250
 
260
251
  (concat "(function("
261
252
  (join ", " (map args (lambda (arg) (translate (second arg)))))
262
253
  ") {"
263
- (indent comment-string doc-string args-string
254
+ (indent doc-string args-string
264
255
  (join "\n"
265
256
  (map body
266
257
  (lambda (stmt)
@@ -301,6 +292,23 @@
301
292
  (send (second match) to-upper-case)))))
302
293
 
303
294
 
295
+
296
+ (defun translate-list-token (token hint)
297
+ (if (empty? token)
298
+ (macros.empty-list)
299
+ (if (defined? (get macros (translate (first token))))
300
+ (apply (get macros (translate (first token))) (token.slice 1))
301
+ (apply (get macros (or hint 'call)) token))))
302
+
303
+ (defun translate-string-token (token hint)
304
+ (if (token.match (regex (concat "^" sibilant.tokens.literal "$")))
305
+ (literal token)
306
+ (if (token.match (regex "^;"))
307
+ (token.replace (regex "^;+") "//")
308
+ (if (= "\"" (first token) (last token))
309
+ (chain token (split "\n") (join "\\n\" +\n\""))
310
+ token))))
311
+
304
312
  (defun translate (token hint)
305
313
  (defvar hint hint)
306
314
  (when (and hint (undefined? (get macros hint)))
@@ -310,17 +318,10 @@
310
318
  (when (string? token) (setf token (token.trim)))
311
319
  (try
312
320
  (if (list? token)
313
- (if (defined? (get macros (translate (first token))))
314
- (apply (get macros (translate (first token))) (token.slice 1))
315
- (apply (get macros (or hint 'call)) token))
316
- (if (and (string? token)
317
- (token.match (regex (concat "^" sibilant.tokens.literal "$"))))
318
- (literal token)
319
- (if (and (string? token) (token.match (regex "^;")))
320
- (token.replace (regex "^;+") "//")
321
- (if (and (string? token) (= "\"" (first token) (last token)))
322
- (chain token (split "\n") (join "\\n\" +\n\""))
323
- token))))
321
+ (translate-list-token token hint)
322
+ (if (string? token)
323
+ (translate-string-token token hint)
324
+ token))
324
325
  (error (concat e.stack "\n"
325
326
  "Encountered when attempting to process:\n"
326
327
  (indent (call inspect token)))))))
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env sibilant -x
2
2
  (include "./testHelper.sibilant")
3
3
 
4
+
5
+ (assert-translation "()" "null")
4
6
  (assert-translation "5" "5")
5
7
  (assert-translation "1,000,000.01" "1000000.01")
6
8
  (assert-translation "1,000.00" "1000")
@@ -169,7 +171,6 @@ delete bam.bibble;")
169
171
  (assert-translation "(number? x)" "typeof(x) === 'number'")
170
172
 
171
173
  (assert-translation "(defun foo.bar (a) (* a 2))" "foo.bar = (function(a) {
172
- // a:required
173
174
  return (a * 2);
174
175
  });")
175
176
 
@@ -183,8 +184,7 @@ delete bam.bibble;")
183
184
  })();")
184
185
 
185
186
  (assert-translation "(lambda (&optional first-arg second-arg) true)" "(function(firstArg, secondArg) {
186
- // firstArg:optional secondArg:required
187
- if (arguments.length < 2) // if firstArg is missing
187
+ if (arguments.length < 2)
188
188
  var secondArg = firstArg, firstArg = undefined;
189
189
 
190
190
  return true;
@@ -212,7 +212,6 @@ delete bam.bibble;")
212
212
 
213
213
  (assert-translation "(each (x) arr a b c)"
214
214
  "arr.forEach((function(x) {
215
- // x:required
216
215
  a;
217
216
  b;
218
217
  return c;
@@ -393,7 +392,6 @@ afterInclude2();")
393
392
 
394
393
  (assert-translation "(alias-macro lambda ->) (-> (a) a) (delmacro ->) (-> (a) a)"
395
394
  "(function(a) {
396
- // a:required
397
395
  return a;
398
396
  })
399
397
  ->(a(), a);")
@@ -462,3 +460,24 @@ thunk(\"world\");
462
460
  (assert-translation
463
461
  "(defvar a (setf b c))"
464
462
  "var a = b = c;")
463
+
464
+
465
+ (assert-translation
466
+ "(chainable $) ($ 'div (data 'jquery true) (css {background 'blue color 'light-blue}))"
467
+ "$(\"div\")
468
+ .data(\"jquery\", true)
469
+ .css({
470
+ background: \"blue\",
471
+ color: \"lightBlue\"
472
+ })")
473
+
474
+ (assert-translation
475
+ "(chainable a b) (a target-a (fn-a 1) (fn-a 2)) (b target-b (fn-b 1) (fn-b 2))"
476
+ "a(targetA)
477
+ .fnA(1)
478
+ .fnA(2)
479
+
480
+ b(targetB)
481
+ .fnB(1)
482
+ .fnB(2)")
483
+
@@ -1,3 +1,3 @@
1
1
  module Sibilant
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/sibilant.rb CHANGED
@@ -2,6 +2,12 @@ require "sibilant/version"
2
2
  require 'json'
3
3
 
4
4
  module Sibilant
5
+ class << self
6
+ def [](sibilant_code)
7
+ Sibilant::Compiler.new.translate sibilant_code
8
+ end
9
+ end
10
+
5
11
  class Compiler
6
12
  def sibilant_js_root
7
13
  File.join File.dirname(__FILE__), '..', 'js', 'sibilant'
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sibilant do
4
+ it 'should provide a convenient array accessor sugar' do
5
+ Sibilant['(+ 1 2 3)'].should == '(1 + 2 + 3)'
6
+ end
7
+
4
8
  describe 'with an instance of sibilant compiler' do
5
9
  before(:each) { @compiler = Sibilant::Compiler.new }
6
10