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