src/Tools/isac/BaseDefinitions/unparseC.sml
author wneuper <Walther.Neuper@jku.at>
Wed, 11 Jan 2023 09:23:18 +0100
changeset 60649 b2ff1902420f
parent 60629 20c3d272d79c
child 60666 56625427ce25
permissions -rw-r--r--
eliminate use of Thy_Info 12: prep.arg. ctxt in TermC, UnparseC
     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: Proof.context -> term -> term_as_string *)
    14   val term_in_ctxt: Proof.context -> term -> term_as_string
    15   val term: term -> term_as_string
    16 (*replace by ^^^*)
    17   val term_in_thy: theory -> term -> term_as_string
    18 
    19 (*val term_opt: Proof.context -> term option -> term_as_string *)
    20   val term_opt: term option -> term_as_string
    21 
    22   val terms: term list -> term_as_string
    23 (*replace by ^^^*)
    24   val terms_in_ctxt: Proof.context -> term list -> term_as_string
    25 (*replace by ^^^*)
    26   val terms_in_thy: theory -> term list -> term_as_string
    27 
    28 (*val terms_short: Proof.context -> term list -> term_as_string*)
    29   val terms_short: term list -> term_as_string
    30 (*val typ: Proof.context -> typ -> term_as_string*)
    31   val typ_in_ctxt: Proof.context -> typ -> term_as_string
    32 
    33 \<^isac_test>\<open>
    34   val term_by_thyID: ThyC.id -> term -> term_as_string
    35   val terms_to_strings: term list -> term_as_string list
    36 \<close>
    37 end
    38 
    39 (**)
    40 structure UnparseC(**): UNPARSE_ISAC(**) =
    41 struct
    42 (**)
    43 
    44 type term_as_string = string;
    45 
    46 fun term_in_ctxt ctxt t =
    47   let
    48     val ctxt' = Config.put show_markup false ctxt;
    49   in
    50     Print_Mode.setmp [] (Syntax.string_of_term ctxt') t
    51   end;
    52 fun terms_in_ctxt ctxt ts = ts |> map (term_in_ctxt ctxt) |> strs2str';
    53 
    54 
    55 \<^isac_test>\<open>
    56 fun term_by_thyID thyID t =
    57   let
    58     val ctxt' = Config.put show_markup false (Proof_Context.init_global
    59       (ThyC.get_theory thyID));
    60   in
    61     Print_Mode.setmp [] (Syntax.string_of_term ctxt') t
    62   end;
    63 \<close>
    64 
    65 fun term t = term_in_ctxt (ThyC.id_to_ctxt "Isac_Knowledge") t;
    66 fun term_in_thy thy t = term_in_ctxt (Proof_Context.init_global thy) t;
    67 fun terms_in_thy thy ts = ts |> map (term_in_thy thy) |> strs2str';
    68 fun terms_to_strings ts = map term ts;          (* terms_to_strings [t1,t2] = ["1 + 2", "abc"]; *)
    69 val terms = strs2str o terms_to_strings;        (* terms  [t1,t2] = "[\"1 + 2\",\"abc\"]";      *)
    70 
    71 val terms_short = strs2str' o terms_to_strings; (* terms_short [t1,t2] = "[1 + 2,abc]";         *)
    72 fun term_opt (SOME t) = "(SOME " ^ term t ^ ")"
    73   | term_opt NONE = "NONE";
    74 
    75 fun type_to_string' ctxt typ =
    76   Print_Mode.setmp [] (Syntax.string_of_typ ctxt) typ
    77 fun typ_in_ctxt ctxt typ = type_to_string' ctxt typ
    78 
    79 val typ_empty = Type ("empty", []);
    80 val term_empty = Const ("empty", Type("'a", []));
    81 
    82 (**)end(**)