Note: the regtest is broken by this commit.
~selection_mode ?ok ?enable_button_for_non_vars ~title ~msg ~id choices =
List.filter !uri_predicate choices
- let interactive_interpretation_choice _ = fail "Multiple interpretations"
+ let interactive_interpretation_choice =
+ let rec aux n =
+ function
+ [] -> []
+ | _::tl -> n::(aux (n+1) tl)
+ in
+ aux 0
+
let input_or_locate_uri ~title = fail "Unknown identifier"
end
let empty_context = [] in
let empty_metasenv = [] in
fun input ->
- let (_, metasenv, term) =
- Disambiguate'.disambiguate_term
- mqi_handle empty_context empty_metasenv input empty_environment
- in
- (metasenv, term)
+ List.map (fun (_,metasenv,term) -> metasenv,term)
+ (Disambiguate'.disambiguate_term
+ mqi_handle empty_context empty_metasenv input empty_environment)
let parse_pp mqi_handle ?uri_pred input =
- CicPp.ppterm (snd (parse mqi_handle ?uri_pred input))
+ List.map (fun (_,t) -> CicPp.ppterm t)
+ (parse mqi_handle ?uri_pred input)
* batch mode if possible, otherwise raises Failure above.
* uri_pred is the predicate used to select which uris are tried. Per default
* only constant URIs are accepted *)
-val parse: MQIConn.handle -> ?uri_pred:(string -> bool) -> string -> Cic.metasenv * Cic.term
+val parse: MQIConn.handle -> ?uri_pred:(string -> bool) -> string -> (Cic.metasenv * Cic.term) list
(** as above, but instead of returning the parsed cic term, pretty prints it
* (ignoring returned metasenv)
*)
-val parse_pp: MQIConn.handle -> ?uri_pred:(string -> bool) -> string -> string
+val parse_pp: MQIConn.handle -> ?uri_pred:(string -> bool) -> string -> string list
Cic.metasenv ->
string ->
EnvironmentP3.t -> (* previous interpretation status *)
- EnvironmentP3.t * (* new interpretation status *)
- Cic.metasenv * (* new metasenv *)
- Cic.term (* disambiguated term *)
+ (EnvironmentP3.t * (* new interpretation status *)
+ Cic.metasenv * (* new metasenv *)
+ Cic.term) list (* disambiguated term *)
end
GtkThread.main ();
match !chosen with
None -> raise NoChoice
- | Some n -> n
+ | Some n -> [n]
;;
?enable_button_for_non_vars:bool ->
title:string -> msg:string -> id:string -> string list -> string list
val interactive_interpretation_choice :
- (string * string) list list -> int
+ (string * string) list list -> int list
val input_or_locate_uri : title:string -> UriManager.uri
end
;;
exit 1
end
) resolve_ids ;
- let resolve_id',term,metasenv' =
+ let res =
match resolve_ids with
[] -> raise ThereDoesNotExistAnyWellTypedInterpretationOfTheInput
- | [resolve_id] -> resolve_id
+ | [_] -> resolve_ids
| _ ->
let choices =
List.map
) dom
) resolve_ids
in
- let index = C.interactive_interpretation_choice choices in
- List.nth resolve_ids index
+ let indexes = C.interactive_interpretation_choice choices in
+ List.map (List.nth resolve_ids) indexes
in
- (known_ids @ dom', resolve_id'), metasenv',term
+ List.map
+ (fun (resolve_id',term,metasenv') ->
+ (known_ids @ dom', resolve_id'), metasenv',term
+ ) res
end
;;
?enable_button_for_non_vars:bool ->
title:string -> msg:string -> id:string -> string list -> string list
val interactive_interpretation_choice :
- (string * string) list list -> int
+ (string * string) list list -> int list
val input_or_locate_uri : title:string -> UriManager.uri
end
CicTextualParser0.interpretation_domain_item list ->
(CicTextualParser0.interpretation -> Cic.metasenv * Cic.term) ->
id_to_uris:domain_and_interpretation ->
- domain_and_interpretation * Cic.metasenv * Cic.term
+ (domain_and_interpretation * Cic.metasenv * Cic.term) list
end
module EnvironmentP3 :
ereduced: string; (* expected reduced term *)
}
-let print_test test fname =
+let print_test tests fname =
let oc = open_out fname in
- output_string oc
- (String.concat ""
- [ test.term;
- sprintf "%s (* METASENV after disambiguation *)\n" rawsep;
- test.emetasenv;
- sprintf "%s (* TERM after disambiguation *)\n" rawsep;
- test.eterm;
- sprintf "%s (* TYPE_OF the disambiguated term *)\n" rawsep;
- test.etype;
- sprintf "%s (* REDUCED disambiguated term *)\n" rawsep;
- test.ereduced ]);
+ output_string oc (List.hd tests).term;
+ let i = ref 0 in
+ List.iter
+ (function test ->
+ incr i ;
+ output_string oc
+ (String.concat ""
+ [ sprintf "INTERPRETATION NUMBER %d\n" !i;
+ sprintf "%s (* METASENV after disambiguation *)\n" rawsep;
+ test.emetasenv;
+ sprintf "%s (* TERM after disambiguation *)\n" rawsep;
+ test.eterm;
+ sprintf "%s (* TYPE_OF the disambiguated term *)\n" rawsep;
+ test.etype;
+ sprintf "%s (* REDUCED disambiguated term *)\n" rawsep;
+ test.ereduced;
+ "\n" ])
+ ) tests;
close_out oc
let parse_regtest =
| l -> Buffer.add_string (buffer_of_state !state) (line ^ "\n")
done
with End_of_file -> ());
- { term = Buffer.contents term;
+ [{ term = Buffer.contents term;
emetasenv = Buffer.contents emetasenv;
eterm = Buffer.contents eterm;
etype = Buffer.contents etype;
- ereduced = Buffer.contents ereduced }
+ ereduced = Buffer.contents ereduced }]
-let as_expected report_fname expected found = (* ignores "term" field *)
+let as_expected_one och expected found = (* ignores "term" field *)
let eterm_ok = expected.eterm = found.eterm 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
- if outcome then
- (if Sys.file_exists report_fname then Sys.remove report_fname)
- else
begin
- let och = open_out report_fname in
- let print_endline = print_endline_to_channel och in
+ let print_endline = print_endline_to_channel (Lazy.force och) in
if not eterm_ok then begin
print_endline "### Term mismatch ###";
print_endline "# expected:";
print_endline "# found:";
print_endline (" " ^ found.ereduced);
end;
- close_out och ;
end;
outcome
+let as_expected report_fname expected found =
+ (if Sys.file_exists report_fname then Sys.remove report_fname) ;
+ let och = lazy (open_out report_fname) in
+ let print_endline = print_endline_to_channel (Lazy.force och) in
+ let rec aux =
+ function
+ [],[] -> true
+ | ex::extl, fo::fotl ->
+ as_expected_one och ex fo &&
+ aux (extl,fotl)
+ | [],found ->
+ print_endline "### Too many interpretations found" ;
+ false
+ | expected,[] ->
+ print_endline "### Too few interpretations found" ;
+ false
+ in
+ let outcome = aux (expected,found) in
+ (if Lazy.lazy_is_val och then close_out (Lazy.force och)) ;
+ outcome
+
let test_this mqi_handle uri_pred raw_term =
let empty_context = [] in
- let (metasenv, cic_term) = BatchParser.parse mqi_handle ~uri_pred raw_term in
- let etype =
- try
- CicPp.ppterm (CicTypeChecker.type_of_aux' metasenv empty_context cic_term)
- with _ -> "MALFORMED"
- in
- let ereduced =
- try
- CicPp.ppterm (CicReduction.whd empty_context cic_term)
- with _ -> "MALFORMED"
- in
- {
- term = raw_term; (* useless *)
- emetasenv = CicMetaSubst.ppmetasenv metasenv [] ^ "\n";
- eterm = CicPp.ppterm cic_term ^ "\n";
- etype = etype ^ "\n";
- ereduced = ereduced ^ "\n";
- }
+ List.map
+ (function (metasenv, cic_term) ->
+ let etype =
+ try
+ CicPp.ppterm
+ (CicTypeChecker.type_of_aux' metasenv empty_context cic_term)
+ with _ -> "MALFORMED"
+ in
+ let ereduced =
+ try
+ CicPp.ppterm (CicReduction.whd empty_context cic_term)
+ with _ -> "MALFORMED"
+ in
+ {
+ term = raw_term; (* useless *)
+ emetasenv = CicMetaSubst.ppmetasenv metasenv [] ^ "\n";
+ eterm = CicPp.ppterm cic_term ^ "\n";
+ etype = etype ^ "\n";
+ ereduced = ereduced ^ "\n";
+ }
+ ) (BatchParser.parse mqi_handle ~uri_pred raw_term)
let dump_environment filename =
try
let env_fname = fname ^ ".env" in
print_endline (sprintf "Generating regtest %s -> %s\n ..."
fname test_fname);
- let raw_term = (parse_regtest fname).term in
- let result = test_this mqi_handle uri_pred raw_term in
- print_test result test_fname ;
+ let raw_term = (List.hd (parse_regtest fname)).term in
+ let results = test_this mqi_handle uri_pred raw_term in
+ print_test results test_fname ;
if dump then dump_environment env_fname ;
) fnames
end else
let is_ok =
try
let expected = parse_regtest test_fname in
- let actual = test_this mqi_handle uri_pred expected.term in
+ let actual = test_this mqi_handle uri_pred (List.hd expected).term in
if dump then dump_environment env_fname ;
if as_expected report_fname expected actual then
(incr ok ; true)
) context
in
let environment',metasenv,expr =
+ match
Disambiguate'.disambiguate_term mqi_handle context metasenv
(input#buffer#get_text ()) !environment
+ with
+ [environment',metasenv,expr] -> environment',metasenv,expr
+ | _ -> assert false
in
environment := environment';
(metasenv, expr)
debug_print ("ast:\n" ^ new_pp);
let new_ast = CicTextualParser2.parse_term (Stream.of_string new_pp) in
debug_print ("new_ast:\n" ^ CicAstPp.pp_term ast);
- let (_, _, term) =
- Disambiguate'.disambiguate_term mqi_handle [] [] new_ast
- DisambiguateTypes.Environment.empty
- in
- debug_print ("term: " ^ CicPp.ppterm term)
+ List.iter
+ (fun (_, _, term) ->
+ debug_print ("term: " ^ CicPp.ppterm term))
+ (Disambiguate'.disambiguate_term mqi_handle [] [] new_ast
+ DisambiguateTypes.Environment.empty)
in
match annobj with
| Cic.AConstant (_, _, _, None, ty, _) ->
in
debug_print ("TexTermEditor: Raw Tex: " ^ (Mathml_editor.get_tex tex_editor)) ;
let environment',metasenv,expr =
- Disambiguate'.disambiguate_term mqi_handle
- context metasenv (Mathml_editor.get_tex tex_editor) !environment
+ match
+ Disambiguate'.disambiguate_term mqi_handle
+ context metasenv (Mathml_editor.get_tex tex_editor) !environment
+ with
+ [environment',metasenv,expr] -> environment',metasenv,expr
+ | _ -> assert false
in
environment := environment' ;
metasenv,expr