Debian Codegraph @

plugins/ssr/ssrprinters.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 (* This file is (C) Copyright 2006-2015 Microsoft Corporation and Inria. *)
12
13 open Pp
14 open Names
15
16 open Ssrast
17
18 let pr_spc () = str " "
19 let pr_bar () = Pp.cut() ++ str "|"
20 let pr_list = prlist_with_sep
21
22 let pp_concat hd ?(sep=str", ") = function [] -> hd | x :: xs ->
23 hd ++ List.fold_left (fun acc x -> acc ++ sep ++ x) x xs
24
25 (* Term printing utilities functions for deciding bracketing. *)
26 let pr_paren prx x = hov 1 (str "(" ++ prx x ++ str ")")
27 (* String lexing utilities *)
28 let skip_wschars s =
29 let rec loop i = match s.[i] with '\n'..' ' -> loop (i + 1) | _ -> i in loop
30 (* We also guard characters that might interfere with the ssreflect *)
31 (* tactic syntax. *)
32 let guard_term kind s i = match s.[i] with
33 | '(' -> false
34 | '{' | '/' | '=' -> true
35 | _ -> kind = Ssrmatching_plugin.Ssrmatching.InParens
36
37 (* We also guard characters that might interfere with the ssreflect *)
38 (* tactic syntax. *)
39 let pr_guarded guard prc c =
40 pp_with Format.str_formatter (prc c);
41 let s = Format.flush_str_formatter () ^ "$" in
42 if guard s (skip_wschars s 0) then pr_paren prc c else prc c
43
44 let with_global_env_evm f x =
45 let env = Global.env () in
46 let sigma = Evd.from_env env in
47 f env sigma x
48
49 let prl_constr_expr c = with_global_env_evm Ppconstr.(pr_lconstr_expr ~flags:(current_flags())) c
50 let pr_glob_constr = with_global_env_evm Printer.pr_glob_constr_env
51 let prl_glob_constr = with_global_env_evm Printer.pr_lglob_constr_env
52 let pr_glob_constr_and_expr = function
53 | _, Some c -> with_global_env_evm Ppconstr.(pr_constr_expr ~flags:(current_flags())) c
54 | c, None -> pr_glob_constr c
55 let pr_term (k, c) = pr_guarded (guard_term k) pr_glob_constr_and_expr c
56
57 let pr_hyp (SsrHyp (_, id)) = Id.print id
58 let pr_hyps = pr_list pr_spc pr_hyp
59
60 let pr_occ = function
61 | Some (true, occ) ->
62 if CList.is_empty occ then mt () else str "{-" ++ pr_list pr_spc int occ ++ str "}"
63 | Some (false, occ) ->
64 if CList.is_empty occ then mt () else str "{+" ++ pr_list pr_spc int occ ++ str "}"
65 | None -> str "{}"
66
67 let pr_clear_ne clr =
68 if CList.is_empty clr then mt () else str "{" ++ pr_hyps clr ++ str "}"
69 let pr_clear sep clr = sep () ++ pr_clear_ne clr
70
71 let pr_dir = function L2R -> str "->" | R2L -> str "<-"
72
73 let pr_simpl = function
74 | Simpl -1 -> str "/="
75 | Cut -1 -> str "//"
76 | Simpl n -> str "/" ++ int n ++ str "="
77 | Cut n -> str "/" ++ int n ++ str"/"
78 | SimplCut (-1,-1) -> str "//="
79 | SimplCut (n,-1) -> str "/" ++ int n ++ str "/="
80 | SimplCut (-1,n) -> str "//" ++ int n ++ str "="
81 | SimplCut (n,m) -> str "/" ++ int n ++ str "/" ++ int m ++ str "="
82 | Nop -> mt ()
83
84 (* New terms *)
85
86 let pr_ast_closure_term { body } =
87 let env = Global.env () in
88 let sigma = Evd.from_env env in
89 Ppconstr.(pr_constr_expr ~flags:(current_flags())) env sigma body
90
91 let pr_view2 = pr_list mt (fun c -> str "/" ++ pr_ast_closure_term c)
92
93 let rec pr_ipat p =
94 match p with
95 | IPatId id -> Id.print id
96 | IPatSimpl sim -> pr_simpl sim
97 | IPatClear clr -> pr_clear mt clr
98 | IPatCase (Regular iorpat) -> hov 1 (str "[" ++ pr_iorpat iorpat ++ str "]")
99 | IPatCase (Block m) -> hov 1 (str"[" ++ pr_block m ++ str"]")
100 | IPatDispatch(Regular iorpat) -> hov 1 (str "(" ++ pr_iorpat iorpat ++ str ")")
101 | IPatDispatch (Block m) -> hov 1 (str"(" ++ pr_block m ++ str")")
102 | IPatInj iorpat -> hov 1 (str "[=" ++ pr_iorpat iorpat ++ str "]")
103 | IPatRewrite (occ, dir) -> pr_occ occ ++ pr_dir dir
104 | IPatAnon All -> str "*"
105 | IPatAnon Drop -> str "_"
106 | IPatAnon (One _) -> str "?"
107 | IPatView v -> pr_view2 v
108 | IPatAnon Temporary -> str "+"
109 | IPatNoop -> str "-"
110 | IPatAbstractVars l -> str "[:" ++ pr_list spc Id.print l ++ str "]"
111 | IPatFastNondep -> str">"
112 and pr_ipats ipats = pr_list spc pr_ipat ipats
113 and pr_iorpat iorpat = pr_list pr_bar pr_ipats iorpat
114 and pr_block = function (Prefix id) -> str"^" ++ Id.print id
115 | (SuffixId id) -> str"^~" ++ Id.print id
116 | (SuffixNum n) -> str"^~" ++ int n
117
118 let debug_ssr = CDebug.create ~name:"ssreflect" ()