src/Tools/isac/Specify/p-model.sml
author wneuper <Walther.Neuper@jku.at>
Mon, 11 Dec 2023 17:26:30 +0100
changeset 60782 e797d1bdfe37
parent 60776 c2e6848d3dce
permissions -rw-r--r--
eliminate the intermediate *_POS
     1 (* Title: Specify/p-model.sml
     2    Author: Walther Neuper 170207
     3    (c) due to copyright terms
     4 
     5 This will mostly be dropped at switch to Isabelle/PIDE .
     6 *)
     7 
     8 signature PRESENTATION_MODEL =
     9 sig
    10   (* for the OLD P_Model.T *)
    11   type T
    12   val empty: T
    13   val to_string: T -> string
    14 
    15   datatype item = (*shall be dropped with PIDE*)
    16     Correct of TermC.as_string | False of TermC.as_string | Incompl of TermC.as_string
    17   | Missing of TermC.as_string | Superfl of string | SyntaxE of string | TypeE of string
    18   type 'a model     (*shall be dropped with PIDE*)
    19 
    20   val from: theory -> I_Model.T -> Pre_Conds.T ->
    21     {Find: item list, Given: item list, Relate: item list, Where: item list, With: item list}
    22 
    23   val to_list: 'a model -> 'a list
    24   val mk_delete: theory -> string -> I_Model.feedback -> Tactic.input
    25   val mk_additem: string -> TermC.as_string -> Tactic.input
    26 
    27   val item_from_feedback: theory -> I_Model.feedback -> item
    28 (*from isac_test for Minisubpbl*)
    29   val add_sel_ppc: theory -> string -> {Find: 'a list, Given: 'a list, Relate: 'a list, Where: 'a list, With: 'b} -> 'a -> {Find: 'a list, Given: 'a list, Relate: 'a list, Where: 'a list, With: 'b}
    30 
    31 (**)
    32 
    33 \<^isac_test>\<open>
    34 (**)
    35 \<close>
    36 end
    37 
    38 (**)
    39 structure P_Model(**) : PRESENTATION_MODEL(**) =
    40 struct
    41 (**)
    42 
    43 datatype switch_pbl_met = For_Problem | For_Method
    44 
    45 (** types for OLD presentation**)
    46 
    47 type 'a model = 
    48   {Given : 'a list, Where: 'a list, Find  : 'a list, With : 'a list, Relate: 'a list};
    49 datatype item = 
    50     Correct of TermC.as_string (* labels a correct formula (type cterm') *)
    51   | SyntaxE of string (**)
    52   | TypeE   of string (**)
    53   | False   of TermC.as_string (* WN050618 notexistent in itm_: only used in Where *)
    54   | Incompl of TermC.as_string (**)
    55   | Superfl of string (**)
    56   | Missing of TermC.as_string; (*REVIEW: a "missing" item is not shown, thus cannot be marked*)
    57 
    58 type T = item model;
    59 fun item2str (Correct  s) = "Correct " ^ s
    60   | item2str (SyntaxE  s) = "SyntaxE " ^ s
    61   | item2str (TypeE    s) = "TypeE " ^ s
    62   | item2str (False    s) = "False " ^ s
    63   | item2str (Incompl  s) = "Incompl " ^ s
    64   | item2str (Superfl  s) = "Superfl " ^ s
    65   | item2str (Missing  s) = "Missing " ^ s;
    66 
    67 fun to_string ({Given=Given,Where=Where,
    68 		 Find=Find,With=With,Relate=Relate}:item model)=
    69     ("{Given =" ^ ((strs2str' o (map item2str))	 Given ) ^
    70      ",Where=" ^ ((strs2str' o (map item2str))	 Where) ^
    71      ",Find  =" ^ ((strs2str' o (map item2str))	 Find  ) ^
    72      ",With =" ^ ((strs2str' o (map item2str))	 With ) ^
    73      ",Relate=" ^ ((strs2str' o (map item2str))	 Relate) ^ "}");
    74 
    75 val empty = {Given = [], Where= [], Find  = [], With = [], Relate= []};
    76 
    77 
    78 (** build T **)
    79 
    80 fun item_from_feedback thy (I_Model.Cor ((d, ts))) =
    81     Correct (UnparseC.term_in_thy thy (Input_Descript.join (d, ts)))
    82   | item_from_feedback _ (I_Model.Syn c) = SyntaxE c
    83   | item_from_feedback thy (I_Model.Inc ((d, ts))) =
    84     Incompl (UnparseC.term_in_thy thy  (Input_Descript.join (d, ts)))
    85   | item_from_feedback thy (I_Model.Sup (d, ts)) =
    86     Superfl (UnparseC.term_in_thy thy  (Input_Descript.join (d, ts)))
    87 
    88 fun add_sel_ppc (_: theory) sel {Given = gi, Where = wh, Find = fi, With = wi, Relate = re} x =
    89   case sel of
    90     "#Given" => {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re}
    91   | "#Where" => {Given = gi, Where = wh @ [x], Find = fi, With = wi, Relate = re}
    92   | "#Find"  => {Given = gi, Where = wh, Find = fi @ [x], With = wi, Relate = re}
    93   | "#Relate"=> {Given = gi, Where = wh, Find = fi, With = wi, Relate = re @ [x]}
    94   | "#undef" =>         {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re} (*ori2itmSup*)
    95   | "i_model_empty" => {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re} (*ori2itmSup*)
    96   | _  => raise ERROR ("add_sel_ppc tried to select by \"" ^ sel ^ "\"")
    97 fun add_where {Given = gi, Where = _, Find = fi, With = wi, Relate = re} wh =
    98   {Given = gi, Where = wh, Find= fi , With = wi, Relate = re}
    99 
   100 fun boolterm2item ctxt (true, term) = Correct (UnparseC.term ctxt term)
   101   | boolterm2item ctxt(false, term) = False (UnparseC.term ctxt term);
   102 
   103 fun from thy i_model where_ =
   104   let                                                                                     
   105     fun coll model [] = model
   106       | coll model ((_, _, _, field, (feedb, _)) :: itms) =
   107         coll (add_sel_ppc thy field model (item_from_feedback thy feedb)) itms;
   108     val gfr = coll empty i_model;
   109   in add_where gfr (map (boolterm2item (Proof_Context.init_global thy)) where_) end;
   110 
   111 fun mk_delete thy "#Given" itm_ = Tactic.Del_Given (I_Model.to_p_model thy itm_)
   112   | mk_delete thy "#Find" itm_ = Tactic.Del_Find (I_Model.to_p_model thy itm_)
   113   | mk_delete thy "#Relate" itm_ = Tactic.Del_Relation (I_Model.to_p_model thy itm_)
   114   | mk_delete _ str _ = raise ERROR ("mk_delete: called with field \"" ^ str ^ "\"")
   115 fun mk_additem "#Given" ct = Tactic.Add_Given ct
   116   | mk_additem "#Find" ct = Tactic.Add_Find ct    
   117   | mk_additem "#Relate"ct = Tactic.Add_Relation ct
   118   | mk_additem str _ = raise ERROR ("mk_additem: called with field \"" ^ str ^ "\"")
   119 
   120 fun to_list {Given = gis, Where = whs, Find = fis, With = wis, Relate = res} =
   121   gis @ whs @ fis @ wis @ res
   122 
   123 (**)end(*struct*);