24 val set_stmt: bool -> Proof.context -> Proof.context |
24 val set_stmt: bool -> Proof.context -> Proof.context |
25 val naming_of: Proof.context -> NameSpace.naming |
25 val naming_of: Proof.context -> NameSpace.naming |
26 val name_decl: (string * 'a -> Proof.context -> 'b * Proof.context) |
26 val name_decl: (string * 'a -> Proof.context -> 'b * Proof.context) |
27 -> Name.binding * 'a -> Proof.context -> (string * 'b) * Proof.context |
27 -> Name.binding * 'a -> Proof.context -> (string * 'b) * Proof.context |
28 val full_name: Proof.context -> bstring -> string |
28 val full_name: Proof.context -> bstring -> string |
|
29 val full_binding: Proof.context -> Name.binding -> string |
29 val consts_of: Proof.context -> Consts.T |
30 val consts_of: Proof.context -> Consts.T |
30 val const_syntax_name: Proof.context -> string -> string |
31 val const_syntax_name: Proof.context -> string -> string |
31 val the_const_constraint: Proof.context -> string -> typ |
32 val the_const_constraint: Proof.context -> string -> typ |
32 val mk_const: Proof.context -> string * typ list -> term |
33 val mk_const: Proof.context -> string * typ list -> term |
33 val set_syntax_mode: Syntax.mode -> Proof.context -> Proof.context |
34 val set_syntax_mode: Syntax.mode -> Proof.context -> Proof.context |
134 val notation: bool -> Syntax.mode -> (term * mixfix) list -> Proof.context -> Proof.context |
135 val notation: bool -> Syntax.mode -> (term * mixfix) list -> Proof.context -> Proof.context |
135 val target_notation: bool -> Syntax.mode -> (term * mixfix) list -> morphism -> |
136 val target_notation: bool -> Syntax.mode -> (term * mixfix) list -> morphism -> |
136 Context.generic -> Context.generic |
137 Context.generic -> Context.generic |
137 val add_const_constraint: string * typ option -> Proof.context -> Proof.context |
138 val add_const_constraint: string * typ option -> Proof.context -> Proof.context |
138 val add_abbrev: string -> Properties.T -> |
139 val add_abbrev: string -> Properties.T -> |
139 bstring * term -> Proof.context -> (term * term) * Proof.context |
140 Name.binding * term -> Proof.context -> (term * term) * Proof.context |
140 val revert_abbrev: string -> string -> Proof.context -> Proof.context |
141 val revert_abbrev: string -> string -> Proof.context -> Proof.context |
141 val verbose: bool ref |
142 val verbose: bool ref |
142 val setmp_verbose: ('a -> 'b) -> 'a -> 'b |
143 val setmp_verbose: ('a -> 'b) -> 'a -> 'b |
143 val print_syntax: Proof.context -> unit |
144 val print_syntax: Proof.context -> unit |
144 val print_abbrevs: Proof.context -> unit |
145 val print_abbrevs: Proof.context -> unit |
246 fun set_stmt stmt = |
247 fun set_stmt stmt = |
247 map_mode (fn (_, pattern, schematic, abbrev) => (stmt, pattern, schematic, abbrev)); |
248 map_mode (fn (_, pattern, schematic, abbrev) => (stmt, pattern, schematic, abbrev)); |
248 |
249 |
249 val naming_of = #naming o rep_context; |
250 val naming_of = #naming o rep_context; |
250 |
251 |
251 fun name_decl decl (binding, x) ctxt = |
252 fun name_decl decl (b, x) ctxt = |
252 let |
253 let |
253 val naming = naming_of ctxt; |
254 val naming = naming_of ctxt; |
254 val (naming', name) = Name.namify naming binding; |
255 val (naming', name) = Name.namify naming b; |
255 in |
256 in |
256 ctxt |
257 ctxt |
257 |> map_naming (K naming') |
258 |> map_naming (K naming') |
258 |> decl (Name.name_of binding, x) |
259 |> decl (Name.name_of b, x) |
259 |>> pair name |
260 |>> pair name |
260 ||> map_naming (K naming) |
261 ||> map_naming (K naming) |
261 end; |
262 end; |
262 |
263 |
263 val full_name = NameSpace.full o naming_of; |
264 val full_name = NameSpace.full o naming_of; |
|
265 val full_binding = NameSpace.full_binding o naming_of; |
264 |
266 |
265 val syntax_of = #syntax o rep_context; |
267 val syntax_of = #syntax o rep_context; |
266 val syn_of = LocalSyntax.syn_of o syntax_of; |
268 val syn_of = LocalSyntax.syn_of o syntax_of; |
267 val set_syntax_mode = map_syntax o LocalSyntax.set_mode; |
269 val set_syntax_mode = map_syntax o LocalSyntax.set_mode; |
268 val restore_syntax_mode = map_syntax o LocalSyntax.restore_mode o syntax_of; |
270 val restore_syntax_mode = map_syntax o LocalSyntax.restore_mode o syntax_of; |
975 |
977 |
976 (* facts *) |
978 (* facts *) |
977 |
979 |
978 local |
980 local |
979 |
981 |
980 fun update_thms _ (bname, NONE) ctxt = ctxt |> map_facts (Facts.del (full_name ctxt bname)) |
982 fun update_thms _ (b, NONE) ctxt = ctxt |> map_facts (Facts.del (full_binding ctxt b)) |
981 | update_thms do_props (bname, SOME ths) ctxt = ctxt |> map_facts |
983 | update_thms do_props (b, SOME ths) ctxt = ctxt |> map_facts |
982 (Facts.add_local do_props (naming_of ctxt) (full_name ctxt bname, ths)); |
984 (Facts.add_local do_props (naming_of ctxt) (full_binding ctxt b, ths)); |
983 |
985 |
984 fun gen_note_thmss get k = fold_map (fn ((binding, more_attrs), raw_facts) => fn ctxt => |
986 fun gen_note_thmss get k = fold_map (fn ((b, more_attrs), raw_facts) => fn ctxt => |
985 let |
987 let |
986 val bname = Name.name_of binding; |
988 val pos = Name.pos_of b; |
987 val pos = Name.pos_of binding; |
989 val name = full_binding ctxt b; |
988 val name = full_name ctxt bname; |
|
989 val _ = ContextPosition.report_visible ctxt (Markup.local_fact_decl name) pos; |
990 val _ = ContextPosition.report_visible ctxt (Markup.local_fact_decl name) pos; |
990 |
991 |
991 val facts = PureThy.name_thmss false pos name (map (apfst (get ctxt)) raw_facts); |
992 val facts = PureThy.name_thmss false pos name (map (apfst (get ctxt)) raw_facts); |
992 fun app (th, attrs) x = |
993 fun app (th, attrs) x = |
993 swap (foldl_map (Thm.proof_attributes (surround (Thm.kind k) (attrs @ more_attrs))) (x, th)); |
994 swap (foldl_map (Thm.proof_attributes (surround (Thm.kind k) (attrs @ more_attrs))) (x, th)); |
994 val (res, ctxt') = fold_map app facts ctxt; |
995 val (res, ctxt') = fold_map app facts ctxt; |
995 val thms = PureThy.name_thms false false pos name (flat res); |
996 val thms = PureThy.name_thms false false pos name (flat res); |
996 val Mode {stmt, ...} = get_mode ctxt; |
997 val Mode {stmt, ...} = get_mode ctxt; |
997 in ((name, thms), ctxt' |> update_thms stmt (bname, SOME thms)) end); |
998 in ((name, thms), ctxt' |> update_thms stmt (b, SOME thms)) end); |
998 |
999 |
999 in |
1000 in |
1000 |
1001 |
1001 fun note_thmss k = gen_note_thmss get_fact k; |
1002 fun note_thmss k = gen_note_thmss get_fact k; |
1002 fun note_thmss_i k = gen_note_thmss (K I) k; |
1003 fun note_thmss_i k = gen_note_thmss (K I) k; |
1003 |
1004 |
1004 fun put_thms do_props thms ctxt = ctxt |
1005 fun put_thms do_props thms ctxt = ctxt |
1005 |> map_naming (K local_naming) |
1006 |> map_naming (K local_naming) |
1006 |> ContextPosition.set_visible false |
1007 |> ContextPosition.set_visible false |
1007 |> update_thms do_props thms |
1008 |> update_thms do_props (apfst Name.binding thms) |
1008 |> ContextPosition.restore_visible ctxt |
1009 |> ContextPosition.restore_visible ctxt |
1009 |> restore_naming ctxt; |
1010 |> restore_naming ctxt; |
1010 |
1011 |
1011 end; |
1012 end; |
1012 |
1013 |
1021 in ((x, T, mx), ctxt |> Variable.declare_constraints (Free (x, T))) end; |
1022 in ((x, T, mx), ctxt |> Variable.declare_constraints (Free (x, T))) end; |
1022 |
1023 |
1023 local |
1024 local |
1024 |
1025 |
1025 fun prep_vars prep_typ internal = |
1026 fun prep_vars prep_typ internal = |
1026 fold_map (fn (raw_binding, raw_T, raw_mx) => fn ctxt => |
1027 fold_map (fn (raw_b, raw_T, raw_mx) => fn ctxt => |
1027 let |
1028 let |
1028 val raw_x = Name.name_of raw_binding; |
1029 val raw_x = Name.name_of raw_b; |
1029 val (x, mx) = Syntax.const_mixfix raw_x raw_mx; |
1030 val (x, mx) = Syntax.const_mixfix raw_x raw_mx; |
1030 val _ = Syntax.is_identifier (no_skolem internal x) orelse |
1031 val _ = Syntax.is_identifier (no_skolem internal x) orelse |
1031 error ("Illegal variable name: " ^ quote x); |
1032 error ("Illegal variable name: " ^ quote x); |
1032 |
1033 |
1033 fun cond_tvars T = |
1034 fun cond_tvars T = |
1034 if internal then T |
1035 if internal then T |
1035 else Type.no_tvars T handle TYPE (msg, _, _) => error msg; |
1036 else Type.no_tvars T handle TYPE (msg, _, _) => error msg; |
1036 val opt_T = Option.map (cond_tvars o cert_typ ctxt o prep_typ ctxt) raw_T; |
1037 val opt_T = Option.map (cond_tvars o cert_typ ctxt o prep_typ ctxt) raw_T; |
1037 val var = (Name.map_name (K x) raw_binding, opt_T, mx); |
1038 val var = (Name.map_name (K x) raw_b, opt_T, mx); |
1038 in (var, ctxt |> declare_var (x, opt_T, mx) |> #2) end); |
1039 in (var, ctxt |> declare_var (x, opt_T, mx) |> #2) end); |
1039 |
1040 |
1040 in |
1041 in |
1041 |
1042 |
1042 val read_vars = prep_vars Syntax.parse_typ false; |
1043 val read_vars = prep_vars Syntax.parse_typ false; |
1103 fun prepT raw_T = |
1104 fun prepT raw_T = |
1104 let val T = cert_typ ctxt raw_T |
1105 let val T = cert_typ ctxt raw_T |
1105 in cert_term ctxt (Const (c, T)); T end; |
1106 in cert_term ctxt (Const (c, T)); T end; |
1106 in ctxt |> (map_consts o apfst) (Consts.constrain (c, Option.map prepT opt_T)) end; |
1107 in ctxt |> (map_consts o apfst) (Consts.constrain (c, Option.map prepT opt_T)) end; |
1107 |
1108 |
1108 fun add_abbrev mode tags (c, raw_t) ctxt = |
1109 fun add_abbrev mode tags (b, raw_t) ctxt = |
1109 let |
1110 let |
1110 val t0 = cert_term (ctxt |> set_mode mode_abbrev) raw_t |
1111 val t0 = cert_term (ctxt |> set_mode mode_abbrev) raw_t |
1111 handle ERROR msg => cat_error msg ("in constant abbreviation " ^ quote c); |
1112 handle ERROR msg => cat_error msg ("in constant abbreviation " ^ quote (Name.display b)); |
1112 val [t] = Variable.exportT_terms (Variable.declare_term t0 ctxt) ctxt [t0]; |
1113 val [t] = Variable.exportT_terms (Variable.declare_term t0 ctxt) ctxt [t0]; |
1113 val ((lhs, rhs), consts') = consts_of ctxt |
1114 val ((lhs, rhs), consts') = consts_of ctxt |
1114 |> Consts.abbreviate (Syntax.pp ctxt) (tsig_of ctxt) (naming_of ctxt) mode tags (c, t); |
1115 |> Consts.abbreviate (Syntax.pp ctxt) (tsig_of ctxt) (naming_of ctxt) mode tags (b, t); |
1115 in |
1116 in |
1116 ctxt |
1117 ctxt |
1117 |> (map_consts o apfst) (K consts') |
1118 |> (map_consts o apfst) (K consts') |
1118 |> Variable.declare_term rhs |
1119 |> Variable.declare_term rhs |
1119 |> pair (lhs, rhs) |
1120 |> pair (lhs, rhs) |
1138 val (xs', ctxt') = Variable.add_fixes (map (Name.name_of o #1) vars) ctxt; |
1139 val (xs', ctxt') = Variable.add_fixes (map (Name.name_of o #1) vars) ctxt; |
1139 val ctxt'' = |
1140 val ctxt'' = |
1140 ctxt' |
1141 ctxt' |
1141 |> fold_map declare_var (map2 (fn x' => fn (_, T, mx) => (x', T, mx)) xs' vars) |
1142 |> fold_map declare_var (map2 (fn x' => fn (_, T, mx) => (x', T, mx)) xs' vars) |
1142 |-> (map_syntax o LocalSyntax.add_syntax (theory_of ctxt) o map prep_mixfix); |
1143 |-> (map_syntax o LocalSyntax.add_syntax (theory_of ctxt) o map prep_mixfix); |
1143 val _ = (vars ~~ xs') |> List.app (fn ((binding, _, _), x') => |
1144 val _ = (vars ~~ xs') |> List.app (fn ((b, _, _), x') => |
1144 ContextPosition.report_visible ctxt (Markup.fixed_decl x') (Name.pos_of binding)); |
1145 ContextPosition.report_visible ctxt (Markup.fixed_decl x') (Name.pos_of b)); |
1145 in (xs', ctxt'') end; |
1146 in (xs', ctxt'') end; |
1146 |
1147 |
1147 in |
1148 in |
1148 |
1149 |
1149 val add_fixes = gen_fixes read_vars; |
1150 val add_fixes = gen_fixes read_vars; |