forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
camlp4boot.ml
14721 lines (14238 loc) · 722 KB
/
camlp4boot.ml
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
module R =
struct
open Camlp4
(* -*- camlp4r -*- *)
(****************************************************************************)
(* *)
(* Objective Caml *)
(* *)
(* INRIA Rocquencourt *)
(* *)
(* Copyright 2002-2006 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed under *)
(* the terms of the GNU Library General Public License, with the special *)
(* exception on linking described in LICENSE at the top of the Objective *)
(* Caml source tree. *)
(* *)
(****************************************************************************)
(* Authors:
* - Daniel de Rauglaudre: initial version
* - Nicolas Pouillard: refactoring
*)
module Id =
struct
let name = "Camlp4OCamlRevisedParser"
let version = Sys.ocaml_version
end
module Make (Syntax : Sig.Camlp4Syntax) =
struct
open Sig
include Syntax
(* Camlp4_config.constructors_arity.val := True; *)
let _ = Camlp4_config.constructors_arity := false
let help_sequences () =
(Printf.eprintf
"\
New syntax:\n\
(e1; e2; ... ; en) OR begin e1; e2; ... ; en end\n\
while e do e1; e2; ... ; en done\n\
for v = v1 to/downto v2 do e1; e2; ... ; en done\n\
Old syntax (still supported):\n\
do {e1; e2; ... ; en}\n\
while e do {e1; e2; ... ; en}\n\
for v = v1 to/downto v2 do {e1; e2; ... ; en}\n\
Very old (no more supported) syntax:\n\
do e1; e2; ... ; en-1; return en\n\
while e do e1; e2; ... ; en; done\n\
for v = v1 to/downto v2 do e1; e2; ... ; en; done\n\
";
flush stderr;
exit 1)
let _ =
Options.add "-help_seq" (Arg.Unit help_sequences)
"Print explanations about new sequences and exit."
let _ = Gram.Entry.clear a_CHAR
let _ = Gram.Entry.clear a_FLOAT
let _ = Gram.Entry.clear a_INT
let _ = Gram.Entry.clear a_INT32
let _ = Gram.Entry.clear a_INT64
let _ = Gram.Entry.clear a_LABEL
let _ = Gram.Entry.clear a_LIDENT
let _ = Gram.Entry.clear a_NATIVEINT
let _ = Gram.Entry.clear a_OPTLABEL
let _ = Gram.Entry.clear a_STRING
let _ = Gram.Entry.clear a_UIDENT
let _ = Gram.Entry.clear a_ident
let _ = Gram.Entry.clear amp_ctyp
let _ = Gram.Entry.clear and_ctyp
let _ = Gram.Entry.clear match_case
let _ = Gram.Entry.clear match_case0
let _ = Gram.Entry.clear match_case_quot
let _ = Gram.Entry.clear binding
let _ = Gram.Entry.clear binding_quot
let _ = Gram.Entry.clear rec_binding_quot
let _ = Gram.Entry.clear class_declaration
let _ = Gram.Entry.clear class_description
let _ = Gram.Entry.clear class_expr
let _ = Gram.Entry.clear class_expr_quot
let _ = Gram.Entry.clear class_fun_binding
let _ = Gram.Entry.clear class_fun_def
let _ = Gram.Entry.clear class_info_for_class_expr
let _ = Gram.Entry.clear class_info_for_class_type
let _ = Gram.Entry.clear class_longident
let _ = Gram.Entry.clear class_longident_and_param
let _ = Gram.Entry.clear class_name_and_param
let _ = Gram.Entry.clear class_sig_item
let _ = Gram.Entry.clear class_sig_item_quot
let _ = Gram.Entry.clear class_signature
let _ = Gram.Entry.clear class_str_item
let _ = Gram.Entry.clear class_str_item_quot
let _ = Gram.Entry.clear class_structure
let _ = Gram.Entry.clear class_type
let _ = Gram.Entry.clear class_type_declaration
let _ = Gram.Entry.clear class_type_longident
let _ = Gram.Entry.clear class_type_longident_and_param
let _ = Gram.Entry.clear class_type_plus
let _ = Gram.Entry.clear class_type_quot
let _ = Gram.Entry.clear comma_ctyp
let _ = Gram.Entry.clear comma_expr
let _ = Gram.Entry.clear comma_ipatt
let _ = Gram.Entry.clear comma_patt
let _ = Gram.Entry.clear comma_type_parameter
let _ = Gram.Entry.clear constrain
let _ = Gram.Entry.clear constructor_arg_list
let _ = Gram.Entry.clear constructor_declaration
let _ = Gram.Entry.clear constructor_declarations
let _ = Gram.Entry.clear ctyp
let _ = Gram.Entry.clear ctyp_quot
let _ = Gram.Entry.clear cvalue_binding
let _ = Gram.Entry.clear direction_flag
let _ = Gram.Entry.clear dummy
let _ = Gram.Entry.clear eq_expr
let _ = Gram.Entry.clear expr
let _ = Gram.Entry.clear expr_eoi
let _ = Gram.Entry.clear expr_quot
let _ = Gram.Entry.clear field_expr
let _ = Gram.Entry.clear field_expr_list
let _ = Gram.Entry.clear fun_binding
let _ = Gram.Entry.clear fun_def
let _ = Gram.Entry.clear ident
let _ = Gram.Entry.clear ident_quot
let _ = Gram.Entry.clear implem
let _ = Gram.Entry.clear interf
let _ = Gram.Entry.clear ipatt
let _ = Gram.Entry.clear ipatt_tcon
let _ = Gram.Entry.clear label
let _ = Gram.Entry.clear label_declaration
let _ = Gram.Entry.clear label_declaration_list
let _ = Gram.Entry.clear label_expr_list
let _ = Gram.Entry.clear label_expr
let _ = Gram.Entry.clear label_ipatt
let _ = Gram.Entry.clear label_ipatt_list
let _ = Gram.Entry.clear label_longident
let _ = Gram.Entry.clear label_patt
let _ = Gram.Entry.clear label_patt_list
let _ = Gram.Entry.clear labeled_ipatt
let _ = Gram.Entry.clear let_binding
let _ = Gram.Entry.clear meth_list
let _ = Gram.Entry.clear meth_decl
let _ = Gram.Entry.clear module_binding
let _ = Gram.Entry.clear module_binding0
let _ = Gram.Entry.clear module_binding_quot
let _ = Gram.Entry.clear module_declaration
let _ = Gram.Entry.clear module_expr
let _ = Gram.Entry.clear module_expr_quot
let _ = Gram.Entry.clear module_longident
let _ = Gram.Entry.clear module_longident_with_app
let _ = Gram.Entry.clear module_rec_declaration
let _ = Gram.Entry.clear module_type
let _ = Gram.Entry.clear module_type_quot
let _ = Gram.Entry.clear more_ctyp
let _ = Gram.Entry.clear name_tags
let _ = Gram.Entry.clear opt_as_lident
let _ = Gram.Entry.clear opt_class_self_patt
let _ = Gram.Entry.clear opt_class_self_type
let _ = Gram.Entry.clear opt_comma_ctyp
let _ = Gram.Entry.clear opt_dot_dot
let _ = Gram.Entry.clear opt_eq_ctyp
let _ = Gram.Entry.clear opt_expr
let _ = Gram.Entry.clear opt_meth_list
let _ = Gram.Entry.clear opt_mutable
let _ = Gram.Entry.clear opt_polyt
let _ = Gram.Entry.clear opt_private
let _ = Gram.Entry.clear opt_rec
let _ = Gram.Entry.clear opt_virtual
let _ = Gram.Entry.clear opt_when_expr
let _ = Gram.Entry.clear patt
let _ = Gram.Entry.clear patt_as_patt_opt
let _ = Gram.Entry.clear patt_eoi
let _ = Gram.Entry.clear patt_quot
let _ = Gram.Entry.clear patt_tcon
let _ = Gram.Entry.clear phrase
let _ = Gram.Entry.clear poly_type
let _ = Gram.Entry.clear row_field
let _ = Gram.Entry.clear sem_expr
let _ = Gram.Entry.clear sem_expr_for_list
let _ = Gram.Entry.clear sem_patt
let _ = Gram.Entry.clear sem_patt_for_list
let _ = Gram.Entry.clear semi
let _ = Gram.Entry.clear sequence
let _ = Gram.Entry.clear sig_item
let _ = Gram.Entry.clear sig_item_quot
let _ = Gram.Entry.clear sig_items
let _ = Gram.Entry.clear star_ctyp
let _ = Gram.Entry.clear str_item
let _ = Gram.Entry.clear str_item_quot
let _ = Gram.Entry.clear str_items
let _ = Gram.Entry.clear top_phrase
let _ = Gram.Entry.clear type_constraint
let _ = Gram.Entry.clear type_declaration
let _ = Gram.Entry.clear type_ident_and_parameters
let _ = Gram.Entry.clear type_kind
let _ = Gram.Entry.clear type_longident
let _ = Gram.Entry.clear type_longident_and_parameters
let _ = Gram.Entry.clear type_parameter
let _ = Gram.Entry.clear type_parameters
let _ = Gram.Entry.clear typevars
let _ = Gram.Entry.clear use_file
let _ = Gram.Entry.clear val_longident
let _ = Gram.Entry.clear value_let
let _ = Gram.Entry.clear value_val
let _ = Gram.Entry.clear with_constr
let _ = Gram.Entry.clear with_constr_quot
let neg_string n =
let len = String.length n
in
if (len > 0) && (n.[0] = '-')
then String.sub n 1 (len - 1)
else "-" ^ n
let mkumin _loc f arg =
match arg with
| Ast.ExInt (_, n) -> Ast.ExInt (_loc, neg_string n)
| Ast.ExInt32 (_, n) -> Ast.ExInt32 (_loc, neg_string n)
| Ast.ExInt64 (_, n) -> Ast.ExInt64 (_loc, neg_string n)
| Ast.ExNativeInt (_, n) -> Ast.ExNativeInt (_loc, neg_string n)
| Ast.ExFlo (_, n) -> Ast.ExFlo (_loc, neg_string n)
| _ ->
Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdLid (_loc, "~" ^ f)),
arg)
let mklistexp _loc last =
let rec loop top =
function
| [] ->
(match last with
| Some e -> e
| None -> Ast.ExId (_loc, Ast.IdUid (_loc, "[]")))
| e1 :: el ->
let _loc =
if top then _loc else Loc.merge (Ast.loc_of_expr e1) _loc
in
Ast.ExApp (_loc,
Ast.ExApp (_loc, Ast.ExId (_loc, Ast.IdUid (_loc, "::")),
e1),
loop false el)
in loop true
let mkassert _loc =
function
| Ast.ExId (_, (Ast.IdUid (_, "False"))) -> Ast.ExAsf _loc
| (* this case takes care about
the special assert false node *)
e -> Ast.ExAsr (_loc, e)
let append_eLem el e = el @ [ e ]
let mk_anti ?(c = "") n s = "\\$" ^ (n ^ (c ^ (":" ^ s)))
let mksequence _loc =
function
| (Ast.ExSem (_, _, _) | Ast.ExAnt (_, _) as e) ->
Ast.ExSeq (_loc, e)
| e -> e
let mksequence' _loc =
function
| (Ast.ExSem (_, _, _) as e) -> Ast.ExSeq (_loc, e)
| e -> e
let rec lid_of_ident =
function
| Ast.IdAcc (_, _, i) -> lid_of_ident i
| Ast.IdLid (_, lid) -> lid
| _ -> assert false
let module_type_app mt1 mt2 =
match (mt1, mt2) with
| (Ast.MtId (_loc, i1), Ast.MtId (_, i2)) ->
Ast.MtId (_loc, Ast.IdApp (_loc, i1, i2))
| _ -> raise Stream.Failure
let module_type_acc mt1 mt2 =
match (mt1, mt2) with
| (Ast.MtId (_loc, i1), Ast.MtId (_, i2)) ->
Ast.MtId (_loc, Ast.IdAcc (_loc, i1, i2))
| _ -> raise Stream.Failure
let bigarray_get _loc arr arg =
let coords =
match arg with
| Ast.ExTup (_, (Ast.ExCom (_, e1, e2))) | Ast.ExCom (_, e1, e2)
-> Ast.list_of_expr e1 (Ast.list_of_expr e2 [])
| _ -> [ arg ]
in
match coords with
| [ c1 ] ->
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array1"),
Ast.IdLid (_loc, "get")))),
arr),
c1)
| [ c1; c2 ] ->
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array2"),
Ast.IdLid (_loc, "get")))),
arr),
c1),
c2)
| [ c1; c2; c3 ] ->
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array3"),
Ast.IdLid (_loc, "get")))),
arr),
c1),
c2),
c3)
| (* | coords -> <:expr< Bigarray.Genarray.get $arr$ [| $list:coords$ |] >> ] *)
coords ->
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Genarray"),
Ast.IdLid (_loc, "get")))),
arr),
Ast.ExArr (_loc, Ast.exSem_of_list coords))
let bigarray_set _loc var newval =
match var with
| Ast.ExApp (_,
(Ast.ExApp (_,
(Ast.ExId (_,
(Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")),
(Ast.IdAcc (_, (Ast.IdUid (_, "Array1")),
(Ast.IdLid (_, "get")))))))),
arr)),
c1) ->
Some
(Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array1"),
Ast.IdLid (_loc, "set")))),
arr),
c1),
newval))
| Ast.ExApp (_,
(Ast.ExApp (_,
(Ast.ExApp (_,
(Ast.ExId (_,
(Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")),
(Ast.IdAcc (_, (Ast.IdUid (_, "Array2")),
(Ast.IdLid (_, "get")))))))),
arr)),
c1)),
c2) ->
Some
(Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array2"),
Ast.IdLid (_loc, "set")))),
arr),
c1),
c2),
newval))
| Ast.ExApp (_,
(Ast.ExApp (_,
(Ast.ExApp (_,
(Ast.ExApp (_,
(Ast.ExId (_,
(Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")),
(Ast.IdAcc (_, (Ast.IdUid (_, "Array3")),
(Ast.IdLid (_, "get")))))))),
arr)),
c1)),
c2)),
c3) ->
Some
(Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Array3"),
Ast.IdLid (_loc, "set")))),
arr),
c1),
c2),
c3),
newval))
| Ast.ExApp (_,
(Ast.ExApp (_,
(Ast.ExId (_,
(Ast.IdAcc (_, (Ast.IdUid (_, "Bigarray")),
(Ast.IdAcc (_, (Ast.IdUid (_, "Genarray")),
(Ast.IdLid (_, "get")))))))),
arr)),
(Ast.ExArr (_, coords))) ->
Some
(Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExApp (_loc,
Ast.ExId (_loc,
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Bigarray"),
Ast.IdAcc (_loc, Ast.IdUid (_loc, "Genarray"),
Ast.IdLid (_loc, "set")))),
arr),
Ast.ExArr (_loc, coords)),
newval))
| _ -> None
let test_not_left_brace_nor_do =
Gram.Entry.of_parser "test_not_left_brace_nor_do"
(fun strm ->
match Stream.peek strm with
| Some (((KEYWORD "{" | KEYWORD "do"), _)) ->
raise Stream.Failure
| _ -> ())
let stopped_at _loc = Some (Loc.move_line 1 _loc)
(* FIXME be more precise *)
let symbolchar =
let list =
[ '$'; '!'; '%'; '&'; '*'; '+'; '-'; '.'; '/'; ':'; '<'; '=';
'>'; '?'; '@'; '^'; '|'; '~'; '\\' ] in
let rec loop s i =
if i == (String.length s)
then true
else if List.mem s.[i] list then loop s (i + 1) else false
in loop
let _ =
let list = [ '!'; '?'; '~' ] in
let excl = [ "!="; "??" ]
in
Gram.Entry.setup_parser prefixop
(fun (__strm : _ Stream.t) ->
match Stream.peek __strm with
| Some (((KEYWORD x | SYMBOL x), _loc)) when
(not (List.mem x excl)) &&
(((String.length x) >= 2) &&
((List.mem x.[0] list) && (symbolchar x 1)))
->
(Stream.junk __strm;
Ast.ExId (_loc, Ast.IdLid (_loc, x)))
| _ -> raise Stream.Failure)
let _ =
let list_ok =
[ "<"; ">"; "<="; ">="; "="; "<>"; "=="; "!="; "$" ] in
let list_first_char_ok = [ '='; '<'; '>'; '|'; '&'; '$'; '!' ] in
let excl = [ "<-"; "||"; "&&" ]
in
Gram.Entry.setup_parser infixop0
(fun (__strm : _ Stream.t) ->
match Stream.peek __strm with
| Some (((KEYWORD x | SYMBOL x), _loc)) when
(List.mem x list_ok) ||
((not (List.mem x excl)) &&
(((String.length x) >= 2) &&
((List.mem x.[0] list_first_char_ok) &&
(symbolchar x 1))))
->
(Stream.junk __strm;
Ast.ExId (_loc, Ast.IdLid (_loc, x)))
| _ -> raise Stream.Failure)
let _ =
let list = [ '@'; '^' ]
in
Gram.Entry.setup_parser infixop1
(fun (__strm : _ Stream.t) ->
match Stream.peek __strm with
| Some (((KEYWORD x | SYMBOL x), _loc)) when
((String.length x) >= 1) &&
((List.mem x.[0] list) && (symbolchar x 1))
->
(Stream.junk __strm;
Ast.ExId (_loc, Ast.IdLid (_loc, x)))
| _ -> raise Stream.Failure)
let _ =
let list = [ '+'; '-' ]
in
Gram.Entry.setup_parser infixop2
(fun (__strm : _ Stream.t) ->
match Stream.peek __strm with
| Some (((KEYWORD x | SYMBOL x), _loc)) when
(x <> "->") &&
(((String.length x) >= 1) &&
((List.mem x.[0] list) && (symbolchar x 1)))
->
(Stream.junk __strm;
Ast.ExId (_loc, Ast.IdLid (_loc, x)))
| _ -> raise Stream.Failure)
let _ =
let list = [ '*'; '/'; '%'; '\\' ]
in
Gram.Entry.setup_parser infixop3
(fun (__strm : _ Stream.t) ->
match Stream.peek __strm with
| Some (((KEYWORD x | SYMBOL x), _loc)) when
((String.length x) >= 1) &&
((List.mem x.[0] list) &&
(((x.[0] <> '*') ||
(((String.length x) < 2) || (x.[1] <> '*')))
&& (symbolchar x 1)))
->
(Stream.junk __strm;
Ast.ExId (_loc, Ast.IdLid (_loc, x)))
| _ -> raise Stream.Failure)
let _ =
Gram.Entry.setup_parser infixop4
(fun (__strm : _ Stream.t) ->
match Stream.peek __strm with
| Some (((KEYWORD x | SYMBOL x), _loc)) when
((String.length x) >= 2) &&
((x.[0] == '*') && ((x.[1] == '*') && (symbolchar x 2)))
->
(Stream.junk __strm; Ast.ExId (_loc, Ast.IdLid (_loc, x)))
| _ -> raise Stream.Failure)
let rec infix_kwds_filter (__strm : _ Stream.t) =
match Stream.peek __strm with
| Some (((KEYWORD "(", _) as tok)) ->
(Stream.junk __strm;
let xs = __strm in
let (__strm : _ Stream.t) = xs
in
(match Stream.peek __strm with
| Some
((KEYWORD
(("mod" | "land" | "lor" | "lxor" | "lsl" | "lsr" |
"asr"
as i)),
_loc))
->
(Stream.junk __strm;
(match Stream.peek __strm with
| Some ((KEYWORD ")", _)) ->
(Stream.junk __strm;
let xs = __strm
in
Stream.lcons (fun _ -> ((LIDENT i), _loc))
(Stream.slazy
(fun _ -> infix_kwds_filter xs)))
| _ -> raise (Stream.Error "")))
| _ ->
let xs = __strm
in
Stream.icons tok
(Stream.slazy (fun _ -> infix_kwds_filter xs))))
| Some x ->
(Stream.junk __strm;
let xs = __strm
in
Stream.icons x
(Stream.slazy (fun _ -> infix_kwds_filter xs)))
| _ -> raise Stream.Failure
let _ =
Token.Filter.define_filter (Gram.get_filter ())
(fun f strm -> infix_kwds_filter (f strm))
(* transmit the context *)
let _ =
Gram.Entry.setup_parser sem_expr
(let symb1 = Gram.parse_tokens_after_filter expr in
let symb (__strm : _ Stream.t) =
match Stream.peek __strm with
| Some ((ANTIQUOT ((("list" as n)), s), _loc)) ->
(Stream.junk __strm;
Ast.ExAnt (_loc, mk_anti ~c: "expr;" n s))
| _ -> symb1 __strm in
let rec kont al (__strm : _ Stream.t) =
match Stream.peek __strm with
| Some ((KEYWORD ";", _loc)) ->
(Stream.junk __strm;
let a =
(try symb __strm
with | Stream.Failure -> raise (Stream.Error "")) in
let s = __strm in kont (Ast.ExSem (_loc, al, a)) s)
| _ -> al
in
fun (__strm : _ Stream.t) ->
let a = symb __strm in kont a __strm)
let _ =
let _ = (a_CHAR : 'a_CHAR Gram.Entry.t)
and _ = (do_sequence : 'do_sequence Gram.Entry.t)
and _ = (infixop4 : 'infixop4 Gram.Entry.t)
and _ = (infixop3 : 'infixop3 Gram.Entry.t)
and _ = (infixop2 : 'infixop2 Gram.Entry.t)
and _ = (infixop1 : 'infixop1 Gram.Entry.t)
and _ = (infixop0 : 'infixop0 Gram.Entry.t)
and _ = (with_constr_quot : 'with_constr_quot Gram.Entry.t)
and _ = (with_constr : 'with_constr Gram.Entry.t)
and _ = (value_val : 'value_val Gram.Entry.t)
and _ = (value_let : 'value_let Gram.Entry.t)
and _ = (val_longident : 'val_longident Gram.Entry.t)
and _ = (use_file : 'use_file Gram.Entry.t)
and _ = (typevars : 'typevars Gram.Entry.t)
and _ = (type_parameters : 'type_parameters Gram.Entry.t)
and _ = (type_parameter : 'type_parameter Gram.Entry.t)
and _ =
(type_longident_and_parameters :
'type_longident_and_parameters Gram.Entry.t)
and _ = (type_longident : 'type_longident Gram.Entry.t)
and _ = (type_kind : 'type_kind Gram.Entry.t)
and _ =
(type_ident_and_parameters :
'type_ident_and_parameters Gram.Entry.t)
and _ = (type_declaration : 'type_declaration Gram.Entry.t)
and _ = (type_constraint : 'type_constraint Gram.Entry.t)
and _ = (top_phrase : 'top_phrase Gram.Entry.t)
and _ = (str_items : 'str_items Gram.Entry.t)
and _ = (str_item_quot : 'str_item_quot Gram.Entry.t)
and _ = (str_item : 'str_item Gram.Entry.t)
and _ = (star_ctyp : 'star_ctyp Gram.Entry.t)
and _ = (sig_items : 'sig_items Gram.Entry.t)
and _ = (sig_item_quot : 'sig_item_quot Gram.Entry.t)
and _ = (sig_item : 'sig_item Gram.Entry.t)
and _ = (sequence : 'sequence Gram.Entry.t)
and _ = (semi : 'semi Gram.Entry.t)
and _ = (sem_patt_for_list : 'sem_patt_for_list Gram.Entry.t)
and _ = (sem_patt : 'sem_patt Gram.Entry.t)
and _ = (sem_expr_for_list : 'sem_expr_for_list Gram.Entry.t)
and _ = (sem_expr : 'sem_expr Gram.Entry.t)
and _ = (row_field : 'row_field Gram.Entry.t)
and _ = (poly_type : 'poly_type Gram.Entry.t)
and _ = (phrase : 'phrase Gram.Entry.t)
and _ = (patt_tcon : 'patt_tcon Gram.Entry.t)
and _ = (patt_quot : 'patt_quot Gram.Entry.t)
and _ = (patt_eoi : 'patt_eoi Gram.Entry.t)
and _ = (patt_as_patt_opt : 'patt_as_patt_opt Gram.Entry.t)
and _ = (patt : 'patt Gram.Entry.t)
and _ = (opt_when_expr : 'opt_when_expr Gram.Entry.t)
and _ = (opt_virtual : 'opt_virtual Gram.Entry.t)
and _ = (opt_rec : 'opt_rec Gram.Entry.t)
and _ = (opt_private : 'opt_private Gram.Entry.t)
and _ = (opt_polyt : 'opt_polyt Gram.Entry.t)
and _ = (opt_mutable : 'opt_mutable Gram.Entry.t)
and _ = (opt_meth_list : 'opt_meth_list Gram.Entry.t)
and _ = (opt_expr : 'opt_expr Gram.Entry.t)
and _ = (opt_eq_ctyp : 'opt_eq_ctyp Gram.Entry.t)
and _ = (opt_dot_dot : 'opt_dot_dot Gram.Entry.t)
and _ = (opt_comma_ctyp : 'opt_comma_ctyp Gram.Entry.t)
and _ = (opt_class_self_type : 'opt_class_self_type Gram.Entry.t)
and _ = (opt_class_self_patt : 'opt_class_self_patt Gram.Entry.t)
and _ = (opt_as_lident : 'opt_as_lident Gram.Entry.t)
and _ = (name_tags : 'name_tags Gram.Entry.t)
and _ = (more_ctyp : 'more_ctyp Gram.Entry.t)
and _ = (module_type_quot : 'module_type_quot Gram.Entry.t)
and _ = (module_type : 'module_type Gram.Entry.t)
and _ =
(module_rec_declaration : 'module_rec_declaration Gram.Entry.t)
and _ =
(module_longident_with_app :
'module_longident_with_app Gram.Entry.t)
and _ = (module_longident : 'module_longident Gram.Entry.t)
and _ = (module_expr_quot : 'module_expr_quot Gram.Entry.t)
and _ = (module_expr : 'module_expr Gram.Entry.t)
and _ = (module_declaration : 'module_declaration Gram.Entry.t)
and _ = (module_binding_quot : 'module_binding_quot Gram.Entry.t)
and _ = (module_binding0 : 'module_binding0 Gram.Entry.t)
and _ = (module_binding : 'module_binding Gram.Entry.t)
and _ = (meth_decl : 'meth_decl Gram.Entry.t)
and _ = (meth_list : 'meth_list Gram.Entry.t)
and _ = (let_binding : 'let_binding Gram.Entry.t)
and _ = (labeled_ipatt : 'labeled_ipatt Gram.Entry.t)
and _ = (label_patt_list : 'label_patt_list Gram.Entry.t)
and _ = (label_patt : 'label_patt Gram.Entry.t)
and _ = (label_longident : 'label_longident Gram.Entry.t)
and _ = (label_ipatt_list : 'label_ipatt_list Gram.Entry.t)
and _ = (label_ipatt : 'label_ipatt Gram.Entry.t)
and _ = (label_expr_list : 'label_expr_list Gram.Entry.t)
and _ = (label_expr : 'label_expr Gram.Entry.t)
and _ =
(label_declaration_list : 'label_declaration_list Gram.Entry.t)
and _ = (label_declaration : 'label_declaration Gram.Entry.t)
and _ = (label : 'label Gram.Entry.t)
and _ = (ipatt_tcon : 'ipatt_tcon Gram.Entry.t)
and _ = (ipatt : 'ipatt Gram.Entry.t)
and _ = (interf : 'interf Gram.Entry.t)
and _ = (implem : 'implem Gram.Entry.t)
and _ = (ident_quot : 'ident_quot Gram.Entry.t)
and _ = (ident : 'ident Gram.Entry.t)
and _ = (fun_def : 'fun_def Gram.Entry.t)
and _ = (fun_binding : 'fun_binding Gram.Entry.t)
and _ = (field_expr_list : 'field_expr_list Gram.Entry.t)
and _ = (field_expr : 'field_expr Gram.Entry.t)
and _ = (expr_quot : 'expr_quot Gram.Entry.t)
and _ = (expr_eoi : 'expr_eoi Gram.Entry.t)
and _ = (expr : 'expr Gram.Entry.t)
and _ = (eq_expr : 'eq_expr Gram.Entry.t)
and _ = (dummy : 'dummy Gram.Entry.t)
and _ = (direction_flag : 'direction_flag Gram.Entry.t)
and _ = (cvalue_binding : 'cvalue_binding Gram.Entry.t)
and _ = (ctyp_quot : 'ctyp_quot Gram.Entry.t)
and _ = (ctyp : 'ctyp Gram.Entry.t)
and _ =
(constructor_declarations :
'constructor_declarations Gram.Entry.t)
and _ =
(constructor_declaration : 'constructor_declaration Gram.Entry.t)
and _ = (constructor_arg_list : 'constructor_arg_list Gram.Entry.t)
and _ = (constrain : 'constrain Gram.Entry.t)
and _ = (comma_type_parameter : 'comma_type_parameter Gram.Entry.t)
and _ = (comma_patt : 'comma_patt Gram.Entry.t)
and _ = (comma_ipatt : 'comma_ipatt Gram.Entry.t)
and _ = (comma_expr : 'comma_expr Gram.Entry.t)
and _ = (comma_ctyp : 'comma_ctyp Gram.Entry.t)
and _ = (class_type_quot : 'class_type_quot Gram.Entry.t)
and _ = (class_type_plus : 'class_type_plus Gram.Entry.t)
and _ =
(class_type_longident_and_param :
'class_type_longident_and_param Gram.Entry.t)
and _ = (class_type_longident : 'class_type_longident Gram.Entry.t)
and _ =
(class_type_declaration : 'class_type_declaration Gram.Entry.t)
and _ = (class_type : 'class_type Gram.Entry.t)
and _ = (class_structure : 'class_structure Gram.Entry.t)
and _ = (class_str_item_quot : 'class_str_item_quot Gram.Entry.t)
and _ = (class_str_item : 'class_str_item Gram.Entry.t)
and _ = (class_signature : 'class_signature Gram.Entry.t)
and _ = (class_sig_item_quot : 'class_sig_item_quot Gram.Entry.t)
and _ = (class_sig_item : 'class_sig_item Gram.Entry.t)
and _ = (class_name_and_param : 'class_name_and_param Gram.Entry.t)
and _ =
(class_longident_and_param :
'class_longident_and_param Gram.Entry.t)
and _ = (class_longident : 'class_longident Gram.Entry.t)
and _ =
(class_info_for_class_type :
'class_info_for_class_type Gram.Entry.t)
and _ =
(class_info_for_class_expr :
'class_info_for_class_expr Gram.Entry.t)
and _ = (class_fun_def : 'class_fun_def Gram.Entry.t)
and _ = (class_fun_binding : 'class_fun_binding Gram.Entry.t)
and _ = (class_expr_quot : 'class_expr_quot Gram.Entry.t)
and _ = (class_expr : 'class_expr Gram.Entry.t)
and _ = (class_description : 'class_description Gram.Entry.t)
and _ = (class_declaration : 'class_declaration Gram.Entry.t)
and _ = (binding_quot : 'binding_quot Gram.Entry.t)
and _ = (binding : 'binding Gram.Entry.t)
and _ = (match_case_quot : 'match_case_quot Gram.Entry.t)
and _ = (match_case0 : 'match_case0 Gram.Entry.t)
and _ = (match_case : 'match_case Gram.Entry.t)
and _ = (and_ctyp : 'and_ctyp Gram.Entry.t)
and _ = (amp_ctyp : 'amp_ctyp Gram.Entry.t)
and _ = (a_ident : 'a_ident Gram.Entry.t)
and _ = (a_UIDENT : 'a_UIDENT Gram.Entry.t)
and _ = (a_STRING : 'a_STRING Gram.Entry.t)
and _ = (a_OPTLABEL : 'a_OPTLABEL Gram.Entry.t)
and _ = (a_NATIVEINT : 'a_NATIVEINT Gram.Entry.t)
and _ = (rec_binding_quot : 'rec_binding_quot Gram.Entry.t)
and _ = (a_LIDENT : 'a_LIDENT Gram.Entry.t)
and _ = (a_LABEL : 'a_LABEL Gram.Entry.t)
and _ = (a_INT64 : 'a_INT64 Gram.Entry.t)
and _ = (a_INT32 : 'a_INT32 Gram.Entry.t)
and _ = (a_INT : 'a_INT Gram.Entry.t)
and _ = (a_FLOAT : 'a_FLOAT Gram.Entry.t) in
let grammar_entry_create = Gram.Entry.mk in
let (* Here it's LABEL and not tilde_label since ~a:b is different than ~a : b *)
(* Same remark for ?a:b *) infixop5 : 'infixop5 Gram.Entry.t =
grammar_entry_create "infixop5"
and (* | i = opt_label; "("; p = patt_tcon; ")" -> *)
(* <:patt< ? $i$ : ($p$) >> *)
(* | i = opt_label; "("; p = ipatt_tcon; ")" ->
<:patt< ? $i$ : ($p$) >>
| i = opt_label; "("; p = ipatt_tcon; "="; e = expr; ")" ->
<:patt< ? $i$ : ($p$ = $e$) >> *)
string_list : 'string_list Gram.Entry.t =
grammar_entry_create "string_list"
and fun_def_cont : 'fun_def_cont Gram.Entry.t =
grammar_entry_create "fun_def_cont"
and sequence' : 'sequence' Gram.Entry.t =
grammar_entry_create "sequence'"
and infixop6 : 'infixop6 Gram.Entry.t =
grammar_entry_create "infixop6"
in
(Gram.extend (module_expr : 'module_expr Gram.Entry.t)
((fun () ->
(None,
[ ((Some "top"), None,
[ ([ Gram.Skeyword "struct";
Gram.Snterm
(Gram.Entry.obj
(str_items : 'str_items Gram.Entry.t));
Gram.Skeyword "end" ],
(Gram.Action.mk
(fun _ (st : 'str_items) _ (_loc : Gram.Loc.t)
-> (Ast.MeStr (_loc, st) : 'module_expr))));
([ Gram.Skeyword "functor"; Gram.Skeyword "(";
Gram.Snterm
(Gram.Entry.obj
(a_UIDENT : 'a_UIDENT Gram.Entry.t));
Gram.Skeyword ":";
Gram.Snterm
(Gram.Entry.obj
(module_type : 'module_type Gram.Entry.t));
Gram.Skeyword ")"; Gram.Skeyword "->"; Gram.Sself ],
(Gram.Action.mk
(fun (me : 'module_expr) _ _ (t : 'module_type)
_ (i : 'a_UIDENT) _ _ (_loc : Gram.Loc.t) ->
(Ast.MeFun (_loc, i, t, me) : 'module_expr)))) ]);
((Some "apply"), None,
[ ([ Gram.Sself; Gram.Sself ],
(Gram.Action.mk
(fun (me2 : 'module_expr) (me1 : 'module_expr)
(_loc : Gram.Loc.t) ->
(Ast.MeApp (_loc, me1, me2) : 'module_expr)))) ]);
((Some "simple"), None,
[ ([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ")" ],
(Gram.Action.mk
(fun _ (me : 'module_expr) _ (_loc : Gram.Loc.t)
-> (me : 'module_expr))));
([ Gram.Skeyword "("; Gram.Sself; Gram.Skeyword ":";
Gram.Snterm
(Gram.Entry.obj
(module_type : 'module_type Gram.Entry.t));
Gram.Skeyword ")" ],
(Gram.Action.mk
(fun _ (mt : 'module_type) _ (me : 'module_expr)
_ (_loc : Gram.Loc.t) ->
(Ast.MeTyc (_loc, me, mt) : 'module_expr))));
([ Gram.Snterm
(Gram.Entry.obj