-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqua-demo.js
1925 lines (1828 loc) · 107 KB
/
qua-demo.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
require=(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
(function (global){
// This small file becomes the main file of a browser bundle: it
// requires the VM, and sets the qua global variable, so that it can
// be accessed from JS (without burdening users to understand/use
// Browserify's require()).
global.qua = require("../src/main.js");
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"../src/main.js":5}],2:[function(require,module,exports){
module.exports=["%%progn",["%%def",["qua-function","def"],["qua-function","%%def"]],["def",["qua-function","car"],["qua-function","%%car"]],["def",["qua-function","cdr"],["qua-function","%%cdr"]],["def",["qua-function","cons"],["qua-function","%%cons"]],["def",["qua-function","defconstant"],["qua-function","def"]],["def",["qua-function","dynamic"],["qua-function","%%dynamic"]],["def",["qua-function","dynamic-bind"],["qua-function","%%dynamic-bind"]],["def",["qua-function","eq"],["qua-function","%%eq"]],["def",["qua-function","eql"],["qua-function","eq"]],["def",["qua-function","eval"],["qua-function","%%eval"]],["def",["qua-function","if"],["qua-function","%%if"]],["def",["qua-function","make-dynamic"],["qua-function","%%make-dynamic"]],["def",["qua-function","make-environment"],["qua-function","%%make-environment"]],["def",["qua-function","panic"],["qua-function","%%panic"]],["def",["qua-function","progn"],["qua-function","%%progn"]],["def",["qua-function","setq"],["qua-function","%%setq"]],["def",["qua-function","to-fun-sym"],["qua-function","%%to-fun-sym"]],["def",["qua-function","to-type-sym"],["qua-function","%%to-type-sym"]],["def",["qua-function","unwrap"],["qua-function","%%unwrap"]],["def",["qua-function","wrap"],["qua-function","%%wrap"]],["def",["qua-function","class-of"],["qua-function","%%class-of"]],["def",["qua-function","make-class"],["qua-function","%%make-class"]],["def",["qua-function","send-message"],["qua-function","%%send-message"]],["def",["qua-function","js-apply"],["qua-function","%%js-apply"]],["def",["qua-function","js-function"],["qua-function","%%js-function"]],["def",["qua-function","js-get"],["qua-function","%%js-get"]],["def",["qua-function","js-global"],["qua-function","%%js-global"]],["def",["qua-function","js-new"],["qua-function","%%js-new"]],["def",["qua-function","js-set"],["qua-function","%%js-set"]],["def",["qua-function","own-property?"],["qua-function","%%own-property?"]],["def",["qua-function","list*"],["qua-function","%%list*"]],["def",["qua-function","list-to-js-array"],["qua-function","%%list-to-array"]],["def",["qua-function","plist-to-js-object"],["qua-function","%%plist-to-js-object"]],["def",["qua-function","reverse-list"],["qua-function","%%reverse-list"]],["def","*print-escape*","%%*print-escape*"],["def",["qua-function","quote"],["%%vau",["operand"],"#ign","operand"]],["def",["qua-function","list"],["wrap",["%%vau","arguments","#ign","arguments"]]],["def",["qua-function","the-environment"],["%%vau","#ign","environment","environment"]],["def",["qua-function","vau"],["%%vau",["params","env-param",".","body"],"env",["eval",["list",["qua-function","%%vau"],"params","env-param",["list*",["qua-function","progn"],"body"]],"env"]]],["def",["qua-function","deffexpr"],["vau",["name","params","env-param",".","body"],"env",["eval",["list",["qua-function","def"],["to-fun-sym","name"],["list*",["qua-function","vau"],"params","env-param","body"]],"env"]]],["def",["qua-function","make-macro"],["wrap",["vau",["expander"],"#ign",["vau","form","env",["eval",["eval",["cons","expander","form"],["make-environment"]],"env"]]]]],["def",["qua-function","macro"],["make-macro",["vau",["params",".","body"],"#ign",["list",["qua-function","make-macro"],["list*",["qua-function","vau"],"params","#ign","body"]]]]],["def",["qua-function","defmacro"],["macro",["name","params",".","body"],["list",["qua-function","def"],["to-fun-sym","name"],["list*",["qua-function","macro"],"params","body"]]]],["defmacro","lambda",["params",".","body"],["list",["qua-function","wrap"],["list*",["qua-function","vau"],"params","#ign","body"]]],["defmacro","defun",["name","params",".","body"],["list",["qua-function","def"],["to-fun-sym","name"],["list*",["qua-function","lambda"],"params","body"]]],["defmacro","lambda/env",["params","env-param",".","body"],["list",["qua-function","wrap"],["list*",["qua-function","vau"],"params","env-param","body"]]],["defmacro","defun/env",["name","params","env-param",".","body"],["list",["qua-function","def"],["to-fun-sym","name"],["list*",["qua-function","lambda/env"],"params","env-param","body"]]],["defun","optional",["opt-arg",".","opt-default"],["if",["nil?","opt-arg"],["if",["nil?","opt-default"],"#void",["car","opt-default"]],["car","opt-arg"]]],["defun","apply",["fun","arguments",".","opt-env"],["eval",["cons",["unwrap","fun"],"arguments"],["optional","opt-env",["make-environment"]]]],["defun","funcall",["fun",".","arguments"],["apply","fun","arguments"]],["defun","compose",[["qua-function","f"],["qua-function","g"]],["lambda",["arg"],["f",["g","arg"]]]],["defun","identity",["x"],"x"],["defun","symbol?",["sym"],["eq",["class-of","sym"],["class","symbol"]]],["defun","cons?",["cons"],["eq",["class-of","cons"],["class","cons"]]],["defun","nil?",["obj"],["eq","obj",[]]],["defun","void?",["obj"],["eq","obj","#void"]],["def",["qua-function","caar"],["compose",["qua-function","car"],["qua-function","car"]]],["def",["qua-function","cadr"],["compose",["qua-function","car"],["qua-function","cdr"]]],["def",["qua-function","cdar"],["compose",["qua-function","cdr"],["qua-function","car"]]],["def",["qua-function","cddr"],["compose",["qua-function","cdr"],["qua-function","cdr"]]],["defmacro","function",["name"],["to-fun-sym","name"]],["defmacro","class",["name"],["to-type-sym","name"]],["defun","symbol-name",["sym"],["%%slot-value","sym",["qua-string","name"]]],["defun","map-list",[["qua-function","fun"],"list"],["if",["nil?","list"],[],["cons",["fun",["car","list"]],["map-list",["qua-function","fun"],["cdr","list"]]]]],["def",["qua-function","list-for-each"],["qua-function","map-list"]],["defun","fold-list",[["qua-function","fun"],"init","list"],["if",["nil?","list"],"init",["fold-list",["qua-function","fun"],["fun","init",["car","list"]],["cdr","list"]]]],["defmacro","let",["bindings",".","body"],["list*",["list*",["qua-function","lambda"],["map-list",["qua-function","car"],"bindings"],"body"],["map-list",["qua-function","cadr"],"bindings"]]],["defmacro","let*",["bindings",".","body"],["if",["nil?","bindings"],["list*",["qua-function","let"],[],"body"],["list",["qua-function","let"],["list",["car","bindings"]],["list*",["qua-function","let*"],["cdr","bindings"],"body"]]]],["defmacro","letrec",["bindings",".","body"],["list*",["qua-function","let"],[],["list",["qua-function","def"],["map-list",["qua-function","car"],"bindings"],["list*",["qua-function","list"],["map-list",["qua-function","cadr"],"bindings"]]],"body"]],["defun","var-bindingize",[["fun-name","fun-params",".","fun-body"]],["list",["to-fun-sym","fun-name"],["list*",["qua-function","lambda"],"fun-params","fun-body"]]],["defmacro","flet",["fun-bindings",".","body"],["list*",["qua-function","let"],["map-list",["qua-function","var-bindingize"],"fun-bindings"],"body"]],["defmacro","labels",["fun-bindings",".","body"],["list*",["qua-function","letrec"],["map-list",["qua-function","var-bindingize"],"fun-bindings"],"body"]],["defun","not",["boolean"],["if","boolean",false,true]],["deffexpr","cond","clauses","env",["if",["nil?","clauses"],"#void",["let",[[[["test",".","body"],".","rest-clauses"],"clauses"]],["if",["eval","test","env"],["eval",["cons",["qua-function","progn"],"body"],"env"],["eval",["cons",["qua-function","cond"],"rest-clauses"],"env"]]]]],["deffexpr","and","ops","env",["cond",[["nil?","ops"],true],[["nil?",["cdr","ops"]],["eval",["car","ops"],"env"]],[["eval",["car","ops"],"env"],["eval",["cons",["qua-function","and"],["cdr","ops"]],"env"]],[true,false]]],["deffexpr","or","ops","env",["cond",[["nil?","ops"],false],[["nil?",["cdr","ops"]],["eval",["car","ops"],"env"]],[["eval",["car","ops"],"env"],true],[true,["eval",["cons",["qua-function","or"],["cdr","ops"]],"env"]]]],["defconstant","+setter-prop+",["qua-string","qua_setter"]],["defun","setter",["obj"],["js-get","obj","+setter-prop+"]],["defun","defsetf",["access-fn","update-fn"],["js-set","access-fn","+setter-prop+","update-fn"]],["defsetf",["qua-function","setter"],["lambda",["new-setter","getter"],["js-set","getter","+setter-prop+","new-setter"]]],["defmacro","setf",["place","new-val"],["if",["symbol?","place"],["list",["qua-function","setq"],"place","new-val"],["let*",[[["getter-form",".","arguments"],"place"],["getter",["if",["symbol?","getter-form"],["to-fun-sym","getter-form"],"getter-form"]]],["list*",["list",["qua-function","setter"],"getter"],"new-val","arguments"]]]],["defmacro","incf",["place",".","opt-increment"],["let",[["increment",["optional","opt-increment",1]]],["list",["qua-function","setf"],"place",["list",["qua-function","+"],"place","increment"]]]],["defmacro","decf",["place",".","opt-decrement"],["let",[["decrement",["optional","opt-decrement",1]]],["list",["qua-function","setf"],"place",["list",["qua-function","-"],"place","decrement"]]]],["defun/env","find-class",["class-desig"],"env",["eval",["to-type-sym","class-desig"],"env"]],["defun","make-instance",["class-desig",".","initargs"],["%%make-instance",["find-class","class-desig"],["plist-to-js-object","initargs"]]],["deffexpr","defgeneric",["name",".","#ign"],"env",["let",[["generic",["lambda","arguments",["send-message",["car","arguments"],["symbol-name","name"],"arguments"]]]],["eval",["list",["qua-function","def"],["to-fun-sym","name"],"generic"],"env"]]],["deffexpr","defmethod",["name",[["self","class-spec"],".","arguments"],".","body"],"env",["let",[["class",["find-class","class-spec"]],["method",["eval",["list*",["qua-function","lambda"],["list*","self","arguments"],"body"],"env"]]],["%%put-method","class",["symbol-name","name"],"method"]]],["deffexpr","defstruct",["name",".","#ign"],"env",["let*",[["class-name",["symbol-name","name"]],["class",["make-class",["class","structure-class"],"class-name"]]],["eval",["list",["qua-function","def"],["to-type-sym","name"],"class"],"env"]]],["defun","slot-value",["obj","name"],["%%slot-value","obj",["symbol-name","name"]]],["defun","set-slot-value",["obj","name","value"],["%%set-slot-value","obj",["symbol-name","name"],"value"]],["defun","slot-bound?",["obj","name"],["%%slot-bound?","obj",["symbol-name","name"]]],["defsetf",["qua-function","slot-value"],["lambda",["new-val","obj","slot-name"],["set-slot-value","obj","slot-name","new-val"]]],["defun","slot-void?",["obj","slot-name"],["if",["slot-bound?","obj","slot-name"],["void?",["slot-value","obj","slot-name"]],true]],["defgeneric","compute-method",["class","receiver","message","arguments"]],["defmacro","loop","body",["list",["qua-function","%%loop"],["list*",["qua-function","progn"],"body"]]],["deffexpr","while",["test",".","body"],"env",["let",[["body",["list*",["qua-function","progn"],"body"]]],["block","exit",["loop",["if",["eval","test","env"],["eval","body","env"],["return-from","exit"]]]]]],["defmacro","if",["test","then","else"],["list",["qua-function","%%if"],"test","then","else"]],["defmacro","when",["test",".","body"],["list",["qua-function","if"],"test",["list*",["qua-function","progn"],"body"],"#void"]],["defmacro","unless",["test",".","body"],["list",["qua-function","if"],"test","#void",["list*",["qua-function","progn"],"body"]]],["defun","call-with-escape",[["qua-function","fn"]],["labels",[["escape","opt-val",["%%raise",["make-instance",["quote","%%tag"],["qua-keyword","id"],["qua-function","escape"],["qua-keyword","val"],["optional","opt-val"]]]]],["%%rescue",["lambda",["exc"],["if",["and",["eq",["class-of","exc"],["class","%%tag"]],["eq",["slot-value","exc",["quote","id"]],["qua-function","escape"]]],["slot-value","exc",["quote","val"]],["%%raise","exc"]]],["lambda",[],["fn",["qua-function","escape"]]]]]],["defmacro","block",["name",".","body"],["list",["qua-function","call-with-escape"],["list*",["qua-function","lambda"],["list","name"],"body"]]],["defun","return-from",["escape",".","opt-val"],["apply","escape","opt-val"]],["deffexpr","prog1","forms","env",["if",["nil?","forms"],"#void",["let",[["result",["eval",["car","forms"],"env"]]],["eval",["list*",["qua-function","progn"],["cdr","forms"]],"env"],"result"]]],["defmacro","prog2",["form",".","forms"],["list",["qua-function","progn"],"form",["list*",["qua-function","prog1"],"forms"]]],["deffexpr","unwind-protect",["protected-form",".","cleanup-forms"],"env",["prog1",["%%rescue",["lambda",["exc"],["eval",["list*",["qua-function","progn"],"cleanup-forms"],"env"],["%%raise","exc"]],["lambda",[],["eval","protected-form","env"]]],["eval",["list*",["qua-function","progn"],"cleanup-forms"],"env"]]],["deffexpr","case",["expr",".","clauses"],"env",["let",[["val",["eval","expr","env"]]],["block","match",["list-for-each",["lambda",[["other-val",".","body"]],["when",["eql","val",["eval","other-val","env"]],["return-from","match",["eval",["list*",["qua-function","progn"],"body"],"env"]]]],"clauses"],"#void"]]],["defstruct","box","val"],["defun","make-box","opt-val",["make-instance",["quote","box"],["qua-keyword","val"],["optional","opt-val"]]],["defun","box-value",["box"],["slot-value","box",["quote","val"]]],["defsetf",["qua-function","box-value"],["lambda",["new-val","box"],["setf",["slot-value","box",["quote","val"]],"new-val"]]],["defmacro","push-prompt",["prompt",".","body"],["list",["qua-function","%%push-prompt"],"prompt",["list*",["qua-function","lambda"],[],"body"]]],["defmacro","take-subcont",["prompt","name",".","body"],["list",["qua-function","%%take-subcont"],"prompt",["list*",["qua-function","lambda"],["list","name"],"body"]]],["defmacro","push-subcont",["continuation",".","body"],["list",["qua-function","%%push-subcont"],"continuation",["list*",["qua-function","lambda"],[],"body"]]],["defmacro","push-prompt-subcont",["prompt","continuation",".","body"],["list",["qua-function","%%push-prompt-subcont"],"prompt","continuation",["list*",["qua-function","lambda"],[],"body"]]],["defconstant","+default-prompt+",["qua-keyword","default-prompt"]],["defmacro","push-default-prompt","body",["list*",["qua-function","push-prompt"],"+default-prompt+","body"]],["defmacro","take-default-subcont",["name",".","body"],["list*",["qua-function","take-subcont"],"+default-prompt+","name","body"]],["defmacro","push-default-subcont",["continuation",".","body"],["list*",["qua-function","push-prompt-subcont"],"+default-prompt+","continuation","body"]],["defmacro","defdynamic",["name",".","opt-val"],["list",["qua-function","def"],"name",["list",["qua-function","make-dynamic"],["optional","opt-val"]]]],["deffexpr","dynamic-let",["bindings",".","body"],"env",["let",[["pairs",["map-list",["lambda",[["dynamic-name","expr"]],["cons",["eval","dynamic-name","env"],["eval","expr","env"]]],"bindings"]]],["labels",[["process-pairs",["pairs"],["if",["nil?","pairs"],["eval",["list*",["qua-function","progn"],"body"],"env"],["let*",[[[["dynamic",".","value"],".","rest-pairs"],"pairs"]],["dynamic-bind","dynamic","value",["lambda",[],["process-pairs","rest-pairs"]]]]]]],["process-pairs","pairs"]]]],["defun","js-getter",["prop-name"],["flet",[["getter",["obj"],["js-get","obj","prop-name"]]],["defsetf",["qua-function","getter"],["lambda",["new-val","obj"],["js-set","obj","prop-name","new-val"]]],["qua-function","getter"]]],["defun","js-invoker",["method-name"],["lambda",["this",".","arguments"],["let",[["js-fun",["js-get","this","method-name"]]],["js-apply","js-fun","this",["list-to-js-array","arguments"]]]]],["defun","js-object","plist",["plist-to-js-object","plist"]],["defun","js-array","elements",["list-to-js-array","elements"]],["defmacro","js-lambda",["lambda-list",".","body"],["list",["qua-function","js-function"],["list*",["qua-function","lambda"],"lambda-list","body"]]],["defun","js-relational-op",["name"],["let",[[["qua-function","binop"],["%%js-binop","name"]]],["labels",[["op",["arg1","arg2",".","rest"],["if",["binop","arg1","arg2"],["if",["nil?","rest"],true,["apply",["qua-function","op"],["list*","arg2","rest"]]],false]]],["qua-function","op"]]]],["def",["qua-function","=="],["js-relational-op",["qua-string","=="]]],["def",["qua-function","==="],["js-relational-op",["qua-string","==="]]],["def",["qua-function","<"],["js-relational-op",["qua-string","<"]]],["def",["qua-function",">"],["js-relational-op",["qua-string",">"]]],["def",["qua-function","<="],["js-relational-op",["qua-string","<="]]],["def",["qua-function",">="],["js-relational-op",["qua-string",">="]]],["def",["qua-function","lt"],["qua-function","<"]],["def",["qua-function","lte"],["qua-function","<="]],["def",["qua-function","gt"],["qua-function",">"]],["def",["qua-function","gte"],["qua-function",">="]],["defun","!=","arguments",["not",["apply",["qua-function","=="],"arguments"]]],["defun","!==","arguments",["not",["apply",["qua-function","==="],"arguments"]]],["def",["qua-function","*"],["let",[[["qua-function","binop"],["%%js-binop",["qua-string","*"]]]],["lambda","arguments",["fold-list",["qua-function","binop"],1,"arguments"]]]],["def",["qua-function","+"],["let",[[["qua-function","binop"],["%%js-binop",["qua-string","+"]]]],["lambda","arguments",["if",["nil?","arguments"],0,["fold-list",["qua-function","binop"],["car","arguments"],["cdr","arguments"]]]]]],["defun","js-negative-op",["name","unit"],["let",[[["qua-function","binop"],["%%js-binop","name"]]],["lambda",["arg1",".","rest"],["if",["nil?","rest"],["binop","unit","arg1"],["fold-list",["qua-function","binop"],"arg1","rest"]]]]],["def",["qua-function","-"],["js-negative-op",["qua-string","-"],0]],["def",["qua-function","/"],["js-negative-op",["qua-string","/"],1]],["defun","list-length",["list"],["if",["nil?","list"],0,["+",1,["list-length",["cdr","list"]]]]],["defun","list-elt",["list","i"],["if",["eql","i",0],["car","list"],["list-elt",["cdr","list"],["-","i",1]]]],["defun","filter-list",[["qua-function","pred?"],"list"],["if",["nil?","list"],["quote",[]],["if",["pred?",["car","list"]],["cons",["car","list"],["filter-list",["qua-function","pred?"],["cdr","list"]]],["filter-list",["qua-function","pred?"],["cdr","list"]]]]],["defun","append-lists",["list-1","list-2"],["if",["nil?","list-1"],"list-2",["cons",["car","list-1"],["append-lists",["cdr","list-1"],"list-2"]]]],["defgeneric","type?",["obj","type-spec"]],["defmethod","type?",[["obj","object"],"type-spec"],["default-type?","obj","type-spec"]],["defun","default-type?",["obj","type-spec"],["let",[["c",["find-class","type-spec"]]],["or",["eq","c",["class","object"]],["eq","c",["class-of","obj"]]]]],["deffexpr","typecase",["expr",".","clauses"],"env",["let",[["val",["eval","expr","env"]]],["block","match",["list-for-each",["lambda",[["type-spec",".","body"]],["if",["eq","type-spec",true],["return-from","match",["eval",["list*",["qua-function","progn"],"body"],"env"]],["when",["type?","val","type-spec"],["return-from","match",["eval",["list*",["qua-function","progn"],"body"],"env"]]]]],"clauses"],"#void"]]],["defstruct","type-mismatch-error","type-spec","obj"],["deffexpr","the",["type-spec","obj"],"env",["let",[["evaluated-obj",["eval","obj","env"]]],["if",["type?","evaluated-obj","type-spec"],"evaluated-obj",["error",["make-instance",["quote","type-mismatch-error"],["qua-keyword","type-spec"],"type-spec",["qua-keyword","obj"],"evaluated-obj"]]]]],["defstruct","handler-frame","handlers","parent"],["defun","make-handler-frame",["handlers","parent"],["make-instance",["quote","handler-frame"],["qua-keyword","handlers"],"handlers",["qua-keyword","parent"],"parent"]],["defstruct","condition-handler","condition-type","handler-function"],["defun","make-condition-handler",["condition-type","handler-function"],["the","symbol","condition-type"],["the","function","handler-function"],["make-instance",["quote","condition-handler"],["qua-keyword","condition-type"],"condition-type",["qua-keyword","handler-function"],"handler-function"]],["defstruct","restart-handler","restart-name","handler-function","associated-condition","interactive-function"],["defun","make-restart-handler",["restart-name","handler-function","interactive-function","associated-condition"],["the","symbol","restart-name"],["the","function","handler-function"],["the","function","interactive-function"],["make-instance",["quote","restart-handler"],["qua-keyword","restart-name"],"restart-name",["qua-keyword","handler-function"],"handler-function",["qua-keyword","associated-condition"],"associated-condition",["qua-keyword","interactive-function"],"interactive-function"]],["defdynamic","*condition-handler-frame*"],["defdynamic","*restart-handler-frame*"],["defun","apply-handler-function",["handler","arguments"],["apply",["slot-value","handler",["quote","handler-function"]],"arguments"]],["defun","make-handler-bind-operator",[["qua-function","handler-spec-parser"],"handler-frame-dynamic"],["vau",["handler-specs",".","body"],"env",["let*",[["handlers",["map-list",["lambda",["spec"],["handler-spec-parser","spec","env"]],"handler-specs"]],["handler-frame",["make-handler-frame","handlers",["dynamic","handler-frame-dynamic"]]]],["dynamic-bind","handler-frame-dynamic","handler-frame",["lambda",[],["eval",["list*",["qua-function","progn"],"body"],"env"]]]]]],["def",["qua-function","handler-bind"],["make-handler-bind-operator",["lambda",[["class-name","function-form"],"env"],["make-condition-handler","class-name",["eval","function-form","env"]]],"*condition-handler-frame*"]],["def",["qua-function","restart-bind"],["make-handler-bind-operator",["lambda",[["restart-name","function-form",".","keywords"],"env"],["let*",[["dict",["plist-to-js-object","keywords"]],["interactive-function",["if",["own-property?","dict",["qua-string","interactive-function"]],["eval",[["js-getter",["qua-string","interactive-function"]],"dict"],"env"],["lambda",[],["quote",[]]]]],["associated-condition",["if",["own-property?","dict",["qua-string","associated-condition"]],["eval",[["js-getter",["qua-string","associated-condition"]],"dict"],"env"],"#void"]]],["make-restart-handler","restart-name",["eval","function-form","env"],"interactive-function","associated-condition"]]],"*restart-handler-frame*"]],["defun","signal",["condition"],["signal-condition","condition",["dynamic","*condition-handler-frame*"],["list","condition"]]],["defun","warn",["condition"],["signal","condition"],["print","condition"]],["defun","error",["condition"],["signal","condition"],["invoke-debugger","condition"]],["defstruct","restart-not-found","restart-designator"],["defun","restart-not-found",["restart-designator"],["make-instance",["quote","restart-not-found"],["qua-keyword","restart-designator"],"restart-designator"]],["defun","invoke-restart",["restart-designator",".","arguments"],["cond",[["symbol?","restart-designator"],["signal-condition","restart-designator",["dynamic","*restart-handler-frame*"],"arguments"]],[["type?","restart-designator",["quote","restart-handler"]],["apply-handler-function","restart-designator","arguments"]],[true,["error",["restart-not-found","restart-designator"]]]]],["defun","signal-condition",["condition","dynamic-frame","arguments"],["let",[["handler-and-frame",["find-applicable-handler","condition","dynamic-frame","#void"]]],["if",["void?","handler-and-frame"],"#void",["let",[[["handler","frame"],"handler-and-frame"]],["call-condition-handler","handler","frame","arguments"],["signal-condition","condition",["slot-value","frame",["quote","parent"]],"arguments"]]]]],["defun","find-applicable-handler",["condition","dynamic-frame","payload"],["if",["void?","dynamic-frame"],"#void",["block","found",["list-for-each",["lambda",["handler"],["when",["condition-applicable?","handler","condition","payload"],["return-from","found",["list","handler","dynamic-frame"]]]],["slot-value","dynamic-frame",["quote","handlers"]]],["find-applicable-handler","condition",["slot-value","dynamic-frame",["quote","parent"]],"payload"]]]],["defun","find-restart",["restart-name",".","opt-condition"],["the","symbol","restart-name"],["let*",[["associated-condition",["optional","opt-condition"]],["handler-and-frame",["find-applicable-handler","restart-name",["dynamic","*restart-handler-frame*"],"associated-condition"]]],["if",["void?","handler-and-frame"],"#void",["let",[[["handler","#ign"],"handler-and-frame"]],"handler"]]]],["defgeneric","condition-applicable?",["handler","condition","payload"]],["defmethod","condition-applicable?",[["handler","condition-handler"],"condition","#ign"],["type?","condition",["slot-value","handler",["quote","condition-type"]]]],["defmethod","condition-applicable?",[["handler","restart-handler"],"restart-name","associated-condition"],["and",["eql",["symbol-name","restart-name"],["symbol-name",["slot-value","handler",["quote","restart-name"]]]],["or",["void?","associated-condition"],["slot-void?","handler",["quote","associated-condition"]],["eq","associated-condition",["slot-value","handler",["quote","associated-condition"]]]]]],["defgeneric","call-condition-handler",["handler","handler-frame","arguments"]],["defmethod","call-condition-handler",[["handler","condition-handler"],"handler-frame","arguments"],["dynamic-let",[["*condition-handler-frame*",["slot-value","handler-frame",["quote","parent"]]]],["apply-handler-function","handler","arguments"]]],["defmethod","call-condition-handler",[["handler","restart-handler"],"handler-frame","arguments"],["apply-handler-function","handler","arguments"]],["defun","compute-restarts","opt-condition",["reverse-list",["do-compute-restarts",["optional","opt-condition"],["quote",[]],["dynamic","*restart-handler-frame*"]]]],["defun","do-compute-restarts",["condition","restart-list","handler-frame"],["if",["void?","handler-frame"],"restart-list",["let",[["restarts",["filter-list",["lambda",["handler"],["or",["void?","condition"],["slot-void?","handler",["quote","associated-condition"]],["eq",["slot-value","handler",["quote","associated-condition"]],"condition"]]],["slot-value","handler-frame",["quote","handlers"]]]]],["do-compute-restarts","condition",["append-lists","restarts","restart-list"],["slot-value","handler-frame",["quote","parent"]]]]]],["defun","invoke-restart-interactively",["restart-designator"],["let*",[["restart",["cond",[["symbol?","restart-designator"],["let",[["restart",["find-restart","restart-designator"]]],["if",["void?","restart"],["error",["restart-not-found","restart-designator"]],"restart"]]],[["type?","restart-designator",["quote","restart-handler"]],"restart-designator"],[true,["error",["restart-not-found","restart-designator"]]]]],["arguments",["funcall",["slot-value","restart",["quote","interactive-function"]]]]],["apply",["qua-function","invoke-restart"],["list*","restart","arguments"]]]],["defstruct","simple-error","message"],["defun","simple-error",["message"],["error",["make-instance",["quote","simple-error"],["qua-keyword","message"],"message"]]],["defgeneric","start-iteration",["sequence"]],["defgeneric","more?",["sequence","iteration-state"]],["defgeneric","current",["sequence","iteration-state"]],["defgeneric","advance",["sequence","iteration-state"]],["defgeneric","empty-clone",["sequence"]],["defgeneric","add-for-iteration",["sequence","element"]],["defgeneric","finish-clone",["sequence"]],["defun","for-each",[["qua-function","fn"],"seq"],["let",[["state",["start-iteration","seq"]]],["while",["more?","seq","state"],["fn",["current","seq","state"]],["setq","state",["advance","seq","state"]]]]],["defun","map",[["qua-function","fn"],"seq"],["let",[["result",["empty-clone","seq"]],["state",["start-iteration","seq"]]],["while",["more?","seq","state"],["setq","result",["add-for-iteration","result",["fn",["current","seq","state"]]]],["setq","state",["advance","seq","state"]]],["finish-clone","result"]]],["defun","subseq",["seq","start",".","opt-end"],["the","number","start"],["let",[["end",["optional","opt-end"]]],["unless",["or",["void?","end"],[">=","end","start"]],["simple-error",["qua-string","End must be greater than or equal to start"]]],["let",[["result",["empty-clone","seq"]],["state",["start-iteration","seq"]]],["let",[["skip","start"]],["while",["and",["more?","seq","state"],[">","skip",0]],["setq","state",["advance","seq","state"]],["decf","skip"]]],["let",[["ct",0]],["while",["and",["more?","seq","state"],["or",["void?","end"],["<","ct",["-","end","start"]]]],["setq","result",["add-for-iteration","result",["current","seq","state"]]],["setq","state",["advance","seq","state"]],["incf","ct"]]],["finish-clone","result"]]]],["defmethod","start-iteration",[["self","cons"]],"self"],["defmethod","more?",[["self","cons"],"state"],["cons?","state"]],["defmethod","current",[["self","cons"],"state"],["car","state"]],["defmethod","advance",[["self","cons"],"state"],["cdr","state"]],["defmethod","empty-clone",[["self","cons"]],[]],["defmethod","add-for-iteration",[["self","cons"],"elt"],["cons","elt","self"]],["defmethod","finish-clone",[["self","cons"]],["reverse-list","self"]],["defmethod","start-iteration",[["self","nil"]],[]],["defmethod","more?",[["self","nil"],"state"],false],["defmethod","current",[["self","nil"],"state"],["simple-error",["qua-string","At end"]]],["defmethod","advance",[["self","nil"],"state"],["simple-error",["qua-string","Can't advance past end"]]],["defmethod","empty-clone",[["self","nil"]],[]],["defmethod","add-for-iteration",[["self","nil"],"elt"],["cons","elt","self"]],["defmethod","finish-clone",[["self","nil"]],[]],["defmethod","start-iteration",[["self","js-array"]],0],["defmethod","more?",[["self","js-array"],"state"],["lt","state",[["js-getter",["qua-string","length"]],"self"]]],["defmethod","current",[["self","js-array"],"state"],["js-get","self","state"]],["defmethod","advance",[["self","js-array"],"state"],["+","state",1]],["defmethod","empty-clone",[["self","js-array"]],["js-array"]],["defmethod","add-for-iteration",[["self","js-array"],"elt"],[["js-invoker",["qua-string","push"]],"self","elt"],"self"],["defmethod","finish-clone",[["self","js-array"]],"self"],["defgeneric","read-string-from-stream",["stream"]],["defgeneric","write-string-to-stream",["stream","string"]],["defdynamic","*standard-input*"],["defdynamic","*standard-output*"],["defun","print-object",["self","stream"],["write-string-to-stream","stream",["%%object-to-string","self"]]],["defun","read","opt-stream",["let*",[["stream",["optional","opt-stream",["dynamic","*standard-input*"]]],["string",["read-string-from-stream","stream"]]],["%%parse-forms","string"]]],["defun","write",["object",".","opt-stream"],["let*",[["stream",["optional","opt-stream",["dynamic","*standard-output*"]]]],["if",["void?","stream"],["%%print","object"],["print-object","object","stream"]]]],["defun","print",["object",".","opt-stream"],["let*",[["stream",["optional","opt-stream",["dynamic","*standard-output*"]]]],["if",["void?","stream"],["%%print","object"],["progn",["dynamic-let",[["*print-escape*",false]],["write","object","stream"],["write-string-to-stream","stream",["qua-string","\n"]]]]]]],["defun","prin1",["object",".","opt-stream"],["let*",[["stream",["optional","opt-stream",["dynamic","*standard-output*"]]]],["if",["void?","stream"],["progn",["%%print",["qua-string","you have no stdout"]],["%%print","object"]],["progn",["dynamic-let",[["*print-escape*",true]],["write","object","stream"],["write-string-to-stream","stream",["qua-string","\n"]]]]]]],["defconstant","+user-prompt+",["qua-keyword","user-prompt"]],["deffexpr","push-userspace","body","env",["push-prompt","+user-prompt+",["dynamic-let",[["*standard-input*",["%arch-standard-input"]],["*standard-output*",["%arch-standard-output"]]],["eval",["list*",["qua-function","progn"],"body"],"env"]]]],["defmacro","js-callback",["params",".","body"],["list",["qua-function","js-lambda"],"params",["list*",["qua-function","push-userspace"],"body"]]],["defun","log","args",["apply",["js-invoker",["qua-string","log"]],["list*",["js-global",["qua-string","console"]],"args"]]],["defun","invoke-debugger",["condition"],["def","k",["get-current-continuation"]],["print",["qua-string",""]],["print",["qua-string","Welcome to the debugger!"]],["loop",["block","continue",["print",["qua-string","Condition: "]],["print","condition"],["print",["qua-string","Stack: "]],["print-stacktrace","k"],["let",[["restarts",["compute-restarts","condition"]]],["if",[">",["list-length","restarts"],0],["progn",["print",["qua-string","Restarts:"]],["let",[["i",0]],["list-for-each",["lambda",["restart"],["print",["+","i",["qua-string",": "],["symbol-name",["slot-value","restart",["quote","restart-name"]]]]],["incf","i"]],"restarts"],["print",["qua-string","Enter a restart number:"]],["let*",[["n",["car",["read"]]]],["if",[["js-global",["qua-string","isNaN"]],"n"],["progn",["print",["qua-string","You didn't enter a number. Please try again."]],["return-from","continue"]],["invoke-restart-interactively",["list-elt","restarts","n"]]]]]],["panic","condition"]]]]]],["defun","continuation-to-list",["k"],["block","end",["let",[["list",["quote",[]]]],["loop",["setq","list",["cons","k","list"]],["if",["eq",null,[["js-getter",["qua-string","inner"]],"k"]],["return-from","end","list"],["setq","k",[["js-getter",["qua-string","inner"]],"k"]]]]]]],["defun","get-current-continuation",[],["take-subcont","+user-prompt+","k",["push-prompt-subcont","+user-prompt+","k","k"]]],["defconstant","+qua-magic-frames+",6],["defun","print-stacktrace",["k"],["for-each",["lambda",["frame"],["if",[["js-getter",["qua-string","dbg_info"]],"frame"],["prin1",[["js-getter",["qua-string","expr"]],[["js-getter",["qua-string","dbg_info"]],"frame"]]],["print",["qua-string","* Mystery continuation (please report bug)"]]]],["subseq",["continuation-to-list","k"],"+qua-magic-frames+",["+","+qua-magic-frames+",10]]]],["def",["qua-function","node:require"],["js-global",["qua-string","require"]]],["defun","get-element-by-id",["id"],["the","string","id"],[["js-invoker",["qua-string","getElementById"]],["js-global",["qua-string","document"]],"id"]],["defun","create-element",["tag"],["the","string","tag"],[["js-invoker",["qua-string","createElement"]],["js-global",["qua-string","document"]],"tag"]],["defun","create-text-node",["text"],["the","string","text"],[["js-invoker",["qua-string","createTextNode"]],["js-global",["qua-string","document"]],"text"]],["defstruct","browser-stream","id"],["def","-browser-stream-counter-",-1],["defun","make-browser-stream",[],["make-instance",["quote","browser-stream"],["qua-keyword","id"],["incf","-browser-stream-counter-"]]],["defmethod","read-string-from-stream",[["stream","browser-stream"]],["if",["js-global",["qua-string","Ymacs"]],["take-subcont","+user-prompt+","k",["setq","-the-continuation-","k"]],["the","string",[["js-global",["qua-string","prompt"]],["qua-string","LISP input"]]]]],["defmethod","write-string-to-stream",[["stream","browser-stream"],"string"],["if",["js-global",["qua-string","Ymacs"]],[["js-invoker",["qua-string","_insertText"]],"-the-buffer-","string"],["log","string"]]],["def","-the-continuation-","#void"],["def","-the-buffer-","#void"],["when",["js-global",["qua-string","Ymacs"]],[["js-global",["qua-string","DEFINE_SINGLETON"]],["qua-string","Qua_Keymap_REPL"],["js-global",["qua-string","Ymacs_Keymap"]],["js-lambda",["#ign","D","P",".","#ign"],["setf",[["js-getter",["qua-string","KEYS"]],"D"],["js-object",["qua-keyword","ENTER"],["qua-string","qua_repl_enter"]]]]],[["js-invoker",["qua-string","newMode"]],["js-global",["qua-string","Ymacs_Buffer"]],["qua-string","qua_repl_mode"],["js-lambda",["this",".","#ign"],["let",[["keymap",[["js-global",["qua-string","Qua_Keymap_REPL"]]]]],[["js-invoker",["qua-string","pushKeymap"]],"this","keymap"],["js-lambda",["this",".","#ign"],[["js-invoker",["qua-string","popKeymap"]],"this","keymap"]]]]],[["js-invoker",["qua-string","newCommands"]],["js-global",["qua-string","Ymacs_Buffer"]],["js-object",["qua-keyword","qua_repl_enter"],[["js-global",["qua-string","Ymacs_Interactive"]],["js-lambda",["this",".","#ign"],["let*",[["pos",[["js-invoker",["qua-string","point"]],"this"]],["rc",[["js-getter",["qua-string","_rowcol"]],"this"]],["line",["js-get",[["js-getter",["qua-string","code"]],"this"],[["js-getter",["qua-string","row"]],"rc"]]]],[["js-invoker",["qua-string","cmd"]],"this",["qua-string","insert"],["qua-string","\n"]],["push-prompt-subcont","+user-prompt+","-the-continuation-","line"]]]]]],["def","repl-buffer",["js-new",["js-global",["qua-string","Ymacs_Buffer"]],["js-object",["qua-keyword","name"],["qua-string","Qua REPL"]]]],[["js-invoker",["qua-string","setCode"]],"repl-buffer",["qua-string",""]],[["js-invoker",["qua-string","cmd"]],"repl-buffer",["qua-string","qua_repl_mode"]],["def","-the-buffer-","repl-buffer"],["def","ymacs",["js-new",["js-global",["qua-string","Ymacs"]],["js-object",["qua-keyword","buffers"],["js-array","repl-buffer"]]]],[["js-invoker",["qua-string","setColorTheme"]],"ymacs",["js-array",["qua-string","dark"],["qua-string","y"]]],["def","dialog",["js-new",["js-global",["qua-string","DlDialog"]],["js-object",["qua-keyword","title"],["qua-string","Qua REPL"],["qua-keyword","resizable"],true]]],["def","layout",["js-new",["js-global",["qua-string","DlLayout"]],["js-object",["qua-keyword","parent"],"dialog"]]],[["js-invoker",["qua-string","packWidget"]],"layout","ymacs",["js-object",["qua-keyword","pos"],["qua-string","bottom"],["qua-keyword","fill"],["qua-string","*"]]],["setf",[["js-getter",["qua-string","_focusedWidget"]],"dialog"],"ymacs"],[["js-invoker",["qua-string","setSize"]],"dialog",["js-object",["qua-keyword","x"],1024,["qua-keyword","y"],768]],[["js-invoker",["qua-string","show"]],"dialog",true],[["js-invoker",["qua-string","maximize"]],"dialog",true]],["defconstant","+default-browser-stream+",["make-browser-stream"]],["defun","%arch-standard-input",[],"+default-browser-stream+"],["defun","%arch-standard-output",[],"+default-browser-stream+"]]
},{}],3:[function(require,module,exports){
// Copyright (C) 2007 Chris Double.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
var jsparse;
try {
jsparse = exports;
} catch(e) {
jsparse = {};
}
jsparse.foldl = function foldl(f, initial, seq) {
for(var i=0; i< seq.length; ++i)
initial = f(initial, seq[i]);
return initial;
}
jsparse.memoize = true;
jsparse.ParseState = (function() {
function ParseState(input, index) {
this.input = input;
this.index = index || 0;
this.length = input.length - this.index;
this.cache = { };
return this;
}
ParseState.prototype.from = function(index) {
var r = new ParseState(this.input, this.index + index);
r.cache = this.cache;
r.length = this.length - index;
return r;
}
ParseState.prototype.substring = function(start, end) {
return this.input.substring(start + this.index, (end || this.length) + this.index);
}
ParseState.prototype.trimLeft = function() {
var s = this.substring(0);
var m = s.match(/^\s+/);
return m ? this.from(m[0].length) : this;
}
ParseState.prototype.at = function(index) {
return this.input.charAt(this.index + index);
}
ParseState.prototype.toString = function() {
return 'PS"' + this.substring(0) + '"';
}
ParseState.prototype.getCached = function(pid) {
if(!jsparse.memoize)
return false;
var p = this.cache[pid];
if(p)
return p[this.index];
else
return false;
}
ParseState.prototype.putCached = function(pid, cached) {
if(!jsparse.memoize)
return false;
var p = this.cache[pid];
if(p)
p[this.index] = cached;
else {
p = this.cache[pid] = { };
p[this.index] = cached;
}
}
return ParseState;
})()
jsparse.ps = function ps(str) {
return new jsparse.ParseState(str);
}
// 'r' is the remaining string to be parsed.
// 'matched' is the portion of the string that
// was successfully matched by the parser.
// 'ast' is the AST returned by the successfull parse.
jsparse.make_result = function make_result(r, matched, ast) {
return { remaining: r, matched: matched, ast: ast };
}
jsparse.parser_id = 0;
// 'token' is a parser combinator that given a string, returns a parser
// that parses that string value. The AST contains the string that was parsed.
jsparse.token = function token(s) {
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var r = state.length >= s.length && state.substring(0,s.length) == s;
if(r)
cached = { remaining: state.from(s.length), matched: s, ast: s };
else
cached = false;
savedState.putCached(pid, cached);
return cached;
};
}
// Like 'token' but for a single character. Returns a parser that given a string
// containing a single character, parses that character value.
jsparse.ch = function ch(c) {
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var r = state.length >= 1 && state.at(0) == c;
if(r)
cached = { remaining: state.from(1), matched: c, ast: c };
else
cached = false;
savedState.putCached(pid, cached);
return cached;
};
}
// 'range' is a parser combinator that returns a single character parser
// (similar to 'ch'). It parses single characters that are in the inclusive
// range of the 'lower' and 'upper' bounds ("a" to "z" for example).
jsparse.range = function range(lower, upper) {
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
if(state.length < 1)
cached = false;
else {
var ch = state.at(0);
if(ch >= lower && ch <= upper)
cached = { remaining: state.from(1), matched: ch, ast: ch };
else
cached = false;
}
savedState.putCached(pid, cached);
return cached;
};
}
// Helper function to convert string literals to token parsers
// and perform other implicit parser conversions.
jsparse.toParser = function toParser(p) {
return (typeof(p) == "string") ? jsparse.token(p) : p;
}
// Parser combinator that returns a parser that
// skips whitespace before applying parser.
jsparse.whitespace = function whitespace(p) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
cached = p(state.trimLeft());
savedState.putCached(pid, cached);
return cached;
};
}
// Parser combinator that passes the AST generated from the parser 'p'
// to the function 'f'. The result of 'f' is used as the AST in the result.
jsparse.action = function action(p, f) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var x = p(state);
if(x) {
x.ast = f(x.ast);
cached = x;
}
else {
cached = false;
}
savedState.putCached(pid, cached);
return cached;
};
}
// Given a parser that produces an array as an ast, returns a
// parser that produces an ast with the array joined by a separator.
jsparse.join_action = function join_action(p, sep) {
return jsparse.action(p, function(ast) { return ast.join(sep); });
}
// Given an ast of the form [ Expression, [ a, b, ...] ], convert to
// [ [ [ Expression [ a ] ] b ] ... ]
// This is used for handling left recursive entries in the grammar. e.g.
// MemberExpression:
// PrimaryExpression
// FunctionExpression
// MemberExpression [ Expression ]
// MemberExpression . Identifier
// new MemberExpression Arguments
jsparse.left_factor = function left_factor(ast) {
return jsparse.foldl(function(v, action) {
return [ v, action ];
},
ast[0],
ast[1]);
}
// Return a parser that left factors the ast result of the original
// parser.
jsparse.left_factor_action = function left_factor_action(p) {
return jsparse.action(p, jsparse.left_factor);
}
// 'negate' will negate a single character parser. So given 'ch("a")' it will successfully
// parse any character except for 'a'. Or 'negate(range("a", "z"))' will successfully parse
// anything except the lowercase characters a-z.
jsparse.negate = function negate(p) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
if(state.length >= 1) {
var r = p(state);
if(!r)
cached = jsparse.make_result(state.from(1), state.at(0), state.at(0));
else
cached = false;
}
else {
cached = false;
}
savedState.putCached(pid, cached);
return cached;
};
}
// 'end' is a parser that is successful if the input string is empty (ie. end of parse).
jsparse.end = function end(state) {
if(state.length == 0)
return jsparse.make_result(state, undefined, undefined);
else
return false;
}
jsparse.end_p = jsparse.end;
// 'nothing' is a parser that always fails.
jsparse.nothing = function nothing(state) {
return false;
}
jsparse.nothing_p = jsparse.nothing;
// 'sequence' is a parser combinator that processes a number of parsers in sequence.
// It can take any number of arguments, each one being a parser. The parser that 'sequence'
// returns succeeds if all the parsers in the sequence succeeds. It fails if any of them fail.
jsparse.sequence = function sequence() {
var parsers = [];
for(var i = 0; i < arguments.length; ++i)
parsers.push(jsparse.toParser(arguments[i]));
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached) {
return cached;
}
var ast = [];
var matched = "";
var i;
for(i=0; i< parsers.length; ++i) {
var parser = parsers[i];
var result = parser(state);
if(result) {
state = result.remaining;
if(result.ast != undefined) {
ast.push(result.ast);
matched = matched + result.matched;
}
}
else {
break;
}
}
if(i == parsers.length) {
cached = jsparse.make_result(state, matched, ast);
}
else
cached = false;
savedState.putCached(pid, cached);
return cached;
};
}
// Like sequence, but ignores whitespace between individual parsers.
jsparse.wsequence = function wsequence() {
var parsers = [];
for(var i=0; i < arguments.length; ++i) {
parsers.push(jsparse.whitespace(jsparse.toParser(arguments[i])));
}
return jsparse.sequence.apply(null, parsers);
}
// 'choice' is a parser combinator that provides a choice between other parsers.
// It takes any number of parsers as arguments and returns a parser that will try
// each of the given parsers in order. The first one that succeeds results in a
// successfull parse. It fails if all parsers fail.
jsparse.choice = function choice() {
var parsers = [];
for(var i = 0; i < arguments.length; ++i)
parsers.push(jsparse.toParser(arguments[i]));
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached) {
return cached;
}
var i;
for(i=0; i< parsers.length; ++i) {
var parser=parsers[i];
var result = parser(state);
if(result) {
break;
}
}
if(i == parsers.length)
cached = false;
else
cached = result;
savedState.putCached(pid, cached);
return cached;
}
}
// 'butnot' is a parser combinator that takes two parsers, 'p1' and 'p2'.
// It returns a parser that succeeds if 'p1' matches and 'p2' does not, or
// 'p1' matches and the matched text is longer that p2's.
// Useful for things like: butnot(IdentifierName, ReservedWord)
jsparse.butnot = function butnot(p1,p2) {
var p1 = jsparse.toParser(p1);
var p2 = jsparse.toParser(p2);
var pid = jsparse.parser_id++;
// match a but not b. if both match and b's matched text is shorter
// than a's, a failed match is made
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var br = p2(state);
if(!br) {
cached = p1(state);
} else {
var ar = p1(state);
if (ar) {
if(ar.matched.length > br.matched.length)
cached = ar;
else
cached = false;
}
else {
cached = false;
}
}
savedState.putCached(pid, cached);
return cached;
}
}
// 'difference' is a parser combinator that takes two parsers, 'p1' and 'p2'.
// It returns a parser that succeeds if 'p1' matches and 'p2' does not. If
// both match then if p2's matched text is shorter than p1's it is successfull.
jsparse.difference = function difference(p1,p2) {
var p1 = jsparse.toParser(p1);
var p2 = jsparse.toParser(p2);
var pid = jsparse.parser_id++;
// match a but not b. if both match and b's matched text is shorter
// than a's, a successfull match is made
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var br = p2(state);
if(!br) {
cached = p1(state);
} else {
var ar = p1(state);
if(ar.matched.length >= br.matched.length)
cached = br;
else
cached = ar;
}
savedState.putCached(pid, cached);
return cached;
}
}
// 'xor' is a parser combinator that takes two parsers, 'p1' and 'p2'.
// It returns a parser that succeeds if 'p1' or 'p2' match but fails if
// they both match.
jsparse.xor = function xor(p1, p2) {
var p1 = jsparse.toParser(p1);
var p2 = jsparse.toParser(p2);
var pid = jsparse.parser_id++;
// match a or b but not both
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var ar = p1(state);
var br = p2(state);
if(ar && br)
cached = false;
else
cached = ar || br;
savedState.putCached(pid, cached);
return cached;
}
}
// A parser combinator that takes one parser. It returns a parser that
// looks for zero or more matches of the original parser.
jsparse.repeat0 = function repeat0(p) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached) {
return cached;
}
var ast = [];
var matched = "";
var result;
while(result = p(state)) {
ast.push(result.ast);
matched = matched + result.matched;
if(result.remaining.index == state.index)
break;
state = result.remaining;
}
cached = jsparse.make_result(state, matched, ast);
savedState.putCached(pid, cached);
return cached;
}
}
// A parser combinator that takes one parser. It returns a parser that
// looks for one or more matches of the original parser.
jsparse.repeat1 = function repeat1(p) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var ast = [];
var matched = "";
var result= p(state);
if(!result)
cached = false;
else {
while(result) {
ast.push(result.ast);
matched = matched + result.matched;
if(result.remaining.index == state.index)
break;
state = result.remaining;
result = p(state);
}
cached = jsparse.make_result(state, matched, ast);
}
savedState.putCached(pid, cached);
return cached;
}
}
// A parser combinator that takes one parser. It returns a parser that
// matches zero or one matches of the original parser.
jsparse.optional = function optional(p) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var r = p(state);
cached = r || jsparse.make_result(state, "", false);
savedState.putCached(pid, cached);
return cached;
}
}
// A parser combinator that ensures that the given parser succeeds but
// ignores its result. This can be useful for parsing literals that you
// don't want to appear in the ast. eg:
// sequence(expect("("), Number, expect(")")) => ast: Number
jsparse.expect = function expect(p) {
return jsparse.action(p, function(ast) { return undefined; });
}
jsparse.chain = function chain(p, s, f) {
var p = jsparse.toParser(p);
return jsparse.action(jsparse.sequence(p, jsparse.repeat0(jsparse.action(jsparse.sequence(s, p), f))),
function(ast) { return [ast[0]].concat(ast[1]); });
}
// A parser combinator to do left chaining and evaluation. Like 'chain', it expects a parser
// for an item and for a seperator. The seperator parser's AST result should be a function
// of the form: function(lhs,rhs) { return x; }
// Where 'x' is the result of applying some operation to the lhs and rhs AST's from the item
// parser.
jsparse.chainl = function chainl(p, s) {
var p = jsparse.toParser(p);
return jsparse.action(jsparse.sequence(p, jsparse.repeat0(jsparse.sequence(s, p))),
function(ast) {
return jsparse.foldl(function(v, action) { return action[0](v, action[1]); }, ast[0], ast[1]);
});
}
// A parser combinator that returns a parser that matches lists of things. The parser to
// match the list item and the parser to match the seperator need to
// be provided. The AST is the array of matched items.
jsparse.list = function list(p, s) {
return jsparse.chain(p, s, function(ast) { return ast[1]; });
}
// Like list, but ignores whitespace between individual parsers.
jsparse.wlist = function wlist() {
var parsers = [];
for(var i=0; i < arguments.length; ++i) {
parsers.push(jsparse.whitespace(arguments[i]));
}
return jsparse.list.apply(null, parsers);
}
// A parser that always returns a zero length match
jsparse.epsilon_p = function epsilon_p(state) {
return jsparse.make_result(state, "", undefined);
}
// Allows attaching of a function anywhere in the grammer. If the function returns
// true then parse succeeds otherwise it fails. Can be used for testing if a symbol
// is in the symbol table, etc.
jsparse.semantic = function semantic(f) {
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
cached = f() ? jsparse.make_result(state, "", undefined) : false;
savedState.putCached(pid, cached);
return cached;
}
}
// The and predicate asserts that a certain conditional
// syntax is satisfied before evaluating another production. Eg:
// sequence(and("0"), oct_p)
// (if a leading zero, then parse octal)
// It succeeds if 'p' succeeds and fails if 'p' fails. It never
// consume any input however, and doesn't put anything in the resulting
// AST.
jsparse.and = function and(p) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
var r = p(state);
cached = r ? jsparse.make_result(state, "", undefined) : false;
savedState.putCached(pid, cached);
return cached;
}
}
// The opposite of 'and'. It fails if 'p' succeeds and succeeds if
// 'p' fails. It never consumes any input. This combined with 'and' can
// be used for 'lookahead' and disambiguation of cases.
//
// Compare:
// sequence("a",choice("+","++"),"b")
// parses a+b
// but not a++b because the + matches the first part and peg's don't
// backtrack to other choice options if they succeed but later things fail.
//
// sequence("a",choice(sequence("+", not("+")),"++"),"b")
// parses a+b
// parses a++b
//
jsparse.not = function not(p) {
var p = jsparse.toParser(p);
var pid = jsparse.parser_id++;
return function(state) {
var savedState = state;
var cached = savedState.getCached(pid);
if(cached)
return cached;
cached = p(state) ? false : jsparse.make_result(state, "", undefined);
savedState.putCached(pid, cached);
return cached;
}
}
// For ease of use, it's sometimes nice to be able to not have to prefix all
// of the jsparse functions with `jsparse.` and since the original version of
// this library put everything in the toplevel namespace, this makes it easy
// to use this version with old code.
//
// The only caveat there is that changing `memoize` MUST be done on
// jsparse.memoize
//
// Typical usage:
// jsparse.inject_into(window)
//
jsparse.inject_into = function inject_into(into) {
for (var key in jsparse) {
if (typeof jsparse[key] === 'function') {
into[key] = jsparse[key];
}
}
}
},{}],4:[function(require,module,exports){
// Browser-specific code. The package.json's browser field contains a
// mapping so that this gets used instead of arch.js if we're doing a
// browser build.
module.exports = function(vm, init_env) {
// Here we could do browser-specific exports to Lisp.
};
},{}],5:[function(require,module,exports){
// This is the main Qua file, that pulls together all components and
// creates a user environment in which Qua code can be evaluated.
//
// The major weakness is that only a single Qua VM per JS process is
// currently supported. Changing this is simply a matter of
// refactoring `vm.js' so that it does its thing within a function,
// instead of globally.
var qua = module.exports;
// The boot bytecode is the precompiled version of the
// `bootstrap.lisp' file plus either `arch.lisp' or
// `arch-browser.lisp' depending on whether we run in Node or are
// doing a browser build.
var boot_bytecode = require("../build/out/bootstrap.json");
qua.vm = function() {
// VM initialization: The `vm.init' function from the file `vm.js'
// performs the major part of initialization: it populates a fresh
// environment, called the init environment, with primitive bindings.
var vm = require("./vm.js");
vm.init();
// Once that is done, we run some "plug-in" files, each of which
// receives the VM module, and the created init environment, and can
// add new primitive functionality to both. Most of these are
// plug-ins simply to keep the `vm.js' file a bit leaner and more
// readable. The only files where this is really required are the
// `arch.js'/`arch-browser.js' files that get used depending on what
// architecture we're building for with some Browserify magic in
// `package.json'.
require("./read.js")(vm, vm.init_env); // S-Expression Parser
require("./print.js")(vm, vm.init_env); // (Not Yet) Pretty Printer
require("./arch.js")(vm, vm.init_env); // Architecture-Specific Code
// Add some convenient API functions
vm.eval_sexp = function(x, e) {
return vm.evaluate(e ? e : vm.init_env, x);
};
vm.eval_string = function(s, e) {
return vm.eval_sexp(vm.parse_forms_progn(s), e);
};
vm.eval_bytecode = function(c, e) {
return vm.eval_sexp(vm.parse_bytecode(c), e);
};
// Only userful in browsers; runs the bundled user bytecode
vm.eval_user_bytecode = function() {
return vm.eval_bytecode(["push-userspace", require("qua-user-bytecode")]);
};
// Finally, we run the Lisp boot bytecode, i.e. the preparsed Lisp
// code from the file `bootstrap.lisp', that sets up the
// user-level language.
vm.eval_bytecode(boot_bytecode);
return vm;
};
},{"../build/out/bootstrap.json":2,"./arch.js":4,"./print.js":6,"./read.js":7,"./vm.js":8,"qua-user-bytecode":"qua-user-bytecode"}],6:[function(require,module,exports){
// The whole printing is stuff not very good indeed
module.exports = function(vm, init_env) {
vm.PRINT_ESCAPE = vm.make_dynamic(true);
vm.unreadable_object_to_string = function(object) {
var c = vm.class_of(object);
var class_name = c.class_name || c.name; // FIXME: why?
return "#[" + class_name + " " + object + "]";
};
vm.object_to_string = function(object) {
switch(typeof(object)) {
case "string":
if (vm.dynamic(vm.PRINT_ESCAPE)) {
return JSON.stringify(object);
} else {
return object;
}
case "number":
return String(object);
default:
if (object && object.qua_to_string) {
return object.qua_to_string(object);
} else {
return vm.unreadable_object_to_string(object);
}
}
};
vm.Sym.prototype.qua_to_string = function(sym) {
switch(sym.ns) {
case vm.VAR_NS: return sym.name;
case vm.FUN_NS: return "#'" + sym.name;
case vm.KWD_NS: return ":" + sym.name;
default: return vm.sym_key(sym);
}
};
vm.Prim.prototype.qua_to_string = function(prim) {
return "#[primitive " + prim.name + "]";
};
vm.Cons.prototype.qua_to_string = function(cons) {
return "(" + vm.cons_to_string(cons) + ")"
};
vm.cons_to_string = function (c) {
if (vm.cdr(c) === vm.NIL) {
return vm.object_to_string(vm.car(c));
} else if (vm.cdr(c) instanceof vm.Cons) {
return vm.object_to_string(vm.car(c)) + " " + vm.cons_to_string(vm.cdr(c));
} else {
return vm.object_to_string(vm.car(c)) + " . " + vm.object_to_string(vm.cdr(c));
}
};
vm.def(vm.init_env, "%%*print-escape*", vm.PRINT_ESCAPE);
vm.defun(vm.init_env, "%%object-to-string", vm.jswrap(vm.object_to_string));
};
},{}],7:[function(require,module,exports){
/*
This whole parsing stuff is a mess haphazardly grown over the years,
and ripe to be replaced with a shiny platinum mechanism.
The way it works is that the initial stage of the parser,
`parse_sexp', turns Lisp syntax S-expression strings into a format
called bytecode, which is essentially one big honking JSON list
mirroring the original S-expression.
The second stage, `parse_bytecode', then turns such a JSON bytecode
object into forms (i.e. vm.Sym, vm.Cons, vm.Nil, etc) that can
actually be evaluated by the VM.
The bytecode format is roughly:
S-expression Bytecode
--------------------------------------------------------------------
foo "foo"
#t true
(foo 1 (2)) ["foo", 1, [2]]
"a string" ["qua-string", "a string"]
#'my-function-symbol ["qua-function", "my-function-symbol"]
:the-keyword ["qua-keyword", "the-keyword"]
(dotted list . end) ["dotted", "list", ".", "end"]
Note that since we use JSON strings for symbols, we have to
specially encode strings as a list with "qua-string" as first
element (which is probably a layering violation). Similar encodings
are used for function namespaced symbols and keyword symbols.
Some objects like booleans, numbers, null, undefined can appear
as-is in the bytecode and there are some hacks to support that.
Further hacks make dotted lists possible, as well as the JS syntax
.property, @method, and $global.
A whole bytecode file is a single JSON list, usually a %%PROGN.
*/
var jsparse = require("jsparse");
module.exports = function(vm, init_env) {
// Bytecode to forms
vm.parse_bytecode = function(obj) {
switch(Object.prototype.toString.call(obj)) {
case "[object String]":
switch(obj) {
case "#ign": return vm.IGN;
case "#void": return vm.VOID;
default: return vm.sym(obj);
}
case "[object Array]": return vm.parse_bytecode_array(obj);
default: return obj;
}
};
vm.parse_bytecode_array = function(arr) {
if ((arr.length == 2) && arr[0] === "qua-string") { return arr[1]; }
if ((arr.length == 2) && arr[0] === "qua-function") { return vm.fun_sym(arr[1]); }
if ((arr.length == 2) && arr[0] === "qua-keyword") { return vm.keyword(arr[1]); }
var i = arr.indexOf(".");
if (i === -1) {
return vm.array_to_list(arr.map(vm.parse_bytecode));
} else {
var front = arr.slice(0, i);
return vm.array_to_list(front.map(vm.parse_bytecode),
vm.parse_bytecode(arr[i + 1]));
}
};
// Strings to bytecode to forms
vm.parse_forms = function (string) {
return vm.parse_bytecode(parse_sexp(string));
};
vm.parse_forms_progn = function (string) {
return vm.parse_bytecode(parse_sexp_progn(string));
};
// This is what we export to userland
vm.defun(init_env, "%%parse-forms", vm.jswrap(vm.parse_forms));
};
// Need to export these so that the build process can construct
// bootstrap bytecode file.
module.exports.parse_sexp = parse_sexp;
module.exports.parse_sexp_progn = parse_sexp_progn;
function parse_sexp_progn(string) {
return ["%%progn"].concat(parse_sexp(string));
}
// It begins...
var ps = jsparse.ps;
var choice = jsparse.choice;
var range = jsparse.range;
var action = jsparse.action;
var sequence = jsparse.sequence;
var join = jsparse.join;
var join_action = jsparse.join_action;
var negate = jsparse.negate;
var repeat0 = jsparse.repeat0;
var optional = jsparse.optional;
var repeat1 = jsparse.repeat1;
var wsequence = jsparse.wsequence;
var whitespace = jsparse.whitespace;
var ch = jsparse.ch;
var butnot = jsparse.butnot;
/* S-expr parser */
// Remove comments; trim string (brute-force kludge)
function prepare_string(s) {
var lines = s.split("\n"); // FIXME: support other line endings?
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
var x = line.indexOf(";");
if (x !== -1) {
lines[i] = line.substring(0, x);
}
}
return lines.join("\n").trim(); // ahem
}
function parse_sexp(s) {
s = prepare_string(s);
var res = program_stx(ps(s));
if (res.remaining.index === s.length) return res.ast;
else throw("parse error at " + res.remaining.index + " in " + s); }
var x_stx = function(input) { return x_stx(input); }; // forward decl.
var id_special_char =
choice(":", ",", "-", "&", "!", "=", ">", "<", "%", "+", "?", "/", "*", "$", "_", "#", ".", "@", "|", "~", "^", "'");
var id_char = choice(range("a", "z"), range("A", "Z"), range("0", "9"), id_special_char);
// Kludge: don't allow single dot as id, so as not to conflict with dotted pair stx.
var id_stx = action(join_action(butnot(repeat1(id_char), "."), ""), handle_identifier);
var keyword_stx = action(sequence(":", id_stx), function(ast) {
return ["qua-keyword", ast[1]];
});
function handle_identifier(str) {
if ((str[0] === ".") && (str.length > 1)) { return ["js-getter", ["qua-string", str.substring(1)]]; }
else if (str[0] === "@") { return ["js-invoker", ["qua-string", str.substring(1)]]; }
else if (str[0] === "$") { return ["js-global", ["qua-string", str.substring(1)]]; }
else if (str.startsWith("#'")) { return ["qua-function", str.substring(2)]; }
else return str; }
var escape_char = choice("\"", "\\", "n", "r", "t", "0");
var escape_sequence = action(sequence("\\", escape_char), function (ast) {
switch(ast[1]) {
case "n": return "\n";
case "r": return "\r";
case "t": return "\t";
case "0": return "\0";
default: return ast[1]; }});
var line_terminator = choice(ch("\r"), ch("\n"));
var string_char = choice(escape_sequence, line_terminator, negate("\""));
var string_stx = action(sequence("\"", join_action(repeat0(string_char), ""), "\""),
function (ast) { return ["qua-string", ast[1]]; });
var digits = join_action(repeat1(range("0", "9")), "");
var number_stx =
action(sequence(optional(choice("+", "-")), digits, optional(join_action(sequence(".", digits), ""))),
function (ast) {
var sign = ast[0] ? ast[0] : "";
var integral_digits = ast[1];
var fractional_digits = ast[2] || "";
return Number(sign + integral_digits + fractional_digits); });
function make_constant_stx(string, constant) { return action(string, function(ast) { return constant; }); }
var nil_stx = make_constant_stx("()", []);
var nil_stx_2 = make_constant_stx("#nil", []);
var ign_stx = make_constant_stx("#ign", "#ign");
var void_stx = make_constant_stx("#void", "#void");
var t_stx = make_constant_stx("#t", true);
var f_stx = make_constant_stx("#f", false);
var null_stx = make_constant_stx("#null", null);
var undef_stx = make_constant_stx("#undefined", undefined);
var dot_stx = action(wsequence(".", x_stx), function (ast) { return ast[1]; });
var compound_stx = action(wsequence("(", repeat1(x_stx), optional(dot_stx), ")"),
function(ast) {
var exprs = ast[1];
var end = ast[2] ? [".", ast[2]] : [];
return exprs.concat(end); });
var quote_stx = action(sequence("'", x_stx), function(ast) { return ["quote", ast[1]]; });
var x_stx = whitespace(choice(ign_stx, void_stx, nil_stx, nil_stx_2, t_stx, f_stx, null_stx, undef_stx, number_stx,
quote_stx, compound_stx, keyword_stx, id_stx, string_stx));