src/Tools/isac/Specify/p-model.sml
author wneuper <Walther.Neuper@jku.at>
Fri, 01 Dec 2023 06:08:22 +0100
changeset 60771 1b072aab8f4e
parent 60760 3b173806efe2
child 60772 ac0317936138
permissions -rw-r--r--
PIDE turn 13: rename ALL(?) code already handling Position.T from *_TEST to *_POS

Note: after switching all src to Position.T *_POS shall be cut of identifiers.
     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 -> T
    21 
    22   val to_list: 'a model -> 'a list
    23   val mk_delete: theory -> string -> I_Model.feedback -> Tactic.input
    24   val mk_additem: string -> TermC.as_string -> Tactic.input
    25 
    26   val item_from_feedback: theory -> I_Model.feedback -> item
    27 (*from isac_test for Minisubpbl*)
    28   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}
    29 
    30 (**)
    31 
    32 \<^isac_test>\<open>
    33 (**)
    34 \<close>
    35 end
    36 
    37 (**)
    38 structure P_Model(**) : PRESENTATION_MODEL(**) =
    39 struct
    40 (**)
    41 
    42 datatype switch_pbl_met = For_Problem | For_Method
    43 
    44 (** types for OLD presentation**)
    45 
    46 type 'a model = 
    47   {Given : 'a list, Where: 'a list, Find  : 'a list, With : 'a list, Relate: 'a list};
    48 datatype item = 
    49     Correct of TermC.as_string (* labels a correct formula (type cterm') *)
    50   | SyntaxE of string (**)
    51   | TypeE   of string (**)
    52   | False   of TermC.as_string (* WN050618 notexistent in itm_: only used in Where *)
    53   | Incompl of TermC.as_string (**)
    54   | Superfl of string (**)
    55   | Missing of TermC.as_string; (*REVIEW: a "missing" item is not shown, thus cannot be marked*)
    56 
    57 type T = item model;
    58 fun item2str (Correct  s) = "Correct " ^ s
    59   | item2str (SyntaxE  s) = "SyntaxE " ^ s
    60   | item2str (TypeE    s) = "TypeE " ^ s
    61   | item2str (False    s) = "False " ^ s
    62   | item2str (Incompl  s) = "Incompl " ^ s
    63   | item2str (Superfl  s) = "Superfl " ^ s
    64   | item2str (Missing  s) = "Missing " ^ s;
    65 
    66 fun to_string ({Given=Given,Where=Where,
    67 		 Find=Find,With=With,Relate=Relate}:item model)=
    68     ("{Given =" ^ ((strs2str' o (map item2str))	 Given ) ^
    69      ",Where=" ^ ((strs2str' o (map item2str))	 Where) ^
    70      ",Find  =" ^ ((strs2str' o (map item2str))	 Find  ) ^
    71      ",With =" ^ ((strs2str' o (map item2str))	 With ) ^
    72      ",Relate=" ^ ((strs2str' o (map item2str))	 Relate) ^ "}");
    73 
    74 val empty = {Given = [], Where= [], Find  = [], With = [], Relate= []};
    75 
    76 
    77 (** build T **)
    78 
    79 (*T_POSold*)
    80 fun item_from_feedback thy (I_Model.Cor ((d, ts), _)) = Correct (UnparseC.term_in_thy thy (Input_Descript.join (d, ts)))
    81   | item_from_feedback _ (I_Model.Syn c) = SyntaxE c
    82   | item_from_feedback _ (I_Model.Typ c) = TypeE c
    83   | item_from_feedback thy (I_Model.Inc ((d, ts), _)) = Incompl (UnparseC.term_in_thy thy  (Input_Descript.join (d, ts)))
    84   | item_from_feedback thy (I_Model.Sup (d, ts)) = Superfl (UnparseC.term_in_thy thy  (Input_Descript.join (d, ts)))
    85   | item_from_feedback thy (I_Model.Mis (d, pid)) = Missing (UnparseC.term_in_thy thy d ^ " " ^ UnparseC.term_in_thy thy  pid)
    86   | item_from_feedback _ _ = raise ERROR "item_from_feedback: uncovered definition"
    87 (*T_POS* )
    88 fun item_from_feedback_POS thy (I_Model.Cor_POS ((d, ts), _)) = Correct (UnparseC.term_in_thy thy (Input_Descript.join (d, ts)))
    89   | item_from_feedback_POS _ (I_Model.Syn_POS c) = SyntaxE c
    90   | item_from_feedback_POS thy (I_Model.Inc_POS ((d, ts), _)) = Incompl (UnparseC.term_in_thy thy  (Input_Descript.join (d, ts)))
    91   | item_from_feedback_POS thy (I_Model.Sup_POS (d, ts)) = Superfl (UnparseC.term_in_thy thy  (Input_Descript.join (d, ts)))
    92 ( *T_POSnew*)
    93 
    94 fun add_sel_ppc (_: theory) sel {Given = gi, Where = wh, Find = fi, With = wi, Relate = re} x =
    95   case sel of
    96     "#Given" => {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re}
    97   | "#Where" => {Given = gi, Where = wh @ [x], Find = fi, With = wi, Relate = re}
    98   | "#Find"  => {Given = gi, Where = wh, Find = fi @ [x], With = wi, Relate = re}
    99   | "#Relate"=> {Given = gi, Where = wh, Find = fi, With = wi, Relate = re @ [x]}
   100   | "#undef" =>         {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re} (*ori2itmSup*)
   101   | "i_model_empty" => {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re} (*ori2itmSup*)
   102   | _  => raise ERROR ("add_sel_ppc tried to select by \"" ^ sel ^ "\"")
   103 fun add_where {Given = gi, Where = _, Find = fi, With = wi, Relate = re} wh =
   104   {Given = gi, Where = wh, Find= fi , With = wi, Relate = re}
   105 
   106 fun boolterm2item ctxt (true, term) = Correct (UnparseC.term ctxt term)
   107   | boolterm2item ctxt(false, term) = False (UnparseC.term ctxt term);
   108 
   109 fun from thy itms where_ =
   110   let                                                                                     
   111     fun coll model [] = model
   112       | coll model ((_, _, _, field, itm_) :: itms) =
   113         coll (add_sel_ppc thy field model (item_from_feedback thy itm_)) itms;
   114     val gfr = coll empty itms;
   115   in add_where gfr (map (boolterm2item (Proof_Context.init_global thy)) where_) end;
   116 
   117 fun mk_delete thy "#Given" itm_ = Tactic.Del_Given (I_Model.to_p_model thy itm_)
   118   | mk_delete thy "#Find" itm_ = Tactic.Del_Find (I_Model.to_p_model thy itm_)
   119   | mk_delete thy "#Relate" itm_ = Tactic.Del_Relation (I_Model.to_p_model thy itm_)
   120   | mk_delete _ str _ = raise ERROR ("mk_delete: called with field \"" ^ str ^ "\"")
   121 fun mk_additem "#Given" ct = Tactic.Add_Given ct
   122   | mk_additem "#Find" ct = Tactic.Add_Find ct    
   123   | mk_additem "#Relate"ct = Tactic.Add_Relation ct
   124   | mk_additem str _ = raise ERROR ("mk_additem: called with field \"" ^ str ^ "\"")
   125 
   126 fun to_list {Given = gis, Where = whs, Find = fis, With = wis, Relate = res} =
   127   gis @ whs @ fis @ wis @ res
   128 
   129 (**)end(*struct*);