src/Tools/isac/BaseDefinitions/unparseC.sml
author wneuper <walther.neuper@jku.at>
Tue, 10 Aug 2021 11:01:18 +0200
changeset 60360 49680d595342
parent 60223 740ebee5948b
child 60500 59a3af532717
permissions -rw-r--r--
eliminate ThyC.to_ctxt, use Proof_Context.init_global inline
     1 (* Title:  BaseDefinitions/unparseC.sml
     2    Author: Walther Neuper 2018
     3    (c) copyright due to lincense terms
     4 *)
     5 
     6 signature UNPARSE_ISAC =
     7 sig
     8   eqtype term_as_string
     9 
    10   val term_empty: term
    11   val typ_empty: typ
    12 
    13   val term: term -> term_as_string
    14   val term_in_ctxt: Proof.context -> term -> term_as_string
    15   val term_in_thy: theory -> term -> term_as_string
    16 
    17   val term_opt: term option -> term_as_string
    18 
    19   val terms_short: term list -> term_as_string
    20   val terms_in_thy: theory -> term list -> term_as_string
    21 
    22   val typ: typ -> term_as_string
    23   val typ_by_thyID: ThyC.id -> typ -> term_as_string
    24 
    25   val terms: term list -> term_as_string
    26 
    27 \<^isac_test>\<open>
    28   val term_by_thyID: ThyC.id -> term -> term_as_string
    29   val terms_to_strings: term list -> term_as_string list
    30 \<close>
    31 end
    32 
    33 (**)
    34 structure UnparseC(**): UNPARSE_ISAC(**) =
    35 struct
    36 (**)
    37 
    38 type term_as_string = string;
    39 
    40 fun term_in_ctxt ctxt t =
    41   let
    42     val ctxt' = Config.put show_markup false ctxt;
    43   in
    44     Print_Mode.setmp [] (Syntax.string_of_term ctxt') t
    45   end;
    46 \<^isac_test>\<open>
    47 fun term_by_thyID thyID t =
    48   let
    49     val ctxt' = Config.put show_markup false (Proof_Context.init_global
    50       (ThyC.get_theory thyID));
    51   in
    52     Print_Mode.setmp [] (Syntax.string_of_term ctxt') t
    53   end;
    54 \<close>
    55 
    56 fun term t = term_in_ctxt (ThyC.id_to_ctxt "Isac_Knowledge") t;
    57 fun term_in_thy thy t = term_in_ctxt (Proof_Context.init_global thy) t;
    58 fun terms_in_thy thy ts = ts |> map (term_in_thy thy) |> strs2str';
    59 fun terms_to_strings ts = map term ts;          (* terms_to_strings [t1,t2] = ["1 + 2", "abc"]; *)
    60 val terms = strs2str o terms_to_strings;        (* terms  [t1,t2] = "[\"1 + 2\",\"abc\"]";      *)
    61 
    62 val terms_short = strs2str' o terms_to_strings; (* terms_short [t1,t2] = "[1 + 2,abc]";         *)
    63 fun term_opt (SOME t) = "(SOME " ^ term t ^ ")"
    64   | term_opt NONE = "NONE";
    65 
    66 fun type_to_string'' (thyID : ThyC.id) t =
    67   let
    68     val ctxt' = Config.put show_markup false (Proof_Context.init_global
    69       (ThyC.get_theory thyID))
    70   in
    71     Print_Mode.setmp [] (Syntax.string_of_typ ctxt') t
    72   end;
    73 fun typ typ = type_to_string'' "Isac_Knowledge" typ; (*TODO legacy*)
    74 fun typ_by_thyID thy typ = type_to_string'' thy typ; (*legacy*)
    75 
    76 val typ_empty = Type ("empty", []);
    77 val term_empty = Const ("empty", Type("'a", []));
    78 
    79 (**)end(**)