src/Pure/Isar/isar_cmd.ML
author wenzelm
Thu Jul 15 17:54:58 1999 +0200 (1999-07-15)
changeset 7012 ae9dac5af9d1
parent 6742 6b5cb872d997
child 7023 5d1eafaff50c
permissions -rw-r--r--
improved print_thms;
     1 (*  Title:      Pure/Isar/isar_cmd.ML
     2     ID:         $Id$
     3     Author:     Markus Wenzel, TU Muenchen
     4 
     5 Non-logical toplevel commands.
     6 *)
     7 
     8 signature ISAR_CMD =
     9 sig
    10   val break: Toplevel.transition -> Toplevel.transition
    11   val exit: Toplevel.transition -> Toplevel.transition
    12   val restart: Toplevel.transition -> Toplevel.transition
    13   val quit: Toplevel.transition -> Toplevel.transition
    14   val cannot_undo: string -> Toplevel.transition -> Toplevel.transition
    15   val clear_undo: Toplevel.transition -> Toplevel.transition
    16   val redo: Toplevel.transition -> Toplevel.transition
    17   val undos_proof: int -> Toplevel.transition -> Toplevel.transition
    18   val kill_proof: Toplevel.transition -> Toplevel.transition
    19   val undo_theory: Toplevel.transition -> Toplevel.transition
    20   val kill_theory: Toplevel.transition -> Toplevel.transition
    21   val undo: Toplevel.transition -> Toplevel.transition
    22   val use: string -> Toplevel.transition -> Toplevel.transition
    23   val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
    24   val use_mltext: string -> Toplevel.transition -> Toplevel.transition
    25   val use_commit: Toplevel.transition -> Toplevel.transition
    26   val cd: string -> Toplevel.transition -> Toplevel.transition
    27   val pwd: Toplevel.transition -> Toplevel.transition
    28   val use_thy: string -> Toplevel.transition -> Toplevel.transition
    29   val use_thy_only: string -> Toplevel.transition -> Toplevel.transition
    30   val update_thy: string -> Toplevel.transition -> Toplevel.transition
    31   val print_theory: Toplevel.transition -> Toplevel.transition
    32   val print_syntax: Toplevel.transition -> Toplevel.transition
    33   val print_theorems: Toplevel.transition -> Toplevel.transition
    34   val print_attributes: Toplevel.transition -> Toplevel.transition
    35   val print_methods: Toplevel.transition -> Toplevel.transition
    36   val print_binds: Toplevel.transition -> Toplevel.transition
    37   val print_lthms: Toplevel.transition -> Toplevel.transition
    38   val print_thms: (string * Args.src list) list -> Toplevel.transition -> Toplevel.transition
    39   val print_prop: string -> Toplevel.transition -> Toplevel.transition
    40   val print_term: string -> Toplevel.transition -> Toplevel.transition
    41   val print_type: string -> Toplevel.transition -> Toplevel.transition
    42 end;
    43 
    44 structure IsarCmd: ISAR_CMD =
    45 struct
    46 
    47 
    48 (* variations on exit *)
    49 
    50 val break = Toplevel.keep (fn state => raise Toplevel.BREAK state);
    51 
    52 val exit = Toplevel.keep (fn state =>
    53   (Context.set_context (try Toplevel.theory_of state);
    54     writeln "Leaving the Isar loop.  Invoke 'loop();' to restart.";
    55     raise Toplevel.TERMINATE));
    56 
    57 val restart = Toplevel.imperative (fn () => raise Toplevel.RESTART);
    58 val quit = Toplevel.imperative quit;
    59 
    60 
    61 (* history commands *)
    62 
    63 fun cannot_undo txt = Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt));
    64 val clear_undo = Toplevel.history History.clear o Toplevel.proof ProofHistory.clear;
    65 val redo = Toplevel.history History.redo o Toplevel.proof ProofHistory.redo;
    66 
    67 fun undos_proof n = Toplevel.proof (fn prf =>
    68   if ProofHistory.is_initial prf then raise Toplevel.UNDEF else funpow n ProofHistory.undo prf);
    69 
    70 val kill_proof = Toplevel.history (fn hist =>
    71   (case History.current hist of
    72     Toplevel.Theory _ => raise Toplevel.UNDEF
    73   | Toplevel.Proof _ => History.undo hist));
    74 
    75 val undo_theory = Toplevel.history (fn hist =>
    76   if History.is_initial hist then raise Toplevel.UNDEF else History.undo hist);
    77 
    78 val kill_theory = Toplevel.imperative (fn () => warning "Nothing to kill.") o Toplevel.kill;
    79 val undo = kill_theory o undo_theory o undos_proof 1;
    80 
    81 
    82 (* use ML text *)
    83 
    84 fun use name = Toplevel.keep (fn state =>
    85   Context.setmp (try Toplevel.theory_of state) ThyInfo.use name);
    86 
    87 (*passes changes of theory context*)
    88 val use_mltext_theory = Toplevel.theory o IsarThy.use_mltext_theory;
    89 
    90 (*ignore result theory context*)
    91 fun use_mltext txt = Toplevel.keep (fn state =>
    92   (IsarThy.use_mltext txt (try Toplevel.theory_of state); ()));
    93 
    94 (*Note: commit is dynamically bound*)
    95 val use_commit = use_mltext "commit();";
    96 
    97 
    98 (* current working directory *)
    99 
   100 fun print_cd _ = writeln (Path.pack (File.pwd ()));
   101 
   102 fun cd dir = Toplevel.imperative (fn () => (File.cd (Path.unpack dir); print_cd ()));
   103 val pwd = Toplevel.imperative print_cd;
   104 
   105 
   106 (* load theory files *)
   107 
   108 fun use_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy name);
   109 fun use_thy_only name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy_only name);
   110 fun update_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.update_thy name);
   111 
   112 
   113 (* print theory contents *)
   114 
   115 val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
   116 val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
   117 val print_theorems = Toplevel.keep (PureThy.print_theorems o Toplevel.theory_of);
   118 val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
   119 val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
   120 
   121 
   122 (* print proof context contents *)
   123 
   124 val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of);
   125 val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of);
   126 
   127 
   128 (* print theorems / types / terms / props *)
   129 
   130 fun print_thms args = Toplevel.keep (fn state =>
   131   let val st = Toplevel.node_case Proof.init_state Proof.enter_forward state
   132   in Display.print_thms (IsarThy.get_thmss args st) end);
   133 
   134 
   135 fun read_typ thy = Sign.read_typ (Theory.sign_of thy, K None);
   136 
   137 fun read_term T thy s =
   138   Thm.term_of (#1 (Thm.read_def_cterm (Theory.sign_of thy, K None, K None) [] true (s, T)));
   139 
   140 
   141 fun print_type s = Toplevel.keep (fn state =>
   142   let
   143     val sign = Toplevel.sign_of state;
   144     val T = Toplevel.node_case read_typ (ProofContext.read_typ o Proof.context_of) state s;
   145   in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
   146 
   147 fun print_term s = Toplevel.keep (fn state =>
   148   let
   149     val sign = Toplevel.sign_of state;
   150     val t = Toplevel.node_case (read_term (TVar (("'z", 0), logicS)))
   151       (ProofContext.read_term o Proof.context_of) state s;
   152     val T = Term.type_of t;
   153   in
   154     Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
   155       Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
   156   end);
   157 
   158 fun print_prop s = Toplevel.keep (fn state =>
   159   let
   160     val sign = Toplevel.sign_of state;
   161     val prop =
   162       Toplevel.node_case (read_term propT) (ProofContext.read_prop o Proof.context_of) state s;
   163   in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
   164 
   165 
   166 end;