forked from ocaml/ocaml
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlexer.ml
3466 lines (3245 loc) · 161 KB
/
lexer.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
# 18 "parsing/lexer.mll"
open Lexing
open Misc
open Parser
type directive_value =
| Dir_bool of bool
| Dir_float of float
| Dir_int of int
| Dir_string of string
| Dir_null
type directive_type =
| Dir_type_bool
| Dir_type_float
| Dir_type_int
| Dir_type_string
| Dir_type_null
let type_of_directive x =
match x with
| Dir_bool _ -> Dir_type_bool
| Dir_float _ -> Dir_type_float
| Dir_int _ -> Dir_type_int
| Dir_string _ -> Dir_type_string
| Dir_null -> Dir_type_null
let string_of_type_directive x =
match x with
| Dir_type_bool -> "bool"
| Dir_type_float -> "float"
| Dir_type_int -> "int"
| Dir_type_string -> "string"
| Dir_type_null -> "null"
type error =
| Illegal_character of char
| Illegal_escape of string
| Unterminated_comment of Location.t
| Unterminated_string
| Unterminated_string_in_comment of Location.t * Location.t
| Keyword_as_label of string
| Invalid_literal of string
| Invalid_directive of string * string option
| Unterminated_paren_in_conditional
| Unterminated_if
| Unterminated_else
| Unexpected_token_in_conditional
| Expect_hash_then_in_conditional
| Illegal_semver of string
| Unexpected_directive
| Conditional_expr_expected_type of directive_type * directive_type
;;
exception Error of error * Location.t;;
let assert_same_type lexbuf x y =
let lhs = type_of_directive x in let rhs = type_of_directive y in
if lhs <> rhs then
raise (Error(Conditional_expr_expected_type(lhs,rhs), Location.curr lexbuf))
else y
let directive_built_in_values =
Hashtbl.create 51
let replace_directive_built_in_value k v =
Hashtbl.replace directive_built_in_values k v
let remove_directive_built_in_value k =
Hashtbl.replace directive_built_in_values k Dir_null
let replace_directive_int k v =
Hashtbl.replace directive_built_in_values k (Dir_int v)
let replace_directive_bool k v =
Hashtbl.replace directive_built_in_values k (Dir_bool v)
let replace_directive_string k v =
Hashtbl.replace directive_built_in_values k (Dir_string v)
let () =
(* Note we use {!Config} instead of {!Sys} becasue
we want to overwrite in some cases with the
same stdlib
*)
let version =
Config.version (* so that it can be overridden*)
in
replace_directive_built_in_value "OCAML_VERSION"
(Dir_string version);
replace_directive_built_in_value "OCAML_PATCH"
(Dir_string
(match String.rindex version '+' with
| exception Not_found -> ""
| i ->
String.sub version (i + 1)
(String.length version - i - 1)))
;
replace_directive_built_in_value "OS_TYPE"
(Dir_string Sys.os_type);
replace_directive_built_in_value "BIG_ENDIAN"
(Dir_bool Sys.big_endian);
replace_directive_built_in_value "WORD_SIZE"
(Dir_int Sys.word_size)
let find_directive_built_in_value k =
Hashtbl.find directive_built_in_values k
let iter_directive_built_in_value f = Hashtbl.iter f directive_built_in_values
(*
{[
# semver 0 "12";;
- : int * int * int * string = (12, 0, 0, "");;
# semver 0 "12.3";;
- : int * int * int * string = (12, 3, 0, "");;
semver 0 "12.3.10";;
- : int * int * int * string = (12, 3, 10, "");;
# semver 0 "12.3.10+x";;
- : int * int * int * string = (12, 3, 10, "+x")
]}
*)
let zero = Char.code '0'
let dot = Char.code '.'
let semantic_version_parse str start last_index =
let rec aux start acc last_index =
if start <= last_index then
let c = Char.code (String.unsafe_get str start) in
if c = dot then (acc, start + 1) (* consume [4.] instead of [4]*)
else
let v = c - zero in
if v >=0 && v <= 9 then
aux (start + 1) (acc * 10 + v) last_index
else (acc , start)
else (acc, start)
in
let major, major_end = aux start 0 last_index in
let minor, minor_end = aux major_end 0 last_index in
let patch, patch_end = aux minor_end 0 last_index in
let additional = String.sub str patch_end (last_index - patch_end +1) in
(major, minor, patch), additional
(**
{[
semver Location.none "1.2.3" "~1.3.0" = false;;
semver Location.none "1.2.3" "^1.3.0" = true ;;
semver Location.none "1.2.3" ">1.3.0" = false ;;
semver Location.none "1.2.3" ">=1.3.0" = false ;;
semver Location.none "1.2.3" "<1.3.0" = true ;;
semver Location.none "1.2.3" "<=1.3.0" = true ;;
]}
*)
let semver loc lhs str =
let last_index = String.length str - 1 in
if last_index < 0 then raise (Error(Illegal_semver str, loc))
else
let pred, ((major, minor, _patch) as version, _) =
let v = String.unsafe_get str 0 in
match v with
| '>' ->
if last_index = 0 then raise (Error(Illegal_semver str, loc)) else
if String.unsafe_get str 1 = '=' then
`Ge, semantic_version_parse str 2 last_index
else `Gt, semantic_version_parse str 1 last_index
| '<'
->
if last_index = 0 then raise (Error(Illegal_semver str, loc)) else
if String.unsafe_get str 1 = '=' then
`Le, semantic_version_parse str 2 last_index
else `Lt, semantic_version_parse str 1 last_index
| '^'
-> `Compatible, semantic_version_parse str 1 last_index
| '~' -> `Approximate, semantic_version_parse str 1 last_index
| _ -> `Exact, semantic_version_parse str 0 last_index
in
let ((l_major, l_minor, _l_patch) as lversion,_) =
semantic_version_parse lhs 0 (String.length lhs - 1) in
match pred with
| `Ge -> lversion >= version
| `Gt -> lversion > version
| `Le -> lversion <= version
| `Lt -> lversion < version
| `Approximate -> major = l_major && minor = l_minor
| `Compatible -> major = l_major
| `Exact -> lversion = version
let pp_directive_value fmt (x : directive_value) =
match x with
| Dir_bool b -> Format.pp_print_bool fmt b
| Dir_int b -> Format.pp_print_int fmt b
| Dir_float b -> Format.pp_print_float fmt b
| Dir_string s -> Format.fprintf fmt "%S" s
| Dir_null -> Format.pp_print_string fmt "null"
let list_variables fmt =
iter_directive_built_in_value
(fun s dir_value ->
Format.fprintf
fmt "@[%s@ %a@]@."
s pp_directive_value dir_value
)
let defined str =
begin match find_directive_built_in_value str with
| Dir_null -> false
| _ -> true
| exception _ ->
try ignore @@ Sys.getenv str; true with _ -> false
end
let query _loc str =
begin match find_directive_built_in_value str with
| Dir_null -> Dir_bool false
| v -> v
| exception Not_found ->
begin match Sys.getenv str with
| v ->
begin
try Dir_bool (bool_of_string v) with
_ ->
begin
try Dir_int (int_of_string v )
with
_ ->
begin try (Dir_float (float_of_string v))
with _ -> Dir_string v
end
end
end
| exception Not_found ->
Dir_bool false
end
end
let define_key_value key v =
if String.length key > 0
&& Char.uppercase_ascii (key.[0]) = key.[0] then
begin
replace_directive_built_in_value key
begin
(* NEED Sync up across {!lexer.mll} {!bspp.ml} and here,
TODO: put it in {!lexer.mll}
*)
try Dir_bool (bool_of_string v) with
_ ->
begin
try Dir_int (int_of_string v )
with
_ ->
begin try (Dir_float (float_of_string v))
with _ -> Dir_string v
end
end
end;
true
end
else false
let cvt_int_literal s =
- int_of_string ("-" ^ s)
let value_of_token loc (t : Parser.token) =
match t with
| INT (i,None) -> Dir_int (cvt_int_literal i)
| STRING (s,_) -> Dir_string s
| FLOAT (s,None) -> Dir_float (float_of_string s)
| TRUE -> Dir_bool true
| FALSE -> Dir_bool false
| UIDENT s -> query loc s
| _ -> raise (Error (Unexpected_token_in_conditional, loc))
let directive_parse token_with_comments lexbuf =
let look_ahead = ref None in
let token () : Parser.token =
let v = !look_ahead in
match v with
| Some v ->
look_ahead := None ;
v
| None ->
let rec skip () =
match token_with_comments lexbuf with
| COMMENT _
| DOCSTRING _
| EOL -> skip ()
| EOF -> raise (Error (Unterminated_if, Location.curr lexbuf))
| t -> t
in skip ()
in
let push e =
(* INVARIANT: only look at most one token *)
assert (!look_ahead = None);
look_ahead := Some e
in
let rec
token_op calc ~no lhs =
match token () with
| (LESS
| GREATER
| INFIXOP0 "<="
| INFIXOP0 ">="
| EQUAL
| INFIXOP0 "<>" as op) ->
let f =
match op with
| LESS -> (<)
| GREATER -> (>)
| INFIXOP0 "<=" -> (<=)
| EQUAL -> (=)
| INFIXOP0 "<>" -> (<>)
| _ -> assert false
in
let curr_loc = Location.curr lexbuf in
let rhs = value_of_token curr_loc (token ()) in
not calc ||
f lhs (assert_same_type lexbuf lhs rhs)
| INFIXOP0 "=~" ->
not calc ||
begin match lhs with
| Dir_string s ->
let curr_loc = Location.curr lexbuf in
let rhs = value_of_token curr_loc (token ()) in
begin match rhs with
| Dir_string rhs ->
semver curr_loc s rhs
| _ ->
raise
(Error
( Conditional_expr_expected_type
(Dir_type_string, type_of_directive lhs), Location.curr lexbuf))
end
| _ -> raise
(Error
( Conditional_expr_expected_type
(Dir_type_string, type_of_directive lhs), Location.curr lexbuf))
end
| e -> no e
and
parse_or calc : bool =
parse_or_aux calc (parse_and calc)
and (* a || (b || (c || d))*)
parse_or_aux calc v : bool =
(* let l = v in *)
match token () with
| BARBAR ->
let b = parse_or (calc && not v) in
v || b
| e -> push e ; v
and parse_and calc =
parse_and_aux calc (parse_relation calc)
and parse_and_aux calc v = (* a && (b && (c && d)) *)
(* let l = v in *)
match token () with
| AMPERAMPER ->
let b = parse_and (calc && v) in
v && b
| e -> push e ; v
and parse_relation (calc : bool) : bool =
let curr_token = token () in
let curr_loc = Location.curr lexbuf in
match curr_token with
| TRUE -> true
| FALSE -> false
| UIDENT v ->
let value_v = query curr_loc v in
token_op calc
~no:(fun e -> push e ;
match value_v with
| Dir_bool b -> b
| _ ->
let ty = type_of_directive value_v in
raise
(Error(Conditional_expr_expected_type (Dir_type_bool, ty),
curr_loc)))
value_v
| INT (v,None) ->
let num_v = cvt_int_literal v in
token_op calc
~no:(fun e ->
push e;
num_v <> 0
)
(Dir_int num_v)
| FLOAT (v,None) ->
token_op calc
~no:(fun _e ->
raise (Error(Conditional_expr_expected_type(Dir_type_bool, Dir_type_float),
curr_loc)))
(Dir_float (float_of_string v))
| STRING (v,_) ->
token_op calc
~no:(fun _e ->
raise (Error
(Conditional_expr_expected_type(Dir_type_bool, Dir_type_string),
curr_loc)))
(Dir_string v)
| LIDENT ("defined" | "undefined" as r) ->
let t = token () in
let loc = Location.curr lexbuf in
begin match t with
| UIDENT s ->
not calc ||
if r.[0] = 'u' then
not @@ defined s
else defined s
| _ -> raise (Error (Unexpected_token_in_conditional, loc))
end
| LPAREN ->
let v = parse_or calc in
begin match token () with
| RPAREN -> v
| _ -> raise (Error(Unterminated_paren_in_conditional, Location.curr lexbuf))
end
| _ -> raise (Error (Unexpected_token_in_conditional, curr_loc))
in
let v = parse_or true in
begin match token () with
| THEN -> v
| _ -> raise (Error (Expect_hash_then_in_conditional, Location.curr lexbuf))
end
type dir_conditional =
| Dir_if_true
| Dir_if_false
| Dir_out
(* let string_of_dir_conditional (x : dir_conditional) = *)
(* match x with *)
(* | Dir_if_true -> "Dir_if_true" *)
(* | Dir_if_false -> "Dir_if_false" *)
(* | Dir_out -> "Dir_out" *)
let is_elif (i : Parser.token ) =
match i with
| LIDENT "elif" -> true
| _ -> false (* avoid polymorphic equal *)
(* The table of keywords *)
let keyword_table =
create_hashtable 149 [
"and", AND;
"as", AS;
"assert", ASSERT;
"begin", BEGIN;
"class", CLASS;
"constraint", CONSTRAINT;
"do", DO;
"done", DONE;
"downto", DOWNTO;
"else", ELSE;
"end", END;
"exception", EXCEPTION;
"external", EXTERNAL;
"false", FALSE;
"for", FOR;
"fun", FUN;
"function", FUNCTION;
"functor", FUNCTOR;
"if", IF;
"in", IN;
"include", INCLUDE;
"inherit", INHERIT;
"initializer", INITIALIZER;
"lazy", LAZY;
"let", LET;
"match", MATCH;
"method", METHOD;
"module", MODULE;
"mutable", MUTABLE;
"new", NEW;
"nonrec", NONREC;
"object", OBJECT;
"of", OF;
"open", OPEN;
"or", OR;
(* "parser", PARSER; *)
"private", PRIVATE;
"rec", REC;
"sig", SIG;
"struct", STRUCT;
"then", THEN;
"to", TO;
"true", TRUE;
"try", TRY;
"type", TYPE;
"val", VAL;
"virtual", VIRTUAL;
"when", WHEN;
"while", WHILE;
"with", WITH;
"lor", INFIXOP3("lor"); (* Should be INFIXOP2 *)
"lxor", INFIXOP3("lxor"); (* Should be INFIXOP2 *)
"mod", INFIXOP3("mod");
"land", INFIXOP3("land");
"lsl", INFIXOP4("lsl");
"lsr", INFIXOP4("lsr");
"asr", INFIXOP4("asr")
]
(* To buffer string literals *)
let string_buffer = Buffer.create 256
let reset_string_buffer () = Buffer.reset string_buffer
let get_stored_string () = Buffer.contents string_buffer
let store_string_char c = Buffer.add_char string_buffer c
let store_string_utf_8_uchar u = Buffer.add_utf_8_uchar string_buffer u
let store_string s = Buffer.add_string string_buffer s
let store_lexeme lexbuf = store_string (Lexing.lexeme lexbuf)
(* To store the position of the beginning of a string and comment *)
let string_start_loc = ref Location.none;;
let comment_start_loc = ref [];;
let in_comment () = !comment_start_loc <> [];;
let is_in_string = ref false
let in_string () = !is_in_string
let print_warnings = ref true
let if_then_else = ref Dir_out
let sharp_look_ahead = ref None
let update_if_then_else v =
(* Format.fprintf Format.err_formatter "@[update %s \n@]@." (string_of_dir_conditional v); *)
if_then_else := v
(* Escaped chars are interpreted in strings unless they are in comments. *)
let store_escaped_char lexbuf c =
if in_comment () then store_lexeme lexbuf else store_string_char c
let store_escaped_uchar lexbuf u =
if in_comment () then store_lexeme lexbuf else store_string_utf_8_uchar u
let with_comment_buffer comment lexbuf =
let start_loc = Location.curr lexbuf in
comment_start_loc := [start_loc];
reset_string_buffer ();
let end_loc = comment lexbuf in
let s = get_stored_string () in
reset_string_buffer ();
let loc = { start_loc with Location.loc_end = end_loc.Location.loc_end } in
s, loc
(* To translate escape sequences *)
let hex_digit_value d = (* assert (d in '0'..'9' 'a'..'f' 'A'..'F') *)
let d = Char.code d in
if d >= 97 then d - 87 else
if d >= 65 then d - 55 else
d - 48
let hex_num_value lexbuf ~first ~last =
let rec loop acc i = match i > last with
| true -> acc
| false ->
let value = hex_digit_value (Lexing.lexeme_char lexbuf i) in
loop (16 * acc + value) (i + 1)
in
loop 0 first
let char_for_backslash = function
| 'n' -> '\010'
| 'r' -> '\013'
| 'b' -> '\008'
| 't' -> '\009'
| c -> c
let char_for_decimal_code lexbuf i =
let c = 100 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) +
10 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) +
(Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48) in
if (c < 0 || c > 255) then
if in_comment ()
then 'x'
else raise (Error(Illegal_escape (Lexing.lexeme lexbuf),
Location.curr lexbuf))
else Char.chr c
let char_for_octal_code lexbuf i =
let c = 64 * (Char.code(Lexing.lexeme_char lexbuf i) - 48) +
8 * (Char.code(Lexing.lexeme_char lexbuf (i+1)) - 48) +
(Char.code(Lexing.lexeme_char lexbuf (i+2)) - 48) in
Char.chr c
let char_for_hexadecimal_code lexbuf i =
let byte = hex_num_value lexbuf ~first:i ~last:(i+1) in
Char.chr byte
let uchar_for_uchar_escape lexbuf =
let err e =
raise
(Error (Illegal_escape (Lexing.lexeme lexbuf ^ e), Location.curr lexbuf))
in
let len = Lexing.lexeme_end lexbuf - Lexing.lexeme_start lexbuf in
let first = 3 (* skip opening \u{ *) in
let last = len - 2 (* skip closing } *) in
let digit_count = last - first + 1 in
match digit_count > 6 with
| true -> err ", too many digits, expected 1 to 6 hexadecimal digits"
| false ->
let cp = hex_num_value lexbuf ~first ~last in
if Uchar.is_valid cp then Uchar.unsafe_of_int cp else
err (", " ^ Printf.sprintf "%X" cp ^ " is not a Unicode scalar value")
(* recover the name from a LABEL or OPTLABEL token *)
let get_label_name lexbuf =
let s = Lexing.lexeme lexbuf in
let name = String.sub s 1 (String.length s - 2) in
if Hashtbl.mem keyword_table name then
raise (Error(Keyword_as_label name, Location.curr lexbuf));
name
;;
(* Update the current location with file name and line number. *)
let update_loc lexbuf file line absolute chars =
let pos = lexbuf.lex_curr_p in
let new_file = match file with
| None -> pos.pos_fname
| Some s -> s
in
lexbuf.lex_curr_p <- { pos with
pos_fname = new_file;
pos_lnum = if absolute then line else pos.pos_lnum + line;
pos_bol = pos.pos_cnum - chars;
}
;;
let preprocessor = ref None
let escaped_newlines = ref false
(* Warn about Latin-1 characters used in idents *)
let warn_latin1 lexbuf =
Location.deprecated (Location.curr lexbuf)"ISO-Latin1 characters in identifiers"
let handle_docstrings = ref true
let comment_list = ref []
let add_comment com =
comment_list := com :: !comment_list
let add_docstring_comment ds =
let com =
("*" ^ Docstrings.docstring_body ds, Docstrings.docstring_loc ds)
in
add_comment com
let comments () = List.rev !comment_list
(* Error report *)
open Format
let report_error ppf = function
| Illegal_character c ->
fprintf ppf "Illegal character (%s)" (Char.escaped c)
| Illegal_escape s ->
fprintf ppf "Illegal backslash escape in string or character (%s)" s
| Unterminated_comment _ ->
fprintf ppf "Comment not terminated"
| Unterminated_string ->
fprintf ppf "String literal not terminated"
| Unterminated_string_in_comment (_, loc) ->
fprintf ppf "This comment contains an unterminated string literal@.\
%aString literal begins here"
Location.print_error loc
| Keyword_as_label kwd ->
fprintf ppf "`%s' is a keyword, it cannot be used as label name" kwd
| Invalid_literal s ->
fprintf ppf "Invalid literal %s" s
| Invalid_directive (dir, explanation) ->
fprintf ppf "Invalid lexer directive %S" dir;
begin match explanation with
| None -> ()
| Some expl -> fprintf ppf ": %s" expl
end
| Unterminated_if ->
fprintf ppf "#if not terminated"
| Unterminated_else ->
fprintf ppf "#else not terminated"
| Unexpected_directive -> fprintf ppf "Unexpected directive"
| Unexpected_token_in_conditional ->
fprintf ppf "Unexpected token in conditional predicate"
| Unterminated_paren_in_conditional ->
fprintf ppf "Unterminated parens in conditional predicate"
| Expect_hash_then_in_conditional ->
fprintf ppf "Expect `then` after conditional predicate"
| Conditional_expr_expected_type (a,b) ->
fprintf ppf "Conditional expression type mismatch (%s,%s)"
(string_of_type_directive a )
(string_of_type_directive b )
| Illegal_semver s ->
fprintf ppf "Illegal semantic version string %s" s
let () =
Location.register_error_of_exn
(function
| Error (err, loc) ->
Some (Location.error_of_printer loc report_error err)
| _ ->
None
)
# 717 "parsing/lexer.ml"
let __ocaml_lex_tables = {
Lexing.lex_base =
"\000\000\162\255\163\255\224\000\003\001\038\001\073\001\108\001\
\143\001\186\255\178\001\215\001\194\255\091\000\252\001\031\002\
\068\000\071\000\065\002\100\002\212\255\214\255\217\255\135\002\
\230\002\009\003\088\000\255\000\039\003\236\255\123\003\207\003\
\035\004\243\004\195\005\147\006\114\007\206\007\158\008\122\000\
\254\255\001\000\005\000\255\255\006\000\007\000\125\009\155\009\
\107\010\250\255\249\255\059\011\011\012\247\255\246\255\219\012\
\047\013\131\013\215\013\043\014\127\014\211\014\039\015\123\015\
\207\015\035\016\087\000\119\016\203\016\031\017\115\017\199\017\
\108\000\192\255\235\255\007\003\034\018\106\000\107\000\011\000\
\234\255\233\255\228\255\152\002\099\000\118\000\113\000\232\255\
\128\000\147\000\231\255\224\000\003\001\148\000\230\255\110\004\
\149\000\229\255\148\000\224\255\217\000\223\255\222\000\034\018\
\222\255\073\018\101\005\009\003\221\255\012\000\014\001\080\001\
\115\001\024\001\221\255\013\000\119\018\158\018\193\018\231\018\
\010\019\209\255\204\255\205\255\206\255\202\255\045\019\154\000\
\183\000\195\255\196\255\197\255\217\000\182\255\180\255\189\255\
\080\019\185\255\187\255\115\019\150\019\185\019\220\019\130\005\
\243\255\244\255\017\000\245\255\174\001\223\005\253\255\248\000\
\249\000\255\255\254\255\252\255\005\006\238\019\003\001\004\001\
\018\000\251\255\250\255\249\255\222\006\026\003\005\001\248\255\
\036\003\008\001\247\255\066\008\020\001\246\255\059\001\234\001\
\245\255\246\255\247\255\060\001\055\020\255\255\248\255\193\000\
\233\008\038\001\133\004\253\255\073\001\094\001\113\001\143\004\
\252\255\192\002\027\004\251\255\230\009\250\255\182\010\089\020\
\249\255\129\001\130\001\252\255\085\007\254\255\255\255\146\001\
\147\001\253\255\177\007\033\001\044\001\148\001\151\001\045\001\
\153\001\044\001\019\000\255\255";
Lexing.lex_backtrk =
"\255\255\255\255\255\255\090\000\089\000\086\000\085\000\078\000\
\076\000\255\255\067\000\064\000\255\255\057\000\056\000\054\000\
\052\000\048\000\045\000\081\000\255\255\255\255\255\255\036\000\
\035\000\042\000\040\000\039\000\062\000\255\255\014\000\014\000\
\013\000\012\000\011\000\010\000\007\000\004\000\003\000\002\000\
\255\255\093\000\093\000\255\255\255\255\255\255\084\000\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\018\000\
\018\000\016\000\015\000\018\000\015\000\015\000\014\000\016\000\
\015\000\016\000\255\255\017\000\017\000\014\000\014\000\016\000\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\027\000\027\000\027\000\027\000\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\028\000\255\255\029\000\255\255\030\000\088\000\
\255\255\091\000\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\037\000\087\000\082\000\044\000\
\047\000\255\255\255\255\255\255\255\255\255\255\055\000\074\000\
\071\000\255\255\255\255\255\255\072\000\255\255\255\255\255\255\
\065\000\255\255\255\255\083\000\077\000\080\000\079\000\255\255\
\255\255\255\255\012\000\255\255\012\000\012\000\255\255\012\000\
\012\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\010\000\010\000\255\255\255\255\007\000\
\007\000\007\000\007\000\255\255\001\000\007\000\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\003\000\255\255\255\255\003\000\
\255\255\255\255\255\255\002\000\255\255\255\255\001\000\255\255\
\255\255\255\255\255\255\255\255";
Lexing.lex_default =
"\001\000\000\000\000\000\255\255\255\255\255\255\255\255\255\255\
\255\255\000\000\255\255\255\255\000\000\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\000\000\000\000\000\000\255\255\
\255\255\255\255\255\255\077\000\255\255\000\000\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\000\000\255\255\255\255\000\000\255\255\255\255\255\255\255\255\
\255\255\000\000\000\000\255\255\255\255\000\000\000\000\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
\255\255\000\000\000\000\255\255\082\000\255\255\255\255\255\255\
\000\000\000\000\000\000\255\255\255\255\255\255\255\255\000\000\
\255\255\255\255\000\000\255\255\255\255\255\255\000\000\255\255\
\255\255\000\000\255\255\000\000\255\255\000\000\255\255\255\255\
\000\000\255\255\110\000\255\255\000\000\255\255\110\000\111\000\
\110\000\113\000\000\000\255\255\255\255\255\255\255\255\255\255\
\255\255\000\000\000\000\000\000\000\000\000\000\255\255\255\255\
\255\255\000\000\000\000\000\000\255\255\000\000\000\000\000\000\
\255\255\000\000\000\000\255\255\255\255\255\255\255\255\144\000\
\000\000\000\000\255\255\000\000\158\000\255\255\000\000\255\255\
\255\255\000\000\000\000\000\000\255\255\255\255\255\255\255\255\
\255\255\000\000\000\000\000\000\255\255\255\255\255\255\000\000\
\255\255\255\255\000\000\255\255\255\255\000\000\255\255\176\000\
\000\000\000\000\000\000\255\255\182\000\000\000\000\000\255\255\
\255\255\255\255\255\255\000\000\255\255\255\255\255\255\255\255\
\000\000\255\255\255\255\000\000\255\255\000\000\255\255\255\255\
\000\000\255\255\203\000\000\000\255\255\000\000\000\000\255\255\
\255\255\000\000\255\255\255\255\255\255\213\000\216\000\255\255\
\216\000\255\255\255\255\000\000";
Lexing.lex_trans =
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\039\000\040\000\040\000\039\000\041\000\045\000\043\000\
\043\000\040\000\044\000\044\000\045\000\078\000\108\000\114\000\
\079\000\109\000\115\000\145\000\159\000\219\000\174\000\160\000\
\039\000\008\000\029\000\024\000\006\000\004\000\023\000\027\000\
\026\000\021\000\025\000\007\000\020\000\019\000\018\000\003\000\
\031\000\030\000\030\000\030\000\030\000\030\000\030\000\030\000\
\030\000\030\000\017\000\016\000\015\000\014\000\010\000\036\000\
\005\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\013\000\042\000\012\000\005\000\038\000\
\022\000\035\000\035\000\035\000\035\000\035\000\035\000\035\000\
\035\000\035\000\035\000\035\000\035\000\035\000\035\000\035\000\
\035\000\035\000\035\000\035\000\035\000\035\000\035\000\035\000\
\035\000\035\000\035\000\028\000\011\000\009\000\037\000\125\000\
\127\000\124\000\098\000\039\000\123\000\122\000\039\000\065\000\
\065\000\065\000\065\000\065\000\065\000\065\000\065\000\065\000\
\065\000\081\000\080\000\091\000\091\000\091\000\091\000\130\000\
\087\000\129\000\039\000\128\000\071\000\071\000\071\000\071\000\
\071\000\071\000\071\000\071\000\071\000\071\000\088\000\088\000\
\088\000\088\000\088\000\088\000\088\000\088\000\088\000\088\000\
\089\000\089\000\089\000\089\000\089\000\089\000\089\000\089\000\
\089\000\089\000\090\000\094\000\097\000\099\000\100\000\134\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\131\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\034\000\
\034\000\034\000\034\000\034\000\034\000\034\000\034\000\034\000\
\034\000\034\000\034\000\034\000\034\000\034\000\034\000\034\000\
\034\000\034\000\034\000\034\000\034\000\034\000\034\000\132\000\
\034\000\034\000\034\000\034\000\034\000\034\000\034\000\034\000\
\002\000\003\000\101\000\102\000\003\000\003\000\003\000\101\000\
\102\000\078\000\003\000\003\000\079\000\003\000\003\000\003\000\
\092\000\092\000\092\000\092\000\092\000\092\000\092\000\092\000\
\108\000\133\000\003\000\109\000\003\000\003\000\003\000\003\000\
\003\000\154\000\114\000\153\000\003\000\115\000\255\255\003\000\
\003\000\003\000\163\000\162\000\167\000\003\000\003\000\170\000\
\003\000\003\000\003\000\093\000\093\000\093\000\093\000\093\000\
\093\000\093\000\093\000\173\000\198\000\003\000\003\000\003\000\
\003\000\003\000\003\000\003\000\212\000\145\000\178\000\005\000\
\174\000\201\000\005\000\005\000\005\000\213\000\217\000\218\000\
\005\000\005\000\188\000\005\000\005\000\005\000\193\000\193\000\
\193\000\193\000\108\000\076\000\003\000\109\000\003\000\000\000\
\005\000\003\000\005\000\005\000\005\000\005\000\005\000\000\000\
\188\000\188\000\006\000\190\000\000\000\006\000\006\000\006\000\
\000\000\000\000\113\000\006\000\006\000\000\000\006\000\006\000\
\006\000\000\000\000\000\188\000\112\000\108\000\190\000\003\000\
\109\000\003\000\000\000\006\000\005\000\006\000\006\000\006\000\
\006\000\006\000\000\000\178\000\206\000\117\000\201\000\207\000\
\117\000\117\000\117\000\112\000\000\000\111\000\117\000\117\000\
\000\000\117\000\142\000\117\000\206\000\206\000\214\000\208\000\
\208\000\215\000\005\000\215\000\005\000\000\000\117\000\006\000\
\117\000\141\000\117\000\117\000\117\000\000\000\000\000\000\000\
\139\000\000\000\000\000\139\000\139\000\139\000\000\000\000\000\
\159\000\139\000\139\000\160\000\139\000\139\000\139\000\000\000\
\000\000\000\000\000\000\000\000\000\000\006\000\000\000\006\000\
\000\000\139\000\117\000\139\000\140\000\139\000\139\000\139\000\
\000\000\000\000\000\000\006\000\000\000\161\000\006\000\006\000\
\006\000\000\000\000\000\000\000\006\000\006\000\000\000\006\000\
\006\000\006\000\000\000\000\000\000\000\000\000\000\000\000\000\
\117\000\000\000\117\000\000\000\006\000\139\000\006\000\006\000\
\006\000\006\000\006\000\000\000\178\000\000\000\000\000\179\000\
\006\000\000\000\000\000\006\000\006\000\006\000\204\000\255\255\
\000\000\006\000\006\000\000\000\006\000\006\000\006\000\000\000\
\000\000\000\000\157\000\139\000\181\000\139\000\255\255\138\000\
\006\000\006\000\000\000\006\000\006\000\006\000\006\000\006\000\
\255\255\000\000\000\000\000\000\000\000\006\000\000\000\000\000\
\006\000\006\000\006\000\000\000\000\000\000\000\006\000\006\000\
\000\000\006\000\006\000\006\000\000\000\000\000\006\000\137\000\
\006\000\000\000\000\000\000\000\135\000\006\000\006\000\000\000\
\006\000\006\000\006\000\006\000\006\000\000\000\000\000\000\000\
\006\000\000\000\000\000\006\000\006\000\006\000\180\000\000\000\
\000\000\006\000\006\000\000\000\126\000\006\000\006\000\000\000\
\255\255\000\000\000\000\136\000\000\000\006\000\000\000\000\000\
\000\000\006\000\006\000\006\000\006\000\006\000\006\000\006\000\
\000\000\000\000\120\000\000\000\000\000\120\000\120\000\120\000\
\000\000\000\000\000\000\120\000\120\000\000\000\120\000\121\000\
\120\000\000\000\000\000\255\255\000\000\000\000\000\000\000\000\
\006\000\000\000\006\000\120\000\000\000\006\000\120\000\120\000\
\120\000\120\000\205\000\000\000\000\000\117\000\000\000\000\000\
\117\000\117\000\117\000\000\000\000\000\000\000\117\000\117\000\
\000\000\117\000\118\000\117\000\255\255\000\000\000\000\255\255\
\000\000\255\255\000\000\006\000\000\000\006\000\117\000\120\000\
\117\000\117\000\119\000\117\000\117\000\000\000\000\000\000\000\
\006\000\000\000\000\000\006\000\006\000\116\000\255\255\000\000\
\000\000\006\000\006\000\000\000\006\000\006\000\006\000\000\000\
\000\000\000\000\000\000\000\000\000\000\120\000\000\000\120\000\
\000\000\006\000\117\000\006\000\006\000\006\000\006\000\006\000\
\095\000\095\000\095\000\095\000\095\000\095\000\095\000\095\000\
\095\000\095\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\095\000\095\000\095\000\095\000\095\000\095\000\000\000\
\117\000\000\000\117\000\000\000\000\000\006\000\000\000\000\000\
\000\000\000\000\177\000\000\000\000\000\000\000\000\000\107\000\
\194\000\194\000\194\000\194\000\194\000\194\000\194\000\194\000\
\000\000\095\000\095\000\095\000\095\000\095\000\095\000\000\000\
\000\000\000\000\000\000\006\000\000\000\006\000\107\000\105\000\
\000\000\105\000\105\000\105\000\105\000\000\000\000\000\000\000\
\105\000\105\000\107\000\105\000\105\000\105\000\106\000\106\000\
\106\000\106\000\106\000\106\000\106\000\106\000\106\000\106\000\
\105\000\000\000\105\000\105\000\105\000\105\000\105\000\000\000\
\000\000\107\000\003\000\000\000\000\000\003\000\003\000\003\000\
\000\000\000\000\104\000\103\000\003\000\000\000\003\000\003\000\
\003\000\106\000\106\000\106\000\106\000\106\000\106\000\106\000\
\106\000\106\000\106\000\003\000\105\000\003\000\003\000\003\000\
\003\000\003\000\168\000\168\000\168\000\168\000\168\000\168\000\
\168\000\168\000\168\000\168\000\169\000\169\000\169\000\169\000\
\169\000\169\000\169\000\169\000\169\000\169\000\000\000\000\000\
\000\000\000\000\105\000\073\000\105\000\000\000\075\000\003\000\
\075\000\075\000\075\000\075\000\075\000\075\000\075\000\075\000\
\075\000\075\000\075\000\075\000\075\000\075\000\075\000\075\000\
\075\000\075\000\075\000\075\000\075\000\075\000\075\000\075\000\
\075\000\075\000\000\000\074\000\000\000\003\000\075\000\003\000\
\075\000\075\000\075\000\075\000\075\000\075\000\075\000\075\000\
\075\000\075\000\075\000\075\000\075\000\075\000\075\000\075\000\
\075\000\075\000\075\000\075\000\075\000\075\000\075\000\075\000\
\075\000\075\000\055\000\074\000\000\000\000\000\000\000\000\000\
\000\000\057\000\000\000\030\000\030\000\030\000\030\000\030\000\
\030\000\030\000\030\000\030\000\030\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\055\000\055\000\055\000\055\000\
\056\000\055\000\058\000\058\000\058\000\058\000\058\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\000\000\000\000\
\000\000\000\000\030\000\000\000\055\000\055\000\055\000\055\000\
\056\000\055\000\058\000\058\000\058\000\058\000\058\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\055\000\000\000\
\000\000\000\000\000\000\000\000\000\000\057\000\000\000\030\000\
\030\000\030\000\030\000\030\000\030\000\030\000\030\000\030\000\
\030\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\055\000\059\000\055\000\055\000\056\000\055\000\058\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\060\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\058\000\061\000\
\058\000\058\000\000\000\000\000\000\000\000\000\030\000\000\000\
\055\000\059\000\055\000\055\000\056\000\055\000\058\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\060\000\058\000\
\058\000\058\000\058\000\058\000\058\000\058\000\058\000\061\000\
\058\000\058\000\032\000\195\000\195\000\195\000\195\000\195\000\
\195\000\195\000\195\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\000\000\000\000\
\000\000\000\000\032\000\000\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\096\000\096\000\
\096\000\096\000\096\000\096\000\096\000\096\000\096\000\096\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\096\000\
\096\000\096\000\096\000\096\000\096\000\191\000\191\000\191\000\
\191\000\191\000\191\000\191\000\191\000\191\000\191\000\192\000\
\192\000\192\000\192\000\192\000\192\000\192\000\192\000\192\000\
\192\000\000\000\000\000\000\000\000\000\000\000\000\000\096\000\
\096\000\096\000\096\000\096\000\096\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\000\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\033\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\000\000\000\000\
\000\000\000\000\033\000\000\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\033\000\033\000\
\033\000\033\000\033\000\033\000\033\000\033\000\112\000\108\000\
\000\000\000\000\109\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
\000\000\000\000\000\000\000\000\000\000\112\000\000\000\111\000\
\000\000\000\000\000\000\000\000\145\000\000\000\000\000\146\000\
\000\000\000\000\000\000\000\000\000\000\106\000\106\000\106\000\
\106\000\106\000\106\000\106\000\106\000\106\000\106\000\000\000\
\000\000\000\000\000\000\000\000\150\000\000\000\000\000\000\000\
\000\000\148\000\152\000\000\000\151\000\000\000\000\000\000\000\
\000\000\000\000\000\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\000\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\034\000\032\000\032\000\032\000\032\000\032\000\
\032\000\032\000\032\000\034\000\034\000\034\000\034\000\034\000\
\034\000\034\000\034\000\034\000\034\000\149\000\000\000\000\000\
\000\000\000\000\000\000\000\000\034\000\034\000\034\000\034\000\
\034\000\034\000\034\000\034\000\034\000\034\000\034\000\034\000\
\034\000\034\000\034\000\034\000\034\000\034\000\034\000\034\000\