]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/software/components/content_pres/termContentPres.ml
more push/pop to avoid confusion with imperative data structures employed by
[helm.git] / helm / software / components / content_pres / termContentPres.ml
index 3ee9e7fe9f90d266d4ba4e158684e0bda3a50634..378708bce764e9e0e8010ff5b64e696f9e52f7eb 100644 (file)
@@ -144,7 +144,7 @@ let pp_ast0 t k =
         let mk_case_pattern =
          function
             Ast.Pattern (head, href, vars) ->
-             hbox true false (ident_w_href href head :: List.map aux_var vars)
+             hvbox true false (ident_w_href href head :: List.map aux_var vars)
           | Ast.Wildcard -> builtin_symbol "_"
         in
         let patterns' =
@@ -281,11 +281,32 @@ let pp_ast0 t k =
 
   (* persistent state *)
 
-let level1_patterns21 = Hashtbl.create 211
-
+let initial_level1_patterns21 () = Hashtbl.create 211
+let level1_patterns21 = ref (initial_level1_patterns21 ())
 let compiled21 = ref None
-
 let pattern21_matrix = ref []
+let counter = ref ~-1 
+
+let stack = ref [];;
+
+let push () =
+  stack := (!counter,!level1_patterns21,!compiled21,!pattern21_matrix)::!stack;
+  counter := ~-1;
+  level1_patterns21 := initial_level1_patterns21 ();
+  compiled21 := None;
+  pattern21_matrix := []
+;;
+
+let pop () =
+ match !stack with
+    [] -> assert false
+  | (ocounter,olevel1_patterns21,ocompiled21,opatterns21_matrix)::old ->
+     stack := old;
+     counter := ocounter;
+     level1_patterns21 := olevel1_patterns21;
+     compiled21 := ocompiled21;
+     pattern21_matrix := opatterns21_matrix
+;;
 
 let get_compiled21 () =
   match !compiled21 with
@@ -319,7 +340,11 @@ let instantiate21 idrefs env l1 =
         assert (CicNotationEnv.well_typed ty value); (* INVARIANT *)
         (* following assertion should be a conditional that makes this
          * instantiation fail *)
-        assert (CicNotationEnv.well_typed expected_ty value);
+        if not (CicNotationEnv.well_typed expected_ty value) then
+         begin
+          prerr_endline ("The variable " ^ name ^ " is used with the wrong type in the notation declaration");
+          assert false
+         end;
         let value = CicNotationEnv.term_of_value value in
         let value = 
           match expected_ty with
@@ -437,7 +462,7 @@ let rec pp_ast1 term =
           in
           let l1 =
             try
-              Hashtbl.find level1_patterns21 pid
+              Hashtbl.find !level1_patterns21 pid
             with Not_found -> assert false
           in
           instantiate21 idrefs (ast_env_of_env env) l1)
@@ -466,11 +491,6 @@ let fill_pos_info l1_pattern = l1_pattern
   in
   aux true l1_pattern *)
 
-let counter = ref ~-1 
-let reset () =
-  counter := ~-1;
-  Hashtbl.clear level1_patterns21
-;;
 let fresh_id =
   fun () ->
     incr counter;
@@ -480,14 +500,14 @@ let add_pretty_printer l2 (CicNotationParser.CL1P (l1,precedence)) =
   let id = fresh_id () in
   let l1' = add_level_info precedence (fill_pos_info l1) in
   let l2' = CicNotationUtil.strip_attributes l2 in
-  Hashtbl.add level1_patterns21 id l1';
+  Hashtbl.add !level1_patterns21 id l1';
   pattern21_matrix := (l2', id) :: !pattern21_matrix;
   load_patterns21 !pattern21_matrix;
   id
 
 let remove_pretty_printer id =
   (try
-    Hashtbl.remove level1_patterns21 id;
+    Hashtbl.remove !level1_patterns21 id;
   with Not_found -> raise Pretty_printer_not_found);
   pattern21_matrix := List.filter (fun (_, id') -> id <> id') !pattern21_matrix;
   load_patterns21 !pattern21_matrix