1 (* Title: Specify/p-spec.sml
3 (c) due to copyright terms
5 Major parts will be dropped at switch to Isabelle/PIDE.
6 Thus the switch to I_Model.T is prepared quick and dirty.
9 signature PRESENTATION_SPECIFICATION =
12 (*/------- rename -------\*)
14 Find of TermC.as_string list
15 | Given of TermC.as_string list
16 | Relate of TermC.as_string list
18 val appl_add': ThyC.id -> O_Model.T -> I_Model.T -> Model_Pattern.T ->
19 string * TermC.as_string -> I_Model.single
20 val appl_adds: ThyC.id -> O_Model.T -> I_Model.T -> Model_Pattern.T ->
21 (Model_Def.m_field * TermC.as_string) list -> I_Model.T
22 val eq7: ''a * ''b -> ''a * (''b * 'c) -> bool
23 val fstr2itm_: theory -> Model_Pattern.T -> Model_Def.m_field * string ->
24 int list * bool * Model_Def.m_field * (I_Model.feedback * Position.T)
25 val imodel2fstr: p_model list -> (string * TermC.as_string) list
26 val is_e_ts: term list -> bool
27 val itms2fstr: Proof.context -> I_Model.single -> string * string
28 val par2fstr: I_Model.single -> string * TermC.as_string
29 val unknown_expl: ThyC.id -> Model_Pattern.T -> (Model_Def.m_field * string) list -> I_Model.T
30 (*\----- from isac_test for Minisubpbl*)
35 (*\------- rename -------/*)
39 structure P_Spec(**): PRESENTATION_SPECIFICATION(**) =
43 type record = {thy_id: ThyC.id, pbl_id: Problem.id, (* headline of Problem *)
44 givens: TermC.as_string list, wheres: TermC.as_string list, (* Model.T *)
45 find: TermC.as_string, relates: TermC.as_string list,
46 rthy_id: ThyC.id, rpbl_id: Problem.id, rmet_id: MethodC.id} (* References.T *)
48 fun flattup2 (a, (b ,c, d, e)) = (a, b, c, d, e)
50 (** handle an input P_Specific'action **)
53 Given of TermC.as_string list
54 (*Where is still not input*)
55 | Find of TermC.as_string list
56 | Relate of TermC.as_string list
59 | is_e_ts [Const (\<^const_name>\<open>Nil\<close>, _)] = true
62 fun appl_add' dI oris (model: I_Model.T) pbt (sel, ct) =
64 val ctxt = Know_Store.get_via_last_thy dI |> Proof_Context.init_global;
66 (*/------------ replace by ParseC.term_position ------------------\*)
67 case ParseC.term_opt ctxt ct of
68 (*\------------ replace by ParseC.term_position ------------------/*)
69 NONE => (0, [], false, sel, (I_Model.Syn ct, Position.none))
71 (case O_Model.contains ctxt sel oris t of
73 (case I_Model.is_notyet_input ctxt model all ori' pbt of
75 | (msg,_) => raise ERROR ("P_Spec.appl_add': " ^ msg))
76 | (_, (i, v, _, d, ts), _) =>
78 then (i, v, false, sel, (I_Model.Inc (d, ts), Position.none))
79 else (i, v, false, sel, (I_Model.Sup (d, ts), Position.none)))
82 (* generate preliminary itm_ from a string (with field "#Given" etc.) *)
83 fun eq7 (f, d) (f', (d', _)) = f = f' andalso d = d';
84 fun fstr2itm_ thy pbt (f, str) =
86 (*/------------ replace by ParseC.term_position ? ------------\*)
87 val topt = ParseC.term_opt (Proof_Context.init_global thy) str
88 (*\------------ replace by ParseC.term_position ? ------------/*)
91 NONE => ([], false, f, (I_Model.Syn str, Position.none))
94 val (d, ts) = Input_Descript.split ct
95 val popt = find_first (eq7 (f, d)) pbt
98 NONE => ([1](*??*), true(*??*), f, (I_Model.Sup (d, ts), Position.none))
99 | SOME (f, (d, id)) => ([1], true, f, (I_Model.Cor (d, ts), Position.none))
103 (*.input into empty PblObj, i.e. empty fmz+origin (unknown example).*)
104 fun unknown_expl dI pbt selcts =
106 val thy = Know_Store.get_via_last_thy dI
107 val its_ = map (fstr2itm_ thy pbt) selcts
108 val its = O_Model.add_enumerate its_
109 in map flattup2 its end
111 fun eq_dsc ((_, _, _, _, (itm_, _)), (_, _, _, _, (iitm_, _))) =
112 (I_Model.descriptor itm_ = I_Model.descriptor iitm_)
113 fun add itm (itms: I_Model.T) = if member eq_dsc itms itm then itms else itms @ [itm] (* @ new itm *)
114 fun appl_adds dI [] _ pbt selcts = unknown_expl dI pbt selcts
115 (*already present itms in model are being overwritten*)
116 | appl_adds _ _ (model: I_Model.T) _ [] = model
117 | appl_adds dI oris (model: I_Model.T) pbt (selct :: ss) =
118 let val itm = appl_add' dI oris model pbt selct;
119 in appl_adds dI oris (add itm model) pbt ss end
121 fun par2fstr (_, _, _, f, (I_Model.Syn s, _)) = (f, s)
122 | par2fstr itm = raise ERROR ("par2fstr: called with " ^
123 I_Model.single_to_string (ContextC.for_ERROR ()) itm)
125 fun itms2fstr _ (_, _, _, f, (I_Model.Cor (d, ts), _)) = (f, Input_Descript.join''' (d, ts))
126 | itms2fstr _ (_, _, _, f, (I_Model.Syn str, _)) = (f, str)
127 | itms2fstr _ (_, _, _, f, (I_Model.Inc (d, ts), _)) = (f, Input_Descript.join''' (d,ts))
128 | itms2fstr _ (_, _, _, f, (I_Model.Sup (d, ts), _)) = (f, Input_Descript.join''' (d, ts))
130 fun imodel2fstr iitems =
133 | xxx is ((Given strs)::iis) = xxx (is @ (map (pair "#Given") strs)) iis
134 | xxx is ((Find strs)::iis) = xxx (is @ (map (pair "#Find") strs)) iis
135 | xxx is ((Relate strs)::iis) = xxx (is @ (map (pair "#Relate") strs)) iis
136 in xxx [] iitems end;