let print_endline s = print_endline s
let print_endline_to_channel ch s = output_string ch (s ^ "\n")
-type state = Term | EMetasenv | ETerm | EType | EReduced
+type state = Term | EEnv | EMetasenv | ETerm | EType | EReduced
(* regtest file format
* < cic term in concrete syntax >
+ * separatorseparator INTERPRETATION NUMBER <n> separatorseparator
+ * separator (* see sep above *)
+ * < expected disambiguating environment (EnvironmentP3.to_string) >
* separator (* see sep above *)
* < expected metasenv after disambiguation (CicMetaSubst.ppmetasenv) >
* separator (* see sep above *)
* < expected cic type as per type_of (CicPp.ppterm) >
* separator (* see sep above *)
* < expected reduced cic term as (CicPp.ppterm) >
+ * ... (* repeat from ... INTERPRETATION NUMBER ... *)
*)
type regtest = {
term: string; (* raw cic term *)
+ eenv : string; (* disambiguating parsing environment *)
emetasenv : string; (* expected metasenv *)
eterm: string; (* expected term *)
etype: string; (* expected type *)
output_string oc
(String.concat ""
[ sprintf "%s%s INTERPRETATION NUMBER %d %s%s\n" rawsep rawsep !i rawsep rawsep ;
+ sprintf "%s (* disambiguation environment *)\n" rawsep;
+ test.eenv;
sprintf "%s (* METASENV after disambiguation *)\n" rawsep;
test.emetasenv;
sprintf "%s (* TERM after disambiguation *)\n" rawsep;
let parse_regtest =
let term = Buffer.create 1024 in (* raw term *)
+ let eenv = Buffer.create 1024 in (* disambiguating parser environment *)
let emetasenv = Buffer.create 1024 in (* expected metasenv *)
let eterm = Buffer.create 1024 in (* raw expected term *)
let etype = Buffer.create 1024 in (* raw expected type *)
let state = ref Term in
let bump_state () =
match !state with
- | Term -> state := EMetasenv
+ | Term -> state := EEnv
+ | EEnv -> state := EMetasenv
| EMetasenv -> state := ETerm
| ETerm -> state := EType
| EType -> state := EReduced
| EReduced -> assert false
in
let buffer_of_state = function
- | Term -> term | EMetasenv -> emetasenv | ETerm -> eterm | EType -> etype
+ | Term -> term | EEnv -> eenv | EMetasenv -> emetasenv | ETerm -> eterm | EType -> etype
| EReduced -> ereduced
in
let clear_buffers () =
- List.iter Buffer.clear [ emetasenv; eterm; etype; ereduced ]
+ List.iter Buffer.clear [ eenv; emetasenv; eterm; etype; ereduced ]
in
fun fname ->
state := Term;
let res = ref [] in
let push_res () =
res :=
- { term = Buffer.contents term;
+ {term = Buffer.contents term;
+ eenv = Buffer.contents eenv;
emetasenv = Buffer.contents emetasenv;
eterm = Buffer.contents eterm;
etype = Buffer.contents etype;
let as_expected_one och expected found = (* ignores "term" field *)
let eterm_ok = expected.eterm = found.eterm in
+ let eenv_ok = expected.eenv = found.eenv in
let emetasenv_ok = expected.emetasenv = found.emetasenv in
let etype_ok = expected.etype = found.etype in
let ereduced_ok = expected.ereduced = found.ereduced in
- let outcome = eterm_ok && emetasenv_ok && etype_ok && ereduced_ok in
+ let outcome =
+ eterm_ok && eenv_ok && emetasenv_ok && etype_ok && ereduced_ok
+ in
begin
let print_endline s = print_endline_to_channel (Lazy.force och) s in
if not eterm_ok then begin
print_endline "# found:";
print_endline (" " ^ found.eterm);
end;
+ if not eenv_ok then begin
+ print_endline "### Disambiguation environment mismatch ###";
+ print_endline "# expected:";
+ print_endline (" " ^ expected.eenv);
+ print_endline "# found:";
+ print_endline (" " ^ found.eenv);
+ end;
if not emetasenv_ok then begin
print_endline "### Metasenv mismatch ###";
print_endline "# expected:";
let test_this mqi_handle uri_pred raw_term =
let empty_context = [] in
List.map
- (function (metasenv, cic_term) ->
+ (function (env, metasenv, cic_term) ->
let etype =
try
CicPp.ppterm
CicPp.ppterm (CicReduction.whd empty_context cic_term)
with _ -> "MALFORMED"
in
- {
- term = raw_term; (* useless *)
+ { term = raw_term; (* useless *)
+ eenv = DisambiguatingParser.EnvironmentP3.to_string env ^ "\n";
emetasenv = CicMetaSubst.ppmetasenv metasenv [] ^ "\n";
eterm = CicPp.ppterm cic_term ^ "\n";
etype = etype ^ "\n";