Hello!
I want the following as JSON. In proofs:
- Goal (top one / first)
- all hypotheses
- last applied tactics
For those I do not just need the string representation, but names and also the types (like variable, …). It looks that coqtopide XML output provides this information, but it is a nightmare to parse. So I’m currently trying to write a plugin to get this information.
I managed to setup everything for the plugin and the skeleton kind of works:
let hypothesis_to_json sigma env (name: Names.Id.t) (typ: Constr.t) =
let typ_str = Printer.pr_ltype_env env sigma typ in
let name_str = Names.Id.to_string name in
"{ \"name\": \"" ^ name_str ^ "\", \"type\": \"" ^ (Pp.string_of_ppcmds typ_str) ^ "\" }"
let extract_hypotheses sigma env =
let named_ctx = Environ.named_context env in
let hypotheses_json_list = List.map (fun decl ->
let name = Context.Named.Declaration.get_id decl in
let typ = Context.Named.Declaration.get_type decl in
hypothesis_to_json sigma env name typ
) named_ctx in
String.concat ", " hypotheses_json_list
let printProofStateAsJson ~pstate =
let sigma, env = Declare.Proof.get_current_context pstate in
let hypotheses_json = extract_hypotheses sigma env in
let goals_json = "{ \"dummy\": \"goal\" }" in
Feedback.msg_notice
(Pp.str (Printf.sprintf "{ \"hypotheses\": [%s], \"goals\": [%s] }"
hypotheses_json goals_json))
Test / Example:
Theorem add_0_r : forall n:nat, n + 0 = n.
Proof.
ProofStateAsJson. intros n. ProofStateAsJson. induction n as [| n' IHn'].
- ProofStateAsJson. (* n = 0 *) reflexivity. ProofStateAsJson.
- ProofStateAsJson. (* n = S n' *) simpl. ProofStateAsJson. rewrite -> IHn'. ProofStateAsJson. reflexivity. ProofStateAsJson. Qed.
Currently I’m stuck as I have no idea how to get the the goal and last tactic information and also how to get the more detailed information of the hypotheses (like type, name, …).
I had a look at different plugins, but did not find any decent way.
Any help and hint is highly welcome!