src/Pure/Isar/rule_insts.ML
author wenzelm
Sat Jun 14 23:20:12 2008 +0200 (2008-06-14)
changeset 27219 a248dba028ff
parent 27120 b21eec437295
child 27236 80356567e7ad
permissions -rw-r--r--
export subgoal_tac, subgoals_tac, thin_tac;
wenzelm@20336
     1
(*  Title:      Pure/Isar/rule_insts.ML
wenzelm@20336
     2
    ID:         $Id$
wenzelm@20336
     3
    Author:     Makarius
wenzelm@20336
     4
wenzelm@20336
     5
Rule instantiations -- operations within a rule/subgoal context.
wenzelm@20336
     6
*)
wenzelm@20336
     7
wenzelm@20336
     8
signature RULE_INSTS =
wenzelm@20336
     9
sig
wenzelm@20336
    10
  val bires_inst_tac: bool -> Proof.context -> (indexname * string) list ->
wenzelm@20336
    11
    thm -> int -> tactic
wenzelm@27120
    12
  val res_inst_tac: Proof.context -> (indexname * string) list -> thm -> int -> tactic
wenzelm@27120
    13
  val eres_inst_tac: Proof.context -> (indexname * string) list -> thm -> int -> tactic
wenzelm@27219
    14
  val subgoal_tac: Proof.context -> string -> int -> tactic
wenzelm@27219
    15
  val subgoals_tac: Proof.context -> string list -> int -> tactic
wenzelm@27219
    16
  val thin_tac: Proof.context -> string -> int -> tactic
wenzelm@20336
    17
end;
wenzelm@20336
    18
wenzelm@20336
    19
structure RuleInsts: RULE_INSTS =
wenzelm@20336
    20
struct
wenzelm@20336
    21
wenzelm@20336
    22
wenzelm@20343
    23
(** reading instantiations **)
wenzelm@20336
    24
wenzelm@20336
    25
local
wenzelm@20336
    26
wenzelm@20343
    27
fun is_tvar (x, _) = String.isPrefix "'" x;
wenzelm@20336
    28
wenzelm@22681
    29
fun error_var msg xi = error (msg ^ Term.string_of_vname xi);
wenzelm@20336
    30
wenzelm@20343
    31
fun the_sort tvars xi = the (AList.lookup (op =) tvars xi)
wenzelm@20336
    32
  handle Option.Option => error_var "No such type variable in theorem: " xi;
wenzelm@20336
    33
wenzelm@20343
    34
fun the_type vars xi = the (AList.lookup (op =) vars xi)
wenzelm@20336
    35
  handle Option.Option => error_var "No such variable in theorem: " xi;
wenzelm@20336
    36
wenzelm@20343
    37
fun unify_vartypes thy vars (xi, u) (unifier, maxidx) =
wenzelm@20336
    38
  let
wenzelm@20343
    39
    val T = the_type vars xi;
wenzelm@20336
    40
    val U = Term.fastype_of u;
wenzelm@20343
    41
    val maxidx' = Term.maxidx_term u (Int.max (#2 xi, maxidx));
wenzelm@20336
    42
  in
wenzelm@20336
    43
    Sign.typ_unify thy (T, U) (unifier, maxidx')
wenzelm@20336
    44
      handle Type.TUNIFY => error_var "Incompatible type for instantiation of " xi
wenzelm@20336
    45
  end;
wenzelm@20336
    46
wenzelm@20343
    47
fun instantiate inst =
wenzelm@20509
    48
  TermSubst.instantiate ([], map (fn (xi, t) => ((xi, Term.fastype_of t), t)) inst) #>
wenzelm@20343
    49
  Envir.beta_norm;
wenzelm@20336
    50
wenzelm@20343
    51
fun make_instT f v =
wenzelm@20336
    52
  let
wenzelm@20343
    53
    val T = TVar v;
wenzelm@20343
    54
    val T' = f T;
wenzelm@20343
    55
  in if T = T' then NONE else SOME (T, T') end;
wenzelm@20343
    56
wenzelm@20343
    57
fun make_inst f v =
wenzelm@20343
    58
  let
wenzelm@20343
    59
    val t = Var v;
wenzelm@20343
    60
    val t' = f t;
wenzelm@20343
    61
  in if t aconv t' then NONE else SOME (t, t') end;
wenzelm@20336
    62
wenzelm@20336
    63
in
wenzelm@20336
    64
wenzelm@25333
    65
fun read_termTs ctxt schematic ss Ts =
wenzelm@25329
    66
  let
wenzelm@25329
    67
    fun parse T = if T = propT then Syntax.parse_prop ctxt else Syntax.parse_term ctxt;
wenzelm@25329
    68
    val ts = map2 parse Ts ss;
wenzelm@25329
    69
    val ts' =
wenzelm@25329
    70
      map2 (TypeInfer.constrain o TypeInfer.paramify_vars) Ts ts
wenzelm@25333
    71
      |> Syntax.check_terms ((schematic ? ProofContext.set_mode ProofContext.mode_schematic) ctxt)
wenzelm@25329
    72
      |> Variable.polymorphic ctxt;
wenzelm@25329
    73
    val Ts' = map Term.fastype_of ts';
wenzelm@25329
    74
    val tyenv = fold Type.raw_match (Ts ~~ Ts') Vartab.empty;
wenzelm@25329
    75
  in (ts', map (apsnd snd) (Vartab.dest tyenv)) end;
wenzelm@25329
    76
wenzelm@20343
    77
fun read_insts ctxt mixed_insts (tvars, vars) =
wenzelm@20336
    78
  let
wenzelm@20343
    79
    val thy = ProofContext.theory_of ctxt;
wenzelm@20343
    80
    val cert = Thm.cterm_of thy;
wenzelm@20343
    81
    val certT = Thm.ctyp_of thy;
wenzelm@20336
    82
wenzelm@20343
    83
    val (type_insts, term_insts) = List.partition (is_tvar o fst) mixed_insts;
wenzelm@20336
    84
    val internal_insts = term_insts |> map_filter
wenzelm@20336
    85
      (fn (xi, Args.Term t) => SOME (xi, t)
wenzelm@21500
    86
        | (_, Args.Text _) => NONE
wenzelm@20343
    87
        | (xi, _) => error_var "Term argument expected for " xi);
wenzelm@20336
    88
    val external_insts = term_insts |> map_filter
wenzelm@21500
    89
      (fn (xi, Args.Text s) => SOME (xi, s) | _ => NONE);
wenzelm@20336
    90
wenzelm@20336
    91
wenzelm@20343
    92
    (* mixed type instantiations *)
wenzelm@20336
    93
wenzelm@20336
    94
    fun readT (xi, arg) =
wenzelm@20336
    95
      let
wenzelm@20343
    96
        val S = the_sort tvars xi;
wenzelm@20336
    97
        val T =
wenzelm@20336
    98
          (case arg of
wenzelm@25333
    99
            Args.Text s => Syntax.read_typ ctxt s
wenzelm@20336
   100
          | Args.Typ T => T
wenzelm@20336
   101
          | _ => error_var "Type argument expected for " xi);
wenzelm@20336
   102
      in
wenzelm@20343
   103
        if Sign.of_sort thy (T, S) then ((xi, S), T)
wenzelm@20336
   104
        else error_var "Incompatible sort for typ instantiation of " xi
wenzelm@20336
   105
      end;
wenzelm@20336
   106
wenzelm@20343
   107
    val type_insts1 = map readT type_insts;
wenzelm@20509
   108
    val instT1 = TermSubst.instantiateT type_insts1;
wenzelm@20343
   109
    val vars1 = map (apsnd instT1) vars;
wenzelm@20336
   110
wenzelm@20336
   111
wenzelm@20336
   112
    (* internal term instantiations *)
wenzelm@20336
   113
wenzelm@20343
   114
    val instT2 = Envir.norm_type
wenzelm@20343
   115
      (#1 (fold (unify_vartypes thy vars1) internal_insts (Vartab.empty, 0)));
wenzelm@20343
   116
    val vars2 = map (apsnd instT2) vars1;
wenzelm@20548
   117
    val internal_insts2 = map (apsnd (map_types instT2)) internal_insts;
wenzelm@20343
   118
    val inst2 = instantiate internal_insts2;
wenzelm@20336
   119
wenzelm@20336
   120
wenzelm@20336
   121
    (* external term instantiations *)
wenzelm@20336
   122
wenzelm@20343
   123
    val (xs, strs) = split_list external_insts;
wenzelm@20343
   124
    val Ts = map (the_type vars2) xs;
wenzelm@25354
   125
    val (ts, inferred) = read_termTs ctxt false strs Ts;
wenzelm@20336
   126
wenzelm@20343
   127
    val instT3 = Term.typ_subst_TVars inferred;
wenzelm@20343
   128
    val vars3 = map (apsnd instT3) vars2;
wenzelm@20548
   129
    val internal_insts3 = map (apsnd (map_types instT3)) internal_insts2;
wenzelm@20343
   130
    val external_insts3 = xs ~~ ts;
wenzelm@20343
   131
    val inst3 = instantiate external_insts3;
wenzelm@20336
   132
wenzelm@20336
   133
wenzelm@20343
   134
    (* results *)
wenzelm@20343
   135
wenzelm@20343
   136
    val type_insts3 = map (fn ((a, _), T) => (a, instT3 (instT2 T))) type_insts1;
wenzelm@20343
   137
    val term_insts3 = internal_insts3 @ external_insts3;
wenzelm@20336
   138
wenzelm@20343
   139
    val inst_tvars = map_filter (make_instT (instT3 o instT2 o instT1)) tvars;
wenzelm@20343
   140
    val inst_vars = map_filter (make_inst (inst3 o inst2)) vars3;
wenzelm@20343
   141
  in
wenzelm@20343
   142
    ((type_insts3, term_insts3),
wenzelm@20343
   143
      (map (pairself certT) inst_tvars, map (pairself cert) inst_vars))
wenzelm@20343
   144
  end;
wenzelm@20343
   145
wenzelm@20343
   146
fun read_instantiate ctxt mixed_insts thm =
wenzelm@20343
   147
  let
wenzelm@20487
   148
    val ctxt' = ctxt |> Variable.declare_thm thm
wenzelm@20487
   149
      |> fold (fn a => Variable.declare_internal (Logic.mk_type (TFree (a, [])))) (Drule.add_used thm []);  (* FIXME tmp *)
wenzelm@22692
   150
    val tvars = Thm.fold_terms Term.add_tvars thm [];
wenzelm@22692
   151
    val vars = Thm.fold_terms Term.add_vars thm [];
wenzelm@20343
   152
    val ((type_insts, term_insts), insts) = read_insts ctxt' (map snd mixed_insts) (tvars, vars);
wenzelm@20343
   153
wenzelm@20343
   154
    val _ = (*assign internalized values*)
wenzelm@20336
   155
      mixed_insts |> List.app (fn (arg, (xi, _)) =>
wenzelm@20336
   156
        if is_tvar xi then
wenzelm@20343
   157
          Args.assign (SOME (Args.Typ (the (AList.lookup (op =) type_insts xi)))) arg
wenzelm@20336
   158
        else
wenzelm@20343
   159
          Args.assign (SOME (Args.Term (the (AList.lookup (op =) term_insts xi)))) arg);
wenzelm@20343
   160
  in
wenzelm@20343
   161
    Drule.instantiate insts thm |> RuleCases.save thm
wenzelm@20343
   162
  end;
wenzelm@20336
   163
wenzelm@20343
   164
fun read_instantiate' ctxt (args, concl_args) thm =
wenzelm@20343
   165
  let
wenzelm@20343
   166
    fun zip_vars _ [] = []
wenzelm@20343
   167
      | zip_vars (_ :: xs) ((_, NONE) :: rest) = zip_vars xs rest
wenzelm@20343
   168
      | zip_vars ((x, _) :: xs) ((arg, SOME t) :: rest) = (arg, (x, t)) :: zip_vars xs rest
wenzelm@20343
   169
      | zip_vars [] _ = error "More instantiations than variables in theorem";
wenzelm@20343
   170
    val insts =
wenzelm@20343
   171
      zip_vars (rev (Term.add_vars (Thm.full_prop_of thm) [])) args @
wenzelm@20343
   172
      zip_vars (rev (Term.add_vars (Thm.concl_of thm) [])) concl_args;
wenzelm@20343
   173
  in read_instantiate ctxt insts thm end;
wenzelm@20336
   174
wenzelm@20336
   175
end;
wenzelm@20336
   176
wenzelm@20336
   177
wenzelm@20343
   178
wenzelm@20343
   179
(** attributes **)
wenzelm@20343
   180
wenzelm@20336
   181
(* where: named instantiation *)
wenzelm@20336
   182
wenzelm@20336
   183
local
wenzelm@20336
   184
wenzelm@20336
   185
val value =
wenzelm@20336
   186
  Args.internal_typ >> Args.Typ ||
wenzelm@20336
   187
  Args.internal_term >> Args.Term ||
wenzelm@21500
   188
  Args.name >> Args.Text;
wenzelm@20336
   189
wenzelm@20336
   190
val inst = Args.var -- (Args.$$$ "=" |-- Args.ahead -- value)
wenzelm@20336
   191
  >> (fn (xi, (a, v)) => (a, (xi, v)));
wenzelm@20336
   192
wenzelm@20336
   193
in
wenzelm@20336
   194
wenzelm@20343
   195
val where_att = Attrib.syntax (Args.and_list (Scan.lift inst) >> (fn args =>
wenzelm@20343
   196
  Thm.rule_attribute (fn context => read_instantiate (Context.proof_of context) args)));
wenzelm@20336
   197
wenzelm@20336
   198
end;
wenzelm@20336
   199
wenzelm@20336
   200
wenzelm@20343
   201
(* of: positional instantiation (terms only) *)
wenzelm@20336
   202
wenzelm@20336
   203
local
wenzelm@20336
   204
wenzelm@20336
   205
val value =
wenzelm@20336
   206
  Args.internal_term >> Args.Term ||
wenzelm@21500
   207
  Args.name >> Args.Text;
wenzelm@20336
   208
wenzelm@20336
   209
val inst = Args.ahead -- Args.maybe value;
wenzelm@20336
   210
val concl = Args.$$$ "concl" -- Args.colon;
wenzelm@20336
   211
wenzelm@20336
   212
val insts =
wenzelm@20336
   213
  Scan.repeat (Scan.unless concl inst) --
wenzelm@20336
   214
  Scan.optional (concl |-- Scan.repeat inst) [];
wenzelm@20336
   215
wenzelm@20336
   216
in
wenzelm@20336
   217
wenzelm@20343
   218
val of_att = Attrib.syntax (Scan.lift insts >> (fn args =>
wenzelm@20343
   219
  Thm.rule_attribute (fn context => read_instantiate' (Context.proof_of context) args)));
wenzelm@20336
   220
wenzelm@20336
   221
end;
wenzelm@20336
   222
wenzelm@20336
   223
wenzelm@20336
   224
(* setup *)
wenzelm@20336
   225
wenzelm@26463
   226
val _ = Context.>> (Context.map_theory
wenzelm@26463
   227
  (Attrib.add_attributes
wenzelm@26463
   228
   [("where", where_att, "named instantiation of theorem"),
wenzelm@26463
   229
    ("of", of_att, "positional instantiation of theorem")]));
wenzelm@20336
   230
wenzelm@20336
   231
wenzelm@20336
   232
wenzelm@20336
   233
(** methods **)
wenzelm@20336
   234
wenzelm@27120
   235
(* rule_tac etc. -- refer to dynamic goal state!! *)   (* FIXME cleanup this mess!!! *)
wenzelm@20336
   236
wenzelm@20336
   237
fun bires_inst_tac bires_flag ctxt insts thm =
wenzelm@20336
   238
  let
wenzelm@20336
   239
    val thy = ProofContext.theory_of ctxt;
wenzelm@20336
   240
    (* Separate type and term insts *)
wenzelm@20336
   241
    fun has_type_var ((x, _), _) = (case Symbol.explode x of
wenzelm@20336
   242
          "'"::cs => true | cs => false);
wenzelm@20336
   243
    val Tinsts = List.filter has_type_var insts;
wenzelm@20336
   244
    val tinsts = filter_out has_type_var insts;
wenzelm@25333
   245
wenzelm@20336
   246
    (* Tactic *)
wenzelm@20336
   247
    fun tac i st =
wenzelm@20336
   248
      let
wenzelm@25333
   249
        val (_, _, Bi, _) = Thm.dest_state (st, i);
wenzelm@25333
   250
        val params = Logic.strip_params Bi;  (*params of subgoal i as string typ pairs*)
wenzelm@25333
   251
        val params = rev (Term.rename_wrt_term Bi params)
wenzelm@25333
   252
          (*as they are printed: bound variables with*)
wenzelm@25333
   253
          (*the same name are renamed during printing*)
wenzelm@25333
   254
wenzelm@25333
   255
        val (param_names, ctxt') = ctxt
wenzelm@25333
   256
          |> Variable.declare_thm thm
wenzelm@25333
   257
          |> Thm.fold_terms Variable.declare_constraints st
wenzelm@25333
   258
          |> ProofContext.add_fixes_i (map (fn (x, T) => (x, SOME T, NoSyn)) params);
wenzelm@25333
   259
wenzelm@25333
   260
        (* Process type insts: Tinsts_env *)
wenzelm@25333
   261
        fun absent xi = error
wenzelm@25333
   262
              ("No such variable in theorem: " ^ Term.string_of_vname xi);
wenzelm@25333
   263
        val (rtypes, rsorts) = Drule.types_sorts thm;
wenzelm@25333
   264
        fun readT (xi, s) =
wenzelm@25333
   265
            let val S = case rsorts xi of SOME S => S | NONE => absent xi;
wenzelm@25333
   266
                val T = Syntax.read_typ ctxt' s;
wenzelm@25333
   267
                val U = TVar (xi, S);
wenzelm@25333
   268
            in if Sign.typ_instance thy (T, U) then (U, T)
wenzelm@25333
   269
               else error ("Instantiation of " ^ Term.string_of_vname xi ^ " fails")
wenzelm@25333
   270
            end;
wenzelm@25333
   271
        val Tinsts_env = map readT Tinsts;
wenzelm@25333
   272
        (* Preprocess rule: extract vars and their types, apply Tinsts *)
wenzelm@25333
   273
        fun get_typ xi =
wenzelm@25333
   274
          (case rtypes xi of
wenzelm@25333
   275
               SOME T => typ_subst_atomic Tinsts_env T
wenzelm@25333
   276
             | NONE => absent xi);
wenzelm@25333
   277
        val (xis, ss) = Library.split_list tinsts;
wenzelm@25333
   278
        val Ts = map get_typ xis;
wenzelm@25333
   279
wenzelm@25333
   280
        val (ts, envT) = read_termTs ctxt' true ss Ts;
wenzelm@20336
   281
        val envT' = map (fn (ixn, T) =>
wenzelm@20336
   282
          (TVar (ixn, the (rsorts ixn)), T)) envT @ Tinsts_env;
wenzelm@20336
   283
        val cenv =
wenzelm@20336
   284
          map
wenzelm@20336
   285
            (fn (xi, t) =>
wenzelm@20336
   286
              pairself (Thm.cterm_of thy) (Var (xi, fastype_of t), t))
wenzelm@20336
   287
            (distinct
wenzelm@20336
   288
              (fn ((x1, t1), (x2, t2)) => x1 = x2 andalso t1 aconv t2)
wenzelm@20336
   289
              (xis ~~ ts));
wenzelm@20336
   290
        (* Lift and instantiate rule *)
wenzelm@20336
   291
        val {maxidx, ...} = rep_thm st;
wenzelm@20336
   292
        val paramTs = map #2 params
wenzelm@20336
   293
        and inc = maxidx+1
wenzelm@20336
   294
        fun liftvar (Var ((a,j), T)) =
wenzelm@20336
   295
              Var((a, j+inc), paramTs ---> Logic.incr_tvar inc T)
wenzelm@20336
   296
          | liftvar t = raise TERM("Variable expected", [t]);
wenzelm@20336
   297
        fun liftterm t = list_abs_free
wenzelm@25333
   298
              (param_names ~~ paramTs, Logic.incr_indexes(paramTs,inc) t)
wenzelm@20336
   299
        fun liftpair (cv,ct) =
wenzelm@20336
   300
              (cterm_fun liftvar cv, cterm_fun liftterm ct)
wenzelm@20336
   301
        val lifttvar = pairself (ctyp_of thy o Logic.incr_tvar inc);
wenzelm@20336
   302
        val rule = Drule.instantiate
wenzelm@20336
   303
              (map lifttvar envT', map liftpair cenv)
wenzelm@20336
   304
              (Thm.lift_rule (Thm.cprem_of st i) thm)
wenzelm@20336
   305
      in
wenzelm@20336
   306
        if i > nprems_of st then no_tac st
wenzelm@20336
   307
        else st |>
wenzelm@20336
   308
          compose_tac (bires_flag, rule, nprems_of thm) i
wenzelm@20336
   309
      end
wenzelm@20336
   310
           handle TERM (msg,_)   => (warning msg; no_tac st)
wenzelm@20336
   311
                | THM  (msg,_,_) => (warning msg; no_tac st);
wenzelm@20336
   312
  in tac end;
wenzelm@20336
   313
wenzelm@27120
   314
val res_inst_tac = bires_inst_tac false;
wenzelm@27120
   315
val eres_inst_tac = bires_inst_tac true;
wenzelm@27120
   316
wenzelm@27120
   317
wenzelm@20336
   318
local
wenzelm@20336
   319
wenzelm@20336
   320
fun gen_inst _ tac _ (quant, ([], thms)) =
wenzelm@20336
   321
      Method.METHOD (fn facts => quant (Method.insert_tac facts THEN' tac thms))
wenzelm@20336
   322
  | gen_inst inst_tac _ ctxt (quant, (insts, [thm])) =
wenzelm@20336
   323
      Method.METHOD (fn facts =>
wenzelm@20336
   324
        quant (Method.insert_tac facts THEN' inst_tac ctxt insts thm))
wenzelm@20336
   325
  | gen_inst _ _ _ _ = error "Cannot have instantiations with multiple rules";
wenzelm@20336
   326
wenzelm@20336
   327
in
wenzelm@20336
   328
wenzelm@27120
   329
val res_inst_meth = gen_inst res_inst_tac Tactic.resolve_tac;
wenzelm@27120
   330
val eres_inst_meth = gen_inst eres_inst_tac Tactic.eresolve_tac;
wenzelm@20336
   331
wenzelm@20336
   332
val cut_inst_meth =
wenzelm@20336
   333
  gen_inst
wenzelm@27120
   334
    (fn ctxt => fn insts => res_inst_tac ctxt insts o Tactic.make_elim_preserve)
wenzelm@20336
   335
    Tactic.cut_rules_tac;
wenzelm@20336
   336
wenzelm@20336
   337
val dres_inst_meth =
wenzelm@20336
   338
  gen_inst
wenzelm@27120
   339
    (fn ctxt => fn insts => eres_inst_tac ctxt insts o Tactic.make_elim_preserve)
wenzelm@20336
   340
    Tactic.dresolve_tac;
wenzelm@20336
   341
wenzelm@20336
   342
val forw_inst_meth =
wenzelm@20336
   343
  gen_inst
wenzelm@20336
   344
    (fn ctxt => fn insts => fn rule =>
wenzelm@27120
   345
       res_inst_tac ctxt insts (Tactic.make_elim_preserve rule) THEN' assume_tac)
wenzelm@20336
   346
    Tactic.forward_tac;
wenzelm@20336
   347
wenzelm@27120
   348
fun subgoal_tac ctxt sprop = DETERM o res_inst_tac ctxt [(("psi", 0), sprop)] cut_rl;
wenzelm@20336
   349
fun subgoals_tac ctxt sprops = EVERY' (map (subgoal_tac ctxt) sprops);
wenzelm@20336
   350
wenzelm@27120
   351
fun thin_tac ctxt s = eres_inst_tac ctxt [(("V", 0), s)] thin_rl;
wenzelm@20336
   352
wenzelm@20336
   353
wenzelm@20336
   354
(* method syntax *)
wenzelm@20336
   355
wenzelm@20336
   356
val insts =
wenzelm@20336
   357
  Scan.optional
wenzelm@20336
   358
    (Args.enum1 "and" (Scan.lift (Args.name -- (Args.$$$ "=" |-- Args.!!! Args.name))) --|
wenzelm@20336
   359
      Scan.lift (Args.$$$ "in")) [] -- Attrib.thms;
wenzelm@20336
   360
wenzelm@20336
   361
fun inst_args f src ctxt =
haftmann@21879
   362
  f ctxt (fst (Method.syntax (Args.goal_spec HEADGOAL -- insts) src ctxt));
wenzelm@20336
   363
wenzelm@20336
   364
val insts_var =
wenzelm@20336
   365
  Scan.optional
wenzelm@20336
   366
    (Args.enum1 "and" (Scan.lift (Args.var -- (Args.$$$ "=" |-- Args.!!! Args.name))) --|
wenzelm@20336
   367
      Scan.lift (Args.$$$ "in")) [] -- Attrib.thms;
wenzelm@20336
   368
wenzelm@20336
   369
fun inst_args_var f src ctxt =
haftmann@21879
   370
  f ctxt (fst (Method.syntax (Args.goal_spec HEADGOAL -- insts_var) src ctxt));
wenzelm@20336
   371
wenzelm@20336
   372
wenzelm@20336
   373
(* setup *)
wenzelm@20336
   374
wenzelm@26463
   375
val _ = Context.>> (Context.map_theory
wenzelm@26463
   376
  (Method.add_methods
wenzelm@26463
   377
   [("rule_tac", inst_args_var res_inst_meth,
wenzelm@26463
   378
      "apply rule (dynamic instantiation)"),
wenzelm@26463
   379
    ("erule_tac", inst_args_var eres_inst_meth,
wenzelm@26463
   380
      "apply rule in elimination manner (dynamic instantiation)"),
wenzelm@26463
   381
    ("drule_tac", inst_args_var dres_inst_meth,
wenzelm@26463
   382
      "apply rule in destruct manner (dynamic instantiation)"),
wenzelm@26463
   383
    ("frule_tac", inst_args_var forw_inst_meth,
wenzelm@26463
   384
      "apply rule in forward manner (dynamic instantiation)"),
wenzelm@26463
   385
    ("cut_tac", inst_args_var cut_inst_meth,
wenzelm@26463
   386
      "cut rule (dynamic instantiation)"),
wenzelm@26463
   387
    ("subgoal_tac", Method.goal_args_ctxt (Scan.repeat1 Args.name) subgoals_tac,
wenzelm@26463
   388
      "insert subgoal (dynamic instantiation)"),
wenzelm@26463
   389
    ("thin_tac", Method.goal_args_ctxt Args.name thin_tac,
wenzelm@26463
   390
      "remove premise (dynamic instantiation)")]));
wenzelm@20336
   391
wenzelm@20336
   392
end;
wenzelm@20336
   393
wenzelm@20336
   394
end;