src/Pure/Isar/isar_cmd.ML
author wenzelm
Sat Sep 25 13:18:38 1999 +0200 (1999-09-25 ago)
changeset 7604 55566b9ec7d7
parent 7503 e8be98558eb8
child 7615 c650147f56f1
permissions -rw-r--r--
tuned;
     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 welcome: Toplevel.transition -> Toplevel.transition
    11   val init_toplevel: Toplevel.transition -> Toplevel.transition
    12   val exit: Toplevel.transition -> Toplevel.transition
    13   val quit: Toplevel.transition -> Toplevel.transition
    14   val touch_all_thys: Toplevel.transition -> Toplevel.transition
    15   val touch_thy: string -> Toplevel.transition -> Toplevel.transition
    16   val remove_thy: string -> Toplevel.transition -> Toplevel.transition
    17   val cannot_undo: string -> Toplevel.transition -> Toplevel.transition
    18   val clear_undo: Toplevel.transition -> Toplevel.transition
    19   val redo: Toplevel.transition -> Toplevel.transition
    20   val undos_proof: int -> Toplevel.transition -> Toplevel.transition
    21   val kill_proof: Toplevel.transition -> Toplevel.transition
    22   val undo_theory: Toplevel.transition -> Toplevel.transition
    23   val undo: Toplevel.transition -> Toplevel.transition
    24   val use: string -> Toplevel.transition -> Toplevel.transition
    25   val use_mltext_theory: string -> Toplevel.transition -> Toplevel.transition
    26   val use_mltext: string -> Toplevel.transition -> Toplevel.transition
    27   val use_commit: Toplevel.transition -> Toplevel.transition
    28   val cd: string -> Toplevel.transition -> Toplevel.transition
    29   val pwd: Toplevel.transition -> Toplevel.transition
    30   val use_thy: string -> Toplevel.transition -> Toplevel.transition
    31   val use_thy_only: string -> Toplevel.transition -> Toplevel.transition
    32   val update_thy: string -> Toplevel.transition -> Toplevel.transition
    33   val update_thy_only: string -> Toplevel.transition -> Toplevel.transition
    34   val pretty_setmargin: int -> Toplevel.transition -> Toplevel.transition
    35   val print_context: Toplevel.transition -> Toplevel.transition
    36   val print_theory: Toplevel.transition -> Toplevel.transition
    37   val print_syntax: Toplevel.transition -> Toplevel.transition
    38   val print_theorems: Toplevel.transition -> Toplevel.transition
    39   val print_attributes: Toplevel.transition -> Toplevel.transition
    40   val print_methods: Toplevel.transition -> Toplevel.transition
    41   val print_binds: Toplevel.transition -> Toplevel.transition
    42   val print_lthms: Toplevel.transition -> Toplevel.transition
    43   val print_thms: (string * Args.src list) list -> Toplevel.transition -> Toplevel.transition
    44   val print_prop: string -> Toplevel.transition -> Toplevel.transition
    45   val print_term: string -> Toplevel.transition -> Toplevel.transition
    46   val print_type: string -> Toplevel.transition -> Toplevel.transition
    47 end;
    48 
    49 structure IsarCmd: ISAR_CMD =
    50 struct
    51 
    52 
    53 (* variations on init / exit *)
    54 
    55 val init_toplevel = Toplevel.imperative (fn () => raise Toplevel.RESTART);
    56 val welcome = Toplevel.imperative (writeln o Session.welcome);
    57 
    58 val exit = Toplevel.keep (fn state =>
    59   (Context.set_context (try Toplevel.theory_of state);
    60     writeln "Leaving the Isar loop.  Invoke 'loop();' to restart.";
    61     raise Toplevel.TERMINATE));
    62 
    63 val quit = Toplevel.imperative quit;
    64 
    65 
    66 (* touch theories *)
    67 
    68 val touch_all_thys = Toplevel.imperative ThyInfo.touch_all_thys;
    69 fun touch_thy name = Toplevel.imperative (fn () => ThyInfo.touch_thy name);
    70 fun remove_thy name = Toplevel.imperative (fn () => ThyInfo.remove_thy name);
    71 
    72 
    73 (* history commands *)
    74 
    75 fun cannot_undo txt = Toplevel.imperative (fn () => error ("Cannot undo " ^ quote txt));
    76 val clear_undo = Toplevel.history History.clear o Toplevel.proof ProofHistory.clear;
    77 val redo = Toplevel.history History.redo o Toplevel.proof ProofHistory.redo;
    78 
    79 fun undos_proof n = Toplevel.proof (fn prf =>
    80   if ProofHistory.is_initial prf then raise Toplevel.UNDEF else funpow n ProofHistory.undo prf);
    81 
    82 val kill_proof = Toplevel.history (fn hist =>
    83   (case History.current hist of
    84     Toplevel.Theory _ => raise Toplevel.UNDEF
    85   | Toplevel.Proof _ => History.undo hist));
    86 
    87 val undo_theory = Toplevel.history (fn hist =>
    88   if History.is_initial hist then raise Toplevel.UNDEF else History.undo hist);
    89 
    90 val undo = Toplevel.kill o undo_theory o undos_proof 1;
    91 
    92 
    93 (* use ML text *)
    94 
    95 fun use name = Toplevel.keep (fn state =>
    96   Context.setmp (try Toplevel.theory_of state) ThyInfo.use name);
    97 
    98 (*passes changes of theory context*)
    99 val use_mltext_theory = Toplevel.theory o IsarThy.use_mltext_theory;
   100 
   101 (*ignore result theory context*)
   102 fun use_mltext txt = Toplevel.keep (fn state =>
   103   (IsarThy.use_mltext txt (try Toplevel.theory_of state); ()));
   104 
   105 (*Note: commit is dynamically bound*)
   106 val use_commit = use_mltext "commit();";
   107 
   108 
   109 (* current working directory *)
   110 
   111 fun print_cd _ = writeln (Path.pack (File.pwd ()));
   112 
   113 fun cd dir = Toplevel.imperative (fn () => (File.cd (Path.unpack dir); print_cd ()));
   114 val pwd = Toplevel.imperative print_cd;
   115 
   116 
   117 (* load theory files *)
   118 
   119 fun use_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy name);
   120 fun use_thy_only name = Toplevel.imperative (fn () => Context.save ThyInfo.use_thy_only name);
   121 fun update_thy name = Toplevel.imperative (fn () => Context.save ThyInfo.update_thy name);
   122 fun update_thy_only name =
   123   Toplevel.imperative (fn () => Context.save ThyInfo.update_thy_only name);
   124 
   125 
   126 (* pretty_setmargin *)
   127 
   128 fun pretty_setmargin n = Toplevel.imperative (fn () => Pretty.setmargin n);
   129 
   130 
   131 (* print theory *)
   132 
   133 val print_context = Toplevel.keep Toplevel.print_state_context;
   134 val print_theory = Toplevel.keep (PureThy.print_theory o Toplevel.theory_of);
   135 val print_syntax = Toplevel.keep (Display.print_syntax o Toplevel.theory_of);
   136 val print_theorems = Toplevel.keep (PureThy.print_theorems o Toplevel.theory_of);
   137 val print_attributes = Toplevel.keep (Attrib.print_attributes o Toplevel.theory_of);
   138 val print_methods = Toplevel.keep (Method.print_methods o Toplevel.theory_of);
   139 
   140 
   141 (* print proof context contents *)
   142 
   143 val print_binds = Toplevel.keep (ProofContext.print_binds o Proof.context_of o Toplevel.proof_of);
   144 val print_lthms = Toplevel.keep (ProofContext.print_thms o Proof.context_of o Toplevel.proof_of);
   145 
   146 
   147 (* print theorems / types / terms / props *)
   148 
   149 fun print_thms args = Toplevel.keep (fn state =>
   150   let val st = Toplevel.node_case Proof.init_state Proof.enter_forward state
   151   in Pretty.writeln (Proof.pretty_thms (IsarThy.get_thmss args st)) end);
   152 
   153 fun print_type s = Toplevel.keep (fn state =>
   154   let
   155     val sign = Toplevel.sign_of state;
   156     val T = ProofContext.read_typ (Toplevel.context_of state) s;
   157   in Pretty.writeln (Pretty.quote (Sign.pretty_typ sign T)) end);
   158 
   159 fun print_term s = Toplevel.keep (fn state =>
   160   let
   161     val sign = Toplevel.sign_of state;
   162     val t = ProofContext.read_term (Toplevel.context_of state) s;
   163     val T = Term.type_of t;
   164   in
   165     Pretty.writeln (Pretty.block [Pretty.quote (Sign.pretty_term sign t), Pretty.fbrk,
   166       Pretty.str "::", Pretty.brk 1, Pretty.quote (Sign.pretty_typ sign T)])
   167   end);
   168 
   169 fun print_prop s = Toplevel.keep (fn state =>
   170   let
   171     val sign = Toplevel.sign_of state;
   172     val prop = ProofContext.read_prop (Toplevel.context_of state) s;
   173   in Pretty.writeln (Pretty.quote (Sign.pretty_term sign prop)) end);
   174 
   175 
   176 end;