]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_notation/cicNotationUtil.ml
snapshot
[helm.git] / helm / ocaml / cic_notation / cicNotationUtil.ml
index f10efa7545d82ff152d40af057fd4c188533b9e6..1f9d9f5ccee6ad17203c5f0d0fb761ccc31d3c88 100644 (file)
@@ -100,7 +100,6 @@ let fresh_name =
 
 let visit_ast ?(special_k = fun _ -> assert false) k =
   let rec aux = function
-
     | Appl terms -> Appl (List.map k terms)
     | Binder (kind, var, body) ->
         Binder (kind, aux_capture_variable var, k body) 
@@ -117,13 +116,11 @@ let visit_ast ?(special_k = fun _ -> assert false) k =
     | Ident (name, Some substs) -> Ident (name, Some (aux_substs substs))
     | Uri (name, Some substs) -> Uri (name, Some (aux_substs substs))
     | Meta (index, substs) -> Meta (index, List.map aux_opt substs)
-
     | (AttributedTerm _
       | Layout _
       | Literal _
       | Magic _
       | Variable _) as t -> special_k t
-
     | (Ident _
       | Implicit
       | Num _
@@ -131,24 +128,16 @@ let visit_ast ?(special_k = fun _ -> assert false) k =
       | Symbol _
       | Uri _
       | UserInput) as t -> t
-
   and aux_opt = function
     | None -> None
     | Some term -> Some (k term)
-
   and aux_capture_variable (term, typ_opt) = k term, aux_opt typ_opt
-
   and aux_patterns patterns = List.map aux_pattern patterns
-
   and aux_pattern ((head, vars), term) =
     ((head, List.map aux_capture_variable vars), k term)
-
   and aux_subst (name, term) = (name, k term)
-
   and aux_substs substs = List.map aux_subst substs
-
   in
-
   aux
 
 let visit_layout k = function
@@ -161,7 +150,7 @@ let visit_layout k = function
   | Frac (t1, t2) -> Frac (k t1, k t2)
   | Sqrt t -> Sqrt (k t)
   | Root (arg, index) -> Root (k arg, k index)
-(*   | Break -> Break *)
+  | Break -> Break
   | Box (kind, terms) -> Box (kind, List.map k terms)
 
 let visit_magic k = function
@@ -170,8 +159,8 @@ let visit_magic k = function
   | Opt t -> Opt (k t)
   | Fold (kind, t1, names, t2) -> Fold (kind, k t1, names, k t2)
   | Default (t1, t2) -> Default (k t1, k t2)
-  | If (t1, t2) -> If (k t1, k t2)
-  | Unless (t1, t2) -> Unless (k t1, k t2)
+  | If (t1, t2, t3) -> If (k t1, k t2, k t3)
+  | Fail -> Fail
 
 let variables_of_term t =
   let rec vars = ref [] in
@@ -207,6 +196,23 @@ let names_of_term t =
   in
     List.map aux (variables_of_term t)
 
+let keywords_of_term t =
+  let rec keywords = ref [] in
+  let add_keyword k = keywords := k :: !keywords in
+  let rec aux = function
+    | AttributedTerm (_, t) -> aux t
+    | Layout l -> Layout (visit_layout aux l)
+    | Literal (`Keyword k) as t ->
+        add_keyword k;
+        t
+    | Literal _ as t -> t
+    | Magic m -> Magic (visit_magic aux m)
+    | Variable _ as v -> v
+    | t -> visit_ast aux t
+  in
+    ignore (aux t) ;
+    !keywords
+
 let rec strip_attributes t =
   let special_k = function
     | AttributedTerm (_, term) -> strip_attributes term
@@ -277,6 +283,11 @@ let meta_names_of_term term =
     | Fold (_, t1, _, t2) ->
         aux t1 ;
         aux t2
+    | If (t1, t2, t3) ->
+        aux t1 ;
+        aux t2 ;
+       aux t3
+    | Fail -> ()
     | _ -> assert false
   in
   aux term ;
@@ -326,3 +337,8 @@ let find_appl_pattern_uris ap =
   in
   aux [] ap
 
+let rec find_branch =
+  function
+      Magic (If (_, Magic Fail, t)) -> find_branch t
+    | Magic (If (_, t, _)) -> find_branch t
+    | t -> t