src/Tools/isac/BridgeLibisabelle/present-tool.sml
author wenzelm
Sun, 18 Apr 2021 23:37:59 +0200
changeset 60223 740ebee5948b
parent 60154 2ab0d1523731
child 60258 a5eed208b22f
permissions -rw-r--r--
conditional compilation via system option "isac_test" and antiquotation \<^isac_test>CARTOUCHE:
option is provided in session ROOT, or interactively via $ISABELLE_HOME_USER/etc/preferences (i.e. Isabelle/jEdit plugin preferences);
walther@59974
     1
(* Title:  BridgeLibisabelle/present-tool.sml
walther@59974
     2
   Author: Walther Neuper
walther@59974
     3
   (c) due to copyright terms
walther@59974
     4
*)
walther@59974
     5
walther@59974
     6
signature PRESENTATION_TOOL =
walther@59974
     7
sig
walther@59974
     8
  datatype ketype = Exp_ | Met_ | Pbl_ | Thy_
walther@59974
     9
  val ketype2str: ketype -> string
walther@59974
    10
  val ketype2str': ketype -> string
walther@59974
    11
  val str2ketype': string -> ketype
walther@59974
    12
walther@59974
    13
  type kestoreID
walther@59974
    14
  val pblID2guh : Problem.id -> Check_Unique.id
walther@60154
    15
  val metID2guh : MethodC.id -> Check_Unique.id
walther@59974
    16
  val kestoreID2guh : ketype -> kestoreID -> Check_Unique.id
walther@59974
    17
  val guh2kestoreID : Check_Unique.id -> string list          (* for interface.sml *)
walther@59974
    18
end
walther@59974
    19
walther@59974
    20
(**)
walther@59974
    21
structure Ptool(**) : PRESENTATION_TOOL(**) =
walther@59974
    22
struct
walther@59974
    23
(**)
walther@59974
    24
walther@59974
    25
(* lookup a guh in hierarchy of problems / methods depending on fst 4 chars in guh *)
walther@59974
    26
fun guh2kestoreID guh =
walther@59974
    27
  case (implode o (take_fromto 1 4) o Symbol.explode) guh of
walther@59974
    28
	  "pbl_" =>
walther@59974
    29
	    let
walther@59974
    30
	      fun node ids gu (Store.Node (id, [{guh, ...}], ns)) =
walther@59974
    31
	        if gu = guh then SOME (ids @ [id]) else nodes (ids @ [id]) gu ns
walther@59974
    32
	        | node _ _ _ = raise ERROR "Ptool.guh2kestoreID node: uncovered fun def."
walther@59974
    33
	      and nodes _ _ [] = NONE 
walther@59974
    34
	        | nodes ids gu (n :: ns) = case node ids gu n of
walther@59974
    35
	            SOME id => SOME id
walther@59974
    36
			      | NONE =>  nodes ids gu ns
walther@59974
    37
	    in case nodes [] guh (get_ptyps ()) of
walther@59974
    38
	      SOME id => rev id
walther@59974
    39
	    | NONE => raise ERROR ("Ptool.guh2kestoreID: \"" ^ guh ^ "\" " ^ "not found in ptyps")
walther@59974
    40
      end
walther@59974
    41
  | "met_" =>
walther@59974
    42
	    let
walther@59974
    43
	      fun node ids gu (Store.Node (id, [{guh, ...}], ns)) =
walther@59974
    44
	        if gu = guh then SOME (ids @ [id]) else nodes (ids @ [id]) gu ns
walther@59974
    45
	        | node _ _ _ = raise ERROR "Ptool.guh2kestoreID node: uncovered fun def."
walther@59974
    46
	      and nodes _ _ [] = NONE 
walther@59974
    47
	        | nodes ids gu (n :: ns) = case node ids gu n of
walther@59974
    48
	            SOME id => SOME id
walther@59974
    49
				    | NONE =>  nodes ids gu ns
walther@59974
    50
	    in case nodes [] guh (get_mets ()) of
walther@59974
    51
	      SOME id => id
walther@59974
    52
	    | NONE => raise ERROR ("Ptool.guh2kestoreID: \"" ^ guh ^ "\" " ^ "not found in mets")
walther@59974
    53
      end
walther@59974
    54
  | _ => raise ERROR ("Ptool.guh2kestoreID called with \"" ^ guh ^ "\":");
walther@59974
    55
walther@59974
    56
(* for distinction of contexts WN130621: disambiguate with Isabelle's Context *)
walther@59974
    57
datatype ketype = Exp_ | Thy_ | Pbl_ | Met_;
walther@59974
    58
fun ketype2str Exp_ = "Exp_"
walther@59974
    59
  | ketype2str Thy_ = "Thy_"
walther@59974
    60
  | ketype2str Pbl_ = "Pbl_"
walther@59974
    61
  | ketype2str Met_ = "Met_";
walther@59974
    62
fun ketype2str' Exp_ = "Example"
walther@59974
    63
  | ketype2str' Thy_ = "Theory"
walther@59974
    64
  | ketype2str' Pbl_ = "Problem"
walther@60154
    65
  | ketype2str' Met_ = "MethodC";
walther@59974
    66
(* for conversion from XML *)
walther@59974
    67
fun str2ketype' "exp" = Exp_
walther@59974
    68
  | str2ketype' "thy" = Thy_
walther@59974
    69
  | str2ketype' "pbl" = Pbl_
walther@59974
    70
  | str2ketype' "met" = Met_
walther@59974
    71
  | str2ketype' str = raise ERROR ("str2ketype': WRONG arg = " ^ str)
walther@59974
    72
walther@60154
    73
(*either ThyC.id or Problem.id or MethodC.id*)
walther@59974
    74
type kestoreID = string list;
walther@59974
    75
walther@59974
    76
(* make a guh from a reference to an element in the kestore;
walther@59974
    77
   EXCEPT theory hierarchy ... compare 'fun keref2xml'    *)
walther@59974
    78
fun pblID2guh pblID = (((#guh o Problem.from_store) pblID)
walther@59974
    79
  handle _ => raise ERROR ("Ptool.pblID2guh: not for \"" ^ strs2str' pblID ^ "\""));
walther@60154
    80
fun metID2guh metID = (((#guh o MethodC.from_store) metID)
walther@59974
    81
  handle _ => raise ERROR ("metID2guh: no 'Met_' for \"" ^ strs2str' metID ^ "\""));
walther@59974
    82
fun kestoreID2guh Pbl_ kestoreID = pblID2guh kestoreID
walther@59974
    83
  | kestoreID2guh Met_ kestoreID = metID2guh kestoreID
walther@59974
    84
  | kestoreID2guh ketype kestoreID =
walther@59974
    85
    raise ERROR ("kestoreID2guh: \"" ^ ketype2str ketype ^ "\" not for \"" ^ strs2str' kestoreID ^ "\"");
walther@59974
    86
walther@59974
    87
(**)end(**);