-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathsibilant.js
7697 lines (7262 loc) · 204 KB
/
sibilant.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function() {
if (!(process.env.DISABLE_SOURCE_MAPS)) {
return require("source-map-support").install();
}
}).call(this);
//# sourceMappingURL=../maps/sibilant.map
;
var util = require("util"),
path = require("path"),
fs = require("fs");
var sibilant = (function(args) {
/* src/node.sibilant:3:14 */
var args = Array.prototype.slice.call(arguments, 0);
return sibilant.entry.apply(this, args);
}),
error = (function(str) {
/* src/node.sibilant:4:14 */
throw str
}),
inspect = util.inspect;
module.exports = sibilant;
sibilant.dir = process.cwd();
var relativeDirAndFile = (function relativeDirAndFile$(fileName) {
/* relative-dir-and-file src/node.sibilant:10:0 */
return [ path.dirname(fileName), fileName ].map((function() {
/* src/node.sibilant:12:15 */
return path.relative(process.cwd(), arguments[0]);
}));
});
sibilant.entry = (function sibilant$entry$(source, options) {
/* sibilant.entry src/node.sibilant:14:0 */
(function() {
if (("object" === typeof source && source !== null && source.constructor.name !== "Array")) {
options = source;
return source = undefined;
}
}).call(this);
options = (typeof options !== "undefined") ? options : { };
(function() {
if (typeof source === "string") {
return options.source = source;
}
}).call(this);
var map = options.map,
source = options.source,
file = options.file,
quoteKeys = options.quoteKeys,
json = options.json;
map = (typeof map !== "undefined") ? map : false;
quoteKeys = (typeof quoteKeys !== "undefined") ? quoteKeys : json;
(function() {
if (((typeof file !== "undefined" && file !== null) && !((typeof source !== "undefined" && source !== null)))) {
return source = (sibilant.sourceCache[file] || sibilant.stripShebang(fs.readFileSync(file, "utf8")));
}
}).call(this);
(function() {
if (file) {
return sibilant.sourceCache[file] = source;
}
}).call(this);
return withFile(file, (function() {
/* src/node.sibilant:38:7 */
var quoteState = sibilant.quoteHashKeys;
(function() {
if (quoteKeys) {
return sibilant.quoteHashKeys = true;
}
}).call(this);
var ast = restructure(parse(source)),
output = transpile(ast),
sourcemap = (function() {
if (map) {
return _sourcemapper(output);
}
}).call(this),
js = outputFormatter(output);
(function() {
if (quoteKeys) {
return sibilant.quoteHashKeys = quoteState;
}
}).call(this);
return {
ast: ast,
output: output,
js: js,
map: sourcemap
};
}));
});
sibilant.transpileFile = (function sibilant$transpileFile$(fileName) {
/* sibilant.transpile-file src/node.sibilant:56:0 */
return withFile(fileName, (function() {
/* src/node.sibilant:59:16 */
var source = sibilant.stripShebang(fs.readFileSync(fileName, "utf8"));
sibilant.sourceCache[fileName] = source;
return transpile(restructure(parse(source)));
}));
});
var withFile = (function withFile$(fileName, fn) {
/* with-file src/node.sibilant:68:0 */
return (function() {
if (fileName) {
return withDirAndFile.apply(this, relativeDirAndFile(fileName).concat([ (function() {
/* src/node.sibilant:70:65 */
return fn(fileName);
}) ]));
} else {
return fn();
}
}).call(this);
});
sibilant.sourcemapFile = (function sibilant$sourcemapFile$(fileName) {
/* sibilant.sourcemap-file src/node.sibilant:73:0 */
return withFile(fileName, (function() {
/* src/node.sibilant:75:16 */
return sourcemap(sibilant.stripShebang(fs.readFileSync(arguments[0], "utf8")));
}));
});
require.extensions[".sibilant"] = (function(module, filename) {
/* src/node.sibilant:82:5 */
return module._compile(sibilant({ file: filename }).js, filename);
});
require.extensions[".son"] = (function(module, filename) {
/* src/node.sibilant:88:5 */
var content = sibilant({
file: filename,
json: true
}).js,
json = (function() {
try {
return JSON.parse(content);
} catch (e) {
console.error("could not parse:\n", content);
throw e
}
}).call(this);
return module.exports = json;
});
sibilant.packageInfo = (function sibilant$packageInfo$() {
/* sibilant.package-info src/node.sibilant:98:0 */
return JSON.parse(fs.readFileSync((__dirname + "/../package.json"), "utf8"));
});
sibilant.versionString = (function sibilant$versionString$() {
/* sibilant.version-string src/node.sibilant:104:0 */
var package = sibilant.packageInfo();
return (package.name + " version " + package.version + "\n(at " + path.join(__dirname, "..") + ")");
});
sibilant.include = (function sibilant$include$(file) {
/* sibilant.include src/node.sibilant:110:0 */
(function() {
if (!(file.match((new RegExp("\\.(sibilant|son)$", undefined))))) {
return file = (file + ".sibilant");
}
}).call(this);
(function() {
if (file.match((new RegExp("^\\.\\.?/", undefined)))) {
return file = path.resolve(sibilant.dir, file);
}
}).call(this);
var resolvedFile = (function() {
try {
return require.resolve(file);
} catch (e) {
return error(("Failed to resolve file for inclusion: " + file));
}
}).call(this);
return sibilant({ file: resolvedFile }).output;
});
var log__BANG = (function log__BANG$(args) {
/* log! src/colors.sibilant:1:0 */
var args = Array.prototype.slice.call(arguments, 0);
return inspect__BANG.apply(this, args).forEach((function() {
/* src/colors.sibilant:2:35 */
return console.log(arguments[0]);
}));
});
var inspect__BANG = (function inspect__BANG$(args) {
/* inspect! src/colors.sibilant:4:0 */
var args = Array.prototype.slice.call(arguments, 0);
return args.map((function() {
/* src/colors.sibilant:5:15 */
return util.inspect(arguments[0], {
colors: false,
depth: 3
});
}));
});
var color = (function color$(code, items, depth) {
/* color src/colors.sibilant:7:0 */
return (code + items.join("") + "\033[0m");
});
var black = (function black$(args) {
/* black src/colors.sibilant:10:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;30m", args);
});
var red = (function red$(args) {
/* red src/colors.sibilant:11:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;31m", args);
});
var green = (function green$(args) {
/* green src/colors.sibilant:12:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;32m", args);
});
var brown = (function brown$(args) {
/* brown src/colors.sibilant:13:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;33m", args);
});
var blue = (function blue$(args) {
/* blue src/colors.sibilant:14:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;34m", args);
});
var purple = (function purple$(args) {
/* purple src/colors.sibilant:15:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;35m", args);
});
var cyan = (function cyan$(args) {
/* cyan src/colors.sibilant:16:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;36m", args);
});
var gray = (function gray$(args) {
/* gray src/colors.sibilant:17:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[0;37m", args);
});
var boldGray = (function boldGray$(args) {
/* bold-gray src/colors.sibilant:18:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;30m", args);
});
var boldRed = (function boldRed$(args) {
/* bold-red src/colors.sibilant:19:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;31m", args);
});
var boldGreen = (function boldGreen$(args) {
/* bold-green src/colors.sibilant:20:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;32m", args);
});
var yellow = (function yellow$(args) {
/* yellow src/colors.sibilant:21:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;33m", args);
});
var boldBlue = (function boldBlue$(args) {
/* bold-blue src/colors.sibilant:22:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;34m", args);
});
var boldPurple = (function boldPurple$(args) {
/* bold-purple src/colors.sibilant:23:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;35m", args);
});
var boldCyan = (function boldCyan$(args) {
/* bold-cyan src/colors.sibilant:24:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;36m", args);
});
var white = (function white$(args) {
/* white src/colors.sibilant:25:0 */
var args = Array.prototype.slice.call(arguments, 0);
return color("\033[1;37m", args);
});
sibilant.prettyPrint = (function sibilant$prettyPrint$(node, color, entry) {
/* sibilant.pretty-print src/pretty-printer.sibilant:3:0 */
entry = (typeof entry !== "undefined") ? entry : true;
color = (typeof color !== "undefined") ? color : true;
return realNewlines((function() {
if (node__QUERY(node)) {
var prettyPrinter = (sibilant.prettyPrint[node.type] || sibilant.prettyPrint.default);
return prettyPrinter(node, color, entry);
} else if (((node) && typeof (node) === "object" && (node).constructor.name === "Array")) {
return ((function() {
if (color) {
return black("[");
} else {
return "";
}
}).call(this) + map(node, (function() {
/* src/pretty-printer.sibilant:14:28 */
return prettify(arguments[0], color, false);
})).join((function() {
if (color) {
return black(",");
} else {
return "";
}
}).call(this)) + (function() {
if (color) {
return black("]");
} else {
return "";
}
}).call(this));
} else if (color) {
return red(inspect(node));
} else {
return realNewlines(inspect(node));
}
}).call(this));
});
var prettify = sibilant.prettyPrint;
sibilant.prettyPrint.default = (function sibilant$prettyPrint$default$(node, color, entry) {
/* sibilant.pretty-print.default src/pretty-printer.sibilant:23:0 */
var mapPretty = (function mapPretty$(attr) {
/* map-pretty src/pretty-printer.sibilant:24:5 */
var arr = node[attr];
return (function() {
if ((arr && arr.length)) {
return map(arr, (function() {
/* src/pretty-printer.sibilant:27:27 */
return prettify(arguments[0], color, false);
})).join("");
} else {
return "";
}
}).call(this);
});
return realNewlines(sibilant.prettyPrint.colorize(node, color, ((function() {
if (entry) {
return "";
} else {
return mapPretty("precedingIgnored");
}
}).call(this) + mapPretty("modifiers") + node.token + mapPretty("contents") + mapPretty("closingIgnored") + ((node.closed && acceptablePairs[node.token]) || ""))));
});
sibilant.prettyPrint.root = (function sibilant$prettyPrint$root$(node, color, entry) {
/* sibilant.pretty-print.root src/pretty-printer.sibilant:39:0 */
return map(node.contents, (function() {
/* src/pretty-printer.sibilant:41:16 */
return prettify(arguments[0], color, false);
})).join("\n");
});
sibilant.prettyPrint.output = (function sibilant$prettyPrint$output$(node, color) {
/* sibilant.pretty-print.output src/pretty-printer.sibilant:44:0 */
return ((function() {
if (color) {
return black("{");
} else {
return "";
}
}).call(this) + (function() {
if (((node.contents) && typeof (node.contents) === "object" && (node.contents).constructor.name === "Array")) {
return map(node.contents, (function() {
/* src/pretty-printer.sibilant:48:28 */
return sibilant.prettyPrint.colorize(node, color, prettify(arguments[0], color, false));
})).join((function() {
if (color) {
return black(",");
} else {
return "";
}
}).call(this));
} else {
return sibilant.prettyPrint.colorize(node, color, node.contents);
}
}).call(this) + (function() {
if (color) {
return black("}");
} else {
return "";
}
}).call(this));
});
var realNewlines = (function realNewlines$(node) {
/* real-newlines src/pretty-printer.sibilant:54:0 */
return node.split("\\n").join("\n");
});
sibilant.prettyPrint.colorize = (function sibilant$prettyPrint$colorize$(node, color, string) {
/* sibilant.pretty-print.colorize src/pretty-printer.sibilant:59:0 */
return (function() {
if (!(color)) {
return string;
} else if (node.hint === "macro") {
return yellow(string);
} else if (node__QUERY(node, "output")) {
return purple(string);
} else {
return green(string);
}
}).call(this);
});
var outputFormatter = (function outputFormatter$(node) {
/* output-formatter src/output-formatter.sibilant:1:0 */
return (function() {
if (((node) && typeof (node) === "object" && (node).constructor.name === "Array")) {
return map(node, outputFormatter).join("");
} else if (node__QUERY(node, "output")) {
return outputFormatter(node.contents);
} else if ((typeof node === "string" || typeof node === "number")) {
return node;
} else if (!((typeof node !== "undefined" && node !== null))) {
return "";
} else if (node__QUERY(node)) {
console.log("WE SHOULD NOT BE HERE");
console.log("node");
console.log(prettify(node));
return outputFormatter(transpile(node));
}
}).call(this);
});
sibilant.outputFormatter = outputFormatter;
var sourceNode = require("source-map").SourceNode;
var sourceMap = (function sourceMap$(node) {
/* source-map src/sourcemap.sibilant:3:0 */
return (function() {
if (node__QUERY(node, "output")) {
return (new sourceNode(node.source.line, node.source.col, node.source.file, (function() {
if (((node.contents) && typeof (node.contents) === "object" && (node.contents).constructor.name === "Array")) {
return map(node.contents, sourceMap);
} else {
return sourceMap(node.contents);
}
}).call(this)));
} else if ((typeof node === "string" || typeof node === "number")) {
return node.toString();
}
}).call(this);
});
var sourcemapper = (function sourcemapper$(untranspiledNode) {
/* sourcemapper src/sourcemap.sibilant:16:0 */
return _sourcemapper(transpile(untranspiledNode));
});
var _sourcemapper = (function _sourcemapper$(transpiledNode) {
/* *sourcemapper src/sourcemap.sibilant:19:0 */
var sourceNodes = sourceMap(transpiledNode),
map = sourceNodes.toStringWithSourceMap().map;
Object.keys(sibilant.sourceCache).forEach((function(key) {
/* src/sourcemap.sibilant:23:5 */
return map.setSourceContent(key, sibilant.sourceCache[key]);
}));
return map.toString();
});
var bulkMap = (function bulkMap$(arr, fn) {
/* bulk-map include/functional.sibilant:1:0 */
var index = 0,
groupSize = fn.length,
retArr = [];
(function() {
var $_symbol1_$ = undefined;
while (index < arr.length) {
$_symbol1_$ = (function() {
retArr.push(fn.apply(this, arr.slice(index, (index + groupSize))));
return index += groupSize;
}).call(this);
};
return $_symbol1_$;
}).call(this);
return retArr;
});
var inject = (function inject$(start, items, fn) {
/* inject include/functional.sibilant:13:0 */
var value = start;
(function() {
if (((items) && typeof (items) === "object" && (items).constructor.name === "Array")) {
return items.forEach((function(item, index) {
/* include/functional.sibilant:16:4 */
return value = fn(value, item, index);
}));
}
}).call(this);
return value;
});
var map = (function map$(items, fn) {
/* map include/functional.sibilant:20:0 */
return inject([], items, (function(collector, item, index) {
/* include/functional.sibilant:22:10 */
collector.push(fn(item, index));
return collector;
}));
});
var select = (function select$(items, fn) {
/* select include/functional.sibilant:26:0 */
return inject([], items, (function(collector, item, index) {
/* include/functional.sibilant:28:10 */
(function() {
if (fn(item, index)) {
return collector.push(item);
}
}).call(this);
return collector;
}));
});
var detect = (function detect$(items, fn) {
/* detect include/functional.sibilant:33:0 */
var returnItem = undefined,
index = 0,
items = (items || []);
(function() {
var $_symbol2_$ = undefined;
while (!((items.length === index || returnItem))) {
$_symbol2_$ = (function() {
(function() {
if (fn(items[index], index)) {
return returnItem = items[index];
}
}).call(this);
return ((index)++);
}).call(this);
};
return $_symbol2_$;
}).call(this);
return returnItem;
});
var all__QUERY = (function all__QUERY$(items, fn) {
/* all? include/functional.sibilant:45:0 */
return typeof detect(items, (function(item, index) {
/* include/functional.sibilant:46:31 */
return !(fn(item, index));
})) === "undefined";
});
var none__QUERY = (function none__QUERY$(items, fn) {
/* none? include/functional.sibilant:48:0 */
return typeof detect(items, fn) === "undefined";
});
var any__QUERY = (function any__QUERY$(items, fn) {
/* any? include/functional.sibilant:51:0 */
return typeof detect(items, fn) !== "undefined";
});
var reject = (function reject$(items, fn) {
/* reject include/functional.sibilant:54:0 */
var args = [ items, fn ];
return select(items, (function() {
/* include/functional.sibilant:56:16 */
return !(fn.apply(this, arguments));
}));
});
var compact = (function compact$(arr) {
/* compact include/functional.sibilant:58:0 */
return select(arr, (function(item) {
/* include/functional.sibilant:59:17 */
return (null !== item && false !== item && typeof item !== "undefined");
}));
});
var interleave = (function interleave$(glue, arr) {
/* interleave include/functional.sibilant:65:0 */
(function() {
if ((typeof arr === "string" && ((glue) && typeof (glue) === "object" && (glue).constructor.name === "Array"))) {
var temp = glue;
glue = arr;
return arr = temp;
}
}).call(this);
return (function() {
if (((glue) && typeof (glue) === "object" && (glue).constructor.name === "Array")) {
return inject([], arr, (function(collector, item, index) {
/* include/functional.sibilant:71:13 */
return collector.concat([ item, glue[index] ]);
}));
} else {
return inject([ arr[0] ], arr.slice(1), (function(collector, item, index) {
/* include/functional.sibilant:75:13 */
return collector.concat([ glue, item ]);
}));
}
}).call(this);
});
var flatten = (function flatten$(items) {
/* flatten include/functional.sibilant:78:0 */
var items = Array.prototype.slice.call(arguments, 0);
return inject([], items, (function(collector, item) {
/* include/functional.sibilant:80:10 */
return collector.concat((function() {
if (((item) && typeof (item) === "object" && (item).constructor.name === "Array")) {
return flatten.apply(this, item);
} else {
return item;
}
}).call(this));
}));
});
var recurseMap = (function recurseMap$(item, fn) {
/* recurse-map include/functional.sibilant:87:0 */
return (function() {
if (((item) && typeof (item) === "object" && (item).constructor.name === "Array")) {
return map(item, (function(subitem) {
/* include/functional.sibilant:88:32 */
return recurseMap(subitem, fn);
}));
} else {
return fn(item);
}
}).call(this);
});
var pluck = (function pluck$(items, attribute) {
/* pluck include/functional.sibilant:91:0 */
return map(items, (function(item) {
/* include/functional.sibilant:92:16 */
return item[attribute];
}));
});
var mergeInto = (function mergeInto$(into, from) {
/* merge-into include/functional.sibilant:94:0 */
Object.keys(from).forEach((function(key) {
/* include/functional.sibilant:95:5 */
return into[key] = from[key];
}));
return into;
});
var clone = (function clone$(object) {
/* clone include/functional.sibilant:98:0 */
return inject({ }, Object.keys(object), (function(collector, key) {
/* include/functional.sibilant:100:13 */
collector[key] = object[key];
return collector;
}));
});
var mapValues = (function mapValues$(object, fn) {
/* map-values include/functional.sibilant:104:0 */
return inject({ }, Object.keys(object), (function(collector, key, index) {
/* include/functional.sibilant:106:13 */
collector[key] = fn(object[key], key);
return collector;
}));
});
var mergeWith = (function mergeWith$(into, from) {
/* merge-with include/functional.sibilant:110:0 */
return mergeInto(clone(into), from);
});
var parser = { };
sibilant.parser = parser;
parser.tokens = {
"regex": "(\\/(\\\\\\\/|[^\\/\\n])+\\/[glim]*)",
"comment": "(;.*)",
"string": "(\"(([^\"]|(\\\\\"))*[^\\\\])?\")",
"number": "(-?[0-9][0-9.,]*)",
"literal": "(-?[*.$a-zA-Z_][/*.a-zA-Z0-9-_]*(\\?|!)?)",
"special": "([&'])",
"at": "@",
"tick": "[`']",
"hat": "(\\^)",
"dots": "(\\.+)",
"argPlaceholder": "(#[0-9]+)",
"otherChar": "([\\|#><=!\\+\\/\\*-]+)",
"openExpression": "(\\(|\\{|\\[)",
"closeExpression": "(\\)|\\}|\\])",
"newline": "\\n",
"whitespace": "\\s+",
"ignored": "."
};
parser.tokenPrecedence = [ "regex", "comment", "string", "number", "dots", "tick", "hat", "at", "special", "literal", "argPlaceholder", "otherChar", "openExpression", "closeExpression", "newline", "whitespace", "ignored" ];
parser.orderedRegexes = parser.tokenPrecedence.map((function(x) {
/* src/parser.sibilant:41:23 */
return mergeInto((new RegExp(("^" + parser.tokens[x]), undefined)), { name: x });
}));
var orderedRegexes = parser.orderedRegexes;
parser.parse = (function parser$parse$(string, context) {
/* parser.parse src/parser.sibilant:46:0 */
context = (typeof context !== "undefined") ? context : {
position: 0,
stack: [],
line: 1,
lastNewline: 0,
col: 0
};
var match = true,
regexName = null,
remainingInput = string;
(function() {
var $_symbol3_$ = undefined;
while (match) {
$_symbol3_$ = (function() {
detect(orderedRegexes, (function(r) {
/* src/parser.sibilant:57:20 */
regexName = r.name;
return match = r.exec(remainingInput);
}));
return (function() {
if ((typeof match !== "undefined" && match !== null)) {
var matchString = match[0],
length = matchString.length;
context.stack.push({
dir: sibilant.dir,
file: sibilant.file,
token: matchString,
type: regexName,
start: context.position,
line: context.line,
col: context.col,
length: length,
contents: []
});
(function() {
if ("newline" === regexName) {
((context.line)++);
context.col = 0;
return context.lastNewline = context.position;
} else if (("string" === regexName && matchString.indexOf("\n") !== -1)) {
var stringNewlineCount = (matchString.split("\n").length - 1);
context.line += stringNewlineCount;
return context.col = (length - matchString.lastIndexOf("\n"));
} else {
return context.col += length;
}
}).call(this);
context.position += length;
return remainingInput = (function() {
if ((remainingInput && remainingInput.length)) {
return remainingInput.slice(length);
} else {
return "";
}
}).call(this);
}
}).call(this);
}).call(this);
};
return $_symbol3_$;
}).call(this);
return context.stack;
});
var parse = parser.parse;
var restructurers = { },
acceptablePairs = {
"(": ")",
"[": "]",
"{": "}"
},
bracketTypes = {
"(": "expression",
"[": "bracket",
"{": "brace"
};
var restructure = (function restructure$(input) {
/* restructure src/restructurer.sibilant:7:0 */
var output = {
type: "root",
contents: [],
file: sibilant.file,
col: 0,
line: 1
},
context = {
parseStack: [ output ],
output: output,
input: input,
ignoredTokens: [],
specials: 0
};
inject(context, input, (function(context, token, index) {
/* src/restructurer.sibilant:20:13 */
var restructurer = (restructurers[token.type] || restructurers.default);
return restructurer(token, context, index);
}));
(function() {
if (!(1 === context.parseStack.length)) {
var unclosedNode = context.parseStack[0];
throw (new Error(("unclosed node at " + unclosedNode.file + ":" + unclosedNode.line + ":" + unclosedNode.col + "\n " + prettify(unclosedNode, false).slice(0, 100))))
}
}).call(this);
return output;
});
sibilant.restructure = restructure;
restructurers.openExpression = (function restructurers$openExpression$(token, context) {
/* restructurers.open-expression src/restructurer.sibilant:35:0 */
var first = context.parseStack[0];
token.contents = [];
token.type = bracketTypes[token.token];
acceptIgnoredTokens(token, context);
acceptSpecials(token, context);
first.contents.push(token);
context.parseStack.unshift(token);
return context;
});
restructurers.closeExpression = (function restructurers$closeExpression$(node, context, index) {
/* restructurers.close-expression src/restructurer.sibilant:47:0 */
var first = context.parseStack[0];
(function() {
if (node__QUERY(first, "root")) {
throw (new Error(("unexpected " + node.token + " on " + node.file + ":" + node.line + ":" + node.col)))
}
}).call(this);
(function() {
if (acceptablePairs[first.token] !== node.token) {
throw (new Error(("trying to close " + yellow(sibilant.prettyPrint(first)) + "\n on " + first.file + ":" + first.line + ":" + first.col + "\n with " + sibilant.prettyPrint(node) + "\n on " + node.file + ":" + node.line + ":" + node.col + "\n")))
}
}).call(this);
first.end = node.end;
first.closed = true;
first.closingIgnored = context.ignoredTokens;
context.ignoredTokens = [];
context.parseStack.shift();
closeSpecials(first, context);
(function() {
if (context.parseStack.length === 0) {
throw (new Error(("unbalanced parens:\n" + inspect(parseStack))))
}
}).call(this);
return context;
});
var openSpecial = (function openSpecial$(node, context) {
/* open-special src/restructurer.sibilant:72:0 */
((context.specials)++);
acceptIgnoredTokens(node, context);
var first = context.parseStack[0];
node.contents = [];
first.contents.push(node);
context.parseStack.unshift(node);
return context;
});
var acceptSpecials = (function acceptSpecials$(node, context) {
/* accept-specials src/restructurer.sibilant:85:0 */
node.specials = context.specials;
context.specials = 0;
return context;
});
var acceptIgnoredTokens = (function acceptIgnoredTokens$(node, context) {
/* accept-ignored-tokens src/restructurer.sibilant:90:0 */
node.precedingIgnored = context.ignoredTokens;
context.ignoredTokens = [];
return context;
});
var closeSpecials = (function closeSpecials$(node, context) {
/* close-specials src/restructurer.sibilant:95:0 */
(function() {
if (node.specials > 0) {
((node.specials)--);
context.parseStack.shift();
return closeSpecials(node, context);
}
}).call(this);
return context;
});
var accumulateIgnoredToken = (function accumulateIgnoredToken$(token, context, index) {
/* accumulate-ignored-token src/restructurer.sibilant:103:0 */
context.ignoredTokens.push(token);
return context;
});
[ "hat", "dots", "tick", "at" ].forEach((function(special) {
/* src/restructurer.sibilant:107:0 */
return restructurers[special] = openSpecial;
}));
[ "whitespace", "newline", "ignored" ].forEach((function(ignored) {
/* src/restructurer.sibilant:110:0 */
return restructurers[ignored] = accumulateIgnoredToken;
}));
restructurers.default = (function restructurers$default$(token, context, index) {
/* restructurers.default src/restructurer.sibilant:113:0 */
acceptSpecials(token, context);
acceptIgnoredTokens(token, context);
context.parseStack[0].contents.push(token);
return closeSpecials(token, context);
});
var coreNamespace = { },
macroNamespaces = { core: coreNamespace };
sibilant.state = { };
sibilant.macros = {
"namespaces": macroNamespaces,
"defaultSearchPath": [ "core" ],
"searchPath": [ "core" ],
"namespace": coreNamespace
};
var namespace = sibilant.macros.namespace,
macros = sibilant.macros.namespace;
sibilant.macros.currentNamespace = (function sibilant$macros$currentNamespace$() {
/* sibilant.macros.current-namespace src/macros.sibilant:14:0 */
return sibilant.macros.namespaces[sibilant.macros.searchPath[0]];
});
sibilant.resolveMacro = (function sibilant$resolveMacro$(macroName) {
/* sibilant.resolve-macro src/macros.sibilant:17:0 */
return (function() {
if ((macroName.indexOf("/") !== -1 && 1 < macroName.length && !(macroName.indexOf("\n") !== -1))) {
var pathComponents = macroName.split("/"),
macro = (sibilant.macros.namespaces.hasOwnProperty(pathComponents[0]) && sibilant.macros.namespaces[pathComponents[0]][pathComponents.slice(1).join("/")]);
return (function() {
if (macro) {
return macro;
} else {
return error(("called namespaced macro " + macroName + " but could not find namespace " + pathComponents[0] + ". you might need to include the file that defines it first."));