1 (* Title: Specify/p-model.sml
2 Author: Walther Neuper 170207
3 (c) due to copyright terms
5 This will be dropped at switch to Isabelle/PIDE .
8 signature PRESENTATION_MODEL =
12 val to_string: T -> string
14 datatype item = (*shall be dropped with PIDE*)
15 Correct of TermC.as_string | False of TermC.as_string | Incompl of TermC.as_string
16 | Missing of TermC.as_string | Superfl of string | SyntaxE of string | TypeE of string
17 type 'a ppc (*shall be dropped with PIDE*)
19 val from : theory -> I_Model.T -> Pre_Conds.T -> T
21 val to_list: 'a ppc -> 'a list
22 (*/------- rename -------\*)
23 (*val mk_delete: theory -> string -> I_Model.feedback -> Tactic.input*)
24 val mk_delete: theory -> string -> I_Model.feedback -> Tactic.input
25 (*val mk_additem: string -> TermC.as_string -> Tactic.input*)
26 val mk_additem: string -> TermC.as_string -> Tactic.input
27 (*\------- rename -------/*)
29 val item_from_feedback: theory -> I_Model.feedback -> item
34 structure P_Model(**) : PRESENTATION_MODEL(**) =
41 {Given : 'a list, Where: 'a list, Find : 'a list, With : 'a list, Relate: 'a list};
43 Correct of TermC.as_string (* labels a correct formula (type cterm') *)
44 | SyntaxE of string (**)
45 | TypeE of string (**)
46 | False of TermC.as_string (* WN050618 notexistent in itm_: only used in Where *)
47 | Incompl of TermC.as_string (**)
48 | Superfl of string (**)
49 | Missing of TermC.as_string; (*REVIEW: a "missing" item is not shown, thus cannot be marked*)
52 fun item2str (Correct s) = "Correct " ^ s
53 | item2str (SyntaxE s) = "SyntaxE " ^ s
54 | item2str (TypeE s) = "TypeE " ^ s
55 | item2str (False s) = "False " ^ s
56 | item2str (Incompl s) = "Incompl " ^ s
57 | item2str (Superfl s) = "Superfl " ^ s
58 | item2str (Missing s) = "Missing " ^ s;
60 fun to_string ({Given=Given,Where=Where,
61 Find=Find,With=With,Relate=Relate}:item ppc)=
62 ("{Given =" ^ ((strs2str' o (map item2str)) Given ) ^
63 ",Where=" ^ ((strs2str' o (map item2str)) Where) ^
64 ",Find =" ^ ((strs2str' o (map item2str)) Find ) ^
65 ",With =" ^ ((strs2str' o (map item2str)) With ) ^
66 ",Relate=" ^ ((strs2str' o (map item2str)) Relate) ^ "}");
68 val empty = {Given = [], Where= [], Find = [], With = [], Relate= []};
73 fun item_from_feedback (_: theory) (I_Model.Cor ((d, ts), _)) = Correct (UnparseC.term (Input_Descript.join (d, ts)))
74 | item_from_feedback _ (I_Model.Syn c) = SyntaxE c
75 | item_from_feedback _ (I_Model.Typ c) = TypeE c
76 | item_from_feedback _ (I_Model.Inc ((d, ts), _)) = Incompl (UnparseC.term (Input_Descript.join (d, ts)))
77 | item_from_feedback _ (I_Model.Sup (d, ts)) = Superfl (UnparseC.term (Input_Descript.join (d, ts)))
78 | item_from_feedback _ (I_Model.Mis (d, pid)) = Missing (UnparseC.term d ^ " " ^ UnparseC.term pid)
79 | item_from_feedback _ _ = raise ERROR "item_from_feedback: uncovered definition"
81 fun add_sel_ppc (_: theory) sel {Given = gi, Where = wh, Find = fi, With = wi, Relate = re} x =
83 "#Given" => {Given = gi @ [x], Where = wh, Find = fi, With = wi,Relate = re}
84 | "#Where" => {Given = gi, Where = wh @ [x], Find = fi, With = wi, Relate = re}
85 | "#Find" => {Given = gi, Where = wh, Find = fi @ [x], With = wi, Relate = re}
86 | "#Relate"=> {Given = gi, Where = wh, Find = fi, With = wi, Relate = re @ [x]}
87 | "#undef" => {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re} (*ori2itmSup*)
88 | _ => raise ERROR ("add_sel_ppc tried to select by \"" ^ sel ^ "\"")
89 fun add_where {Given = gi, Where = _, Find = fi, With = wi, Relate = re} wh =
90 {Given = gi, Where = wh, Find= fi ,With = wi, Relate = re}
92 fun boolterm2item (true, term) = Correct (UnparseC.term term)
93 | boolterm2item (false, term) = False (UnparseC.term term);
95 fun from thy itms pre =
98 | coll ppc ((_, _, _, field, itm_)::itms) =
99 coll (add_sel_ppc thy field ppc (item_from_feedback thy itm_)) itms;
100 val gfr = coll empty itms;
101 in add_where gfr (map boolterm2item pre) end;
103 fun mk_delete thy "#Given" itm_ = Tactic.Del_Given (I_Model.to_p_model thy itm_)
104 | mk_delete thy "#Find" itm_ = Tactic.Del_Find (I_Model.to_p_model thy itm_)
105 | mk_delete thy "#Relate" itm_ = Tactic.Del_Relation (I_Model.to_p_model thy itm_)
106 | mk_delete _ str _ = raise ERROR ("mk_delete: called with field \"" ^ str ^ "\"")
107 fun mk_additem "#Given" ct = Tactic.Add_Given ct
108 | mk_additem "#Find" ct = Tactic.Add_Find ct
109 | mk_additem "#Relate"ct = Tactic.Add_Relation ct
110 | mk_additem str _ = raise ERROR ("mk_additem: called with field \"" ^ str ^ "\"")
112 fun to_list {Given = gis, Where = whs, Find = fis, With = wis, Relate = res} =
113 gis @ whs @ fis @ wis @ res