| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
open Util |
| 12 |
open Pp |
| 13 |
open Genarg |
| 14 |
open Locus |
| 15 |
|
| 16 |
let beautify_comments = ref [] |
| 17 |
|
| 18 |
let rec split_comments comacc acc pos = function |
| 19 |
| [] -> beautify_comments := List.rev acc; comacc |
| 20 |
| ((b,e),c as com)::coms -> |
| 21 |
|
| 22 |
|
| 23 |
if e<=pos || pos=b then split_comments (c::comacc) acc pos coms |
| 24 |
else split_comments comacc (com::acc) pos coms |
| 25 |
|
| 26 |
let extract_comments pos = split_comments [] [] pos !beautify_comments |
| 27 |
|
| 28 |
let pr_located pr (loc, x) = |
| 29 |
match loc with |
| 30 |
| Some loc when !Flags.beautify -> |
| 31 |
let (b, e) = Loc.unloc loc in |
| 32 |
|
| 33 |
let before = Pp.comment (extract_comments b) in |
| 34 |
let x = pr x in |
| 35 |
let after = Pp.comment (extract_comments e) in |
| 36 |
before ++ x ++ after |
| 37 |
| _ -> pr x |
| 38 |
|
| 39 |
let pr_ast pr { CAst.loc; v } = pr_located pr (loc, v) |
| 40 |
|
| 41 |
let pr_lident lid = pr_ast Names.Id.print lid |
| 42 |
|
| 43 |
let pr_lname lna = pr_ast Names.Name.print lna |
| 44 |
|
| 45 |
let pr_or_var pr = function |
| 46 |
| ArgArg x -> pr x |
| 47 |
| ArgVar id -> pr_lident id |
| 48 |
|
| 49 |
let pr_or_by_notation f = let open Constrexpr in CAst.with_val (function |
| 50 |
| AN v -> f v |
| 51 |
| ByNotation (s,sc) -> qs s ++ pr_opt (fun sc -> str "%" ++ str sc) sc) |
| 52 |
|
| 53 |
let hov_if_not_empty n p = if Pp.ismt p then p else hov n p |
| 54 |
|
| 55 |
let rec pr_raw_generic env sigma ?level (GenArg (Rawwit wit, x)) = |
| 56 |
match wit with |
| 57 |
| ListArg wit -> |
| 58 |
let map x = pr_raw_generic env sigma ?level (in_gen (rawwit wit) x) in |
| 59 |
let ans = pr_sequence map x in |
| 60 |
hov_if_not_empty 0 ans |
| 61 |
| OptArg wit -> |
| 62 |
let ans = match x with |
| 63 |
| None -> mt () |
| 64 |
| Some x -> pr_raw_generic env sigma ?level (in_gen (rawwit wit) x) |
| 65 |
in |
| 66 |
hov_if_not_empty 0 ans |
| 67 |
| PairArg (wit1, wit2) -> |
| 68 |
let p, q = x in |
| 69 |
let p = in_gen (rawwit wit1) p in |
| 70 |
let q = in_gen (rawwit wit2) q in |
| 71 |
hov_if_not_empty 0 (pr_sequence (pr_raw_generic env sigma ?level) [p; q]) |
| 72 |
| ExtraArg s -> |
| 73 |
let open Genprint in |
| 74 |
match generic_raw_print (in_gen (rawwit wit) x) with |
| 75 |
| PrinterBasic pp -> pp env sigma |
| 76 |
| PrinterNeedsLevel { default_already_surrounded; printer } -> |
| 77 |
let level = Option.default default_already_surrounded level in |
| 78 |
printer env sigma level |
| 79 |
|
| 80 |
|
| 81 |
let rec pr_glb_generic env sigma ?level (GenArg (Glbwit wit, x)) = |
| 82 |
match wit with |
| 83 |
| ListArg wit -> |
| 84 |
let map x = pr_glb_generic env sigma ?level (in_gen (glbwit wit) x) in |
| 85 |
let ans = pr_sequence map x in |
| 86 |
hov_if_not_empty 0 ans |
| 87 |
| OptArg wit -> |
| 88 |
let ans = match x with |
| 89 |
| None -> mt () |
| 90 |
| Some x -> pr_glb_generic env sigma ?level (in_gen (glbwit wit) x) |
| 91 |
in |
| 92 |
hov_if_not_empty 0 ans |
| 93 |
| PairArg (wit1, wit2) -> |
| 94 |
let p, q = x in |
| 95 |
let p = in_gen (glbwit wit1) p in |
| 96 |
let q = in_gen (glbwit wit2) q in |
| 97 |
let ans = pr_sequence (pr_glb_generic env sigma ?level) [p; q] in |
| 98 |
hov_if_not_empty 0 ans |
| 99 |
| ExtraArg s -> |
| 100 |
let open Genprint in |
| 101 |
match generic_glb_print (in_gen (glbwit wit) x) with |
| 102 |
| PrinterBasic pp -> pp env sigma |
| 103 |
| PrinterNeedsLevel { default_already_surrounded; printer } -> |
| 104 |
let level = Option.default default_already_surrounded level in |
| 105 |
printer env sigma level |