Non-logical toplevel commands.
authorwenzelm
Mon Nov 09 15:34:41 1998 +0100 (1998-11-09 ago)
changeset 5831996361157cfb
parent 5830 95b619c7289b
child 5832 112a67aa9c2c
Non-logical toplevel commands.
src/Pure/Isar/isar_cmd.ML
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/Pure/Isar/isar_cmd.ML	Mon Nov 09 15:34:41 1998 +0100
     1.3 @@ -0,0 +1,141 @@
     1.4 +(*  Title:      Pure/Isar/isar_cmd.ML
     1.5 +    ID:         $Id$
     1.6 +    Author:     Markus Wenzel, TU Muenchen
     1.7 +
     1.8 +Non-logical toplevel commands.
     1.9 +*)
    1.10 +
    1.11 +signature ISAR_CMD =
    1.12 +sig
    1.13 +  val break: Toplevel.transition -> Toplevel.transition
    1.14 +  val exit: Toplevel.transition -> Toplevel.transition
    1.15 +  val quit: Toplevel.transition -> Toplevel.transition
    1.16 +  val use: string -> Toplevel.transition -> Toplevel.transition
    1.17 +  val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
    1.18 +  val use_mltext: string -> Toplevel.transition -> Toplevel.transition
    1.19 +  val use_commit: Toplevel.transition -> Toplevel.transition
    1.20 +  val cd: string -> Toplevel.transition -> Toplevel.transition
    1.21 +  val pwd: Toplevel.transition -> Toplevel.transition
    1.22 +  val use_thy: string -> Toplevel.transition -> Toplevel.transition
    1.23 +  val load: string -> Toplevel.transition -> Toplevel.transition
    1.24 +  val print_theory: Toplevel.transition -> Toplevel.transition
    1.25 +  val print_syntax: Toplevel.transition -> Toplevel.transition
    1.26 +  val print_attributes: Toplevel.transition -> Toplevel.transition
    1.27 +  val print_methods: Toplevel.transition -> Toplevel.transition
    1.28 +  val print_binds: Toplevel.transition -> Toplevel.transition
    1.29 +  val print_lthms: Toplevel.transition -> Toplevel.transition
    1.30 +  val print_thms: xstring -> Toplevel.transition -> Toplevel.transition
    1.31 +  val print_prop: string -> Toplevel.transition -> Toplevel.transition
    1.32 +  val print_term: string -> Toplevel.transition -> Toplevel.transition
    1.33 +  val print_type: string -> Toplevel.transition -> Toplevel.transition
    1.34 +end;
    1.35 +
    1.36 +structure IsarCmd: ISAR_CMD =
    1.37 +struct
    1.38 +
    1.39 +
    1.40 +(* variations on exit *)
    1.41 +
    1.42 +val break = Toplevel.imperative (fn () => raise Toplevel.BREAK);
    1.43 +
    1.44 +val exit = Toplevel.keep (fn state =>
    1.45 +  (Context.set_context (try Toplevel.theory_of state);
    1.46 +    writeln "Leaving the Isar loop.  Invoke 'main_loop();' to restart.";
    1.47 +    raise Toplevel.TERMINATE));
    1.48 +
    1.49 +val quit = Toplevel.imperative quit;
    1.50 +
    1.51 +
    1.52 +(* use ML text *)
    1.53 +
    1.54 +fun use name = Toplevel.imperative (fn () => Use.use name);
    1.55 +
    1.56 +(*passes changes of theory context*)
    1.57 +val use_mltext_theory = Toplevel.theory o IsarThy.use_mltext_theory;
    1.58 +
    1.59 +(*ignore result theory context*)
    1.60 +fun use_mltext txt = Toplevel.keep (fn state =>
    1.61 +  (IsarThy.use_mltext txt (try Toplevel.theory_of state); ()));
    1.62 +
    1.63 +(*Note: commit is dynamically bound*)
    1.64 +val use_commit = use_mltext "commit();";
    1.65 +
    1.66 +
    1.67 +(* current working directory *)
    1.68 +
    1.69 +fun print_cd _ = writeln (Library.pwd ());
    1.70 +
    1.71 +fun cd dir = Toplevel.imperative (fn () => (Use.cd dir; print_cd ()));
    1.72 +val pwd = Toplevel.imperative print_cd;
    1.73 +
    1.74 +
    1.75 +(* load theory files *)
    1.76 +
    1.77 +fun use_thy name = Toplevel.imperative (fn () => ThyRead.use_thy name);
    1.78 +
    1.79 +fun load name =
    1.80 +  Toplevel.imperative (fn () => Toplevel.excursion (OuterSyntax.read_file (name ^ ".thy")));
    1.81 +
    1.82 +
    1.83 +(* print theory contents *)
    1.84 +
    1.85 +val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
    1.86 +val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
    1.87 +val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
    1.88 +val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
    1.89 +
    1.90 +
    1.91 +(* print proof context contents *)
    1.92 +
    1.93 +val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of);
    1.94 +val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of);
    1.95 +
    1.96 +
    1.97 +(* print theorems *)
    1.98 +
    1.99 +fun print_thms name = Toplevel.keep (fn state =>
   1.100 +  let
   1.101 +    val prt_tthm = Attribute.pretty_tthm;
   1.102 +    fun prt_tthms [th] = prt_tthm th
   1.103 +      | prt_tthms ths = Pretty.block (Pretty.fbreaks (map prt_tthm ths));
   1.104 +
   1.105 +    val tthms = map (apfst (Thm.transfer (Toplevel.theory_of state)))
   1.106 +      (Toplevel.node_cases PureThy.get_tthms (ProofContext.get_tthms o Proof.context_of)
   1.107 +        state name);
   1.108 +  in Pretty.writeln (prt_tthms tthms) end);
   1.109 +
   1.110 +
   1.111 +(* print types, terms and props *)
   1.112 +
   1.113 +fun read_typ thy = Sign.read_typ (Theory.sign_of thy, K None);
   1.114 +
   1.115 +fun read_term T thy s =
   1.116 +  Thm.term_of (#1 (Thm.read_def_cterm (Theory.sign_of thy, K None, K None) [] true (s, T)));
   1.117 +
   1.118 +
   1.119 +fun print_type s = Toplevel.keep (fn state =>
   1.120 +  let
   1.121 +    val sign = Toplevel.sign_of state;
   1.122 +    val T = Toplevel.node_cases read_typ (ProofContext.read_typ o Proof.context_of) state s;
   1.123 +  in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
   1.124 +
   1.125 +fun print_term s = Toplevel.keep (fn state =>
   1.126 +  let
   1.127 +    val sign = Toplevel.sign_of state;
   1.128 +    val t = Toplevel.node_cases (read_term (TVar (("'z", 0), logicS)))
   1.129 +      (ProofContext.read_term o Proof.context_of) state s;
   1.130 +    val T = Term.type_of t;
   1.131 +  in
   1.132 +    Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
   1.133 +      Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
   1.134 +  end);
   1.135 +
   1.136 +fun print_prop s = Toplevel.keep (fn state =>
   1.137 +  let
   1.138 +    val sign = Toplevel.sign_of state;
   1.139 +    val prop =
   1.140 +      Toplevel.node_cases (read_term propT) (ProofContext.read_prop o Proof.context_of) state s;
   1.141 +  in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
   1.142 +
   1.143 +
   1.144 +end;