]> matita.cs.unibo.it Git - helm.git/commitdiff
The disambiguation now returns a list of interpretations.
authorClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Tue, 2 Mar 2004 13:20:11 +0000 (13:20 +0000)
committerClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Tue, 2 Mar 2004 13:20:11 +0000 (13:20 +0000)
Note: the regtest is broken by this commit.

helm/gTopLevel/batchParser.ml
helm/gTopLevel/batchParser.mli
helm/gTopLevel/disambiguatingParser.mli
helm/gTopLevel/gTopLevel.ml
helm/gTopLevel/oldDisambiguate.ml
helm/gTopLevel/oldDisambiguate.mli
helm/gTopLevel/regtest.ml
helm/gTopLevel/termEditor.ml
helm/gTopLevel/testlibrary.ml
helm/gTopLevel/texTermEditor.ml

index 7cbc31201ab39f1a3e98c3f27e27a7c3f74401a4..515c417cb4cc1e29d996e3b9ae9b450ba96d9ebc 100644 (file)
@@ -44,7 +44,14 @@ module DisambiguateCallbacks =
    ~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
 
@@ -59,12 +66,11 @@ let parse mqi_handle ?(uri_pred = constants_only) =
   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)
 
index ba5d5ab5801f89c08ccdad56d21c74ec009dff63..ff82e6fa057d9001dc43e4241d5e0a03df0640f1 100644 (file)
@@ -37,10 +37,10 @@ val uri_pred_of_conf: bool -> string -> (string -> bool)
    * 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
 
index 5ddf68377f2f2073e406c7049cd978575108f356..620198a527777da5806d2cdee880cc1dcdc4a97b 100644 (file)
@@ -41,8 +41,8 @@ module Make (C : DisambiguateTypes.Callbacks) :
       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
 
index 9ff7e8fc6cc13a386c41ee316103150abaeb6fae..5df73dc1cacbc71b3fb61443838829c32582888c 100644 (file)
@@ -379,7 +379,7 @@ let interactive_interpretation_choice interpretations =
  GtkThread.main ();
  match !chosen with
     None -> raise NoChoice
-  | Some n -> n
+  | Some n -> [n]
 ;;
 
 
index 39be585e55e3082dd4256fd7207f9ffb6c12f6ec..9b1d4937cfc1de9a3cc660301c4e6caf4a7a2fda 100644 (file)
@@ -46,7 +46,7 @@ module type Callbacks =
       ?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
 ;;
@@ -232,10 +232,10 @@ prerr_endline ("%%% PRUNED!!! " ^ CicPp.ppterm expr) ;
            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
@@ -266,10 +266,13 @@ prerr_endline ("%%% PRUNED!!! " ^ CicPp.ppterm expr) ;
                ) 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
 ;;
 
index 8fcc1c9341544e64390ed6ecd8e85d7b2d6c6796..d9cc5840da990a2ee7f127eed90ba597f2d84486 100644 (file)
@@ -44,7 +44,7 @@ module type Callbacks =
       ?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
 
@@ -62,7 +62,7 @@ module Make (C : Callbacks) :
         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 :
index 76621b5ecf8d611a9507db803e1e1f79e2cf5dfd..4142afa1afcd9b42ce6d16153eda029cc8583666 100644 (file)
@@ -55,19 +55,26 @@ type regtest = {
   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 =
@@ -104,24 +111,20 @@ 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:";
@@ -150,30 +153,53 @@ let as_expected report_fname expected found = (* ignores "term" field *)
       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
@@ -214,9 +240,9 @@ let main mqi_handle generate  dump fnames tryvars varsprefix =
       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
@@ -235,7 +261,7 @@ let main mqi_handle generate  dump fnames tryvars varsprefix =
        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)
index db637554f249e8d4fe9bfee54ccdb516ac4b81ca..3a74ef05111ce88f2948052896e5ce47a9fc598e 100644 (file)
@@ -99,8 +99,12 @@ module Make(C:DisambiguateTypes.Callbacks) =
          ) 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)
index 6c76a6b2d79e09f88c2e991ec4c6adc7cc9ab7cb..e40981861ff756fd3d75b8d12e9ae2d4b011581e 100644 (file)
@@ -44,11 +44,11 @@ let test_uri uri =
     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, _) ->
index b5dea98164bb026c584c2979defa58fb9d46cf9f..e06950508c72ec5570e6667b33fb1fe9def8df97 100644 (file)
@@ -211,8 +211,12 @@ module Make(C:DisambiguateTypes.Callbacks) =
        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