src/Pure/Isar/proof_context.ML
changeset 8426 f6e022588624
parent 8403 a8a0411a8e8c
child 8462 7f4e4e875c13
equal deleted inserted replaced
8425:f03c667cf702 8426:f6e022588624
   101       ((cterm * ((int -> tactic) * (int -> tactic))) list *             (*assumes: A ==> _*)
   101       ((cterm * ((int -> tactic) * (int -> tactic))) list *             (*assumes: A ==> _*)
   102         (string * thm list) list) *
   102         (string * thm list) list) *
   103       ((string * string) list * string list),                           (*fixes: !!x. _*)
   103       ((string * string) list * string list),                           (*fixes: !!x. _*)
   104     binds: (term * typ) option Vartab.table,                            (*term bindings*)
   104     binds: (term * typ) option Vartab.table,                            (*term bindings*)
   105     thms: thm list option Symtab.table,                                 (*local thms*)
   105     thms: thm list option Symtab.table,                                 (*local thms*)
   106     cases: RuleCases.T Symtab.table,                                    (*local contexts*)
   106     cases: (string * RuleCases.T) list,                                 (*local contexts*)
   107     defs:
   107     defs:
   108       typ Vartab.table *                                                (*type constraints*)
   108       typ Vartab.table *                                                (*type constraints*)
   109       sort Vartab.table *                                               (*default sorts*)
   109       sort Vartab.table *                                               (*default sorts*)
   110       string list};                                                     (*used type var names*)
   110       string list};                                                     (*used type var names*)
   111 
   111 
   180     val prt_term = Sign.pretty_term (sign_of ctxt);
   180     val prt_term = Sign.pretty_term (sign_of ctxt);
   181 
   181 
   182     fun prt_sect _ _ [] = []
   182     fun prt_sect _ _ [] = []
   183       | prt_sect s prt xs = [Pretty.block (Pretty.breaks (Pretty.str s :: map prt xs))];
   183       | prt_sect s prt xs = [Pretty.block (Pretty.breaks (Pretty.str s :: map prt xs))];
   184 
   184 
   185     (* FIXME hilite keywords (using Isar-self syntax) (!?); move to rule_cases.ML (!?) *)
       
   186     fun prt_case (name, (xs, ts)) = Pretty.block (Pretty.breaks
   185     fun prt_case (name, (xs, ts)) = Pretty.block (Pretty.breaks
   187       (Pretty.str (name ^ ":") ::
   186       (Pretty.str (name ^ ":") ::
   188         prt_sect "fix" (prt_term o Free) xs @
   187         prt_sect "fix" (prt_term o Free) xs @
   189         prt_sect "assume" (Pretty.quote o prt_term) ts));
   188         prt_sect "assume" (Pretty.quote o prt_term) ts));
       
   189 
       
   190     val cases' = rev (Library.gen_distinct Library.eq_fst cases);
   190   in
   191   in
   191     if Symtab.is_empty cases andalso not (! verbose) then []
   192     if null cases andalso not (! verbose) then []
   192     else [Pretty.string_of (Pretty.big_list "cases:" (map prt_case (Symtab.dest cases)))]
   193     else [Pretty.string_of (Pretty.big_list "cases:" (map prt_case cases'))]
   193   end;
   194   end;
   194 
   195 
   195 val print_cases = seq writeln o strings_of_cases;
   196 val print_cases = seq writeln o strings_of_cases;
   196 
   197 
   197 
   198 
   333 
   334 
   334 (* init context *)
   335 (* init context *)
   335 
   336 
   336 fun init thy =
   337 fun init thy =
   337   let val data = Symtab.map (fn (_, (f, _)) => f thy) (ProofDataData.get thy) in
   338   let val data = Symtab.map (fn (_, (f, _)) => f thy) (ProofDataData.get thy) in
   338     make_context (thy, data, (([], []), ([], [])), Vartab.empty, Symtab.empty, Symtab.empty,
   339     make_context (thy, data, (([], []), ([], [])), Vartab.empty, Symtab.empty, [],
   339       (Vartab.empty, Vartab.empty, []))
   340       (Vartab.empty, Vartab.empty, []))
   340   end;
   341   end;
   341 
   342 
   342 
   343 
   343 
   344 
   832   if null (foldr Term.add_typ_tvars (map snd xs, [])) andalso
   833   if null (foldr Term.add_typ_tvars (map snd xs, [])) andalso
   833     null (foldr Term.add_term_vars (ts, [])) then ()
   834     null (foldr Term.add_term_vars (ts, [])) then ()
   834   else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt);
   835   else raise CONTEXT ("Illegal schematic variable(s) in case " ^ quote name, ctxt);
   835 
   836 
   836 fun get_case (ctxt as Context {cases, ...}) name =
   837 fun get_case (ctxt as Context {cases, ...}) name =
   837   (case Symtab.lookup (cases, name) of
   838   (case assoc (cases, name) of
   838     None => raise CONTEXT ("Unknown case: " ^ quote name, ctxt)
   839     None => raise CONTEXT ("Unknown case: " ^ quote name, ctxt)
   839   | Some c => (check_case ctxt name c; c));
   840   | Some c => (check_case ctxt name c; c));
   840 
   841 
   841 
   842 
   842 fun add_case (tab, ("", _)) = tab
       
   843   | add_case (tab, name_c) = Symtab.update (name_c, tab);
       
   844 
       
   845 fun add_cases xs = map_context (fn (thy, data, asms, binds, thms, cases, defs) =>
   843 fun add_cases xs = map_context (fn (thy, data, asms, binds, thms, cases, defs) =>
   846   (thy, data, asms, binds, thms, foldl add_case (cases, xs), defs));
   844   (thy, data, asms, binds, thms, rev (filter_out (equal "" o #1) xs) @ cases, defs));
   847 
   845 
   848 
   846 
   849 
   847 
   850 (** theory setup **)
   848 (** theory setup **)
   851 
   849