src/Tools/isac/BridgeLibisabelle/present-tool.sml
author wneuper <Walther.Neuper@jku.at>
Wed, 11 Jan 2023 09:23:18 +0100
changeset 60649 b2ff1902420f
parent 60559 aba19e46dd84
permissions -rw-r--r--
eliminate use of Thy_Info 12: prep.arg. ctxt in TermC, UnparseC
walther@59974
     1
(* Title:  BridgeLibisabelle/present-tool.sml
walther@59974
     2
   Author: Walther Neuper
walther@59974
     3
   (c) due to copyright terms
walther@60258
     4
walther@60258
     5
This code remains in order to
walther@60258
     6
keep tests of interaction Java-frontend <-> Kernel running.
walther@59974
     7
*)
walther@59974
     8
walther@59974
     9
signature PRESENTATION_TOOL =
walther@59974
    10
sig
walther@60258
    11
walther@60258
    12
  type ketype
walther@59974
    13
  val ketype2str: ketype -> string
walther@59974
    14
  val str2ketype': string -> ketype
walther@59974
    15
walther@59974
    16
  type kestoreID
Walther@60556
    17
  val pblID2guh : Proof.context -> Problem.id -> Check_Unique.id
Walther@60556
    18
  val metID2guh : (*Proof.context ->*) MethodC.id -> Check_Unique.id
Walther@60556
    19
  val kestoreID2guh : Proof.context -> ketype -> kestoreID -> Check_Unique.id
walther@60258
    20
  val guh2kestoreID : Check_Unique.id -> string list
walther@59974
    21
end
walther@59974
    22
walther@59974
    23
(**)
walther@59974
    24
structure Ptool(**) : PRESENTATION_TOOL(**) =
walther@59974
    25
struct
walther@59974
    26
(**)
walther@59974
    27
walther@59974
    28
(* lookup a guh in hierarchy of problems / methods depending on fst 4 chars in guh *)
walther@59974
    29
fun guh2kestoreID guh =
walther@59974
    30
  case (implode o (take_fromto 1 4) o Symbol.explode) guh of
walther@59974
    31
	  "pbl_" =>
walther@59974
    32
	    let
walther@59974
    33
	      fun node ids gu (Store.Node (id, [{guh, ...}], ns)) =
walther@59974
    34
	        if gu = guh then SOME (ids @ [id]) else nodes (ids @ [id]) gu ns
walther@59974
    35
	        | node _ _ _ = raise ERROR "Ptool.guh2kestoreID node: uncovered fun def."
walther@59974
    36
	      and nodes _ _ [] = NONE 
walther@59974
    37
	        | nodes ids gu (n :: ns) = case node ids gu n of
walther@59974
    38
	            SOME id => SOME id
walther@59974
    39
			      | NONE =>  nodes ids gu ns
Walther@60495
    40
	    in case nodes [] guh (get_pbls ()) of
walther@59974
    41
	      SOME id => rev id
walther@59974
    42
	    | NONE => raise ERROR ("Ptool.guh2kestoreID: \"" ^ guh ^ "\" " ^ "not found in ptyps")
walther@59974
    43
      end
walther@59974
    44
  | "met_" =>
walther@59974
    45
	    let
walther@59974
    46
	      fun node ids gu (Store.Node (id, [{guh, ...}], ns)) =
walther@59974
    47
	        if gu = guh then SOME (ids @ [id]) else nodes (ids @ [id]) gu ns
walther@59974
    48
	        | node _ _ _ = raise ERROR "Ptool.guh2kestoreID node: uncovered fun def."
walther@59974
    49
	      and nodes _ _ [] = NONE 
walther@59974
    50
	        | nodes ids gu (n :: ns) = case node ids gu n of
walther@59974
    51
	            SOME id => SOME id
walther@59974
    52
				    | NONE =>  nodes ids gu ns
walther@59974
    53
	    in case nodes [] guh (get_mets ()) of
walther@59974
    54
	      SOME id => id
walther@59974
    55
	    | NONE => raise ERROR ("Ptool.guh2kestoreID: \"" ^ guh ^ "\" " ^ "not found in mets")
walther@59974
    56
      end
walther@59974
    57
  | _ => raise ERROR ("Ptool.guh2kestoreID called with \"" ^ guh ^ "\":");
walther@59974
    58
walther@59974
    59
(* for distinction of contexts WN130621: disambiguate with Isabelle's Context *)
walther@59974
    60
datatype ketype = Exp_ | Thy_ | Pbl_ | Met_;
walther@59974
    61
fun ketype2str Exp_ = "Exp_"
walther@59974
    62
  | ketype2str Thy_ = "Thy_"
walther@59974
    63
  | ketype2str Pbl_ = "Pbl_"
walther@59974
    64
  | ketype2str Met_ = "Met_";
walther@59974
    65
(* for conversion from XML *)
walther@59974
    66
fun str2ketype' "exp" = Exp_
walther@59974
    67
  | str2ketype' "thy" = Thy_
walther@59974
    68
  | str2ketype' "pbl" = Pbl_
walther@59974
    69
  | str2ketype' "met" = Met_
walther@59974
    70
  | str2ketype' str = raise ERROR ("str2ketype': WRONG arg = " ^ str)
walther@59974
    71
walther@60154
    72
(*either ThyC.id or Problem.id or MethodC.id*)
walther@59974
    73
type kestoreID = string list;
walther@59974
    74
walther@59974
    75
(* make a guh from a reference to an element in the kestore;
walther@59974
    76
   EXCEPT theory hierarchy ... compare 'fun keref2xml'    *)
Walther@60559
    77
fun pblID2guh ctxt pblID = (((#guh o (Problem.from_store ctxt)) pblID)
walther@60264
    78
  handle ERROR _ => raise ERROR ("Ptool.pblID2guh: not for \"" ^ strs2str' pblID ^ "\""));
Walther@60649
    79
fun metID2guh metID =
Walther@60649
    80
  (((#guh o MethodC.from_store ("Isac_Knowledge" |> Know_Store.get_via_last_thy |> Proof_Context.init_global)) metID)
walther@60264
    81
  handle ERROR _ => raise ERROR ("metID2guh: no 'Met_' for \"" ^ strs2str' metID ^ "\""));
Walther@60556
    82
fun kestoreID2guh ctxt Pbl_ kestoreID = pblID2guh ctxt kestoreID
Walther@60556
    83
  | kestoreID2guh _ Met_ kestoreID = metID2guh kestoreID
Walther@60556
    84
  | kestoreID2guh _ ketyp kestoreID =
walther@60258
    85
    raise ERROR ("kestoreID2guh: \"" ^ ketype2str ketyp ^ "\" not for \"" ^ strs2str' kestoreID ^ "\"");
walther@59974
    86
walther@59974
    87
(**)end(**);