package piqilib

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file piqi_json_parser.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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
# 48 "piqilib/piqi_json_parser.mll"
 
  module C = Piqi_common
  open C.Std

  type json = Piqi_json_type.json

  module Lexing =
    (*
      We override Lexing.engine in order to avoid creating a new position
      record each time a rule is matched.
      This reduces total parsing time by about 31%.
    *)
  struct
    include Lexing

    external c_engine : lex_tables -> int -> lexbuf -> int = "caml_lex_engine"

    let engine tbl state buf =
      let result = c_engine tbl state buf in
      (*
      if result >= 0 then begin
	buf.lex_start_p <- buf.lex_curr_p;
	buf.lex_curr_p <- {buf.lex_curr_p
			   with pos_cnum = buf.lex_abs_pos + buf.lex_curr_pos};
      end;
      *)
      result
  end

  open Printf
  open Lexing


  type lexer_state = {
    buf : Buffer.t;
      (* Buffer used to accumulate substrings *)

    mutable lnum : int;
      (* Current line number (starting from 1) *)

    mutable bol : int;
      (* Absolute position of the first character of the current line 
	 (starting from 0) *)

    mutable fname : string option;
      (* Name describing the input file *)

    mutable utf8_delta : int;
      (* bol position correction for multibyte utf8 encoding *)

    mutable loc : Piqloc.loc list;
      (* the list of JSON element locations in reverse order *)
  }


  let location v lexbuf =
    let offs = lexbuf.lex_abs_pos in
    let bol = v.bol in
    let bytes = offs + lexbuf.lex_start_pos - bol in
    let filename =
      match v.fname with
          None -> "" (* XXX, TODO: make it uniform across Piqi *)
        | Some s -> s
    in
    let len = bytes - v.utf8_delta + 1 in (* column positions start from 1 *)
    (filename, v.lnum, len)


  let addloc v lexbuf =
    if not !Piqi_config.pp_mode
    then
      let loc = location v lexbuf in
      v.loc <- loc :: v.loc
    else ()


  let custom_error descr v lexbuf =
    let loc = location v lexbuf in
    C.error_at loc descr


  let lexer_error descr v lexbuf =
    custom_error 
      (sprintf "%s '%s'" descr (Lexing.lexeme lexbuf))
      v lexbuf


  let parse_int64 s =
    match s.[0] with
      | '-' -> `Int (Int64.of_string s) (* negative integer *)
      | _ -> `Uint (Piq_parser.parse_uint s)


  let make_int s v lexbuf =
    try parse_int64 s
    with Failure _ ->
      lexer_error "Invalid int constant" v lexbuf

  let parse_float s v lexbuf =
    try float_of_string s
    with Failure _ ->
      lexer_error "Invalid float constant" v lexbuf

  let set_file_name v fname =
    v.fname <- fname

  let newline v lexbuf =
    v.lnum <- v.lnum + 1;
    v.bol <- lexbuf.lex_abs_pos + lexbuf.lex_curr_pos;
    v.utf8_delta <- 0; (* reset delta at newline *)
    ()


  (* returning length of utf8 string, i.e. unicode character count *)
  let utf8_length s pos bytes =
    let rec aux n i =
      if i = pos + bytes
      then n
      else begin
        let w = Piqi_utf8.width.(Char.code s.[i]) in
        if w > 0 && i + w <= pos + bytes
        then (
          (* check if the next unicode char is correctly encoded in utf8 *)
          ignore (Piqi_utf8.next s i);
          aux (succ n) (i + w)
        ) else raise Piqi_utf8.MalFormed
      end
    in
    aux 0 pos


  let check_adjust_utf8 v lexbuf s start len =
    let utf8_len =
      try utf8_length s start len
      with Piqi_utf8.MalFormed ->
        custom_error "Invalid utf-8 sequence" v lexbuf
    in
    v.utf8_delta <- v.utf8_delta + (len - utf8_len)


  let add_lexeme v lexbuf =
    let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos in
    let s = lexbuf.lex_buffer in
    let start = lexbuf.lex_start_pos in
    check_adjust_utf8 v lexbuf (Bytes.unsafe_to_string s) start len;
    Buffer.add_subbytes v.buf s start len

  let map_lexeme f lexbuf =
    let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos in
    f lexbuf.lex_buffer lexbuf.lex_start_pos len

  (* these exceptions are used internally to terminate top-down parsing
   * branches *)
  exception End_of_array
  exception End_of_object

# 159 "piqilib/piqi_json_parser.ml"
let __ocaml_lex_tables = {
  Lexing.lex_base =
   "\000\000\244\255\245\255\003\000\247\255\248\255\249\255\000\000\
    \024\000\010\000\252\255\000\000\000\000\000\000\001\000\002\000\
    \255\255\000\000\000\000\003\000\254\255\001\000\003\000\253\255\
    \079\000\089\000\099\000\121\000\131\000\141\000\153\000\163\000\
    \221\000\251\255\252\255\001\001\254\255\255\255\255\000\247\255\
    \248\255\020\001\250\255\251\255\252\255\253\255\254\255\255\255\
    \075\001\098\001\136\001\249\255\002\002\253\255\254\255\255\255\
    \037\002\035\002\056\002\111\002\134\002\172\002\034\000\255\255\
    \005\000\008\000\255\255\037\000\253\255\254\255\229\002\062\003\
    \255\255\001\000\255\255\210\000\252\255\253\255\254\255\255\255\
    \001\000\255\255\038\000\252\255\253\255\254\255\255\255\040\000\
    \253\255\254\255\255\255";
  Lexing.lex_backtrk =
   "\255\255\255\255\255\255\009\000\255\255\255\255\255\255\004\000\
    \004\000\011\000\255\255\011\000\011\000\011\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\005\000\255\255\005\000\255\255\005\000\255\255\
    \255\255\255\255\255\255\002\000\255\255\255\255\255\255\255\255\
    \255\255\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\
    \255\255\255\255\255\255\255\255\255\255\255\255\001\000\255\255\
    \002\000\001\000\255\255\255\255\255\255\255\255\001\000\255\255\
    \255\255\001\000\255\255\255\255\255\255\255\255\255\255\255\255\
    \001\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255";
  Lexing.lex_default =
   "\001\000\000\000\000\000\255\255\000\000\000\000\000\000\255\255\
    \255\255\255\255\000\000\255\255\255\255\255\255\255\255\255\255\
    \000\000\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\255\255\
    \035\000\000\000\000\000\035\000\000\000\000\000\040\000\000\000\
    \000\000\255\255\000\000\000\000\000\000\000\000\000\000\000\000\
    \255\255\255\255\255\255\000\000\056\000\000\000\000\000\000\000\
    \056\000\255\255\255\255\255\255\255\255\255\255\255\255\000\000\
    \255\255\255\255\000\000\069\000\000\000\000\000\255\255\255\255\
    \000\000\255\255\000\000\077\000\000\000\000\000\000\000\000\000\
    \255\255\000\000\084\000\000\000\000\000\000\000\000\000\089\000\
    \000\000\000\000\000\000";
  Lexing.lex_trans =
   "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\003\000\004\000\000\000\003\000\003\000\065\000\066\000\
    \003\000\065\000\065\000\000\000\000\000\065\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \003\000\000\000\010\000\003\000\000\000\065\000\000\000\000\000\
    \065\000\000\000\000\000\000\000\000\000\009\000\025\000\000\000\
    \007\000\008\000\008\000\008\000\008\000\008\000\008\000\008\000\
    \008\000\008\000\007\000\008\000\008\000\008\000\008\000\008\000\
    \008\000\008\000\008\000\008\000\000\000\024\000\025\000\070\000\
    \008\000\008\000\008\000\008\000\008\000\008\000\008\000\008\000\
    \008\000\008\000\086\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\005\000\000\000\024\000\074\000\000\000\
    \000\000\017\000\090\000\000\000\000\000\024\000\012\000\016\000\
    \020\000\000\000\000\000\000\000\018\000\022\000\011\000\023\000\
    \000\000\000\000\014\000\019\000\013\000\021\000\015\000\000\000\
    \000\000\000\000\031\000\006\000\031\000\024\000\081\000\030\000\
    \030\000\030\000\030\000\030\000\030\000\030\000\030\000\030\000\
    \030\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
    \026\000\026\000\026\000\026\000\026\000\026\000\026\000\026\000\
    \026\000\026\000\026\000\026\000\026\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\085\000\029\000\000\000\029\000\000\000\
    \027\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
    \028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
    \028\000\028\000\028\000\028\000\028\000\028\000\028\000\028\000\
    \028\000\028\000\028\000\028\000\028\000\028\000\028\000\000\000\
    \027\000\030\000\030\000\030\000\030\000\030\000\030\000\030\000\
    \030\000\030\000\030\000\030\000\030\000\030\000\030\000\030\000\
    \030\000\030\000\030\000\030\000\030\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\034\000\034\000\034\000\
    \034\000\034\000\034\000\034\000\034\000\000\000\079\000\037\000\
    \002\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\255\255\255\255\255\255\255\255\255\255\
    \255\255\047\000\063\000\255\255\000\000\068\000\083\000\000\000\
    \088\000\000\000\000\000\000\000\000\000\000\000\047\000\078\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\036\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\048\000\048\000\048\000\048\000\
    \048\000\048\000\048\000\048\000\048\000\048\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\048\000\048\000\048\000\
    \048\000\048\000\048\000\047\000\000\000\255\255\000\000\000\000\
    \000\000\046\000\000\000\000\000\000\000\045\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\044\000\000\000\000\000\
    \000\000\043\000\000\000\042\000\041\000\048\000\048\000\048\000\
    \048\000\048\000\048\000\049\000\049\000\049\000\049\000\049\000\
    \049\000\049\000\049\000\049\000\049\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\049\000\049\000\049\000\049\000\
    \049\000\049\000\050\000\050\000\050\000\050\000\050\000\050\000\
    \050\000\050\000\050\000\050\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\050\000\050\000\050\000\050\000\050\000\
    \050\000\000\000\000\000\000\000\049\000\049\000\049\000\049\000\
    \049\000\049\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \051\000\051\000\051\000\051\000\051\000\051\000\051\000\051\000\
    \051\000\051\000\000\000\050\000\050\000\050\000\050\000\050\000\
    \050\000\051\000\051\000\051\000\051\000\051\000\051\000\000\000\
    \000\000\000\000\076\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\033\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\051\000\051\000\051\000\051\000\051\000\051\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\039\000\
    \000\000\255\255\054\000\054\000\054\000\054\000\054\000\054\000\
    \054\000\054\000\054\000\054\000\054\000\054\000\054\000\054\000\
    \054\000\054\000\054\000\054\000\054\000\054\000\054\000\054\000\
    \054\000\054\000\054\000\054\000\054\000\054\000\054\000\054\000\
    \054\000\054\000\000\000\000\000\055\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\255\255\
    \255\255\255\255\255\255\255\255\255\255\056\000\000\000\055\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\056\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\057\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \059\000\059\000\059\000\059\000\059\000\059\000\059\000\059\000\
    \059\000\059\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\059\000\059\000\059\000\059\000\059\000\059\000\056\000\
    \000\000\057\000\000\000\000\000\000\000\056\000\000\000\000\000\
    \000\000\056\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\056\000\000\000\000\000\000\000\056\000\000\000\056\000\
    \058\000\059\000\059\000\059\000\059\000\059\000\059\000\060\000\
    \060\000\060\000\060\000\060\000\060\000\060\000\060\000\060\000\
    \060\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \060\000\060\000\060\000\060\000\060\000\060\000\061\000\061\000\
    \061\000\061\000\061\000\061\000\061\000\061\000\061\000\061\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\061\000\
    \061\000\061\000\061\000\061\000\061\000\000\000\000\000\000\000\
    \060\000\060\000\060\000\060\000\060\000\060\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\056\000\056\000\056\000\056\000\
    \056\000\056\000\056\000\056\000\056\000\056\000\000\000\061\000\
    \061\000\061\000\061\000\061\000\061\000\056\000\056\000\056\000\
    \056\000\056\000\056\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\053\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\056\000\056\000\056\000\
    \056\000\056\000\056\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\255\255\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \000\000\000\000\000\000\000\000\071\000\000\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \072\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\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\000\000\000\000\000\000\000\000\071\000\000\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\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\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\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\
    \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\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\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\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\000\000\000\000\000\000\000\000\000\000";
  Lexing.lex_check =
   "\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\000\000\000\000\255\255\003\000\000\000\064\000\064\000\
    \003\000\065\000\064\000\255\255\255\255\065\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\000\000\003\000\255\255\064\000\255\255\255\255\
    \065\000\255\255\255\255\255\255\255\255\000\000\007\000\255\255\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\009\000\009\000\009\000\009\000\009\000\009\000\
    \009\000\009\000\009\000\009\000\255\255\007\000\008\000\067\000\
    \008\000\008\000\008\000\008\000\008\000\008\000\008\000\008\000\
    \008\000\008\000\082\000\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\000\000\255\255\008\000\073\000\255\255\
    \255\255\012\000\087\000\255\255\255\255\007\000\000\000\015\000\
    \019\000\255\255\255\255\255\255\017\000\021\000\000\000\022\000\
    \255\255\255\255\013\000\018\000\000\000\011\000\014\000\255\255\
    \255\255\255\255\024\000\000\000\024\000\008\000\080\000\024\000\
    \024\000\024\000\024\000\024\000\024\000\024\000\024\000\024\000\
    \024\000\025\000\025\000\025\000\025\000\025\000\025\000\025\000\
    \025\000\025\000\025\000\026\000\026\000\026\000\026\000\026\000\
    \026\000\026\000\026\000\026\000\026\000\255\255\255\255\255\255\
    \255\255\255\255\255\255\082\000\027\000\255\255\027\000\255\255\
    \026\000\027\000\027\000\027\000\027\000\027\000\027\000\027\000\
    \027\000\027\000\027\000\028\000\028\000\028\000\028\000\028\000\
    \028\000\028\000\028\000\028\000\028\000\029\000\029\000\029\000\
    \029\000\029\000\029\000\029\000\029\000\029\000\029\000\255\255\
    \026\000\030\000\030\000\030\000\030\000\030\000\030\000\030\000\
    \030\000\030\000\030\000\031\000\031\000\031\000\031\000\031\000\
    \031\000\031\000\031\000\031\000\031\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\032\000\255\255\075\000\032\000\
    \000\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\035\000\035\000\035\000\035\000\035\000\
    \035\000\038\000\062\000\035\000\255\255\067\000\082\000\255\255\
    \087\000\255\255\255\255\255\255\255\255\255\255\038\000\075\000\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\032\000\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\041\000\041\000\041\000\041\000\
    \041\000\041\000\041\000\041\000\041\000\041\000\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\041\000\041\000\041\000\
    \041\000\041\000\041\000\038\000\255\255\035\000\255\255\255\255\
    \255\255\038\000\255\255\255\255\255\255\038\000\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\038\000\255\255\255\255\
    \255\255\038\000\255\255\038\000\038\000\041\000\041\000\041\000\
    \041\000\041\000\041\000\048\000\048\000\048\000\048\000\048\000\
    \048\000\048\000\048\000\048\000\048\000\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\048\000\048\000\048\000\048\000\
    \048\000\048\000\049\000\049\000\049\000\049\000\049\000\049\000\
    \049\000\049\000\049\000\049\000\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\049\000\049\000\049\000\049\000\049\000\
    \049\000\255\255\255\255\255\255\048\000\048\000\048\000\048\000\
    \048\000\048\000\255\255\255\255\255\255\255\255\255\255\255\255\
    \050\000\050\000\050\000\050\000\050\000\050\000\050\000\050\000\
    \050\000\050\000\255\255\049\000\049\000\049\000\049\000\049\000\
    \049\000\050\000\050\000\050\000\050\000\050\000\050\000\255\255\
    \255\255\255\255\075\000\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\032\000\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\050\000\050\000\050\000\050\000\050\000\050\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\038\000\
    \255\255\035\000\052\000\052\000\052\000\052\000\052\000\052\000\
    \052\000\052\000\052\000\052\000\052\000\052\000\052\000\052\000\
    \052\000\052\000\052\000\052\000\052\000\052\000\052\000\052\000\
    \052\000\052\000\052\000\052\000\052\000\052\000\052\000\052\000\
    \052\000\052\000\255\255\255\255\052\000\056\000\056\000\056\000\
    \056\000\056\000\056\000\056\000\056\000\056\000\056\000\056\000\
    \056\000\056\000\056\000\056\000\056\000\056\000\056\000\056\000\
    \056\000\056\000\056\000\056\000\056\000\056\000\056\000\056\000\
    \056\000\056\000\056\000\056\000\056\000\057\000\255\255\056\000\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\057\000\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\052\000\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \058\000\058\000\058\000\058\000\058\000\058\000\058\000\058\000\
    \058\000\058\000\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\058\000\058\000\058\000\058\000\058\000\058\000\057\000\
    \255\255\056\000\255\255\255\255\255\255\057\000\255\255\255\255\
    \255\255\057\000\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\057\000\255\255\255\255\255\255\057\000\255\255\057\000\
    \057\000\058\000\058\000\058\000\058\000\058\000\058\000\059\000\
    \059\000\059\000\059\000\059\000\059\000\059\000\059\000\059\000\
    \059\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \059\000\059\000\059\000\059\000\059\000\059\000\060\000\060\000\
    \060\000\060\000\060\000\060\000\060\000\060\000\060\000\060\000\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\060\000\
    \060\000\060\000\060\000\060\000\060\000\255\255\255\255\255\255\
    \059\000\059\000\059\000\059\000\059\000\059\000\255\255\255\255\
    \255\255\255\255\255\255\255\255\061\000\061\000\061\000\061\000\
    \061\000\061\000\061\000\061\000\061\000\061\000\255\255\060\000\
    \060\000\060\000\060\000\060\000\060\000\061\000\061\000\061\000\
    \061\000\061\000\061\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\052\000\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\061\000\061\000\061\000\
    \061\000\061\000\061\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\056\000\070\000\070\000\
    \070\000\070\000\070\000\070\000\070\000\070\000\070\000\070\000\
    \070\000\070\000\070\000\070\000\070\000\070\000\070\000\070\000\
    \070\000\070\000\070\000\070\000\070\000\070\000\070\000\070\000\
    \255\255\255\255\255\255\255\255\070\000\255\255\070\000\070\000\
    \070\000\070\000\070\000\070\000\070\000\070\000\070\000\070\000\
    \070\000\070\000\070\000\070\000\070\000\070\000\070\000\070\000\
    \070\000\070\000\070\000\070\000\070\000\070\000\070\000\070\000\
    \071\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\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\255\255\255\255\255\255\255\255\071\000\255\255\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\000\071\000\071\000\071\000\071\000\071\000\071\000\071\000\
    \071\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\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\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\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\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\255\255\255\255\255\255\255\255";
  Lexing.lex_base_code =
   "";
  Lexing.lex_backtrk_code =
   "";
  Lexing.lex_default_code =
   "";
  Lexing.lex_trans_code =
   "";
  Lexing.lex_check_code =
   "";
  Lexing.lex_code =
   "";
}

let rec read_json v lexbuf =
   __ocaml_lex_read_json_rec v lexbuf 0
and __ocaml_lex_read_json_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 244 "piqilib/piqi_json_parser.mll"
                ( addloc v lexbuf; `Bool true )
# 495 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 245 "piqilib/piqi_json_parser.mll"
                ( addloc v lexbuf; `Bool false )
# 500 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 246 "piqilib/piqi_json_parser.mll"
                ( addloc v lexbuf; `Null () )
# 505 "piqilib/piqi_json_parser.ml"

  | 3 ->
# 247 "piqilib/piqi_json_parser.mll"
                (
                  addloc v lexbuf;
                  if not !Piqi_config.pp_mode
                  then
	            (Buffer.clear v.buf;
		    `String (finish_string v lexbuf)
                    )
                  else
                    `Stringlit (finish_stringlit v lexbuf)
                )
# 519 "piqilib/piqi_json_parser.ml"

  | 4 ->
# 258 "piqilib/piqi_json_parser.mll"
                (
                  addloc v lexbuf;
                  let s = lexeme lexbuf in
                  if not !Piqi_config.pp_mode
                  then make_int s v lexbuf
                  else `Intlit s
                )
# 530 "piqilib/piqi_json_parser.ml"

  | 5 ->
# 265 "piqilib/piqi_json_parser.mll"
                (
                  addloc v lexbuf;
                  if not !Piqi_config.pp_mode
                  then
                    let s = lexeme lexbuf in
                    `Float (parse_float s v lexbuf)
                  else
                    `Floatlit (lexeme lexbuf)
                )
# 543 "piqilib/piqi_json_parser.ml"

  | 6 ->
# 275 "piqilib/piqi_json_parser.mll"
                 (
                   addloc v lexbuf;
                   let acc = ref [] in
		   try
		     read_space v lexbuf;
		     read_object_end lexbuf;
		     let field_name = read_ident v lexbuf in
		     read_space v lexbuf;
		     read_colon v lexbuf;
		     read_space v lexbuf;
		     acc := (field_name, read_json v lexbuf) :: !acc;
		     while true do
		       read_space v lexbuf;
		       read_object_sep v lexbuf;
		       read_space v lexbuf;
		       let field_name = read_ident v lexbuf in
		       read_space v lexbuf;
		       read_colon v lexbuf;
		       read_space v lexbuf;
		       acc := (field_name, read_json v lexbuf) :: !acc;
		     done;
		     assert false
		   with End_of_object ->
		     `Assoc (List.rev !acc)
		 )
# 572 "piqilib/piqi_json_parser.ml"

  | 7 ->
# 301 "piqilib/piqi_json_parser.mll"
                 (
                   addloc v lexbuf;
                   let acc = ref [] in
		   try
		     read_space v lexbuf;
		     read_array_end lexbuf;
		     acc := read_json v lexbuf :: !acc;
		     while true do
		       read_space v lexbuf;
		       read_array_sep v lexbuf;
		       read_space v lexbuf;
		       acc := read_json v lexbuf :: !acc;
		     done;
		     assert false
		   with End_of_array ->
		     `List (List.rev !acc)
		 )
# 593 "piqilib/piqi_json_parser.ml"

  | 8 ->
# 319 "piqilib/piqi_json_parser.mll"
                 ( newline v lexbuf; read_json v lexbuf )
# 598 "piqilib/piqi_json_parser.ml"

  | 9 ->
# 320 "piqilib/piqi_json_parser.mll"
                 ( read_json v lexbuf )
# 603 "piqilib/piqi_json_parser.ml"

  | 10 ->
# 321 "piqilib/piqi_json_parser.mll"
                 ( custom_error "Unexpected end of input" v lexbuf )
# 608 "piqilib/piqi_json_parser.ml"

  | 11 ->
# 322 "piqilib/piqi_json_parser.mll"
                 ( lexer_error "Invalid token" v lexbuf )
# 613 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_json_rec v lexbuf __ocaml_lex_state

and finish_string v lexbuf =
   __ocaml_lex_finish_string_rec v lexbuf 32
and __ocaml_lex_finish_string_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 326 "piqilib/piqi_json_parser.mll"
                  ( Buffer.contents v.buf )
# 625 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 327 "piqilib/piqi_json_parser.mll"
                  ( finish_escaped_char v lexbuf;
		    finish_string v lexbuf )
# 631 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 330 "piqilib/piqi_json_parser.mll"
                  ( add_lexeme v lexbuf;
		    finish_string v lexbuf )
# 637 "piqilib/piqi_json_parser.ml"

  | 3 ->
# 333 "piqilib/piqi_json_parser.mll"
                  ( custom_error "Invalid string literal" v lexbuf )
# 642 "piqilib/piqi_json_parser.ml"

  | 4 ->
# 334 "piqilib/piqi_json_parser.mll"
                  ( custom_error "Unexpected end of input" v lexbuf )
# 647 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_finish_string_rec v lexbuf __ocaml_lex_state

and finish_escaped_char v lexbuf =
   __ocaml_lex_finish_escaped_char_rec v lexbuf 38
and __ocaml_lex_finish_escaped_char_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
let
# 340 "piqilib/piqi_json_parser.mll"
           c
# 660 "piqilib/piqi_json_parser.ml"
= Lexing.sub_lexeme_char lexbuf lexbuf.Lexing.lex_start_pos in
# 340 "piqilib/piqi_json_parser.mll"
             ( Buffer.add_char v.buf c )
# 664 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 341 "piqilib/piqi_json_parser.mll"
         ( Buffer.add_char v.buf '\b' )
# 669 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 342 "piqilib/piqi_json_parser.mll"
         ( Buffer.add_char v.buf '\012' )
# 674 "piqilib/piqi_json_parser.ml"

  | 3 ->
# 343 "piqilib/piqi_json_parser.mll"
         ( Buffer.add_char v.buf '\n' )
# 679 "piqilib/piqi_json_parser.ml"

  | 4 ->
# 344 "piqilib/piqi_json_parser.mll"
         ( Buffer.add_char v.buf '\r' )
# 684 "piqilib/piqi_json_parser.ml"

  | 5 ->
# 345 "piqilib/piqi_json_parser.mll"
         ( Buffer.add_char v.buf '\t' )
# 689 "piqilib/piqi_json_parser.ml"

  | 6 ->
let
# 346 "piqilib/piqi_json_parser.mll"
                                s
# 695 "piqilib/piqi_json_parser.ml"
= Lexing.sub_lexeme lexbuf (lexbuf.Lexing.lex_start_pos + 1) (lexbuf.Lexing.lex_start_pos + 5) in
# 347 "piqilib/piqi_json_parser.mll"
         ( let i = Piq_lexer.int_of_xstring s in
           Piqi_utf8.store v.buf i )
# 700 "piqilib/piqi_json_parser.ml"

  | 7 ->
# 349 "piqilib/piqi_json_parser.mll"
         ( lexer_error "Invalid escape sequence" v lexbuf )
# 705 "piqilib/piqi_json_parser.ml"

  | 8 ->
# 350 "piqilib/piqi_json_parser.mll"
         ( custom_error "Unexpected end of input" v lexbuf )
# 710 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_finish_escaped_char_rec v lexbuf __ocaml_lex_state

and finish_stringlit v lexbuf =
   __ocaml_lex_finish_stringlit_rec v lexbuf 52
and __ocaml_lex_finish_stringlit_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 356 "piqilib/piqi_json_parser.mll"
         (
           let len = lexbuf.lex_curr_pos - lexbuf.lex_start_pos in
	   let s = Bytes.create (len+1) in
	   Bytes.set s 0 '"';
	   Bytes.blit lexbuf.lex_buffer lexbuf.lex_start_pos s 1 len;
           let s = Bytes.unsafe_to_string s in
           check_adjust_utf8 v lexbuf s 1 len;
	   s
	 )
# 730 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 366 "piqilib/piqi_json_parser.mll"
         ( custom_error "Invalid string literal" v lexbuf )
# 735 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 367 "piqilib/piqi_json_parser.mll"
         ( custom_error "Unexpected end of input" v lexbuf )
# 740 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_finish_stringlit_rec v lexbuf __ocaml_lex_state

and read_eof lexbuf =
   __ocaml_lex_read_eof_rec lexbuf 62
and __ocaml_lex_read_eof_rec lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 373 "piqilib/piqi_json_parser.mll"
             ( true )
# 752 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 374 "piqilib/piqi_json_parser.mll"
             ( false )
# 757 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_eof_rec lexbuf __ocaml_lex_state

and read_space v lexbuf =
   __ocaml_lex_read_space_rec v lexbuf 64
and __ocaml_lex_read_space_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 377 "piqilib/piqi_json_parser.mll"
             ( newline v lexbuf; read_space v lexbuf )
# 769 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 378 "piqilib/piqi_json_parser.mll"
             ( read_space v lexbuf )
# 774 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 379 "piqilib/piqi_json_parser.mll"
             ( () )
# 779 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_space_rec v lexbuf __ocaml_lex_state

and read_ident v lexbuf =
   __ocaml_lex_read_ident_rec v lexbuf 67
and __ocaml_lex_read_ident_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
let
# 382 "piqilib/piqi_json_parser.mll"
                  s
# 792 "piqilib/piqi_json_parser.ml"
= Lexing.sub_lexeme lexbuf (lexbuf.Lexing.lex_start_pos + 1) (lexbuf.Lexing.lex_curr_pos + -1) in
# 383 "piqilib/piqi_json_parser.mll"
             ( addloc v lexbuf; s )
# 796 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 384 "piqilib/piqi_json_parser.mll"
             ( lexer_error "Expected string identifier but found" v lexbuf )
# 801 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 385 "piqilib/piqi_json_parser.mll"
             ( custom_error "Unexpected end of input" v lexbuf )
# 806 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_ident_rec v lexbuf __ocaml_lex_state

and read_array_end lexbuf =
   __ocaml_lex_read_array_end_rec lexbuf 73
and __ocaml_lex_read_array_end_rec lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 389 "piqilib/piqi_json_parser.mll"
             ( raise End_of_array )
# 818 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 390 "piqilib/piqi_json_parser.mll"
             ( () )
# 823 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_array_end_rec lexbuf __ocaml_lex_state

and read_array_sep v lexbuf =
   __ocaml_lex_read_array_sep_rec v lexbuf 75
and __ocaml_lex_read_array_sep_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 393 "piqilib/piqi_json_parser.mll"
             ( () )
# 835 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 394 "piqilib/piqi_json_parser.mll"
             ( raise End_of_array )
# 840 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 395 "piqilib/piqi_json_parser.mll"
             ( lexer_error "Expected ',' or ']' but found" v lexbuf )
# 845 "piqilib/piqi_json_parser.ml"

  | 3 ->
# 396 "piqilib/piqi_json_parser.mll"
             ( custom_error "Unexpected end of input" v lexbuf )
# 850 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_array_sep_rec v lexbuf __ocaml_lex_state

and read_object_end lexbuf =
   __ocaml_lex_read_object_end_rec lexbuf 80
and __ocaml_lex_read_object_end_rec lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 399 "piqilib/piqi_json_parser.mll"
             ( raise End_of_object )
# 862 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 400 "piqilib/piqi_json_parser.mll"
             ( () )
# 867 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_object_end_rec lexbuf __ocaml_lex_state

and read_object_sep v lexbuf =
   __ocaml_lex_read_object_sep_rec v lexbuf 82
and __ocaml_lex_read_object_sep_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 403 "piqilib/piqi_json_parser.mll"
             ( () )
# 879 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 404 "piqilib/piqi_json_parser.mll"
             ( raise End_of_object )
# 884 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 405 "piqilib/piqi_json_parser.mll"
             ( lexer_error "Expected ',' or '}' but found" v lexbuf )
# 889 "piqilib/piqi_json_parser.ml"

  | 3 ->
# 406 "piqilib/piqi_json_parser.mll"
             ( custom_error "Unexpected end of input" v lexbuf )
# 894 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_object_sep_rec v lexbuf __ocaml_lex_state

and read_colon v lexbuf =
   __ocaml_lex_read_colon_rec v lexbuf 87
and __ocaml_lex_read_colon_rec v lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 409 "piqilib/piqi_json_parser.mll"
             ( () )
# 906 "piqilib/piqi_json_parser.ml"

  | 1 ->
# 410 "piqilib/piqi_json_parser.mll"
             ( lexer_error "Expected ':' but found" v lexbuf )
# 911 "piqilib/piqi_json_parser.ml"

  | 2 ->
# 411 "piqilib/piqi_json_parser.mll"
             ( custom_error "Unexpected end of input" v lexbuf )
# 916 "piqilib/piqi_json_parser.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_read_colon_rec v lexbuf __ocaml_lex_state

;;

# 414 "piqilib/piqi_json_parser.mll"
 
  (* XXX: detect JSON encoding and make sure that it is utf-8 *)

  let _ = (read_json : lexer_state -> Lexing.lexbuf -> json)

  let finish v lexbuf =
    read_space v lexbuf;
    if not (read_eof lexbuf) then
      custom_error "Junk after end of JSON value" v lexbuf

  let init_lexer ?buf ?fname ?(lnum = 1) () =
    let buf =
      match buf with
	  None -> Buffer.create 256
	| Some buf -> buf
    in
    {
      buf = buf;
      lnum = lnum;
      bol = 0;
      fname = fname;
      utf8_delta = 0;
      loc = [];
    }


  let rec save_locations v json =
    let addloc loc obj = Piqloc.addloc loc obj in
    let rec aux l x =
      let h, t =
        match l with
          | h::t -> h, t
          | _ -> assert false
      in
      let add x = addloc h x in
      let addret x = add x; t in
      add x;
      match x with
        | `Null () | `Bool _ -> t (* can't save locations for unboxed types *)
        | `Int i -> addret i
        | `Uint i -> addret i
        | `Intlit s -> addret s
        | `Float f -> addret f
        | `Floatlit s -> addret s
        | `String s -> addret s
        | `Stringlit s -> addret s
        | `Assoc l ->
            List.fold_left
              (fun l (n, v) ->
                addloc (List.hd l) n;
                aux (List.tl l) v) t l
        | `List l ->
            List.fold_left (fun t v -> aux t v) t l
    in
    if not !Piqi_config.pp_mode
    then
      let t = aux (List.rev v.loc) json in
      v.loc <- []; (* reset the location list *)
      assert (t = [])
    else ()


  let read_next (v, lexbuf) =
    read_space v lexbuf;
    if read_eof lexbuf
    then None
    else
      let json = read_json v lexbuf in
      save_locations v json;
      Some json


  let read_all json_parser =
    let rec aux accu =
      match read_next json_parser with
        | None -> List.rev accu
        | Some x -> aux (x::accu)
    in aux []


  let init_from_string ?buf ?fname ?lnum s =
    let lexbuf = Lexing.from_string s in
    let v = init_lexer ?buf ?fname ?lnum () in
    (v, lexbuf)


  let init_from_channel ?buf ?fname ?lnum ic =
    let lexbuf = Lexing.from_channel ic in
    let v = init_lexer ?buf ?fname ?lnum () in
    (v, lexbuf)

# 1015 "piqilib/piqi_json_parser.ml"
OCaml

Innovation. Community. Security.