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
(************************************************************************)
9
(*i camlp4deps: "parsing/grammar.cma" i*)
11
(* $Id: whelp.ml4 11309 2008-08-06 10:30:35Z herbelin $ *)
26
open Dischargedhypsmap
33
(* Coq interface to the Whelp query engine developed at
34
the University of Bologna *)
36
let whelp_server_name = ref "http://mowgli.cs.unibo.it:58080"
37
let getter_server_name = ref "http://mowgli.cs.unibo.it:58081"
44
optname = "Whelp server";
45
optkey = (SecondaryTable ("Whelp","Server"));
46
optread = (fun () -> !whelp_server_name);
47
optwrite = (fun s -> whelp_server_name := s) }
52
optname = "Whelp getter";
53
optkey = (SecondaryTable ("Whelp","Getter"));
54
optread = (fun () -> !getter_server_name);
55
optwrite = (fun s -> getter_server_name := s) }
58
let make_whelp_request req c =
59
!whelp_server_name ^ "/apply?xmluri=" ^ !getter_server_name ^ "/getempty¶m.profile=firewall&profile=firewall¶m.keys=d_c%2CC1%2CHC2%2CL¶m.embedkeys=d_c%2CTC1%2CHC2%2CL¶m.thkeys=T1%2CT2%2CL%2CE¶m.prooftreekeys=HAT%2CG%2CHAO%2CL¶m.media-type=text%2Fhtml¶m.thmedia-type=&prooftreemedia-type=¶m.doctype-public=¶m.encoding=¶m.thencoding=¶m.prooftreeencoding=&advanced=no&keys=S%2CT1%2CT2%2CL%2CRT%2CE¶m.expression=" ^ c ^ "¶m.action=" ^ req
61
let b = Buffer.create 16
64
if 'A' <= c & c <= 'Z' or 'a' <= c & c <= 'z' or
65
'0' <= c & c <= '9' or c ='.'
66
then Buffer.add_char b c
67
else Buffer.add_string b (Printf.sprintf "%%%2X" (Char.code c))
69
let url_string s = String.iter url_char s
71
let rec url_list_with_sep sep f = function
74
| a::l -> f a; url_string sep; url_list_with_sep sep f l
76
let url_id id = url_string (string_of_id id)
78
let uri_of_dirpath dir =
79
url_string "cic:/"; url_list_with_sep "/" url_id (List.rev dir)
81
let error_whelp_unknown_reference ref =
82
let qid = Nametab.shortest_qualid_of_global Idset.empty ref in
84
(strbrk "Definitions of the current session, like " ++ pr_qualid qid ++
85
strbrk ", are not supported in Whelp.")
87
let uri_of_repr_kn ref (mp,dir,l) =
90
uri_of_dirpath (id_of_label l :: repr_dirpath dir @ repr_dirpath sl)
92
error_whelp_unknown_reference ref
94
let url_paren f l = url_char '('; f l; url_char ')'
95
let url_bracket f l = url_char '['; f l; url_char ']'
97
let whelp_of_rawsort = function
98
| RProp Null -> "Prop"
102
let uri_int n = Buffer.add_string b (string_of_int n)
104
let uri_of_ind_pointer l =
105
url_string ".ind#xpointer"; url_paren (url_list_with_sep "/" uri_int) l
107
let uri_of_global ref =
109
| VarRef id -> error ("Unknown Whelp reference: "^(string_of_id id)^".")
111
uri_of_repr_kn ref (repr_con cst); url_string ".con"
113
uri_of_repr_kn ref (repr_kn kn); uri_of_ind_pointer [1;i+1]
114
| ConstructRef ((kn,i),j) ->
115
uri_of_repr_kn ref (repr_kn kn); uri_of_ind_pointer [1;i+1;j]
117
let whelm_special = id_of_string "WHELM_ANON_VAR"
119
let url_of_name = function
120
| Name id -> url_id id
121
| Anonymous -> url_id whelm_special (* No anon id in Whelp *)
123
let uri_of_binding f (id,c) = url_id id; url_string "\\Assign "; f c
125
let uri_params f = function
127
| l -> url_string "\\subst";
128
url_bracket (url_list_with_sep ";" (uri_of_binding f)) l
130
let get_discharged_hyp_names sp = List.map basename (get_discharged_hyps sp)
132
let section_parameters = function
133
| RRef (_,(ConstructRef ((induri,_),_) | IndRef (induri,_))) ->
134
get_discharged_hyp_names (sp_of_global (IndRef(induri,0)))
135
| RRef (_,(ConstRef cst as ref)) ->
136
get_discharged_hyp_names (sp_of_global ref)
140
let rec aux acc = function
141
| ([],l) | (_,([] as l)) -> List.rev acc, l
142
| (v::vl,a::al) -> aux ((v,a)::acc) (vl,al)
145
let rec uri_of_constr c =
147
| RVar (_,id) -> url_id id
148
| RRef (_,ref) -> uri_of_global ref
149
| RHole _ | REvar _ -> url_string "?"
150
| RSort (_,s) -> url_string (whelp_of_rawsort s)
151
| _ -> url_paren (fun () -> match c with
153
let inst,rest = merge (section_parameters f) args in
154
uri_of_constr f; url_char ' '; uri_params uri_of_constr inst;
155
url_list_with_sep " " uri_of_constr rest
156
| RLambda (_,na,k,ty,c) ->
157
url_string "\\lambda "; url_of_name na; url_string ":";
158
uri_of_constr ty; url_string "."; uri_of_constr c
159
| RProd (_,Anonymous,k,ty,c) ->
160
uri_of_constr ty; url_string "\\to "; uri_of_constr c
161
| RProd (_,Name id,k,ty,c) ->
162
url_string "\\forall "; url_id id; url_string ":";
163
uri_of_constr ty; url_string "."; uri_of_constr c
164
| RLetIn (_,na,b,c) ->
165
url_string "let "; url_of_name na; url_string "\\def ";
166
uri_of_constr b; url_string " in "; uri_of_constr c
167
| RCast (_,c, CastConv (_,t)) ->
168
uri_of_constr c; url_string ":"; uri_of_constr t
169
| RRec _ | RIf _ | RLetTuple _ | RCases _ ->
170
error "Whelp does not support pattern-matching and (co-)fixpoint."
171
| RVar _ | RRef _ | RHole _ | REvar _ | RSort _ | RCast (_,_, CastCoerce) ->
172
anomaly "Written w/o parenthesis"
173
| RPatVar _ | RDynamic _ ->
174
anomaly "Found constructors not supported in constr") ()
176
let make_string f x = Buffer.reset b; f x; Buffer.contents b
178
let send_whelp req s =
179
let url = make_whelp_request req s in
180
let command = subst_command_placeholder browser_cmd_fmt url in
181
let _ = run_command (fun x -> x) print_string command in ()
183
let whelp_constr req c =
184
let c = detype false [whelm_special] [] c in
185
send_whelp req (make_string uri_of_constr c)
187
let whelp_constr_expr req c =
188
let (sigma,env)= get_current_context () in
189
let _,c = interp_open_constr sigma env c in
193
send_whelp "locate" s
196
send_whelp "elim" (make_string uri_of_global (IndRef ind))
199
let gls = nth_goal_of_pftreestate 1 (get_pftreestate ()) in
200
f (it_mkNamedProd_or_LetIn (pf_concl gls) (pf_hyps gls))
205
| Constr of string * constr
208
| Locate s -> whelp_locate s
209
| Elim ind -> whelp_elim ind
210
| Constr (s,c) -> whelp_constr s c
212
VERNAC ARGUMENT EXTEND whelp_constr_request
213
| [ "Match" ] -> [ "match" ]
214
| [ "Instance" ] -> [ "instance" ]
217
VERNAC COMMAND EXTEND Whelp
218
| [ "Whelp" "Locate" string(s) ] -> [ whelp_locate s ]
219
| [ "Whelp" "Locate" preident(s) ] -> [ whelp_locate s ]
220
| [ "Whelp" "Elim" global(r) ] -> [ whelp_elim (inductive_of_reference_with_alias r) ]
221
| [ "Whelp" whelp_constr_request(req) constr(c) ] -> [ whelp_constr_expr req c]
224
VERNAC COMMAND EXTEND WhelpHint
225
| [ "Whelp" "Hint" constr(c) ] -> [ whelp_constr_expr "hint" c ]
226
| [ "Whelp" "Hint" ] -> [ on_goal (whelp_constr "hint") ]