X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Fsoftware%2Fcomponents%2Facic_procedural%2FproceduralTypes.ml;h=c30251f4838b20c1409e2df321255ee4e3842bbe;hb=a9cf292e7e406a8a2cd88b8f5f84ff2d59bea5e4;hp=1d8bbbc21109120da4cd9f27c21a22abcff6a5e6;hpb=977e819edc19f6c25d9f05c2fafe72c63ad301fd;p=helm.git diff --git a/helm/software/components/acic_procedural/proceduralTypes.ml b/helm/software/components/acic_procedural/proceduralTypes.ml index 1d8bbbc21..c30251f48 100644 --- a/helm/software/components/acic_procedural/proceduralTypes.ml +++ b/helm/software/components/acic_procedural/proceduralTypes.ml @@ -30,41 +30,20 @@ module N = CicNotationPt (* functions to be moved ****************************************************) +let list_rev_map2 map l1 l2 = + let rec aux res = function + | hd1 :: tl1, hd2 :: tl2 -> aux (map hd1 hd2 :: res) (tl1, tl2) + | _ -> res + in + aux [] (l1, l2) + let list_map2_filter map l1 l2 = let rec filter l = function | [] -> l | None :: tl -> filter l tl | Some a :: tl -> filter (a :: l) tl in - filter [] (List.rev_map2 map l1 l2) - -let rec list_split n l = - if n = 0 then [], l else - let l1, l2 = list_split (pred n) (List.tl l) in - List.hd l :: l1, l2 - -let cont sep a = match sep with - | None -> a - | Some sep -> sep :: a - -let list_rev_map_concat map sep a l = - let rec aux a = function - | [] -> a - | [x] -> map a x - | x :: y :: l -> aux (sep :: map a x) (y :: l) - in - aux a l - -let is_atomic = function - | C.ASort _ - | C.AConst _ - | C.AMutInd _ - | C.AMutConstruct _ - | C.AVar _ - | C.ARel _ - | C.AMeta _ - | C.AImplicit _ -> true - | _ -> false + filter [] (list_rev_map2 map l1 l2) (****************************************************************************) @@ -76,6 +55,7 @@ type count = int type note = string type where = (name * name) option type inferred = Cic.annterm +type pattern = Cic.annterm type step = Note of note | Theorem of name * what * note @@ -84,11 +64,11 @@ type step = Note of note | Intros of count option * name list * note | Cut of name * what * note | LetIn of name * what * note - | Rewrite of how * what * where * note - | Elim of what * using option * note + | Rewrite of how * what * where * pattern * note + | Elim of what * using option * pattern * note | Apply of what * note - | Whd of count * note - | Change of inferred * what * note + | Change of inferred * what * where * pattern * note + | ClearBody of name * note | Branch of step list list * note (* annterm constructors *****************************************************) @@ -99,10 +79,11 @@ let mk_arel i b = Cic.ARel ("", "", i, b) let floc = H.dummy_floc -let hole = C.AImplicit ("", Some `Hole) - let mk_note str = G.Comment (floc, G.Note (floc, str)) +let mk_nlnote str a = + if str = "" then mk_note "" :: a else mk_note str :: mk_note "" :: a + let mk_theorem name t = let obj = N.Theorem (`Theorem, name, t, None) in G.Executable (floc, G.Command (floc, G.Obj (floc, obj))) @@ -110,83 +91,91 @@ let mk_theorem name t = let mk_qed = G.Executable (floc, G.Command (floc, G.Qed floc)) -let mk_tactic tactic = - G.Executable (floc, G.Tactical (floc, G.Tactic (floc, tactic), None)) +let mk_tactic tactic punctation = + G.Executable (floc, G.Tactic (floc, Some tactic, punctation)) -let mk_id = +let mk_punctation punctation = + G.Executable (floc, G.Tactic (floc, None, punctation)) + +let mk_id punctation = let tactic = G.IdTac floc in - mk_tactic tactic + mk_tactic tactic punctation -let mk_intros xi ids = +let mk_intros xi ids punctation = let tactic = G.Intros (floc, xi, ids) in - mk_tactic tactic + mk_tactic tactic punctation -let mk_cut name what = +let mk_cut name what punctation = let tactic = G.Cut (floc, Some name, what) in - mk_tactic tactic + mk_tactic tactic punctation -let mk_letin name what = +let mk_letin name what punctation = let tactic = G.LetIn (floc, what, name) in - mk_tactic tactic + mk_tactic tactic punctation -let mk_rewrite direction what where = +let mk_rewrite direction what where pattern punctation = let direction = if direction then `RightToLeft else `LeftToRight in let pattern, rename = match where with - | None -> (None, [], Some hole), [] - | Some (premise, name) -> (None, [premise, hole], None), [name] + | None -> (None, [], Some pattern), [] + | Some (premise, name) -> (None, [premise, pattern], None), [name] in let tactic = G.Rewrite (floc, direction, what, pattern, rename) in - mk_tactic tactic + mk_tactic tactic punctation -let mk_elim what using = - let tactic = G.Elim (floc, what, using, Some 0, []) in - mk_tactic tactic +let mk_elim what using pattern punctation = + let pattern = None, [], Some pattern in + let tactic = G.Elim (floc, what, using, pattern, Some 0, []) in + mk_tactic tactic punctation -let mk_apply t = +let mk_apply t punctation = let tactic = G.Apply (floc, t) in - mk_tactic tactic - -let mk_whd i = - let pattern = None, [], Some hole in - let tactic = G.Reduce (floc, `Whd, pattern) in - mk_tactic tactic + mk_tactic tactic punctation -let mk_change t = - let pattern = None, [], Some hole in +let mk_change t where pattern punctation = + let pattern = match where with + | None -> None, [], Some pattern + | Some (premise, _) -> None, [premise, pattern], None + in let tactic = G.Change (floc, pattern, t) in - mk_tactic tactic + mk_tactic tactic punctation + +let mk_clearbody id punctation = + let tactic = G.ClearBody (floc, id) in + mk_tactic tactic punctation -let mk_dot = G.Executable (floc, G.Tactical (floc, G.Dot floc, None)) +let mk_ob = + let punctation = G.Branch floc in + mk_punctation punctation -let mk_sc = G.Executable (floc, G.Tactical (floc, G.Semicolon floc, None)) +let mk_dot = G.Dot floc -let mk_ob = G.Executable (floc, G.Tactical (floc, G.Branch floc, None)) +let mk_sc = G.Semicolon floc -let mk_cb = G.Executable (floc, G.Tactical (floc, G.Merge floc, None)) +let mk_cb = G.Merge floc -let mk_vb = G.Executable (floc, G.Tactical (floc, G.Shift floc, None)) +let mk_vb = G.Shift floc (* rendering ****************************************************************) let rec render_step sep a = function - | Note s -> mk_note s :: a - | Theorem (n, t, s) -> mk_note s :: mk_theorem n t :: a - | Qed s -> (* mk_note s :: *) mk_qed :: a - | Id s -> mk_note s :: cont sep (mk_id :: a) - | Intros (c, ns, s) -> mk_note s :: cont sep (mk_intros c ns :: a) - | Cut (n, t, s) -> mk_note s :: cont sep (mk_cut n t :: a) - | LetIn (n, t, s) -> mk_note s :: cont sep (mk_letin n t :: a) - | Rewrite (b, t, w, s) -> mk_note s :: cont sep (mk_rewrite b t w :: a) - | Elim (t, xu, s) -> mk_note s :: cont sep (mk_elim t xu :: a) - | Apply (t, s) -> mk_note s :: cont sep (mk_apply t :: a) - | Whd (c, s) -> mk_note s :: cont sep (mk_whd c :: a) - | Change (t, _, s) -> mk_note s :: cont sep (mk_change t :: a) - | Branch ([], s) -> a - | Branch ([ps], s) -> render_steps sep a ps - | Branch (pss, s) -> - let a = mk_ob :: a in - let body = mk_cb :: list_rev_map_concat (render_steps None) mk_vb a pss in - mk_note s :: cont sep body + | Note s -> mk_note s :: a + | Theorem (n, t, s) -> mk_theorem n t :: mk_note s :: a + | Qed s -> mk_qed :: mk_nlnote s a + | Id s -> mk_id sep :: mk_nlnote s a + | Intros (c, ns, s) -> mk_intros c ns sep :: mk_nlnote s a + | Cut (n, t, s) -> mk_cut n t sep :: mk_nlnote s a + | LetIn (n, t, s) -> mk_letin n t sep :: mk_nlnote s a + | Rewrite (b, t, w, e, s) -> mk_rewrite b t w e sep :: mk_nlnote s a + | Elim (t, xu, e, s) -> mk_elim t xu e sep :: mk_nlnote s a + | Apply (t, s) -> mk_apply t sep :: mk_nlnote s a + | Change (t, _, w, e, s) -> mk_change t w e sep :: mk_nlnote s a + | ClearBody (n, s) -> mk_clearbody n sep :: mk_nlnote s a + | Branch ([], s) -> a + | Branch ([ps], s) -> render_steps sep a ps + | Branch (ps :: pss, s) -> + let a = mk_ob :: mk_nlnote s a in + let a = List.fold_left (render_steps mk_vb) a pss in + mk_punctation sep :: render_steps mk_cb a ps and render_steps sep a = function | [] -> a @@ -194,11 +183,11 @@ and render_steps sep a = function | p :: Branch ([], _) :: ps -> render_steps sep a (p :: ps) | p :: ((Branch (_ :: _ :: _, _) :: _) as ps) -> - render_steps sep (render_step (Some mk_sc) a p) ps + render_steps sep (render_step mk_sc a p) ps | p :: ps -> - render_steps sep (render_step (Some mk_dot) a p) ps + render_steps sep (render_step mk_dot a p) ps -let render_steps a = render_steps None a +let render_steps a = render_steps mk_dot a (* counting *****************************************************************)