]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/matita/matitaDisambiguator.ml
snapshot (first version in which some extensions work, e.g. infix +)
[helm.git] / helm / matita / matitaDisambiguator.ml
index 178c7d8c7f18372fc4c1b768470c4e09d2183921..fcbcdea1442cce3be7be508881038f0599ebbce6 100644 (file)
@@ -1,4 +1,4 @@
-(* Copyright (C) 2004, HELM Team.
+(* Copyright (C) 2004-2005, HELM Team.
  * 
  * This file is part of HELM, an Hypertextual, Electronic
  * Library of Mathematics, developed at the Computer Science
  * http://helm.cs.unibo.it/
  *)
 
-open MatitaTypes
-
-class parserr () =
-  object
-    method parseTerm = CicTextualParser2.parse_term
-    method parseTactical = CicTextualParser2.parse_tactical
-  end
-
-let parserr () = new parserr ()
-let parserr_instance = MatitaMisc.singleton parserr
+open Printf
 
-class disambiguator () =
-  let _chooseUris = ref mono_uris_callback in
-  let _chooseInterp = ref mono_interp_callback in
-  let disambiguate_term =
-    let module Callbacks =
-      struct
-        let interactive_user_uri_choice
-          ~selection_mode ?ok ?(enable_button_for_non_vars = true) ~title ~msg
-          ~id uris
-        =
-          !_chooseUris ~selection_mode ~title ~msg
-            ~nonvars_button:enable_button_for_non_vars uris
-
-        let interactive_interpretation_choice interp = !_chooseInterp interp
-
-        let input_or_locate_uri ~(title:string) ?id =
-          (* Zack: I try to avoid using this callback. I therefore assume that
-          * the presence of an identifier that can't be resolved via "locate"
-          * query is a syntax error *)
-          let msg = match id with Some id -> id | _ -> "_" in
-          raise (Unbound_identifier msg)
-      end
-    in
-    let module Disambiguator = Disambiguate.Make (Callbacks) in
-    Disambiguator.disambiguate_term 
-  in
-  object (self)
-    val mutable _env = DisambiguateTypes.Environment.empty
-    method env = _env
-    method setEnv e = _env <- e
+open MatitaTypes
 
-    method chooseUris = !_chooseUris
-    method setChooseUris f = _chooseUris := f
+exception Ambiguous_input
 
-    method chooseInterp = !_chooseInterp
-    method setChooseInterp f = _chooseInterp := f
+type choose_uris_callback = id:string -> string list -> string list
+type choose_interp_callback = (string * string) list list -> int list
 
-    val parserr = parserr_instance ()
-    method parserr = parserr
+let mono_uris_callback ~id = raise Ambiguous_input
+let mono_interp_callback _ = raise Ambiguous_input
 
-    val dbd = MatitaMisc.dbd_instance ()
+let _choose_uris_callback = ref mono_uris_callback
+let _choose_interp_callback = ref mono_interp_callback
+let set_choose_uris_callback f = _choose_uris_callback := f
+let set_choose_interp_callback f = _choose_interp_callback := f
 
-    method disambiguateTermAst ?(context = []) ?(metasenv = []) ?env termAst =
-      let (save_state, env) =
-        match env with
-        | Some env -> (false, env)
-        | None -> (true, _env)
-      in
-      match disambiguate_term ~initial_ugraph:CicUniv.empty_ugraph 
-       ~dbd context metasenv termAst ~aliases:env with
-      | [ (env, metasenv, term,ugraph) as x ] ->
-          if save_state then self#setEnv env;
-          x
-      | _ -> assert false
+module Callbacks =
+  struct
+    let interactive_user_uri_choice ~selection_mode ?ok
+          ?(enable_button_for_non_vars = true) ~title ~msg ~id uris =
+              !_choose_uris_callback ~id uris
 
-    method disambiguateTermAsts ?(metasenv = []) ?env asts =
-      let ast = CicAst.pack asts in
-      let (env, metasenv, term, ugraph) =
-        self#disambiguateTermAst ~context:[] ~metasenv ?env ast
-      in
-      (env, metasenv, CicUtil.unpack term, ugraph)
+    let interactive_interpretation_choice interp =
+      !_choose_interp_callback interp
 
-    method disambiguateTerm ?context ?metasenv ?env stream =
-      self#disambiguateTermAst ?context ?metasenv ?env
-        (parserr#parseTerm stream)
+    let input_or_locate_uri ~(title:string) ?id =
+      (* Zack: I try to avoid using this callback. I therefore assume that
+      * the presence of an identifier that can't be resolved via "locate"
+      * query is a syntax error *)
+      let msg = match id with Some id -> id | _ -> "_" in
+      raise (Unbound_identifier msg)
   end
+  
+module Disambiguator = Disambiguate.Make (Callbacks)
+
+(* implement module's API *)
 
-let disambiguator () = new disambiguator ()
-let instance = MatitaMisc.singleton disambiguator 
+let disambiguate_term = Disambiguator.disambiguate_term