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
walther@59866
     1
(* Title:  BaseDefinitions/unparseC.sml
walther@59861
     2
   Author: Walther Neuper 2018
walther@59861
     3
   (c) copyright due to lincense terms
walther@59861
     4
*)
walther@59861
     5
walther@59861
     6
signature UNPARSE_ISAC =
walther@59861
     7
sig
walther@59865
     8
  eqtype term_as_string
walther@59868
     9
walther@59868
    10
  val term_empty: term
walther@59878
    11
  val typ_empty: typ
walther@59868
    12
Walther@60576
    13
(*val term: Proof.context -> term -> term_as_string *)
Walther@60576
    14
  val term_in_ctxt: Proof.context -> term -> term_as_string
walther@59872
    15
  val term: term -> term_as_string
Walther@60576
    16
(*replace by ^^^*)
walther@59872
    17
  val term_in_thy: theory -> term -> term_as_string
walther@59868
    18
Walther@60576
    19
(*val term_opt: Proof.context -> term option -> term_as_string *)
walther@59872
    20
  val term_opt: term option -> term_as_string
walther@59868
    21
Walther@60576
    22
  val terms: term list -> term_as_string
Walther@60576
    23
(*replace by ^^^*)
Walther@60576
    24
  val terms_in_ctxt: Proof.context -> term list -> term_as_string
Walther@60576
    25
(*replace by ^^^*)
walther@59872
    26
  val terms_in_thy: theory -> term list -> term_as_string
walther@59868
    27
Walther@60576
    28
(*val terms_short: Proof.context -> term list -> term_as_string*)
Walther@60576
    29
  val terms_short: term list -> term_as_string
Walther@60576
    30
(*val typ: Proof.context -> typ -> term_as_string*)
Walther@60578
    31
  val typ_in_ctxt: Proof.context -> typ -> term_as_string
walther@59868
    32
wenzelm@60223
    33
\<^isac_test>\<open>
walther@59879
    34
  val term_by_thyID: ThyC.id -> term -> term_as_string
walther@59872
    35
  val terms_to_strings: term list -> term_as_string list
wenzelm@60223
    36
\<close>
walther@59861
    37
end
walther@59861
    38
walther@59861
    39
(**)
walther@59861
    40
structure UnparseC(**): UNPARSE_ISAC(**) =
walther@59861
    41
struct
walther@59861
    42
(**)
walther@59861
    43
walther@59865
    44
type term_as_string = string;
walther@59861
    45
walther@59870
    46
fun term_in_ctxt ctxt t =
walther@59861
    47
  let
walther@59873
    48
    val ctxt' = Config.put show_markup false ctxt;
walther@59873
    49
  in
walther@59873
    50
    Print_Mode.setmp [] (Syntax.string_of_term ctxt') t
walther@59873
    51
  end;
Walther@60500
    52
fun terms_in_ctxt ctxt ts = ts |> map (term_in_ctxt ctxt) |> strs2str';
Walther@60500
    53
Walther@60500
    54
wenzelm@60223
    55
\<^isac_test>\<open>
walther@59870
    56
fun term_by_thyID thyID t =
walther@59861
    57
  let
walther@59868
    58
    val ctxt' = Config.put show_markup false (Proof_Context.init_global
walther@59879
    59
      (ThyC.get_theory thyID));
walther@59873
    60
  in
walther@59873
    61
    Print_Mode.setmp [] (Syntax.string_of_term ctxt') t
walther@59873
    62
  end;
wenzelm@60223
    63
\<close>
walther@59861
    64
walther@59879
    65
fun term t = term_in_ctxt (ThyC.id_to_ctxt "Isac_Knowledge") t;
walther@60360
    66
fun term_in_thy thy t = term_in_ctxt (Proof_Context.init_global thy) t;
walther@59870
    67
fun terms_in_thy thy ts = ts |> map (term_in_thy thy) |> strs2str';
walther@59873
    68
fun terms_to_strings ts = map term ts;          (* terms_to_strings [t1,t2] = ["1 + 2", "abc"]; *)
walther@59873
    69
val terms = strs2str o terms_to_strings;        (* terms  [t1,t2] = "[\"1 + 2\",\"abc\"]";      *)
wenzelm@60223
    70
walther@59868
    71
val terms_short = strs2str' o terms_to_strings; (* terms_short [t1,t2] = "[1 + 2,abc]";         *)
walther@59868
    72
fun term_opt (SOME t) = "(SOME " ^ term t ^ ")"
walther@59868
    73
  | term_opt NONE = "NONE";
walther@59861
    74
Walther@60578
    75
fun type_to_string' ctxt typ =
Walther@60578
    76
  Print_Mode.setmp [] (Syntax.string_of_typ ctxt) typ
Walther@60578
    77
fun typ_in_ctxt ctxt typ = type_to_string' ctxt typ
Walther@60578
    78
walther@59878
    79
val typ_empty = Type ("empty", []);
walther@59868
    80
val term_empty = Const ("empty", Type("'a", []));
walther@59861
    81
walther@59861
    82
(**)end(**)