-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathgrammar_pp.ml
More file actions
4290 lines (3852 loc) · 171 KB
/
Copy pathgrammar_pp.ml
File metadata and controls
4290 lines (3852 loc) · 171 KB
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
(**************************************************************************)
(* Ott *)
(* *)
(* Peter Sewell, Computer Laboratory, University of Cambridge *)
(* Francesco Zappa Nardelli, Moscova project, INRIA Rocquencourt *)
(* *)
(* Copyright 2005-2010 *)
(* *)
(* Redistribution and use in source and binary forms, with or without *)
(* modification, are permitted provided that the following conditions *)
(* are met: *)
(* 1. Redistributions of source code must retain the above copyright *)
(* notice, this list of conditions and the following disclaimer. *)
(* 2. Redistributions in binary form must reproduce the above copyright *)
(* notice, this list of conditions and the following disclaimer in the *)
(* documentation and/or other materials provided with the distribution. *)
(* 3. The names of the authors may not be used to endorse or promote *)
(* products derived from this software without specific prior written *)
(* permission. *)
(* *)
(* THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS *)
(* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *)
(* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *)
(* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY *)
(* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *)
(* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE *)
(* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *)
(* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER *)
(* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR *)
(* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN *)
(* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *)
(**************************************************************************)
open Types
exception ThisCannotHappen
let c = ref 100 (* FZ *)
let debug s = () (* print_string s; flush stdout*)
(*
Some of the grammar pp functions come in several flavours, with
more-or-less environment. For example, we have:
pp_plain_nonterm nt
just gives a crude ASCII version of nt, primarily for use in error
messages etc where we don't have a syntax defn to hand
pp_nonterm m xd nt
gives a normal Ascii/Tex/Coq/Isa pp of nt, depending on the mode m
and syntax defn xd. This is only really sensible for nt which are
known not to contain a suffix item of the form Si_index i.
(currently this is implemented using the _with_sie version, passing
an empty sie)
pp_nonterm_with_sie m xd sie nt
as above, but any suffix item "Si_index i" is replaced by the i'th
element of the suffix index environment sie.
pp_nonterm_with_de_with_sie m xd sie de nt
as above, but first we lookup nt in the de2 component of de. If
it's not found, we revert to the above, otherwise (eg for an l'j
where there is a list l'1..l'n) we generate isa/coq code for a
projection from a List.nth of a list var. This is only defined for
Coq/Isa modes, not for Ascii/Tex modes.
Moreover, sometimes we pp pieces of a production directly, and
sometimes by synthesising a symterm and then pping that. In
particular, when we want to generate an Isa/Coq list variable (say
from a bindspec x1..xn) we do this.
All this should perhaps be rationalised...
*)
let pp_source_location m l =
let s = Location.pp_t_source l in
match m with
| Ascii _
| Tex _ -> Printf.sprintf "%% %s\n" s
| Coq _ | Isa _ | Hol _ | Lem _ | Twf _ | Caml _ -> Printf.sprintf "(* %s *)\n" s
| Lex _ | Menhir _ -> ""
(* utilities *********************************************************** *)
let list_append m = match m with | Lem _ | Hol _ -> " ++ " | _ -> " @ "
let pad n s =
let m = n - String.length s in
if m>=1 then s ^ String.make m ' ' else s
let pad2 n s s' =
let m = n - String.length s in
if m>=1 then s' ^ String.make m ' ' else s'
(* ASCII tokens ******************************************************** *)
(* NB THIS LEXICAL DATA MUST BE CONSISTENT WITH grammar_lexer.mll AND
THE ... IN lexicalgoo.ml *)
let pp_CCE = "::="
let pp_BAR = "|"
let pp_LEFTBRACE = "{"
let pp_RIGHTBRACE = "}"
let pp_RIGHTBRACEPLUS = "}+"
let pp_LEFTBRACKET = "["
let pp_RIGHTBRACKET = "]"
let pp_DOUBLELEFTBRACKET = "[["
let pp_DOUBLERIGHTBRACKET = "]]"
let pp_DOUBLELEFTBRACE = "{{"
let pp_DOUBLERIGHTBRACE = "}}"
let pp_COLONCOLON = "::"
let pp_LTCOLONCOLON = "<::"
let pp_UNDERSCORECOLONCOLON = "_::"
let pp_DOTDOT = ".."
let pp_DOTDOTDOT = "..."
let pp_DOTDOTDOTDOT = "...."
let pp_EMBED = "embed"
let pp_HOMS = "homs"
let pp_METAVAR = "metavar"
let pp_RULES = "grammar"
let pp_SUBRULES = "subrules" (* FZ CHECK *)
let pp_CONTEXTRULES = "contextrules" (* FZ CHECK *)
let pp_SUBSTITUTIONS = "substitutions" (* FZ CHECK *)
let pp_FREEVARS = "freevars" (* FZ CHECK *)
let pp_BY = "by"
let pp_DEFN = "Defn"
let pp_DEFNCLASS = "Defns"
let pp_FUNDEFN = "fun"
let pp_FUNDEFNCLASS = "funs"
let pp_BIND_LEFT_DELIM = "(+"
let pp_BIND_RIGHT_DELIM = "+)"
let pp_BIND = "bind"
let pp_IN = "in"
let pp_NAMES = "names"
let pp_DISTINCTNAMES = "distinctnames"
let pp_UNION = "union"
let pp_EQ = "="
let pp_HASH = "#"
let pp_LPAREN = "("
let pp_RPAREN = ")"
let pp_EMPTY = "{}"
let pp_COMP_LEFT = "</"
let pp_COMP_MIDDLE = "//"
let pp_COMP_RIGHT = "/>"
let pp_COMP_IN = "IN"
(* Lexicalgoo.listform and Grammar_pp.COMP_LEFT etc must be consistent *)
let quoted_tokens =
[ pp_CCE; pp_BAR;
(* for BNF options etc *)
(* pp_LEFTBRACE; pp_RIGHTBRACE; pp_LEFTBRACKET; *)
(* pp_RIGHTBRACKET; pp_DOUBLELEFTBRACKET; pp_DOUBLERIGHTBRACKET; *)
pp_DOUBLELEFTBRACE; pp_DOUBLERIGHTBRACE; pp_COLONCOLON; pp_DOTDOT;
pp_DOTDOTDOT; pp_DOTDOTDOTDOT; pp_METAVAR; pp_RULES; pp_BY; pp_DEFN;
pp_DEFNCLASS; pp_LTCOLONCOLON; pp_UNDERSCORECOLONCOLON; pp_SUBRULES;
pp_SUBSTITUTIONS; pp_FREEVARS; pp_EMBED; pp_HOMS; pp_BIND_LEFT_DELIM; "" (* ; "''" *) ]
let quote_ident s = if List.mem s quoted_tokens then "'"^s^"'" else s
(** pp raw grammars ***************************************************** *)
let rec
pp_raw_ident_desc s = s (*quote_ident s*)
and pp_raw_ident (_,s) = pp_raw_ident_desc s
and pp_raw_metavardefn mvd =
pp_METAVAR ^ " " ^ (String.concat " , "
(List.map
(function (n,homs)->
n
^ String.concat " " (List.map pp_raw_homomorphism homs))
mvd.raw_mvd_names)
) ^ " "
^ pp_CCE ^ " " ^ pp_raw_metavarrep mvd.raw_mvd_rep ^ "\n"
and pp_raw_metavarrep mvd_rep =
String.concat " " (List.map pp_raw_homomorphism mvd_rep)
and pp_raw_homomorphism (hn,hs,l) =
pp_DOUBLELEFTBRACE ^ " " ^ hn ^ " " ^ pp_raw_hom_spec hs ^ " "
^ pp_DOUBLERIGHTBRACE
and pp_raw_hom_spec hs =
String.concat " " (List.map pp_raw_hom_spec_el hs)
and pp_raw_hom_spec_el hse = match hse with
| Raw_hom_string s -> pp_raw_ident_desc s
| Raw_hom_blanks s -> pp_raw_ident_desc s
| Raw_hom_ident ris ->
pp_DOUBLELEFTBRACKET
^ String.concat " " (List.map pp_raw_ident ris)
^ pp_DOUBLERIGHTBRACKET
| Raw_hom_ident_dots (l,ris,n,ris') ->
pp_DOUBLELEFTBRACKET
^ String.concat " " (List.map pp_raw_ident ris)
^ pp_raw_dots n
^ String.concat " " (List.map pp_raw_ident ris')
^ pp_DOUBLERIGHTBRACKET
| Raw_hom_ident_comp (l,ris,rcb) ->
pp_DOUBLELEFTBRACKET ^" "
^ pp_COMP_LEFT
^ String.concat " " (List.map pp_raw_ident ris)
^ pp_COMP_MIDDLE
^ pp_raw_comp_bound rcb
^ pp_COMP_RIGHT ^" "
^ pp_DOUBLERIGHTBRACKET
and pp_raw_embedmorphism (l,hn,es) =
pp_DOUBLELEFTBRACE ^ " "
^ hn ^ " "
^ (pp_raw_embed_spec es) ^ " "
^ pp_DOUBLERIGHTBRACE
and pp_raw_embed_spec es =
String.concat "" (List.map (pp_raw_embed_spec_el ) es)
and pp_raw_embed_spec_el ese =
match ese with
| Embed_string (l,s) -> s
| Embed_inner (l,s) -> pp_DOUBLELEFTBRACKET^s^pp_DOUBLERIGHTBRACKET
and pp_raw_bindspec b =
match b with
| Raw_Bind (l,mse,ri) ->
pp_BIND^" " ^ pp_raw_mse mse ^ " "
^ pp_IN ^ " " ^ pp_raw_ident ri
| Raw_AuxFnDef (l,f,mse) ->
pp_raw_ident f ^ "" ^ pp_EQ ^ "" ^ pp_raw_mse mse
| Raw_NamesEqual (l,mse,mse') ->
pp_NAMES ^ "" ^ pp_LPAREN ^ "" ^ pp_raw_mse mse ^ "" ^ pp_RPAREN
^ "" ^ pp_EQ ^ "" ^ pp_NAMES ^ ""
^ pp_LPAREN ^ "" ^ pp_raw_mse mse' ^ "" ^ pp_RPAREN
| Raw_NamesDistinct (l,mse,mse') ->
pp_NAMES ^ "" ^ pp_LPAREN ^ "" ^ pp_raw_mse mse ^ "" ^ pp_RPAREN
^ "" ^ pp_HASH ^ "" ^ pp_NAMES ^ "" ^ pp_LPAREN ^ ""
^ pp_raw_mse mse' ^ "" ^ pp_RPAREN
| Raw_AllNamesDistinct (l,mse) ->
pp_DISTINCTNAMES ^ "" ^ pp_LPAREN ^ "" ^ pp_raw_mse mse
^ "" ^ pp_RPAREN
and pp_raw_bindspec_list bs =
match bs with
| [] -> ""
| [b] ->
pp_BIND_LEFT_DELIM ^ " "
^ (pp_raw_bindspec b) ^ " "
^ pp_BIND_RIGHT_DELIM
| bs ->
pp_BIND_LEFT_DELIM ^ " "
^ (String.concat
" "
(List.map (pp_raw_bindspec) bs))
^ " " ^ pp_BIND_RIGHT_DELIM
and pp_raw_mse mse =
match mse with
| Raw_MVorNTExp (l,ri) -> pp_raw_ident ri
| Raw_MVorNTListExp_dotform (l,ri1,n,ri2) -> pp_raw_ident ri1 ^ pp_raw_dots n ^ pp_raw_ident ri2
| Raw_MVorNTListExp_comp (l,ri,rcb) -> pp_COMP_LEFT ^ pp_raw_ident ri ^ pp_COMP_MIDDLE ^ pp_raw_comp_bound rcb ^ pp_COMP_RIGHT
| Raw_Aux(l,f,nt) ->
pp_raw_ident f ^ ""^pp_LPAREN ^ "" ^ pp_raw_ident nt ^ "" ^ pp_RPAREN
| Raw_AuxList_dotform(l,f,nt1,n,nt2) ->
pp_raw_ident f ^ ""^pp_LPAREN ^ "" ^ pp_raw_ident nt1 ^ "" ^pp_raw_dots n ^ pp_raw_ident nt2 ^ "" ^ pp_RPAREN
| Raw_AuxList_comp(l,f,nt,rcb) ->
pp_raw_ident f ^ ""^pp_LPAREN ^ "" ^ pp_COMP_LEFT ^ pp_raw_ident nt ^ pp_COMP_MIDDLE ^pp_raw_comp_bound rcb ^ pp_COMP_RIGHT ^ pp_RPAREN
| Raw_Union(l,mse,mse') ->
pp_raw_mse mse ^ " "^pp_UNION^" " ^ pp_raw_mse mse'
| Raw_Empty(l) ->
pp_EMPTY
and pp_raw_element e = match e with
| Raw_ident (_,ri) -> pp_raw_ident ri
| Raw_option (_,res) ->
pp_LEFTBRACKET ^ " " ^ String.concat " " (List.map pp_raw_element res)
^ " " ^ pp_RIGHTBRACKET
| Raw_list (_,res) ->
pp_LEFTBRACE^" " ^ String.concat " " (List.map pp_raw_element res)
^ " " ^ pp_RIGHTBRACE
| Raw_nelist (_,res) ->
pp_LEFTBRACE^" " ^ String.concat " " (List.map pp_raw_element res)
^ " " ^ pp_RIGHTBRACEPLUS
| Raw_sugaroption (_,re) ->
pp_DOUBLELEFTBRACKET^" "
^ (pp_raw_element re) ^ " "
^ pp_DOUBLERIGHTBRACKET
| Raw_dots (_,n) -> " " ^ pp_raw_dots n ^ " "
| Raw_comp(_,res,rcb,rio) ->
pp_COMP_LEFT^" "
^ String.concat " " (List.map pp_raw_element res)
^ pp_COMP_MIDDLE ^" "
^ (match rio with None -> "" | Some (_,tm) -> tm ^ pp_COMP_MIDDLE ^" ")
^ pp_raw_comp_bound rcb ^" "
^ pp_COMP_RIGHT
and pp_raw_comp_bound rcb = match rcb with
| Raw_bound_comp(l,ri) -> pp_raw_ident ri
| Raw_bound_comp_u(l,ri,ri_u) ->
pp_raw_ident ri ^" "
^ pp_COMP_IN ^" "
^ pp_raw_ident ri_u ^" "
| Raw_bound_comp_lu(l,ri,ri_l,n,ri_u) ->
pp_raw_ident ri ^" "
^ pp_COMP_IN ^" "
^ pp_raw_ident ri_l ^" "
^ pp_raw_dots n ^ " "
^ pp_raw_ident ri_u ^" "
and pp_raw_dots n =
match n with
| 0 -> pp_DOTDOT
| 1 -> pp_DOTDOTDOT
| 2 -> pp_DOTDOTDOTDOT
| _ -> Auxl.error None "internal: >2 in pp_raw_dots"
and pp_raw_prod p =
pad 60 ((match p.raw_prod_flavour with Bar -> pp_BAR)
^ " "
^ (String.concat " " (List.map pp_raw_element p.raw_prod_es )))
^ " " ^ pp_COLONCOLON ^ " "
^ pad 1 (String.concat " " (List.map pp_raw_ident p.raw_prod_categories))
^ " " ^ pp_COLONCOLON ^ " " ^ p.raw_prod_name
^ " " ^ pp_raw_bindspec_list p.raw_prod_bs
^ " " ^ (String.concat " " (List.map pp_raw_homomorphism p.raw_prod_homs))
and pp_raw_rule r =
(String.concat " , " (List.map
(function (n,homs)->
n
^ String.concat " " (List.map pp_raw_homomorphism homs))
r.raw_rule_ntr_names))
^ " " ^ pp_COLONCOLON ^ " " ^ pp_raw_ident_desc r.raw_rule_pn_wrapper
^ " " ^ pp_CCE
^ String.concat " " (List.map pp_raw_homomorphism r.raw_rule_homs)
^ "\n" ^ " "
^ String.concat " "
(List.map (fun rp -> pp_raw_prod rp ^ "\n") r.raw_rule_ps)
and pp_raw_subrule sr =
pp_raw_ident_desc sr.raw_sr_lower ^ " " ^ pp_LTCOLONCOLON ^ " "
^ pp_raw_ident_desc sr.raw_sr_upper ^ " "
^ String.concat " " (List.map pp_raw_homomorphism sr.raw_sr_homs)
and pp_raw_contextrule cr =
pp_raw_ident_desc cr.raw_cr_ntr ^ " " ^ pp_UNDERSCORECOLONCOLON ^ " "
^ pp_raw_ident_desc cr.raw_cr_target ^ " " ^ " " ^ pp_COLONCOLON ^ " "
^ pp_raw_ident_desc cr.raw_cr_hole ^ " "
^ String.concat " " (List.map pp_raw_homomorphism cr.raw_cr_homs)
and pp_raw_subst sb =
pp_raw_ident_desc sb.raw_sb_name ^ " "
^ pp_raw_ident_desc sb.raw_sb_this ^ " "
^ pp_raw_ident_desc sb.raw_sb_that
^ String.concat " " (List.map pp_raw_homomorphism sb.raw_sb_homs)
and pp_raw_freevar fv =
pp_raw_ident_desc fv.raw_fv_name ^ " "
^ pp_raw_ident_desc fv.raw_fv_this ^ " "
^ pp_raw_ident_desc fv.raw_fv_that
^ String.concat " " (List.map pp_raw_homomorphism fv.raw_fv_homs)
and pp_raw_item ri =
match ri with
| Raw_item_md raw_md -> pp_raw_metavardefn raw_md
| Raw_item_rs raw_rs -> pp_RULES ^ "\n"
^ String.concat "\n" (List.map pp_raw_rule raw_rs)
| Raw_item_dcs raw_dcs -> pp_raw_fun_or_reln_defnclass raw_dcs
| Raw_item_srs raw_srs -> pp_SUBRULES ^ "\n"
^ String.concat "\n" (List.map pp_raw_subrule raw_srs)
| Raw_item_crs raw_crs -> pp_CONTEXTRULES ^ "\n"
^ String.concat "\n" (List.map pp_raw_contextrule raw_crs)
| Raw_item_sbs raw_sbs -> pp_SUBSTITUTIONS ^ "\n"
^ String.concat "\n" (List.map pp_raw_subst raw_sbs)
| Raw_item_fvs raw_fvs -> pp_FREEVARS ^ "\n"
^ String.concat "\n" (List.map pp_raw_freevar raw_fvs)
| Raw_item_embed raw_embeds -> pp_EMBED ^ "\n"
^ String.concat "\n" (List.map pp_raw_embedmorphism raw_embeds)
^ "\n"
| Raw_item_pas raw_pas -> "TODO: raw parsing annotation"
| Raw_item_hs raw_hs -> "TODO: raw hom section"
| Raw_item_coq_variable _ -> "TODO: coq variable"
| Raw_item_coq_section _ -> "TODO: coq section"
and pp_raw_syntaxdef xd =
String.concat "" (List.map pp_raw_metavardefn xd.raw_sd_mds)
^ ( match xd.raw_sd_rs with
[] -> ""
| rrs -> pp_RULES ^ "\n"
^ String.concat "\n" (List.map pp_raw_rule xd.raw_sd_rs) )
^ "\n"
^ ( match xd.raw_sd_srs with
[] -> ""
| srs -> pp_SUBRULES ^ "\n"
^ String.concat "\n" (List.map pp_raw_subrule xd.raw_sd_srs) )
^ "\n"
^ ( match xd.raw_sd_crs with
[] -> ""
| crs -> pp_CONTEXTRULES ^ "\n"
^ String.concat "\n" (List.map pp_raw_contextrule xd.raw_sd_crs) )
^ "\n"
^ ( match xd.raw_sd_sbs with
[] -> ""
| sbs -> pp_SUBSTITUTIONS ^ "\n"
^ String.concat "\n" (List.map pp_raw_subst xd.raw_sd_sbs) )
^ "\n"
^ ( match xd.raw_sd_fvs with
[] -> ""
| fvs -> pp_FREEVARS ^ "\n"
^ String.concat "\n" (List.map pp_raw_freevar xd.raw_sd_fvs) )
^ "\n"
^ ( match xd.raw_sd_embed with
[] -> ""
| _ ->
pp_EMBED ^ "\n"
^ String.concat "\n" (List.map pp_raw_embedmorphism xd.raw_sd_embed)
^ "\n" )
^ String.concat "\n" (List.map pp_raw_fun_or_reln_defnclass xd.raw_sd_dcs)
^ "\n"
(* ^ ( match xd.raw_sd_embed_postamble with *)
(* [] -> "" *)
(* | _ -> *)
(* pp_EMBED ^ "\n" *)
(* ^ String.concat "\n" (List.map pp_raw_embedmorphism xd.raw_sd_embed_postamble) *)
(* ^ "\n" ) *)
^ "\n"
and pp_raw_line x = match x with
| Raw_line (_,s) -> s
| Raw_lineline (_,s1,s2) -> s1 ^ s2
| Raw_blankline (_,s) -> "\n"
| Raw_commentline (_,s) -> "%\n"
and pp_raw_defnclass dc =
pp_DEFNCLASS ^ "\n" ^ dc.raw_dc_name ^ " " ^ pp_COLONCOLON ^ " "
^ pp_raw_ident_desc dc.raw_dc_wrapper ^ " " ^ pp_CCE ^ "\n\n"
^ String.concat "\n" (List.map pp_raw_defn dc.raw_dc_defns)
and pp_raw_defn d =
pp_DEFN ^ "\n"
^ (String.concat " " (List.map pp_raw_element d.raw_d_es))
^ " " ^ pp_COLONCOLON ^ " "
^ pad 1 (String.concat " " (List.map pp_raw_ident d.raw_d_categories))
^ " " ^ pp_COLONCOLON ^ " " ^ pp_raw_ident_desc d.raw_d_name ^ " "
^ " " ^ pp_COLONCOLON ^ " " ^ pp_raw_ident_desc d.raw_d_wrapper ^ " "
^ String.concat " " (List.map pp_raw_homomorphism d.raw_d_homs)
^ pp_BY ^ "\n\n" ^ (String.concat "\n" (List.map (* pp_raw_line*) pp_semiraw_rule d.raw_d_body))
and pp_raw_fundefnclass fdc =
pp_FUNDEFNCLASS ^ "\n" ^ fdc.raw_fdc_name ^ " " ^ pp_CCE ^ "\n\n "
(* ^ pp_raw_ident_desc fdc.raw_fdc_wrapper ^ " " ^ pp_CCE ^ "\n\n" *)
^ String.concat "\n" (List.map pp_raw_fundefn fdc.raw_fdc_fundefns)
and pp_raw_fundefn fd =
pp_FUNDEFN ^ "\n"
^ (String.concat " " (List.map pp_raw_element fd.raw_fd_es))
^ " " ^ pp_COLONCOLON ^ " "
^ (pp_raw_ident fd.raw_fd_result)
^ " // " ^fd.raw_fd_pn_wrapper ^ " "
(* ^ pad 1 (String.concat " " (List.map pp_raw_ident d.raw_d_categories)) *)
^ " " ^ pp_COLONCOLON ^ " " ^ pp_raw_ident_desc fd.raw_fd_name ^ " "
(* ^ " " ^ pp_COLONCOLON ^ " " ^ pp_raw_ident_desc fd.raw_fd_wrapper ^ " "*)
^ String.concat " " (List.map pp_raw_homomorphism fd.raw_fd_homs)
^ pp_BY ^ "\n\n" ^ (String.concat "\n" (List.map (* pp_raw_line*) pp_raw_funclause fd.raw_fd_clauses))
and pp_raw_funclause (l,s) = s
and pp_raw_fun_or_reln_defnclass rfrdc =
match rfrdc with
| Raw_FDC rfdc -> pp_raw_fundefnclass rfdc
| Raw_RDC rdc -> pp_raw_defnclass rdc
and pp_semiraw_rule = function
| Lineless_rule (l,lss) ->
"[[\n"
^ (String.concat "" (List.map (function (l,s) -> "| "^s^"\n") lss))
^ "]]\n"
| Lined_rule (l,lss1,ls,lss2) ->
"[[\n"
^ (String.concat "" (List.map (function (l,s) -> "| "^s^"\n") lss1))
^ "---------------"
^ snd ls
^ (String.concat "" (List.map (function (l,s) -> "| "^s^"\n") lss2))
^ "]]\n"
| Defncom (l,es) ->
"[[\n"
^ pp_raw_embed_spec es
^ "]]\n"
(** make a canonical symterm from a production *)
(* TODO: for now this assumes that each production uses nonterminals *)
(* affinely, and that the pp_symterm prints them in the most obvious way *)
(* TODO: the following assumes that no name clashes will be introduced in a *)
(* production by mapping all primary ntrs to secondary ntrs, where they *)
(* exist. This is not true in general *)
(* let si_indexes_of_suff suff = List.filter (function suffi -> match suffi with *)
(* | Si_num _ -> false *)
(* | Si_punct _ -> false *)
(* | Si_var (_,_) -> false *)
(* | Si_index _ -> true) suff *)
(* let secondary_mvr m xd mvrp mvr = *)
(* if mvr=mvrp then *)
(* let mvd = Auxl.mvd_of_mvr xd mvr in *)
(* (match m with *)
(* | Coq _ | Hol _ | Isa _ -> *)
(* (match mvd.mvd_names with *)
(* | [] -> failwith "internal error: empty list of mvd names" *)
(* | [_] ->mvr *)
(* | mvrp'::mvrq'::_ -> fst mvrq') *)
(* | Ascii _ | Tex _ -> mvr) *)
(* else *)
(* mvr *)
(* let new_suff suff suff'' = *)
(* let suff1 = si_indexes_of_suff suff in *)
(* if suff1 = [] then suff'' else suff1 @ [Si_punct "_"] @ suff'' *)
(* let rec canonical_symterm_element_of_element' m xd nts_mapping mvs_mapping e *)
(* = match e with *)
(* | Lang_nonterm (ntrp,((ntr,suff) as nt)) -> *)
(* let nt'' = *)
(* (match m with *)
(* | Ascii _ | Tex _ (\*-> (ntr,suff) *\) *)
(* | Coq _ | Hol _ | Isa _ -> *)
(* let ntr' = secondary_ntr m xd ntrp ntr in *)
(* let nt' = ntr',suff in *)
(* let (_,suff'') = Auxl.fresh_nt (List.map snd !nts_mapping) ntr' in *)
(* (ntr',new_suff suff suff'')) in *)
(* nts_mapping := (nt,nt'') :: !nts_mapping; *)
(* Some(Ste_st(dummy_loc,St_nonterm(dummy_loc,ntrp,nt''))) *)
(* | Lang_metavar (mvrp,((mvr,suff)as mv)) -> *)
(* let mv'' = *)
(* (match m with *)
(* | Ascii _ | Tex _ (\*-> (mvr,suff) *\) *)
(* | Coq _ | Hol _ | Isa _ -> *)
(* let mvr' = secondary_mvr m xd mvrp mvr in *)
(* let mv' = mvr',suff in *)
(* let (_,suff'') = Auxl.fresh_mv (List.map snd !mvs_mapping) mvr' in *)
(* (mvr',new_suff suff suff'')) in *)
(* mvs_mapping := (mv,mv'') :: !mvs_mapping; *)
(* Some (Ste_metavar(dummy_loc,mvrp,mv'')) *)
(* | Lang_terminal _ -> *)
(* None *)
(* | Lang_list elb -> *)
(* let b = (match elb.elb_boundo with *)
(* | None -> Bound_dotform *)
(* {bd_lower=Si_var ("",0);bd_upper=Si_var ("",0);bd_length=2} *)
(* (\* above we invent null index variables. This is ok for tex pp *\) *)
(* (\* of the canonical symterm of a production, which should be *\) *)
(* (\* the only case where it occurs *\) *)
(* (\* raise (Invalid_argument "canonical_symterm_element_of_element no bounds") *\) *)
(* | Some b ->b) in *)
(* Some (Ste_list *)
(* (dummy_loc, *)
(* [Stli_listform {stl_bound = b; *)
(* stl_elements = Auxl.option_map *)
(* (canonical_symterm_element_of_element' m xd nts_mapping mvs_mapping) *)
(* elb.elb_es; *)
(* stl_loc = dummy_loc}])) *)
(* | (Lang_option _ | Lang_sugaroption _)-> *)
(* raise (Invalid_argument *)
(* "canonical_symterm_element_of_element option cases not implemented") *)
(* let canonical_symterm_node_body_of_prod' m xd nts_mapping mvs_mapping ntr p = *)
(* { st_rule_ntr_name = ntr; *)
(* st_prod_name = p.prod_name; *)
(* st_es = Auxl.option_map *)
(* (canonical_symterm_element_of_element' m xd nts_mapping mvs_mapping) *)
(* p.prod_es; *)
(* st_loc = dummy_loc } *)
(* let canonical_symterm_element_of_element m xd e = *)
(* let nts_mapping,mvs_mapping = ref ([]:(nonterm *nonterm) list),ref ([]:(metavar * metavar) list) in *)
(* let ste = canonical_symterm_element_of_element' m xd nts_mapping mvs_mapping e in *)
(* (ste,(!nts_mapping,!mvs_mapping)) *)
(* let canonical_symterm_node_body_of_prod m xd ntr p = *)
(* let nts_mapping,mvs_mapping = ref ([]:(nonterm *nonterm) list),ref ([]:(metavar * metavar) list) in *)
(* let stnb = canonical_symterm_node_body_of_prod' m xd nts_mapping mvs_mapping ntr p in *)
(* (stnb,(!nts_mapping,!mvs_mapping)) *)
(* the vanilla canonical symterms, without secondarification or freshening *)
let rec canonical_symterm_element_of_element e
= match e with
| Lang_nonterm (ntrp,((ntr,suff) as nt)) ->
Some(Ste_st(dummy_loc,St_nonterm(dummy_loc,ntrp,nt)))
| Lang_metavar (mvrp,((mvr,suff)as mv)) ->
Some (Ste_metavar(dummy_loc,mvrp,mv))
| Lang_terminal _ ->
None
| Lang_list elb ->
let b = (match elb.elb_boundo with
| None -> Bound_dotform
{bd_lower=Si_var ("",0);bd_upper=Si_var ("",0);bd_length=2}
(* above we invent null index variables. This is ok for tex pp *)
(* of the canonical symterm of a production, which should be *)
(* the only case where it occurs *)
(* raise (Invalid_argument "canonical_symterm_element_of_element no bounds") *)
| Some b ->b) in
Some (Ste_list
(dummy_loc,
[Stli_listform {stl_bound = b;
stl_elements = Auxl.option_map
(canonical_symterm_element_of_element)
elb.elb_es;
stl_loc = dummy_loc}]))
| (Lang_option _ | Lang_sugaroption _)->
raise (Invalid_argument
"canonical_symterm_element_of_element option cases not implemented")
let canonical_symterm_node_body_of_prod ntr p =
{ st_rule_ntr_name = ntr;
st_prod_name = p.prod_name;
st_es = Auxl.option_map
(canonical_symterm_element_of_element)
p.prod_es;
st_loc = dummy_loc }
(** pp grammars ********************************************************* *)
(* colour definitions ************************************************** *)
let black = 0
let red = 1
let green = 2
let yellow = 3
let blue = 4
let magenta = 5
let cyan = 6
let white = 7
let _reset = "\x1b[0m"
let _color fg br = Printf.sprintf "\x1b[%u;%um" br (fg+30)
let _w = "\x1b[0;1;4m"
let _r = _color red 0
let _b = _color blue 0 (* was blue 1 *)
let _g = _color green 0
let col_wrap opt col s = if opt.ppa_colour then col ^ s ^ _reset else s
let col_red ao s = col_wrap ao _r s
let col_black ao s = col_wrap ao _b s
let col_green ao s = col_wrap ao _g s
let col_yellow ao s = col_wrap ao (_color yellow 0) s
let col_blue ao s = col_wrap ao (_color blue 0) s
let col_magenta ao s = col_wrap ao (_color magenta 0) s
let col_cyan ao s = col_wrap ao (_color cyan 0) s
let col_white ao s = col_wrap ao (_color white 0) s
(* TeX tokens ********************************************************** *)
let classify_TTC_terminal s = if Auxl.is_alpha s then TTC_terminal_alpha else TTC_terminal_symb
let index_of_ttc ttc = match ttc with
| TTC_terminal_alpha -> 0
| TTC_terminal_symb -> 1
| TTC_nonterm_or_metavar -> 2
| TTC_space -> 3
| TTC_dots -> 4
| TTC_comp -> 5
| TTC_dummy -> raise ThisCannotHappen
let spacing_data : string array array =
let s = "\\," in
let no = "" in
[|
(* left right: terminal_alpha terminal_symb nonterm_or_metavar space dots comp *)
(*terminal_alpha *)[| s ; s ; s ; no ; s ; s |];
(*terminal_symb *)[| s ; no ; no ; no ; s ; s |];
(*nonterm_or_metavar*)[| s ; no ; s ; no ; s ; s |];
(*space *)[| no ; no ; no ; no ; no ; no |];
(*dots *)[| s ; s ; s ; no ; s ; s |];
(*comp *)[| s ; s ; s ; no ; s ; s |] |]
let spacing_data_debug : string array array =
[|
(* left right: terminal_alpha terminal_symb nonterm_or_metavar space dots comp *)
(*terminal_alpha *)[| "AA" ; "AS" ; "AN" ;"AW" ;"AD";"AC"|];
(*terminal_symb *)[| "SA" ; "SS" ; "SN" ;"SW" ;"SD";"SC"|];
(*nonterm_or_metavar*)[| "NA" ; "NS" ; "NN" ;"NW" ;"ND";"NC"|];
(*space *)[| "WA" ; "WS" ; "WN" ;"WW" ;"WD";"WC"|];
(*dots *)[| "DA" ; "DS" ; "DN" ;"DW" ;"DD";"DC"|];
(*comp *)[| "CA" ; "CS" ; "CN" ;"CW" ;"CD";"CC"|] |]
let pairwise_spacing ttc ttc' = spacing_data.(index_of_ttc ttc).(index_of_ttc ttc')
let rec pp_tex_insert_spacing (es:(string*tex_token_category) list) : string
=
match es with
| [] -> ""
| (s,ttc)::[] -> s
| (s,ttc)::(((s',ttc')::_) as es') -> s ^ " "^ pairwise_spacing ttc ttc' ^ " "^pp_tex_insert_spacing es'
let pp_tex_BAR = "|"
let pp_tex_LEFTBRACKET = "["
let pp_tex_RIGHTBRACKET = "]"
let pp_tex_BIND = "\\textsf{bind}"
let pp_tex_IN = "\\textsf{in}"
let pp_tex_EQ = "="
let pp_tex_NAMES = "\\textsf{names}"
let pp_tex_LPAREN = "("
let pp_tex_RPAREN = ")"
let pp_tex_HASH = "\\#"
let pp_tex_DISTINCTNAMES = "\\textsf{distinctnames}"
let pp_tex_EMPTY = "\\{\\}"
let pp_tex_UNION = "\\cup "
(* let pp_tex_BEGIN_RULES = "\\[\n\\begin{array}{llclllll}\n" *)
(* let pp_tex_END_RULES = "\\end{array}\n\\]\n" *)
(* let pp_tex_COMP = "\\widetilde{"*)
(* let pp_tex_COMP = "\\widehat{" *)
(* let pp_tex_COMP = "\\overrightarrow{" *)
(* let pp_tex_BIND_LEFT_DELIM = "" *)
(* let pp_tex_BIND_RIGHT_DELIM = "" *)
let pp_tex_DOTDOT = ".."
let pp_tex_DOTDOTDOT = "..."
let pp_tex_DOTDOTDOTDOT = "...."
let pp_tex_NAME_PREFIX m =
match m with
| Tex xo -> xo.ppt_name_prefix
| _ -> Auxl.error None "internal: pp_tex_NAME_PREFIX"
let pp_tex_METAVARS_NAME m = "\\"^pp_tex_NAME_PREFIX m^"metavars"
let pp_tex_RULES_NAME m = "\\"^pp_tex_NAME_PREFIX m^"grammar"
let pp_tex_DEFNSS_NAME m = "\\"^pp_tex_NAME_PREFIX m^"defnss"
let pp_tex_ALL_NAME m = "\\"^pp_tex_NAME_PREFIX m^"all"
let pp_tex_RULEHEAD_NAME m = "\\"^pp_tex_NAME_PREFIX m^"rulehead"
let pp_tex_PROD_NAME m = "\\"^pp_tex_NAME_PREFIX m^"prodline"
let pp_tex_LONG_PROD_NAME m = "\\"^pp_tex_NAME_PREFIX m^"longprodline"
let pp_tex_BINDSPEC_PROD_NAME m = "\\"^pp_tex_NAME_PREFIX m^"bindspecprodline"
let pp_tex_FIRST_LONG_PROD_NAME m = "\\"^pp_tex_NAME_PREFIX m^"firstlongprodline"
let pp_tex_FIRST_PROD_NAME m = "\\"^pp_tex_NAME_PREFIX m^"firstprodline"
let pp_tex_PROD_NEWLINE_NAME m = "\\"^pp_tex_NAME_PREFIX m^"prodnewline"
let pp_tex_INTERRULE_NAME m = "\\"^pp_tex_NAME_PREFIX m^"interrule"
let pp_tex_AFTERLASTRULE_NAME m = "\\"^pp_tex_NAME_PREFIX m^"afterlastrule"
let pp_tex_BEGIN_RULES m = "\\"^pp_tex_NAME_PREFIX m^"grammartabular{\n"
let pp_tex_END_RULES = "}"
let pp_tex_BEGIN_METAVARS m = "\\"^pp_tex_NAME_PREFIX m^"metavartabular{\n"
let pp_tex_END_METAVARS = "}"
let pp_tex_DRULE_NAME m = "\\"^pp_tex_NAME_PREFIX m^"drule"
let pp_tex_DRULE_NAME_NAME m = "\\"^pp_tex_NAME_PREFIX m^"drulename"
let pp_tex_USE_DRULE_NAME m = "\\"^pp_tex_NAME_PREFIX m^"usedrule"
let pp_tex_PREMISE_NAME m = "\\"^pp_tex_NAME_PREFIX m^"premise"
let pp_tex_DEFN_BLOCK_NAME m = pp_tex_NAME_PREFIX m^"defnblock"
let pp_tex_FUNCLAUSE_NAME m = "\\"^pp_tex_NAME_PREFIX m^"funclause"
let pp_tex_FUNDEFN_BLOCK_NAME m = pp_tex_NAME_PREFIX m^"fundefnblock"
let pp_tex_NT_NAME m = "\\"^pp_tex_NAME_PREFIX m^"nt"
let pp_tex_MV_NAME m = "\\"^pp_tex_NAME_PREFIX m^"mv"
let pp_tex_KW_NAME m = "\\"^pp_tex_NAME_PREFIX m^"kw"
let pp_tex_SYM_NAME m = "\\"^pp_tex_NAME_PREFIX m^"sym"
let pp_tex_COM_NAME m = "\\"^pp_tex_NAME_PREFIX m^"com"
let pp_tex_COMP_NAME m = "\\"^pp_tex_NAME_PREFIX m^"comp"
let pp_tex_COMP_U_NAME m = "\\"^pp_tex_NAME_PREFIX m^"compu"
let pp_tex_COMP_LU_NAME m = "\\"^pp_tex_NAME_PREFIX m^"complu"
(* Note: as a hack, we represent unicode characters as base16 shifted forward by 16, i.e. 0, 1, 2,
3, 4, 5, 6, 7, 8, 9, 10, a, b, c, d, e, f become g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v*)
let utf8_tex_escape c =
if c <= 255 then
match char_of_int c with
| '_' ->"XX"
| '#' -> "YY"
| '\'' -> "PP"
| '0' -> "Zero"
| '1' -> "One"
| '2' -> "Two"
| '3' -> "Three"
| '4' -> "Four"
| '5' -> "Five"
| '6' -> "Six"
| '7' -> "Seven"
| '8' -> "Eight"
| '9' -> "Nine"
| c -> String.make 1 c
else
let rec shex s c =
let d = c mod 16 in
let c = c / 16 in
let s = (String.make 1 (char_of_int ((int_of_char 'g') + d))) ^ s in
if c = 0 then s else shex s c
in
shex "" c
let rec tex_command_escape s =
String.concat "" (List.map utf8_tex_escape (Auxl.utf8_cp_list_of_string s))
and tex_rule_name m ntr = "\\"^pp_tex_NAME_PREFIX m^tex_command_escape ntr
and tex_drule_name m s = "\\"^pp_tex_NAME_PREFIX m^"drule"^tex_command_escape s
and tex_defn_name m wrapper s = "\\"^pp_tex_NAME_PREFIX m^"defn"^tex_command_escape (wrapper^s)
and tex_defnclass_name m s = "\\"^pp_tex_NAME_PREFIX m^"defns"^tex_command_escape s
and tex_fundefn_name m s = "\\"^pp_tex_NAME_PREFIX m^"fundefn"^tex_command_escape s
and tex_fundefnclass_name m s = "\\"^pp_tex_NAME_PREFIX m^"fundefns"^tex_command_escape s
and pp_tex_terminal m xd tm =
try (* firstcheck if this terminal is defined in the terminalsproduction *)
let term_rule = Auxl.rule_of_ntr xd "terminals" in
let hom_list = (* FZ define aux function for this *)
(List.find (fun p -> (List.hd p.prod_es) = (Lang_terminal tm))
term_rule.rule_ps).prod_homs in
let hom = List.assoc "tex" hom_list in
pp_hom_spec m xd hom
with Not_found -> (* otherwise, standard behaviour *)
let es = Auxl.pp_tex_escape tm in
if (*(String.length es > 1) ||*) (Auxl.is_alpha tm)
then pp_tex_KW_NAME m ^ "{"^es^"}" else pp_tex_SYM_NAME m ^"{"^es ^"}"
and pp_isa_terminal m xd tm =
try (* firstcheck if this terminal is defined in the terminalsproduction *)
let term_rule = Auxl.rule_of_ntr xd "terminals" in
let hom_list = (* FZ define aux function for this *)
(List.find (fun p -> (List.hd p.prod_es) = (Lang_terminal tm))
term_rule.rule_ps).prod_homs in
let hom = List.assoc "isa" hom_list in
pp_hom_spec m xd hom
with Not_found -> (* otherwise, standard behaviour *)
tm
(* template *)
(* ( *)
(* match m with *)
(* Ascii ao -> *)
(* | Tex xo -> *)
(* | Coq co -> *)
(* | Isa io -> *)
(* match m with *)
(* Ascii _ -> *)
(* | Tex _ -> *)
(* | Coq _ -> *)
(* | Isa _ -> *)
and pp_plain_dots n =
( match n with
| 0 -> pp_DOTDOT
| 1 -> pp_DOTDOTDOT
| 2 -> pp_DOTDOTDOTDOT
| _ -> raise ThisCannotHappen )
and pp_dots m xd n =
match m with
| Ascii ao ->
( match n with
| 0 -> pp_DOTDOT
| 1 -> pp_DOTDOTDOT
| 2 -> pp_DOTDOTDOTDOT
| _ -> raise ThisCannotHappen )
| Tex xo ->
( match n with
| 0 -> pp_tex_DOTDOT
| 1 -> pp_tex_DOTDOTDOT
| 2 -> pp_tex_DOTDOTDOTDOT
| _ -> raise ThisCannotHappen )
| Caml _ | Hol _ | Lem _ | Isa _ | Coq _ | Twf _ | Lex _ | Menhir _ ->
raise ThisCannotHappen
and pp_uninterpreted m xd s =
match m with
| Ascii ao -> col_cyan ao ("(*"^s^"*)")
| Caml _ | Coq _ | Isa _ | Hol _ | Lem _ | Lex _ | Menhir _ -> "(*"^s^"*)"
| Twf _ -> "%{"^s^"}%"
| Tex _ ->
let es = Auxl.pp_tex_escape s in
if (String.length es > 1) || (Auxl.is_alpha es)
then "\\mathbf{"^es^"}" else es (* FZ mathbf should be COLOR *)
and pp_maybe_quote_ident m xd s =
match m with
| Ascii ao -> quote_ident s
| Tex _ | Coq _ | Isa _ | Hol _ | Lem _ | Twf _ | Caml _ | Lex _ | Menhir _ -> s
and pp_prod_flavour m xd pf =
match m with
| Ascii _ -> pp_BAR
| Tex _ -> pp_tex_BAR
| Coq _ | Isa _ | Hol _ | Lem _ | Twf _ | Caml _ | Lex _ | Menhir _ -> raise ThisCannotHappen
and pp_plain_terminal tm = tm
and pp_terminal m xd tm =
match m with
| Ascii ao -> col_green ao (quote_ident tm)
| Tex _ -> pp_tex_terminal m xd tm
| Coq _ -> tm
| Isa _ -> pp_isa_terminal m xd tm
| Hol _ -> tm
| Lem _ -> tm
| Twf _ -> tm
| Caml _ -> "_" (* tm *)
| Lex _ | Menhir _ -> tm
and pp_terminal_unquoted m xd tm =
match m with
| Ascii ao -> col_green ao tm
| Tex _ -> pp_tex_terminal m xd tm
| Coq _ -> tm
| Isa _ -> pp_isa_terminal m xd tm
| Hol _ -> tm
| Lem _ -> tm
| Twf _ -> tm
| Caml _ -> "_" (* tm *)
| Lex _ | Menhir _ -> tm
and pp_lang_name m xd ln = ln
and pp_plain_nontermroot ntr = ntr
and pp_plain_metavarroot mvr = mvr
and pp_plain_nonterm (ntr,suff) = ntr^pp_plain_suffix suff
and pp_plain_metavar (mvr,suff) = mvr^pp_plain_suffix suff
and pp_plain_nt_or_mv (ntmvr,suff) =
match ntmvr with
| Ntr ntr -> pp_plain_nonterm (ntr,suff)
| Mvr mvr -> pp_plain_metavar (mvr,suff)
and pp_plain_nt_or_mv_root ntmvr =
match ntmvr with
| Ntr ntr -> ntr
| Mvr mvr -> mvr
and pp_plain_nt_or_mv_root_option ntmvro =
match ntmvro with
| None -> "None"
| Some ntmvr -> "Some("^pp_plain_nt_or_mv_root ntmvr^")"
and pp_plain_hom_spec_el hse =
match hse with
| Hom_string s -> "Hom_string "^s
| Hom_index i -> "Hom_index "^(string_of_int i)
| Hom_terminal t -> "Hom_terminal "^(pp_plain_terminal t)
| Hom_ln_free_index _ -> "Hom_ln_free_index"
and pp_plain_hom_spec hs =
String.concat ";" (List.map pp_plain_hom_spec_el hs)
and capitalize_if_twelf_non_type as_type m s =
match m,as_type with
| Twf _,false -> String.capitalize_ascii s
| _,_ -> s
and pp_pseudo_hom_spec_el hse =
match hse with
| Hom_string s -> s
| Hom_terminal tm -> tm
| _ -> Auxl.int_error ("nontermroot hom contains "^pp_plain_hom_spec_el hse)
and pp_nonterm_with_sie_internal as_type m xd sie (ntr,suff) =
let pp_hom_spec hs =
String.concat "" (List.map pp_pseudo_hom_spec_el hs) in
(* ("<<< "^pp_plain_nonterm (ntr,suff)^" "^string_of_int (List.length sie)^">>>"); *)
let r = Auxl.rule_of_ntr xd (Auxl.primary_ntr_of_ntr xd ntr) in
(* per P. request, special treatment when printing a nt for which there is a phantom and a tp hom as a type *)
let hr = try (Some (List.assoc (Auxl.hom_name_for_pp_mode m) r.rule_homs)) with Not_found -> None in