src/Tools/isac/Specify/p-model.sml
author Walther Neuper <walther.neuper@jku.at>
Mon, 18 May 2020 11:48:27 +0200
changeset 59990 ca6f741c0ca3
parent 59989 31f54ab9b2ce
child 60111 2e996663e5a7
permissions -rw-r--r--
shift code from Specification to Specify
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@59959
     5
This will be dropped at switch to Isabelle/PIDE.
wneuper@59316
     6
*)
wneuper@59316
     7
walther@59959
     8
signature PRESENTATION_MODEL =
wneuper@59316
     9
sig
walther@59969
    10
  type T
walther@59969
    11
  val empty: T
walther@59969
    12
  val to_string: T -> string
walther@59943
    13
walther@59969
    14
  datatype item = (*shall be dropped with PIDE*)
walther@59969
    15
    Correct of TermC.as_string | False of TermC.as_string | Incompl of TermC.as_string
walther@59969
    16
  | Missing of TermC.as_string | Superfl of string | SyntaxE of string | TypeE of string
walther@59969
    17
  type 'a ppc     (*shall be dropped with PIDE*)
wneuper@59316
    18
walther@59969
    19
  val from : theory -> I_Model.T -> Pre_Conds.T -> T
walther@59989
    20
wneuper@59316
    21
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
walther@59989
    22
  val to_list: 'a ppc -> 'a list
walther@59990
    23
(*/------- rename -------\*)
walther@59990
    24
(*val mk_delete: theory -> string -> I_Model.feedback -> Tactic.input*)
walther@59989
    25
  val mk_delete: theory -> string -> I_Model.feedback -> Tactic.input
walther@59990
    26
(*val mk_additem: string -> TermC.as_string -> Tactic.input*)
walther@59989
    27
  val mk_additem: string -> TermC.as_string -> Tactic.input
walther@59990
    28
(*\------- rename -------/*)
walther@59886
    29
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
walther@59969
    30
  val item_from_feedback: theory -> I_Model.feedback -> item
walther@59886
    31
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
wneuper@59316
    32
end
wneuper@59316
    33
walther@59968
    34
(**)
walther@59959
    35
structure P_Model(**) : PRESENTATION_MODEL(**) =
wneuper@59316
    36
struct
walther@59968
    37
(**)
wneuper@59316
    38
walther@59969
    39
(** types **)
wneuper@59316
    40
walther@59969
    41
type 'a ppc = 
walther@59969
    42
  {Given : 'a list, Where: 'a list, Find  : 'a list, With : 'a list, Relate: 'a list};
wneuper@59316
    43
datatype item = 
walther@59865
    44
    Correct of TermC.as_string (* labels a correct formula (type cterm') *)
wneuper@59316
    45
  | SyntaxE of string (**)
wneuper@59316
    46
  | TypeE   of string (**)
walther@59865
    47
  | False   of TermC.as_string (* WN050618 notexistent in itm_: only used in Where *)
walther@59865
    48
  | Incompl of TermC.as_string (**)
wneuper@59316
    49
  | Superfl of string (**)
walther@59865
    50
  | Missing of TermC.as_string;
walther@59969
    51
walther@59969
    52
type T = item ppc;
walther@59937
    53
fun item2str (Correct  s) = "Correct " ^ s
walther@59937
    54
  | item2str (SyntaxE  s) = "SyntaxE " ^ s
walther@59937
    55
  | item2str (TypeE    s) = "TypeE " ^ s
walther@59937
    56
  | item2str (False    s) = "False " ^ s
walther@59937
    57
  | item2str (Incompl  s) = "Incompl " ^ s
walther@59937
    58
  | item2str (Superfl  s) = "Superfl " ^ s
walther@59937
    59
  | item2str (Missing  s) = "Missing " ^ s;
walther@59937
    60
walther@59969
    61
fun to_string ({Given=Given,Where=Where,
wneuper@59316
    62
		 Find=Find,With=With,Relate=Relate}:item ppc)=
wneuper@59316
    63
    ("{Given =" ^ ((strs2str' o (map item2str))	 Given ) ^
wneuper@59316
    64
     ",Where=" ^ ((strs2str' o (map item2str))	 Where) ^
wneuper@59316
    65
     ",Find  =" ^ ((strs2str' o (map item2str))	 Find  ) ^
wneuper@59316
    66
     ",With =" ^ ((strs2str' o (map item2str))	 With ) ^
wneuper@59316
    67
     ",Relate=" ^ ((strs2str' o (map item2str))	 Relate) ^ "}");
wneuper@59316
    68
walther@59969
    69
val empty = {Given = [], Where= [], Find  = [], With = [], Relate= []};
wneuper@59316
    70
walther@59968
    71
walther@59969
    72
(** build T **)
walther@59969
    73
walther@59969
    74
fun item_from_feedback (_: theory) (I_Model.Cor ((d, ts), _)) = Correct (UnparseC.term (Input_Descript.join (d, ts)))
walther@59969
    75
  | item_from_feedback _ (I_Model.Syn c) = SyntaxE c
walther@59969
    76
  | item_from_feedback _ (I_Model.Typ c) = TypeE c
walther@59969
    77
  | item_from_feedback _ (I_Model.Inc ((d, ts), _)) = Incompl (UnparseC.term (Input_Descript.join (d, ts)))
walther@59969
    78
  | item_from_feedback _ (I_Model.Sup (d, ts)) = Superfl (UnparseC.term (Input_Descript.join (d, ts)))
walther@59969
    79
  | item_from_feedback _ (I_Model.Mis (d, pid)) = Missing (UnparseC.term d ^ " " ^ UnparseC.term pid)
walther@59969
    80
  | item_from_feedback _ _ = raise ERROR "item_from_feedback: uncovered definition"
walther@59968
    81
walther@59968
    82
fun add_sel_ppc (_: theory) sel {Given = gi, Where = wh, Find = fi, With = wi, Relate = re} x =
walther@59968
    83
  case sel of
walther@59968
    84
    "#Given" => {Given = gi @ [x], Where = wh, Find = fi, With = wi,Relate = re}
walther@59968
    85
  | "#Where" => {Given = gi, Where = wh @ [x], Find = fi, With = wi, Relate = re}
walther@59968
    86
  | "#Find"  => {Given = gi, Where = wh, Find = fi @ [x], With = wi, Relate = re}
walther@59968
    87
  | "#Relate"=> {Given = gi, Where = wh, Find = fi, With = wi, Relate = re @ [x]}
walther@59968
    88
  | "#undef" => {Given = gi @ [x], Where = wh, Find = fi, With = wi, Relate = re} (*ori2itmSup*)
walther@59968
    89
  | _  => raise ERROR ("add_sel_ppc tried to select by \"" ^ sel ^ "\"")
walther@59968
    90
fun add_where {Given = gi, Where = _, Find = fi, With = wi, Relate = re} wh =
walther@59968
    91
  {Given = gi, Where = wh, Find= fi ,With = wi, Relate = re}
walther@59968
    92
walther@59968
    93
fun boolterm2item (true, term) = Correct (UnparseC.term term)
walther@59968
    94
  | boolterm2item (false, term) = False (UnparseC.term term);
walther@59968
    95
walther@59969
    96
fun from thy itms pre =
walther@59968
    97
  let
walther@59968
    98
    fun coll ppc [] = ppc
walther@59969
    99
      | coll ppc ((_, _, _, field, itm_)::itms) =
walther@59969
   100
        coll (add_sel_ppc thy field ppc (item_from_feedback thy itm_)) itms;
walther@59969
   101
    val gfr = coll empty itms;
walther@59968
   102
  in add_where gfr (map boolterm2item pre) end;
walther@59968
   103
walther@59989
   104
fun mk_delete thy "#Given" itm_ = Tactic.Del_Given (I_Model.to_p_model thy itm_)
walther@59989
   105
  | mk_delete thy "#Find" itm_ = Tactic.Del_Find (I_Model.to_p_model thy itm_)
walther@59989
   106
  | mk_delete thy "#Relate" itm_ = Tactic.Del_Relation (I_Model.to_p_model thy itm_)
walther@59989
   107
  | mk_delete _ str _ = raise ERROR ("mk_delete: called with field \"" ^ str ^ "\"")
walther@59989
   108
fun mk_additem "#Given" ct = Tactic.Add_Given ct
walther@59989
   109
  | mk_additem "#Find" ct = Tactic.Add_Find ct    
walther@59989
   110
  | mk_additem "#Relate"ct = Tactic.Add_Relation ct
walther@59989
   111
  | mk_additem str _ = raise ERROR ("mk_additem: called with field \"" ^ str ^ "\"")
walther@59989
   112
walther@59989
   113
fun to_list {Given = gis, Where = whs, Find = fis, With = wis, Relate = res} =
walther@59989
   114
  gis @ whs @ fis @ wis @ res
walther@59989
   115
walther@59938
   116
(**)end(**);