~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to parsing/tactic_printer.ml

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(************************************************************************)
 
2
(*  v      *   The Coq Proof Assistant  /  The Coq Development Team     *)
 
3
(* <O___,, * CNRS-Ecole Polytechnique-INRIA Futurs-Universite Paris Sud *)
 
4
(*   \VV/  **************************************************************)
 
5
(*    //   *      This file is distributed under the terms of the       *)
 
6
(*         *       GNU Lesser General Public License Version 2.1        *)
 
7
(************************************************************************)
 
8
 
 
9
(* $Id: tactic_printer.ml 11313 2008-08-07 11:15:03Z barras $ *)
 
10
 
 
11
open Pp
 
12
open Util
 
13
open Sign
 
14
open Evd
 
15
open Tacexpr
 
16
open Proof_type
 
17
open Proof_trees
 
18
open Decl_expr
 
19
open Logic
 
20
open Printer
 
21
 
 
22
let pr_tactic = function
 
23
  | TacArg (Tacexp t) ->
 
24
      (*top tactic from tacinterp*)
 
25
      Pptactic.pr_glob_tactic (Global.env()) t
 
26
  | t -> 
 
27
      Pptactic.pr_tactic (Global.env()) t
 
28
 
 
29
let pr_proof_instr instr = 
 
30
    Ppdecl_proof.pr_proof_instr (Global.env()) instr
 
31
 
 
32
let pr_rule = function
 
33
  | Prim r -> hov 0 (pr_prim_rule r)
 
34
  | Nested(cmpd,_) ->
 
35
      begin
 
36
        match cmpd with 
 
37
          | Tactic (texp,_) -> hov 0 (pr_tactic texp)
 
38
          | Proof_instr (_,instr) -> hov 0 (pr_proof_instr instr)
 
39
      end
 
40
  | Daimon -> str "<Daimon>"
 
41
  | Decl_proof _ -> str "proof" 
 
42
 
 
43
let uses_default_tac = function
 
44
  | Nested(Tactic(_,dflt),_) -> dflt
 
45
  | _ -> false
 
46
 
 
47
(* Does not print change of evars *)
 
48
let pr_rule_dot = function 
 
49
  | Prim Change_evars ->str "PC: ch_evars" ++  mt () 
 
50
      (* PC: this might be redundant *)
 
51
  | r ->
 
52
      pr_rule r ++ if uses_default_tac r then str "..." else str"."
 
53
 
 
54
let pr_rule_dot_fnl = function
 
55
  | Nested (Tactic (TacAtom (_,(TacMutualFix (true,_,_,_)
 
56
                              | TacMutualCofix (true,_,_))),_),_) ->
 
57
      (* Very big hack to not display hidden tactics in "Theorem with" *)
 
58
      (* (would not scale!) *)
 
59
      mt ()
 
60
   | Prim Change_evars -> mt ()
 
61
   | r -> pr_rule_dot r ++ fnl ()
 
62
 
 
63
exception Different
 
64
 
 
65
(* We remove from the var context of env what is already in osign *)
 
66
let thin_sign osign sign =
 
67
  Sign.fold_named_context
 
68
    (fun (id,c,ty as d) sign ->
 
69
       try 
 
70
         if Sign.lookup_named id osign = (id,c,ty) then sign
 
71
         else raise Different
 
72
       with Not_found | Different -> Environ.push_named_context_val d sign)
 
73
    sign ~init:Environ.empty_named_context_val
 
74
 
 
75
let rec print_proof sigma osign pf =
 
76
  let hyps = Environ.named_context_of_val pf.goal.evar_hyps in
 
77
  let hyps' = thin_sign osign hyps in
 
78
  match pf.ref with
 
79
    | None -> 
 
80
        hov 0 (pr_goal {pf.goal with evar_hyps=hyps'})
 
81
    | Some(r,spfl) ->
 
82
        hov 0 
 
83
          (hov 0 (pr_goal {pf.goal with evar_hyps=hyps'}) ++
 
84
           spc () ++ str" BY " ++
 
85
           hov 0 (pr_rule r) ++ fnl () ++
 
86
           str"  " ++
 
87
           hov 0 (prlist_with_sep pr_fnl (print_proof sigma hyps) spfl))
 
88
          
 
89
let pr_change gl = 
 
90
  str"change " ++
 
91
  pr_lconstr_env (Global.env_of_context gl.evar_hyps) gl.evar_concl ++ str"."
 
92
 
 
93
let print_decl_script tac_printer ?(nochange=true) sigma pf =
 
94
  let rec print_prf pf =
 
95
  match pf.ref with
 
96
    | None ->
 
97
        (if nochange then 
 
98
           (str"<Your Proof Text here>")
 
99
         else 
 
100
           pr_change pf.goal)
 
101
        ++ fnl ()
 
102
    | Some (Daimon,[]) -> str "(* Some proof has been skipped here *)"
 
103
    | Some (Prim Change_evars,[subpf]) -> print_prf subpf
 
104
    | Some (Nested(Proof_instr (opened,instr),_) as rule,subprfs) ->
 
105
        begin
 
106
          match instr.instr,subprfs with
 
107
            Pescape,[{ref=Some(_,subsubprfs)}] ->
 
108
              hov 7
 
109
                (pr_rule_dot_fnl rule ++
 
110
                  prlist_with_sep pr_fnl tac_printer subsubprfs) ++ fnl () ++
 
111
              if opened then mt () else str "return."
 
112
          | Pclaim _,[body;cont] ->
 
113
              hov 2 (pr_rule_dot_fnl rule ++ print_prf body) ++ fnl () ++
 
114
              (if opened then mt () else str "end claim." ++ fnl ()) ++
 
115
              print_prf cont
 
116
          | Pfocus _,[body;cont] ->
 
117
              hov 2 (pr_rule_dot_fnl rule ++ print_prf body) ++ 
 
118
              fnl () ++
 
119
              (if opened then mt () else str "end focus." ++ fnl ()) ++
 
120
              print_prf cont
 
121
          | (Psuppose _ |Pcase (_,_,_)),[body;cont] ->
 
122
              hov 2 (pr_rule_dot_fnl rule ++ print_prf body) ++ fnl () ++
 
123
              print_prf cont 
 
124
          | _,[next] ->
 
125
              pr_rule_dot_fnl rule ++ print_prf next
 
126
          | _,[] ->
 
127
              pr_rule_dot rule          
 
128
          | _,_ -> anomaly "unknown branching instruction"
 
129
        end
 
130
    | _ -> anomaly "Not Applicable" in
 
131
  print_prf pf
 
132
 
 
133
let print_script ?(nochange=true) sigma pf =
 
134
  let rec print_prf pf =
 
135
  match pf.ref with
 
136
    | None ->
 
137
        (if nochange then 
 
138
           (str"<Your Tactic Text here>") 
 
139
         else 
 
140
           pr_change pf.goal)
 
141
        ++ fnl ()
 
142
    | Some(Decl_proof opened,script) ->
 
143
        assert (List.length script = 1);
 
144
        begin
 
145
          if nochange then (mt ()) else (pr_change pf.goal ++ fnl ()) 
 
146
        end ++
 
147
          begin
 
148
            hov 0 (str "proof." ++ fnl () ++ 
 
149
                     print_decl_script print_prf 
 
150
                     ~nochange sigma (List.hd script))
 
151
          end ++ fnl () ++
 
152
          begin
 
153
            if opened then mt () else (str "end proof." ++ fnl ())
 
154
          end
 
155
    | Some(Daimon,spfl) ->
 
156
        ((if nochange then (mt ()) else (pr_change pf.goal ++ fnl ())) ++
 
157
           prlist_with_sep pr_fnl print_prf spfl )
 
158
    | Some(rule,spfl) ->
 
159
        ((if nochange then (mt ()) else (pr_change pf.goal ++ fnl ())) ++
 
160
           pr_rule_dot_fnl rule ++
 
161
           prlist_with_sep pr_fnl print_prf spfl ) in
 
162
  print_prf pf
 
163
 
 
164
(* printed by Show Script command *)
 
165
 
 
166
let print_treescript ?(nochange=true) sigma pf =
 
167
  let rec print_prf pf =
 
168
    match pf.ref with
 
169
    | None ->
 
170
        if nochange then 
 
171
          if pf.goal.evar_extra=None then str"<Your Tactic Text here>"
 
172
          else str"<Your Proof Text here>"
 
173
        else pr_change pf.goal
 
174
    | Some(Decl_proof opened,script) ->
 
175
        assert (List.length script = 1);
 
176
        begin
 
177
          if nochange then mt () else pr_change pf.goal ++ fnl ()
 
178
        end ++
 
179
        hov 0 
 
180
          begin str "proof." ++ fnl () ++
 
181
            print_decl_script print_prf ~nochange sigma (List.hd script) 
 
182
          end ++ fnl () ++ 
 
183
        begin
 
184
          if opened then mt () else (str "end proof." ++ fnl ())
 
185
        end
 
186
    | Some(Daimon,spfl) ->
 
187
        (if nochange then mt () else pr_change pf.goal ++ fnl ()) ++
 
188
        prlist_with_sep pr_fnl (print_script ~nochange sigma) spfl
 
189
    | Some(r,spfl) ->
 
190
        let indent = if List.length spfl >= 2 then 1 else 0 in
 
191
        (if nochange then mt () else pr_change pf.goal ++ fnl ()) ++
 
192
        hv indent (pr_rule_dot_fnl r ++ prlist_with_sep fnl print_prf spfl)
 
193
  in hov 0 (print_prf pf)
 
194
 
 
195
let rec print_info_script sigma osign pf =
 
196
  let {evar_hyps=sign; evar_concl=cl} = pf.goal in
 
197
  match pf.ref with
 
198
    | None -> (mt ())
 
199
    | Some(r,spfl) ->
 
200
        (pr_rule r ++ 
 
201
           match spfl with
 
202
             | [pf1] ->
 
203
                 if pf1.ref = None then 
 
204
                   (str "." ++ fnl ())
 
205
                 else 
 
206
                   (str";" ++ brk(1,3) ++
 
207
                      print_info_script sigma 
 
208
                      (Environ.named_context_of_val sign) pf1)
 
209
             | _ -> (str"." ++ fnl () ++
 
210
                       prlist_with_sep pr_fnl
 
211
                         (print_info_script sigma 
 
212
                            (Environ.named_context_of_val sign)) spfl))
 
213
 
 
214
let format_print_info_script sigma osign pf = 
 
215
  hov 0 (print_info_script sigma osign pf)
 
216
    
 
217
let print_subscript sigma sign pf = 
 
218
  if is_tactic_proof pf then 
 
219
    format_print_info_script sigma sign (subproof_of_proof pf)
 
220
  else 
 
221
    format_print_info_script sigma sign pf
 
222
 
 
223
let _ = Refiner.set_info_printer print_subscript
 
224