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