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