1 (* Title: MathEngine/fetch-tactics.sml
3 (c) due to copyright terms
5 Fetch tactics from a program in order to present them for selection by the user
8 signature FETCH_TACTICS =
10 val from_prog : Ctree.ctree -> Pos.pos' -> Tactic.input list
11 val specific_from_prog : Ctree.ctree -> Pos.pos' -> Tactic.input list
15 structure Fetch_Tacs(**): FETCH_TACTICS(**) =
21 (* fetch _all_ tactics from a program *)
22 fun from_prog _ ([], Res) =
23 raise PTREE "no tactics applicable at the end of a calculation"
24 | from_prog pt (p,p_) =
25 if Pos.on_specification p_
26 then [get_obj g_tac pt p]
29 val pp = par_pblobj pt p;
30 val thy' = get_obj g_domID pt pp;
31 val thy = ThyC.get_theory thy';
32 val metID = get_obj g_metID pt pp;
33 val metID' = if metID = Method.id_empty then (thd3 o snd3) (get_obj g_origin pt pp) else metID
34 val (sc, srls) = (case Specify.get_met metID' of
35 {scr = Rule.Prog sc, srls, ...} => (sc, srls) | _ => raise ERROR "from_prog 1")
36 val subst = get_istate_LI pt (p, p_) |> Istate.the_pstate |> Istate.get_subst
37 val ctxt = get_ctxt pt (p, p_)
38 in map ((LItool.tac_from_prog pt thy) o Program.rep_stacexpr o #1 o
39 (LItool.check_leaf "selrul" ctxt srls subst)) (Auto_Prog.stacpbls sc)
42 (* fetch tactics from script and filter _applicable_ tactics;
43 in case of Rewrite_Set* go down to _atomic_ rewrite-tactics *)
44 fun specific_from_prog _ (([], Res) : pos') =
45 raise PTREE "no tactics applicable at the end of a calculation"
46 | specific_from_prog pt (p, p_) =
47 if Pos.on_specification p_
48 then [get_obj g_tac pt p]
51 val pp = par_pblobj pt p
52 val thy' = get_obj g_domID pt pp
53 val thy = ThyC.get_theory thy'
54 val metID = get_obj g_metID pt pp
56 if metID = Method.id_empty
57 then (thd3 o snd3) (get_obj g_origin pt pp)
59 val (sc, srls, erls, ro) = (case Specify.get_met metID' of
60 {scr = Rule.Prog sc, srls, erls, rew_ord' = ro, ...} => (sc, srls, erls, ro)
61 | _ => raise ERROR "specific_from_prog 1")
62 val (env, (a, v)) = (case get_istate_LI pt (p, p_) of
63 Istate.Pstate pst => (Istate.get_subst pst) | _ => error "specific_from_prog 2")
64 val ctxt = get_ctxt pt (p, p_)
65 val alltacs = (*we expect at least 1 Prog_Tac in a program*)
66 map ((LItool.tac_from_prog pt thy) o Program.rep_stacexpr o #1 o
67 (LItool.check_leaf "selrul" ctxt srls (env, (a, v)))) (Auto_Prog.stacpbls sc)
69 (case p_ of Frm => get_obj g_form pt p | Res => (fst o (get_obj g_result pt)) p
70 | _ => raise ERROR "specific_from_prog 2")
71 (*WN071231 ? replace atomic_appl_tacs with applicable_in (ineff!) ?*)
73 ((gen_distinct Tactic.eq_tac) o flat o (map (Tactic.applicable thy ro erls f))) alltacs