author | wenzelm |
Mon, 10 Mar 2014 13:55:03 +0100 | |
changeset 56025 | d74fed45fa8b |
parent 56007 | 1b61dfbcf9a4 |
child 56040 | 98d466e6de8a |
permissions | -rw-r--r-- |
5819 | 1 |
(* Title: Pure/Isar/proof_context.ML |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
||
19001 | 4 |
The key concept of Isar proof contexts: elevates primitive local |
5 |
reasoning Gamma |- phi to a structured concept, with generic context |
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
6 |
elements. See also structure Variable and Assumption. |
5819 | 7 |
*) |
8 |
||
9 |
signature PROOF_CONTEXT = |
|
10 |
sig |
|
20310 | 11 |
val theory_of: Proof.context -> theory |
36610
bafd82950e24
renamed ProofContext.init to ProofContext.init_global to emphasize that this is not the real thing;
wenzelm
parents:
36542
diff
changeset
|
12 |
val init_global: theory -> Proof.context |
51686 | 13 |
val get_global: theory -> string -> Proof.context |
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
14 |
type mode |
24501 | 15 |
val mode_default: mode |
16 |
val mode_stmt: mode |
|
17 |
val mode_pattern: mode |
|
18 |
val mode_schematic: mode |
|
19 |
val mode_abbrev: mode |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
20 |
val set_mode: mode -> Proof.context -> Proof.context |
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
21 |
val get_mode: Proof.context -> mode |
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
22 |
val restore_mode: Proof.context -> Proof.context -> Proof.context |
27286 | 23 |
val abbrev_mode: Proof.context -> bool |
21667
ce813b82c88b
add_notation: permissive about undeclared consts;
wenzelm
parents:
21648
diff
changeset
|
24 |
val set_stmt: bool -> Proof.context -> Proof.context |
42241
dd8029f71e1c
separate module for standard implementation of inner syntax operations;
wenzelm
parents:
42224
diff
changeset
|
25 |
val syntax_of: Proof.context -> Local_Syntax.T |
35111 | 26 |
val syn_of: Proof.context -> Syntax.syntax |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
27 |
val tsig_of: Proof.context -> Type.tsig |
36451 | 28 |
val set_defsort: sort -> Proof.context -> Proof.context |
35680 | 29 |
val default_sort: Proof.context -> indexname -> sort |
20310 | 30 |
val consts_of: Proof.context -> Consts.T |
20784 | 31 |
val set_syntax_mode: Syntax.mode -> Proof.context -> Proof.context |
20310 | 32 |
val restore_syntax_mode: Proof.context -> Proof.context -> Proof.context |
26284 | 33 |
val facts_of: Proof.context -> Facts.T |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
34 |
val map_naming: (Name_Space.naming -> Name_Space.naming) -> Proof.context -> Proof.context |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
35 |
val naming_of: Proof.context -> Name_Space.naming |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
36 |
val restore_naming: Proof.context -> Proof.context -> Proof.context |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
37 |
val full_name: Proof.context -> binding -> string |
42359 | 38 |
val class_space: Proof.context -> Name_Space.T |
39 |
val type_space: Proof.context -> Name_Space.T |
|
40 |
val const_space: Proof.context -> Name_Space.T |
|
41 |
val intern_class: Proof.context -> xstring -> string |
|
42 |
val intern_type: Proof.context -> xstring -> string |
|
43 |
val intern_const: Proof.context -> xstring -> string |
|
44 |
val extern_class: Proof.context -> string -> xstring |
|
55304 | 45 |
val markup_class: Proof.context -> string -> string |
46 |
val pretty_class: Proof.context -> string -> Pretty.T |
|
42359 | 47 |
val extern_type: Proof.context -> string -> xstring |
55304 | 48 |
val markup_type: Proof.context -> string -> string |
49 |
val pretty_type: Proof.context -> string -> Pretty.T |
|
42359 | 50 |
val extern_const: Proof.context -> string -> xstring |
55304 | 51 |
val markup_const: Proof.context -> string -> string |
52 |
val pretty_const: Proof.context -> string -> Pretty.T |
|
20310 | 53 |
val transfer: theory -> Proof.context -> Proof.context |
38756
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
54 |
val background_theory: (theory -> theory) -> Proof.context -> Proof.context |
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
55 |
val background_theory_result: (theory -> 'a * theory) -> Proof.context -> 'a * Proof.context |
28212 | 56 |
val extern_fact: Proof.context -> string -> xstring |
21728 | 57 |
val pretty_term_abbrev: Proof.context -> term -> Pretty.T |
49888 | 58 |
val markup_fact: Proof.context -> string -> Markup.T |
20310 | 59 |
val pretty_fact: Proof.context -> string * thm list -> Pretty.T |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
60 |
val check_class: Proof.context -> xstring * Position.T -> class * Position.report list |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
61 |
val read_class: Proof.context -> string -> class |
20310 | 62 |
val read_typ: Proof.context -> string -> typ |
63 |
val read_typ_syntax: Proof.context -> string -> typ |
|
64 |
val read_typ_abbrev: Proof.context -> string -> typ |
|
65 |
val cert_typ: Proof.context -> typ -> typ |
|
66 |
val cert_typ_syntax: Proof.context -> typ -> typ |
|
67 |
val cert_typ_abbrev: Proof.context -> typ -> typ |
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
68 |
val infer_type: Proof.context -> string * typ -> typ |
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
69 |
val inferred_param: string -> Proof.context -> typ * Proof.context |
25328 | 70 |
val inferred_fixes: Proof.context -> (string * typ) list * Proof.context |
56002 | 71 |
val check_type_name: {proper: bool, strict: bool} -> Proof.context -> |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
72 |
xstring * Position.T -> typ * Position.report list |
56002 | 73 |
val read_type_name: {proper: bool, strict: bool} -> Proof.context -> string -> typ |
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
74 |
val consts_completion_message: Proof.context -> xstring * Position.T list -> string |
56002 | 75 |
val check_const: {proper: bool, strict: bool} -> Proof.context -> |
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
76 |
xstring * Position.T list -> term * Position.report list |
56002 | 77 |
val read_const: {proper: bool, strict: bool} -> Proof.context -> string -> term |
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
78 |
val read_arity: Proof.context -> xstring * string list * string -> arity |
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
79 |
val cert_arity: Proof.context -> arity -> arity |
27259 | 80 |
val allow_dummies: Proof.context -> Proof.context |
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
81 |
val prepare_sortsT: Proof.context -> typ list -> string * typ list |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
82 |
val prepare_sorts: Proof.context -> term list -> string * term list |
36152 | 83 |
val check_tfree: Proof.context -> string * sort -> string * sort |
24684 | 84 |
val read_term_pattern: Proof.context -> string -> term |
85 |
val read_term_schematic: Proof.context -> string -> term |
|
86 |
val read_term_abbrev: Proof.context -> string -> term |
|
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
87 |
val show_abbrevs_raw: Config.raw |
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
88 |
val show_abbrevs: bool Config.T |
25345
dd5b851f8ef0
renamed ProofContext.read_const' to ProofContext.read_const_proper;
wenzelm
parents:
25332
diff
changeset
|
89 |
val expand_abbrevs: Proof.context -> term -> term |
20310 | 90 |
val cert_term: Proof.context -> term -> term |
91 |
val cert_prop: Proof.context -> term -> term |
|
35616
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
92 |
val def_type: Proof.context -> indexname -> typ option |
45429 | 93 |
val standard_typ_check: Proof.context -> typ list -> typ list |
94 |
val standard_term_check_finish: Proof.context -> term list -> term list |
|
95 |
val standard_term_uncheck: Proof.context -> term list -> term list |
|
20310 | 96 |
val goal_export: Proof.context -> Proof.context -> thm list -> thm list |
97 |
val export: Proof.context -> Proof.context -> thm list -> thm list |
|
21531 | 98 |
val export_morphism: Proof.context -> Proof.context -> morphism |
28396 | 99 |
val norm_export_morphism: Proof.context -> Proof.context -> morphism |
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
100 |
val bind_terms: (indexname * term option) list -> Proof.context -> Proof.context |
20310 | 101 |
val auto_bind_goal: term list -> Proof.context -> Proof.context |
102 |
val auto_bind_facts: term list -> Proof.context -> Proof.context |
|
103 |
val match_bind: bool -> (string list * string) list -> Proof.context -> term list * Proof.context |
|
104 |
val match_bind_i: bool -> (term list * term) list -> Proof.context -> term list * Proof.context |
|
45327 | 105 |
val read_propp: (string * string list) list list -> Proof.context -> |
106 |
(term * term list) list list * Proof.context |
|
107 |
val cert_propp: (term * term list) list list -> Proof.context -> |
|
108 |
(term * term list) list list * Proof.context |
|
109 |
val read_propp_schematic: (string * string list) list list -> Proof.context -> |
|
110 |
(term * term list) list list * Proof.context |
|
111 |
val cert_propp_schematic: (term * term list) list list -> Proof.context -> |
|
112 |
(term * term list) list list * Proof.context |
|
113 |
val bind_propp: (string * string list) list list -> Proof.context -> |
|
114 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
115 |
val bind_propp_i: (term * term list) list list -> Proof.context -> |
|
116 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
117 |
val bind_propp_schematic: (string * string list) list list -> Proof.context -> |
|
118 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
119 |
val bind_propp_schematic_i: (term * term list) list list -> Proof.context -> |
|
120 |
(term list list * (Proof.context -> Proof.context)) * Proof.context |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
121 |
val fact_tac: Proof.context -> thm list -> int -> tactic |
20310 | 122 |
val some_fact_tac: Proof.context -> int -> tactic |
26346
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
123 |
val get_fact: Proof.context -> Facts.ref -> thm list |
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
124 |
val get_fact_single: Proof.context -> Facts.ref -> thm |
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
125 |
val get_thms: Proof.context -> xstring -> thm list |
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
126 |
val get_thm: Proof.context -> xstring -> thm |
30761
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
wenzelm
parents:
30758
diff
changeset
|
127 |
val note_thmss: string -> (Thm.binding * (thm list * attribute list) list) list -> |
30211 | 128 |
Proof.context -> (string * thm list) list * Proof.context |
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
129 |
val put_thms: bool -> string * thm list option -> Proof.context -> Proof.context |
29581 | 130 |
val read_vars: (binding * string option * mixfix) list -> Proof.context -> |
131 |
(binding * typ option * mixfix) list * Proof.context |
|
132 |
val cert_vars: (binding * typ option * mixfix) list -> Proof.context -> |
|
133 |
(binding * typ option * mixfix) list * Proof.context |
|
30763
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
wenzelm
parents:
30761
diff
changeset
|
134 |
val add_fixes: (binding * typ option * mixfix) list -> Proof.context -> |
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
wenzelm
parents:
30761
diff
changeset
|
135 |
string list * Proof.context |
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
136 |
val add_assms: Assumption.export -> |
30211 | 137 |
(Thm.binding * (string * string list) list) list -> |
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
138 |
Proof.context -> (string * thm list) list * Proof.context |
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
139 |
val add_assms_i: Assumption.export -> |
30211 | 140 |
(Thm.binding * (term * term list) list) list -> |
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
141 |
Proof.context -> (string * thm list) list * Proof.context |
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
142 |
val dest_cases: Proof.context -> (string * (Rule_Cases.T * bool)) list |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
143 |
val update_cases: bool -> (string * Rule_Cases.T option) list -> Proof.context -> Proof.context |
53380
08f3491c50bf
cases: formal binding of 'assumes', with position provided via invoke_case;
wenzelm
parents:
53378
diff
changeset
|
144 |
val apply_case: Rule_Cases.T -> Proof.context -> (binding * term list) list * Proof.context |
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
145 |
val check_case: Proof.context -> string * Position.T -> binding option list -> Rule_Cases.T |
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
146 |
val type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> Proof.context -> Proof.context |
24949 | 147 |
val notation: bool -> Syntax.mode -> (term * mixfix) list -> Proof.context -> Proof.context |
47247 | 148 |
val generic_type_notation: bool -> Syntax.mode -> (typ * mixfix) list -> morphism -> |
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
149 |
Context.generic -> Context.generic |
47247 | 150 |
val generic_notation: bool -> Syntax.mode -> (term * mixfix) list -> morphism -> |
21744 | 151 |
Context.generic -> Context.generic |
35680 | 152 |
val class_alias: binding -> class -> Proof.context -> Proof.context |
153 |
val type_alias: binding -> string -> Proof.context -> Proof.context |
|
154 |
val const_alias: binding -> string -> Proof.context -> Proof.context |
|
24767 | 155 |
val add_const_constraint: string * typ option -> Proof.context -> Proof.context |
33173
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
wenzelm
parents:
33165
diff
changeset
|
156 |
val add_abbrev: string -> binding * term -> Proof.context -> (term * term) * Proof.context |
25052 | 157 |
val revert_abbrev: string -> string -> Proof.context -> Proof.context |
47275 | 158 |
val generic_add_abbrev: string -> binding * term -> Context.generic -> |
159 |
(term * term) * Context.generic |
|
160 |
val generic_revert_abbrev: string -> string -> Context.generic -> Context.generic |
|
20310 | 161 |
val print_syntax: Proof.context -> unit |
21728 | 162 |
val print_abbrevs: Proof.context -> unit |
20310 | 163 |
val print_binds: Proof.context -> unit |
164 |
val print_lthms: Proof.context -> unit |
|
165 |
val print_cases: Proof.context -> unit |
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
166 |
val debug: bool Config.T |
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
167 |
val verbose: bool Config.T |
20310 | 168 |
val pretty_ctxt: Proof.context -> Pretty.T list |
169 |
val pretty_context: Proof.context -> Pretty.T list |
|
5819 | 170 |
end; |
171 |
||
42360 | 172 |
structure Proof_Context: PROOF_CONTEXT = |
5819 | 173 |
struct |
174 |
||
42363 | 175 |
val theory_of = Proof_Context.theory_of; |
176 |
val init_global = Proof_Context.init_global; |
|
51686 | 177 |
val get_global = Proof_Context.get_global; |
42363 | 178 |
|
12057 | 179 |
|
7270 | 180 |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
181 |
(** inner syntax mode **) |
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
182 |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
183 |
datatype mode = |
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
184 |
Mode of |
24486 | 185 |
{stmt: bool, (*inner statement mode*) |
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
186 |
pattern: bool, (*pattern binding schematic variables*) |
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
187 |
schematic: bool, (*term referencing loose schematic variables*) |
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
188 |
abbrev: bool}; (*abbrev mode -- no normalization*) |
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
189 |
|
24486 | 190 |
fun make_mode (stmt, pattern, schematic, abbrev) = |
191 |
Mode {stmt = stmt, pattern = pattern, schematic = schematic, abbrev = abbrev}; |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
192 |
|
24486 | 193 |
val mode_default = make_mode (false, false, false, false); |
194 |
val mode_stmt = make_mode (true, false, false, false); |
|
195 |
val mode_pattern = make_mode (false, true, false, false); |
|
196 |
val mode_schematic = make_mode (false, false, true, false); |
|
197 |
val mode_abbrev = make_mode (false, false, false, true); |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
198 |
|
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
199 |
|
5819 | 200 |
|
16540 | 201 |
(** Isar proof context information **) |
5819 | 202 |
|
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
203 |
type cases = ((Rule_Cases.T * bool) * int) Name_Space.table; |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
204 |
val empty_cases: cases = Name_Space.empty_table Markup.caseN; |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
205 |
|
45650 | 206 |
datatype data = |
207 |
Data of |
|
36451 | 208 |
{mode: mode, (*inner syntax mode*) |
209 |
syntax: Local_Syntax.T, (*local syntax*) |
|
210 |
tsig: Type.tsig * Type.tsig, (*local/global type signature -- local name space / defsort only*) |
|
211 |
consts: Consts.T * Consts.T, (*local/global consts -- local name space / abbrevs only*) |
|
212 |
facts: Facts.T, (*local facts*) |
|
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
213 |
cases: cases}; (*named case contexts: case, is_proper, running index*) |
5819 | 214 |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
215 |
fun make_data (mode, syntax, tsig, consts, facts, cases) = |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
216 |
Data {mode = mode, syntax = syntax, tsig = tsig, consts = consts, facts = facts, cases = cases}; |
19079
9a7678a0736d
added put_thms_internal: local_naming, no fact index;
wenzelm
parents:
19062
diff
changeset
|
217 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
37145
diff
changeset
|
218 |
structure Data = Proof_Data |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
219 |
( |
45650 | 220 |
type T = data; |
16540 | 221 |
fun init thy = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
222 |
make_data (mode_default, Local_Syntax.init thy, |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
223 |
(Sign.tsig_of thy, Sign.tsig_of thy), |
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
224 |
(Sign.consts_of thy, Sign.consts_of thy), Facts.empty, empty_cases); |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
225 |
); |
5819 | 226 |
|
45650 | 227 |
fun rep_data ctxt = Data.get ctxt |> (fn Data rep => rep); |
5819 | 228 |
|
45650 | 229 |
fun map_data f = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
230 |
Data.map (fn Data {mode, syntax, tsig, consts, facts, cases} => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
231 |
make_data (f (mode, syntax, tsig, consts, facts, cases))); |
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
232 |
|
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
233 |
fun set_mode mode = map_data (fn (_, syntax, tsig, consts, facts, cases) => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
234 |
(mode, syntax, tsig, consts, facts, cases)); |
21443
cc5095d57da4
added stmt mode, which affects naming/indexing of local facts;
wenzelm
parents:
21370
diff
changeset
|
235 |
|
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
236 |
fun map_mode f = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
237 |
map_data (fn (Mode {stmt, pattern, schematic, abbrev}, syntax, tsig, consts, facts, cases) => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
238 |
(make_mode (f (stmt, pattern, schematic, abbrev)), syntax, tsig, consts, facts, cases)); |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
239 |
|
19001 | 240 |
fun map_syntax f = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
241 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
242 |
(mode, f syntax, tsig, consts, facts, cases)); |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
243 |
|
36450 | 244 |
fun map_tsig f = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
245 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
246 |
(mode, syntax, f tsig, consts, facts, cases)); |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
247 |
|
19001 | 248 |
fun map_consts f = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
249 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
250 |
(mode, syntax, tsig, f consts, facts, cases)); |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
251 |
|
26284 | 252 |
fun map_facts f = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
253 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
254 |
(mode, syntax, tsig, consts, f facts, cases)); |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
255 |
|
19001 | 256 |
fun map_cases f = |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
257 |
map_data (fn (mode, syntax, tsig, consts, facts, cases) => |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
258 |
(mode, syntax, tsig, consts, facts, f cases)); |
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
259 |
|
45650 | 260 |
val get_mode = #mode o rep_data; |
28407 | 261 |
val restore_mode = set_mode o get_mode; |
27286 | 262 |
val abbrev_mode = get_mode #> (fn Mode {abbrev, ...} => abbrev); |
21443
cc5095d57da4
added stmt mode, which affects naming/indexing of local facts;
wenzelm
parents:
21370
diff
changeset
|
263 |
|
24486 | 264 |
fun set_stmt stmt = |
265 |
map_mode (fn (_, pattern, schematic, abbrev) => (stmt, pattern, schematic, abbrev)); |
|
19001 | 266 |
|
45650 | 267 |
val syntax_of = #syntax o rep_data; |
33387 | 268 |
val syn_of = Local_Syntax.syn_of o syntax_of; |
269 |
val set_syntax_mode = map_syntax o Local_Syntax.set_mode; |
|
270 |
val restore_syntax_mode = map_syntax o Local_Syntax.restore_mode o syntax_of; |
|
19001 | 271 |
|
45650 | 272 |
val tsig_of = #1 o #tsig o rep_data; |
36451 | 273 |
val set_defsort = map_tsig o apfst o Type.set_defsort; |
35680 | 274 |
fun default_sort ctxt = the_default (Type.defaultS (tsig_of ctxt)) o Variable.def_sort ctxt; |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
275 |
|
45650 | 276 |
val consts_of = #1 o #consts o rep_data; |
277 |
val facts_of = #facts o rep_data; |
|
278 |
val cases_of = #cases o rep_data; |
|
5819 | 279 |
|
280 |
||
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
281 |
(* naming *) |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
282 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
283 |
val naming_of = Name_Space.naming_of o Context.Proof; |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
284 |
val map_naming = Context.proof_map o Name_Space.map_naming; |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
285 |
val restore_naming = map_naming o K o naming_of; |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
286 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
287 |
val full_name = Name_Space.full_name o naming_of; |
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
288 |
|
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
289 |
|
42359 | 290 |
(* name spaces *) |
291 |
||
292 |
val class_space = Type.class_space o tsig_of; |
|
293 |
val type_space = Type.type_space o tsig_of; |
|
294 |
val const_space = Consts.space_of o consts_of; |
|
295 |
||
296 |
val intern_class = Name_Space.intern o class_space; |
|
297 |
val intern_type = Name_Space.intern o type_space; |
|
298 |
val intern_const = Name_Space.intern o const_space; |
|
299 |
||
300 |
fun extern_class ctxt = Name_Space.extern ctxt (class_space ctxt); |
|
301 |
fun extern_type ctxt = Name_Space.extern ctxt (type_space ctxt); |
|
302 |
fun extern_const ctxt = Name_Space.extern ctxt (const_space ctxt); |
|
303 |
||
55304 | 304 |
fun markup_class ctxt c = Name_Space.markup_extern ctxt (class_space ctxt) c |-> Markup.markup; |
305 |
fun markup_type ctxt c = Name_Space.markup_extern ctxt (type_space ctxt) c |-> Markup.markup; |
|
306 |
fun markup_const ctxt c = Name_Space.markup_extern ctxt (const_space ctxt) c |-> Markup.markup; |
|
307 |
||
308 |
fun pretty_class ctxt c = Name_Space.markup_extern ctxt (class_space ctxt) c |> Pretty.mark_str; |
|
309 |
fun pretty_type ctxt c = Name_Space.markup_extern ctxt (type_space ctxt) c |> Pretty.mark_str; |
|
310 |
fun pretty_const ctxt c = Name_Space.markup_extern ctxt (const_space ctxt) c |> Pretty.mark_str; |
|
311 |
||
42359 | 312 |
|
20367 | 313 |
(* theory transfer *) |
12093 | 314 |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
315 |
fun transfer_syntax thy ctxt = ctxt |> |
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
316 |
map_syntax (Local_Syntax.rebuild thy) |> |
36450 | 317 |
map_tsig (fn tsig as (local_tsig, global_tsig) => |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
318 |
let val thy_tsig = Sign.tsig_of thy in |
36450 | 319 |
if Type.eq_tsig (thy_tsig, global_tsig) then tsig |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
320 |
else (Type.merge_tsig (Context.pretty ctxt) (local_tsig, thy_tsig), thy_tsig) |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
321 |
end) |> |
30424
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
322 |
map_consts (fn consts as (local_consts, global_consts) => |
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
323 |
let val thy_consts = Sign.consts_of thy in |
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
324 |
if Consts.eq_consts (thy_consts, global_consts) then consts |
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
325 |
else (Consts.merge (local_consts, thy_consts), thy_consts) |
692279df7cc2
Consts.eq_const is back again (cf. 907da436f8a9) -- required in ProofContext.transfer_syntax to prevent expensive merges of local_consts/global_consts;
wenzelm
parents:
30420
diff
changeset
|
326 |
end); |
17072 | 327 |
|
33031
b75c35574e04
backpatching of structure Proof and ProofContext -- avoid odd aliases;
wenzelm
parents:
32966
diff
changeset
|
328 |
fun transfer thy = Context.raw_transfer thy #> transfer_syntax thy; |
17072 | 329 |
|
38756
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
330 |
fun background_theory f ctxt = transfer (f (theory_of ctxt)) ctxt; |
20367 | 331 |
|
38756
d07959fabde6
renamed ProofContext.theory(_result) to ProofContext.background_theory(_result) to emphasize that this belongs to the infrastructure and is rarely appropriate in user-space tools;
wenzelm
parents:
38328
diff
changeset
|
332 |
fun background_theory_result f ctxt = |
20367 | 333 |
let val (res, thy') = f (theory_of ctxt) |
334 |
in (res, ctxt |> transfer thy') end; |
|
19019 | 335 |
|
12093 | 336 |
|
337 |
||
14828 | 338 |
(** pretty printing **) |
339 |
||
28212 | 340 |
(* extern *) |
341 |
||
42378 | 342 |
fun which_facts ctxt name = |
28212 | 343 |
let |
344 |
val local_facts = facts_of ctxt; |
|
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
345 |
val global_facts = Global_Theory.facts_of (theory_of ctxt); |
28212 | 346 |
in |
347 |
if is_some (Facts.lookup (Context.Proof ctxt) local_facts name) |
|
42378 | 348 |
then local_facts else global_facts |
28212 | 349 |
end; |
350 |
||
42379 | 351 |
fun markup_fact ctxt name = Name_Space.markup (Facts.space_of (which_facts ctxt name)) name; |
42378 | 352 |
|
353 |
fun extern_fact ctxt name = Facts.extern ctxt (which_facts ctxt name) name; |
|
354 |
||
28212 | 355 |
|
356 |
(* pretty *) |
|
357 |
||
24922 | 358 |
fun pretty_term_abbrev ctxt = Syntax.pretty_term (set_mode mode_abbrev ctxt); |
14828 | 359 |
|
42378 | 360 |
fun pretty_fact_name ctxt a = |
361 |
Pretty.block [Pretty.mark_str (markup_fact ctxt a, extern_fact ctxt a), Pretty.str ":"]; |
|
28209
02f3222a392d
pretty_fact: extern fact name wrt. the given context, assuming that is the proper one for presentation;
wenzelm
parents:
28087
diff
changeset
|
362 |
|
51583 | 363 |
fun pretty_fact ctxt = |
364 |
let |
|
365 |
val pretty_thm = Display.pretty_thm ctxt; |
|
51584 | 366 |
val pretty_thms = map (Display.pretty_thm_item ctxt); |
51583 | 367 |
in |
368 |
fn ("", [th]) => pretty_thm th |
|
369 |
| ("", ths) => Pretty.blk (0, Pretty.fbreaks (pretty_thms ths)) |
|
370 |
| (a, [th]) => Pretty.block [pretty_fact_name ctxt a, Pretty.brk 1, pretty_thm th] |
|
371 |
| (a, ths) => Pretty.block (Pretty.fbreaks (pretty_fact_name ctxt a :: pretty_thms ths)) |
|
372 |
end; |
|
14828 | 373 |
|
374 |
||
375 |
||
5819 | 376 |
(** prepare types **) |
377 |
||
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
378 |
(* classes *) |
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
379 |
|
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
380 |
fun check_class ctxt (xname, pos) = |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
381 |
let |
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
382 |
val tsig = tsig_of ctxt; |
55839
ee71b2687c4b
more markup for read_class: imitate Name_Space.check despite lack of Name_Space.table;
wenzelm
parents:
55829
diff
changeset
|
383 |
val class_space = Type.class_space tsig; |
ee71b2687c4b
more markup for read_class: imitate Name_Space.check despite lack of Name_Space.table;
wenzelm
parents:
55829
diff
changeset
|
384 |
|
56007 | 385 |
val name = Type.cert_class tsig (Name_Space.intern class_space xname) |
55839
ee71b2687c4b
more markup for read_class: imitate Name_Space.check despite lack of Name_Space.table;
wenzelm
parents:
55829
diff
changeset
|
386 |
handle TYPE (msg, _, _) => |
55840
2982d233d798
consider completion report as part of error message -- less stateful, may get handled;
wenzelm
parents:
55839
diff
changeset
|
387 |
error (msg ^ Position.here pos ^ |
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
388 |
Markup.markup_report (Completion.reported_text |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
389 |
(Name_Space.completion (Context.Proof ctxt) class_space (xname, pos)))); |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
390 |
val reports = |
55923 | 391 |
if Context_Position.is_reported ctxt pos |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
392 |
then [(pos, Name_Space.markup class_space name)] else []; |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
393 |
in (name, reports) end; |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
394 |
|
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
395 |
fun read_class ctxt text = |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
396 |
let |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
397 |
val (c, reports) = check_class ctxt (Symbol_Pos.source_content (Syntax.read_token text)); |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
398 |
val _ = Position.reports reports; |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
399 |
in c end; |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
400 |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
401 |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
402 |
(* types *) |
24277 | 403 |
|
404 |
fun read_typ_mode mode ctxt s = |
|
24486 | 405 |
Syntax.read_typ (Type.set_mode mode ctxt) s; |
24277 | 406 |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
407 |
val read_typ = read_typ_mode Type.mode_default; |
24277 | 408 |
val read_typ_syntax = read_typ_mode Type.mode_syntax; |
409 |
val read_typ_abbrev = read_typ_mode Type.mode_abbrev; |
|
410 |
||
411 |
||
412 |
fun cert_typ_mode mode ctxt T = |
|
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
413 |
Type.cert_typ_mode mode (tsig_of ctxt) T |
24277 | 414 |
handle TYPE (msg, _, _) => error msg; |
415 |
||
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
416 |
val cert_typ = cert_typ_mode Type.mode_default; |
24277 | 417 |
val cert_typ_syntax = cert_typ_mode Type.mode_syntax; |
418 |
val cert_typ_abbrev = cert_typ_mode Type.mode_abbrev; |
|
419 |
||
420 |
||
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
421 |
|
5819 | 422 |
(** prepare terms and propositions **) |
423 |
||
25328 | 424 |
(* inferred types of parameters *) |
425 |
||
426 |
fun infer_type ctxt x = |
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
427 |
Term.fastype_of (singleton (Syntax.check_terms (set_mode mode_schematic ctxt)) (Free x)); |
25328 | 428 |
|
429 |
fun inferred_param x ctxt = |
|
36505
79c1d2bbe5a9
ProofContext.read_const: allow for type constraint (for fixed variable);
wenzelm
parents:
36503
diff
changeset
|
430 |
let val T = infer_type ctxt (x, dummyT) |
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
431 |
in (T, ctxt |> Variable.declare_term (Free (x, T))) end; |
25328 | 432 |
|
433 |
fun inferred_fixes ctxt = |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
434 |
let |
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
435 |
val xs = map #2 (Variable.dest_fixes ctxt); |
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
436 |
val (Ts, ctxt') = fold_map inferred_param xs ctxt; |
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
437 |
in (xs ~~ Ts, ctxt') end; |
25328 | 438 |
|
439 |
||
55842 | 440 |
(* type names *) |
25328 | 441 |
|
56002 | 442 |
fun check_type_name {proper, strict} ctxt (c, pos) = |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
443 |
if Lexicon.is_tid c then |
55951
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
444 |
if proper then error ("Not a type constructor: " ^ c ^ Position.here pos) |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
445 |
else |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
446 |
let |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
447 |
val reports = |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
448 |
if Context_Position.is_reported ctxt pos |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
449 |
then [(pos, Markup.tfree)] else []; |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
450 |
in (TFree (c, default_sort ctxt (c, ~1)), reports) end |
55922
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
451 |
else |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
452 |
let |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
453 |
val ((d, reports), decl) = Type.check_decl (Context.Proof ctxt) (tsig_of ctxt) (c, pos); |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
454 |
fun err () = error ("Bad type name: " ^ quote d ^ Position.here pos); |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
455 |
val args = |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
456 |
(case decl of |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
457 |
Type.LogicalType n => n |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
458 |
| Type.Abbreviation (vs, _, _) => if strict then err () else length vs |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
459 |
| Type.Nonterminal => if strict then err () else 0); |
710bc66f432c
more markup for inner syntax class/type names (notably for completion);
wenzelm
parents:
55843
diff
changeset
|
460 |
in (Type (d, replicate args dummyT), reports) end; |
25328 | 461 |
|
55951
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
462 |
fun read_type_name ctxt flags text = |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
463 |
let |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
464 |
val (T, reports) = |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
465 |
check_type_name ctxt flags (Symbol_Pos.source_content (Syntax.read_token text)); |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
466 |
val _ = Position.reports reports; |
c07d184aebe9
tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents:
55950
diff
changeset
|
467 |
in T end; |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
468 |
|
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
469 |
|
55842 | 470 |
(* constant names *) |
471 |
||
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
472 |
fun consts_completion_message ctxt (c, ps) = |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
473 |
ps |> map (fn pos => |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
474 |
Name_Space.completion (Context.Proof ctxt) (Consts.space_of (consts_of ctxt)) (c, pos) |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
475 |
|> Completion.reported_text) |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
476 |
|> implode |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
477 |
|> Markup.markup_report; |
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
478 |
|
56002 | 479 |
fun check_const {proper, strict} ctxt (c, ps) = |
55842 | 480 |
let |
55956
94d384d621b0
reject internal term names outright, and complete consts instead;
wenzelm
parents:
55955
diff
changeset
|
481 |
val _ = |
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
482 |
Name.reject_internal (c, ps) handle ERROR msg => |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
483 |
error (msg ^ consts_completion_message ctxt (c, ps)); |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
484 |
fun err msg = error (msg ^ Position.here_list ps); |
55842 | 485 |
val consts = consts_of ctxt; |
55954 | 486 |
val fixed = if proper then NONE else Variable.lookup_fixed ctxt c; |
487 |
val (t, reports) = |
|
488 |
(case (fixed, Variable.lookup_const ctxt c) of |
|
489 |
(SOME x, NONE) => |
|
55843
3fa61f39d1f2
prefer Name_Space.check with its builtin reports (including completion);
wenzelm
parents:
55842
diff
changeset
|
490 |
let |
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
491 |
val reports = ps |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
492 |
|> filter (Context_Position.is_reported ctxt) |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
493 |
|> map (fn pos => |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
494 |
(pos, Markup.name x (if Name.is_skolem x then Markup.skolem else Markup.free))); |
55955
e8f1bf005661
eliminated odd type constraint for read_const (see also 79c1d2bbe5a9);
wenzelm
parents:
55954
diff
changeset
|
495 |
in (Free (x, infer_type ctxt (x, dummyT)), reports) end |
55954 | 496 |
| (_, SOME d) => |
497 |
let |
|
498 |
val T = Consts.type_scheme consts d handle TYPE (msg, _, _) => err msg; |
|
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
499 |
val reports = ps |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
500 |
|> filter (Context_Position.is_reported ctxt) |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
501 |
|> map (fn pos => (pos, Name_Space.markup (Consts.space_of consts) d)); |
55950
3bb5c7179234
clarified treatment of consts -- prefer value-oriented reports;
wenzelm
parents:
55949
diff
changeset
|
502 |
in (Const (d, T), reports) end |
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
503 |
| _ => Consts.check_const (Context.Proof ctxt) consts (c, ps)); |
55842 | 504 |
val _ = |
55954 | 505 |
(case (strict, t) of |
506 |
(true, Const (d, _)) => |
|
507 |
(ignore (Consts.the_const consts d) handle TYPE (msg, _, _) => err msg) |
|
508 |
| _ => ()); |
|
55950
3bb5c7179234
clarified treatment of consts -- prefer value-oriented reports;
wenzelm
parents:
55949
diff
changeset
|
509 |
in (t, reports) end; |
55842 | 510 |
|
55955
e8f1bf005661
eliminated odd type constraint for read_const (see also 79c1d2bbe5a9);
wenzelm
parents:
55954
diff
changeset
|
511 |
fun read_const ctxt flags text = |
55950
3bb5c7179234
clarified treatment of consts -- prefer value-oriented reports;
wenzelm
parents:
55949
diff
changeset
|
512 |
let |
55959
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
513 |
val (xname, pos) = Symbol_Pos.source_content (Syntax.read_token text); |
c3b458435f4f
more decisive commitment to get_free vs. the_const;
wenzelm
parents:
55956
diff
changeset
|
514 |
val (t, reports) = check_const ctxt flags (xname, [pos]); |
55950
3bb5c7179234
clarified treatment of consts -- prefer value-oriented reports;
wenzelm
parents:
55949
diff
changeset
|
515 |
val _ = Position.reports reports; |
3bb5c7179234
clarified treatment of consts -- prefer value-oriented reports;
wenzelm
parents:
55949
diff
changeset
|
516 |
in t end; |
25328 | 517 |
|
518 |
||
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
519 |
(* type arities *) |
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
520 |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
521 |
local |
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
522 |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
523 |
fun prep_arity prep_tycon prep_sort ctxt (t, Ss, S) = |
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
524 |
let val arity = (prep_tycon ctxt t, map (prep_sort ctxt) Ss, prep_sort ctxt S) |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
525 |
in Type.add_arity (Context.pretty ctxt) arity (tsig_of ctxt); arity end; |
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
526 |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
527 |
in |
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
528 |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
529 |
val read_arity = |
56002 | 530 |
prep_arity ((#1 o dest_Type) oo read_type_name {proper = true, strict = true}) Syntax.read_sort; |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
531 |
|
46922
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
532 |
val cert_arity = prep_arity (K I) (Type.cert_sort o tsig_of); |
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
533 |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
534 |
end; |
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
535 |
|
3717f3878714
source positions for locale and class expressions;
wenzelm
parents:
46849
diff
changeset
|
536 |
|
24684 | 537 |
(* read_term *) |
538 |
||
539 |
fun read_term_mode mode ctxt = Syntax.read_term (set_mode mode ctxt); |
|
540 |
||
541 |
val read_term_pattern = read_term_mode mode_pattern; |
|
542 |
val read_term_schematic = read_term_mode mode_schematic; |
|
543 |
val read_term_abbrev = read_term_mode mode_abbrev; |
|
544 |
||
545 |
||
19001 | 546 |
(* local abbreviations *) |
5819 | 547 |
|
24501 | 548 |
local |
549 |
||
42383
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
550 |
fun certify_consts ctxt = Consts.certify (Context.pretty ctxt) (tsig_of ctxt) |
27286 | 551 |
(not (abbrev_mode ctxt)) (consts_of ctxt); |
19001 | 552 |
|
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
553 |
fun expand_binds ctxt = |
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
554 |
let |
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
555 |
val Mode {pattern, schematic, ...} = get_mode ctxt; |
5819 | 556 |
|
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
557 |
fun reject_schematic (t as Var _) = |
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
558 |
error ("Unbound schematic variable: " ^ Syntax.string_of_term ctxt t) |
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
559 |
| reject_schematic (Abs (_, _, t)) = reject_schematic t |
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
560 |
| reject_schematic (t $ u) = (reject_schematic t; reject_schematic u) |
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
561 |
| reject_schematic _ = (); |
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
562 |
in |
24495 | 563 |
if pattern then I |
564 |
else Variable.expand_binds ctxt #> (if schematic then I else tap reject_schematic) |
|
565 |
end; |
|
5819 | 566 |
|
24501 | 567 |
in |
568 |
||
569 |
fun expand_abbrevs ctxt = certify_consts ctxt #> expand_binds ctxt; |
|
570 |
||
571 |
end; |
|
572 |
||
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
573 |
val show_abbrevs_raw = Config.declare "show_abbrevs" (fn _ => Config.Bool true); |
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
574 |
val show_abbrevs = Config.bool show_abbrevs_raw; |
5819 | 575 |
|
24922 | 576 |
fun contract_abbrevs ctxt t = |
577 |
let |
|
578 |
val thy = theory_of ctxt; |
|
579 |
val consts = consts_of ctxt; |
|
580 |
val Mode {abbrev, ...} = get_mode ctxt; |
|
30566
9643f54c4184
reverted abbreviations: improved performance via Item_Net.T;
wenzelm
parents:
30473
diff
changeset
|
581 |
val retrieve = Consts.retrieve_abbrevs consts (print_mode_value () @ [""]); |
9643f54c4184
reverted abbreviations: improved performance via Item_Net.T;
wenzelm
parents:
30473
diff
changeset
|
582 |
fun match_abbrev u = Option.map #1 (get_first (Pattern.match_rew thy u) (retrieve u)); |
24922 | 583 |
in |
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
584 |
if abbrev orelse not (Config.get ctxt show_abbrevs) orelse not (can Term.type_of t) then t |
35211
5d2fe4e09354
Use top-down rewriting to contract abbreviations.
berghofe
parents:
35141
diff
changeset
|
585 |
else Pattern.rewrite_term_top thy [] [match_abbrev] t |
24922 | 586 |
end; |
587 |
||
588 |
||
24518 | 589 |
(* patterns *) |
590 |
||
32003 | 591 |
fun prepare_patternT ctxt T = |
592 |
let |
|
593 |
val Mode {pattern, schematic, ...} = get_mode ctxt; |
|
594 |
val _ = |
|
595 |
pattern orelse schematic orelse |
|
596 |
T |> Term.exists_subtype |
|
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
597 |
(fn T as TVar (xi, _) => |
37145
01aa36932739
renamed structure TypeInfer to Type_Infer, keeping the old name as legacy alias for some time;
wenzelm
parents:
36610
diff
changeset
|
598 |
not (Type_Infer.is_param xi) andalso |
38979
60dbf0b3f6c7
prefer regular print functions over slightly low-level Term.string_of_vname;
wenzelm
parents:
38756
diff
changeset
|
599 |
error ("Illegal schematic type variable: " ^ Syntax.string_of_typ ctxt T) |
32003 | 600 |
| _ => false) |
601 |
in T end; |
|
24518 | 602 |
|
22712 | 603 |
|
24505 | 604 |
local |
6550 | 605 |
|
42360 | 606 |
val dummies = Config.bool (Config.declare "Proof_Context.dummies" (K (Config.Bool false))); |
27259 | 607 |
|
608 |
fun check_dummies ctxt t = |
|
39508
dfacdb01e1ec
simplified some internal flags using Config.T instead of full-blown Proof_Data;
wenzelm
parents:
39507
diff
changeset
|
609 |
if Config.get ctxt dummies then t |
27259 | 610 |
else Term.no_dummy_patterns t handle TERM _ => error "Illegal dummy pattern(s) in term"; |
611 |
||
24767 | 612 |
fun prepare_dummies ts = #1 (fold_map Term.replace_dummy_patterns ts 1); |
6762 | 613 |
|
27259 | 614 |
in |
6550 | 615 |
|
39508
dfacdb01e1ec
simplified some internal flags using Config.T instead of full-blown Proof_Data;
wenzelm
parents:
39507
diff
changeset
|
616 |
val allow_dummies = Config.put dummies true; |
24505 | 617 |
|
24684 | 618 |
fun prepare_patterns ctxt = |
24518 | 619 |
let val Mode {pattern, ...} = get_mode ctxt in |
39296 | 620 |
Type_Infer.fixate ctxt #> |
24767 | 621 |
pattern ? Variable.polymorphic ctxt #> |
24684 | 622 |
(map o Term.map_types) (prepare_patternT ctxt) #> |
27259 | 623 |
(if pattern then prepare_dummies else map (check_dummies ctxt)) |
24505 | 624 |
end; |
625 |
||
626 |
end; |
|
627 |
||
6550 | 628 |
|
42250
cc5ac538f991
eliminated odd object-oriented type_context/term_context;
wenzelm
parents:
42242
diff
changeset
|
629 |
(* sort constraints *) |
27286 | 630 |
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
631 |
local |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
632 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
633 |
fun prepare_sorts_env ctxt tys = |
27286 | 634 |
let |
35669
a91c7ed801b8
added ProofContext.tsig_of -- proforma version for local name space only, not logical content;
wenzelm
parents:
35616
diff
changeset
|
635 |
val tsig = tsig_of ctxt; |
45453 | 636 |
val defaultS = Type.defaultS tsig; |
27286 | 637 |
|
53673
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
638 |
val dummy_var = ("'_dummy_", ~1); |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
639 |
|
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
640 |
fun constraint (xi, raw_S) env = |
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
641 |
let val (ps, S) = Term_Position.decode_positionS raw_S in |
53673
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
642 |
if xi = dummy_var orelse S = dummyS then env |
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
643 |
else |
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
644 |
Vartab.insert (op =) (xi, Type.minimize_sort tsig S) env |
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
645 |
handle Vartab.DUP _ => |
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
646 |
error ("Inconsistent sort constraints for type variable " ^ |
49691 | 647 |
quote (Term.string_of_vname' xi) ^ Position.here_list ps) |
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
648 |
end; |
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
649 |
|
45453 | 650 |
val env = |
651 |
(fold o fold_atyps) |
|
652 |
(fn TFree (x, S) => constraint ((x, ~1), S) |
|
653 |
| TVar v => constraint v |
|
654 |
| _ => I) tys Vartab.empty; |
|
36152 | 655 |
|
53673
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
656 |
fun get_sort xi raw_S = |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
657 |
if xi = dummy_var then |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
658 |
Type.minimize_sort tsig (#2 (Term_Position.decode_positionS raw_S)) |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
659 |
else |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
660 |
(case (Vartab.lookup env xi, Variable.def_sort ctxt xi) of |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
661 |
(NONE, NONE) => defaultS |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
662 |
| (NONE, SOME S) => S |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
663 |
| (SOME S, NONE) => S |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
664 |
| (SOME S, SOME S') => |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
665 |
if Type.eq_sort tsig (S, S') then S' |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
666 |
else |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
667 |
error ("Sort constraint " ^ Syntax.string_of_sort ctxt S ^ |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
668 |
" inconsistent with default " ^ Syntax.string_of_sort ctxt S' ^ |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
669 |
" for type variable " ^ quote (Term.string_of_vname' xi))); |
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
670 |
|
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
671 |
fun add_report S pos reports = |
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
672 |
if Position.is_reported pos andalso not (AList.defined (op =) reports pos) then |
50201
c26369c9eda6
Isabelle-specific implementation of quasi-abstract markup elements -- back to module arrangement before d83797ef0d2d;
wenzelm
parents:
50126
diff
changeset
|
673 |
(pos, Position.reported_text pos Markup.sorting (Syntax.string_of_sort ctxt S)) :: reports |
49685
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
674 |
else reports; |
4341e4d86872
allow position constraints to coexist with 0 or 1 sort constraints;
wenzelm
parents:
49674
diff
changeset
|
675 |
|
49691 | 676 |
fun get_sort_reports xi raw_S = |
677 |
let |
|
678 |
val ps = #1 (Term_Position.decode_positionS raw_S); |
|
53673
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
679 |
val S = get_sort xi raw_S handle ERROR msg => error (msg ^ Position.here_list ps); |
49691 | 680 |
in fold (add_report S) ps end; |
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
681 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
682 |
val reports = |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
683 |
(fold o fold_atyps) |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
684 |
(fn T => |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
685 |
if Term_Position.is_positionT T then I |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
686 |
else |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
687 |
(case T of |
49691 | 688 |
TFree (x, raw_S) => get_sort_reports (x, ~1) raw_S |
689 |
| TVar (xi, raw_S) => get_sort_reports xi raw_S |
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
690 |
| _ => I)) tys []; |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
691 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
692 |
in (implode (map #2 reports), get_sort) end; |
27286 | 693 |
|
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
694 |
fun replace_sortsT get_sort = |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
695 |
map_atyps |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
696 |
(fn T => |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
697 |
if Term_Position.is_positionT T then T |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
698 |
else |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
699 |
(case T of |
53673
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
700 |
TFree (x, raw_S) => TFree (x, get_sort (x, ~1) raw_S) |
bcfd16f65014
treat all dummy type variables separately (in contrast to fca432074fb2);
wenzelm
parents:
53380
diff
changeset
|
701 |
| TVar (xi, raw_S) => TVar (xi, get_sort xi raw_S) |
49674
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
702 |
| _ => T)); |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
703 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
704 |
in |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
705 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
706 |
fun prepare_sortsT ctxt tys = |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
707 |
let val (sorting_report, get_sort) = prepare_sorts_env ctxt tys |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
708 |
in (sorting_report, map (replace_sortsT get_sort) tys) end; |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
709 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
710 |
fun prepare_sorts ctxt tms = |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
711 |
let |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
712 |
val tys = rev ((fold o fold_types) cons tms []); |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
713 |
val (sorting_report, get_sort) = prepare_sorts_env ctxt tys; |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
714 |
in (sorting_report, (map o map_types) (replace_sortsT get_sort) tms) end; |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
715 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
716 |
fun check_tfree ctxt v = |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
717 |
let |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
718 |
val (sorting_report, [TFree a]) = prepare_sortsT ctxt [TFree v]; |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
719 |
val _ = Context_Position.if_visible ctxt Output.report sorting_report; |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
720 |
in a end; |
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
721 |
|
dbadb4d03cbc
report sort assignment of visible type variables;
wenzelm
parents:
48992
diff
changeset
|
722 |
end; |
36152 | 723 |
|
5819 | 724 |
|
725 |
(* certify terms *) |
|
726 |
||
10554 | 727 |
local |
728 |
||
24684 | 729 |
fun gen_cert prop ctxt t = |
730 |
t |
|
731 |
|> expand_abbrevs ctxt |
|
42383
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
732 |
|> (fn t' => |
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
733 |
#1 (Sign.certify' prop (Context.pretty ctxt) false (consts_of ctxt) (theory_of ctxt) t') |
0ae4ad40d7b5
simplified pretty printing context, which is only required for certain kernel operations;
wenzelm
parents:
42381
diff
changeset
|
734 |
handle TYPE (msg, _, _) => error msg | TERM (msg, _) => error msg); |
16501 | 735 |
|
10554 | 736 |
in |
8096 | 737 |
|
24684 | 738 |
val cert_term = gen_cert false; |
739 |
val cert_prop = gen_cert true; |
|
10554 | 740 |
|
741 |
end; |
|
5819 | 742 |
|
743 |
||
42405
13ecdb3057d8
split Type_Infer into early and late part, after Proof_Context;
wenzelm
parents:
42402
diff
changeset
|
744 |
(* check/uncheck *) |
22701 | 745 |
|
35616
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
746 |
fun def_type ctxt = |
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
747 |
let val Mode {pattern, ...} = get_mode ctxt |
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
748 |
in Variable.def_type ctxt pattern end; |
b342390d296f
provide ProofContext.def_type depending on "pattern" mode;
wenzelm
parents:
35429
diff
changeset
|
749 |
|
24518 | 750 |
fun standard_typ_check ctxt = |
45429 | 751 |
map (cert_typ_mode (Type.get_mode ctxt) ctxt #> prepare_patternT ctxt); |
24922 | 752 |
|
45429 | 753 |
val standard_term_check_finish = prepare_patterns; |
24518 | 754 |
|
45429 | 755 |
fun standard_term_uncheck ctxt = map (contract_abbrevs ctxt); |
22701 | 756 |
|
757 |
||
9553 | 758 |
|
21610 | 759 |
(** export results **) |
21531 | 760 |
|
20310 | 761 |
fun common_export is_goal inner outer = |
762 |
map (Assumption.export is_goal inner outer) #> |
|
763 |
Variable.export inner outer; |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
764 |
|
20310 | 765 |
val goal_export = common_export true; |
766 |
val export = common_export false; |
|
12704 | 767 |
|
21531 | 768 |
fun export_morphism inner outer = |
769 |
Assumption.export_morphism inner outer $> |
|
770 |
Variable.export_morphism inner outer; |
|
771 |
||
28396 | 772 |
fun norm_export_morphism inner outer = |
773 |
export_morphism inner outer $> |
|
54883
dd04a8b654fc
proper context for norm_hhf and derived operations;
wenzelm
parents:
54742
diff
changeset
|
774 |
Morphism.thm_morphism "Proof_Context.norm_export" (Goal.norm_result outer); |
28396 | 775 |
|
21531 | 776 |
|
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
777 |
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
778 |
(** term bindings **) |
5819 | 779 |
|
8096 | 780 |
(* simult_matches *) |
781 |
||
19867 | 782 |
fun simult_matches ctxt (t, pats) = |
783 |
(case Seq.pull (Unify.matchers (theory_of ctxt) (map (rpair t) pats)) of |
|
784 |
NONE => error "Pattern match failed!" |
|
32032 | 785 |
| SOME (env, _) => Vartab.fold (fn (v, (_, t)) => cons (v, t)) (Envir.term_env env) []); |
8096 | 786 |
|
787 |
||
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
788 |
(* bind_terms *) |
7925 | 789 |
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
790 |
val bind_terms = fold (fn (xi, t) => fn ctxt => |
24511
69d270cc7e4f
removed obsolete read/cert variations (cf. Syntax.read/check);
wenzelm
parents:
24505
diff
changeset
|
791 |
ctxt |
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
792 |
|> Variable.bind_term (xi, Option.map (cert_term (set_mode mode_default ctxt)) t)); |
5819 | 793 |
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
794 |
|
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
795 |
(* auto_bind *) |
10810 | 796 |
|
20330 | 797 |
fun drop_schematic (b as (xi, SOME t)) = if Term.exists_subterm is_Var t then (xi, NONE) else b |
10554 | 798 |
| drop_schematic b = b; |
799 |
||
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
800 |
fun auto_bind f ts ctxt = ctxt |> bind_terms (map drop_schematic (f (theory_of ctxt) ts)); |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
801 |
|
33386 | 802 |
val auto_bind_goal = auto_bind Auto_Bind.goal; |
803 |
val auto_bind_facts = auto_bind Auto_Bind.facts; |
|
7925 | 804 |
|
5819 | 805 |
|
8096 | 806 |
(* match_bind(_i) *) |
5819 | 807 |
|
8096 | 808 |
local |
809 |
||
24684 | 810 |
fun gen_bind prep_terms gen raw_binds ctxt = |
5819 | 811 |
let |
24684 | 812 |
fun prep_bind (raw_pats, t) ctxt1 = |
813 |
let |
|
814 |
val T = Term.fastype_of t; |
|
815 |
val ctxt2 = Variable.declare_term t ctxt1; |
|
816 |
val pats = prep_terms (set_mode mode_pattern ctxt2) T raw_pats; |
|
817 |
val binds = simult_matches ctxt2 (t, pats); |
|
818 |
in (binds, ctxt2) end; |
|
7670 | 819 |
|
24686 | 820 |
val ts = prep_terms ctxt dummyT (map snd raw_binds); |
821 |
val (binds, ctxt') = apfst flat (fold_map prep_bind (map fst raw_binds ~~ ts) ctxt); |
|
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
822 |
val binds' = |
19916
3bbb9cc5d4f1
export: simultaneous facts, refer to Variable.export;
wenzelm
parents:
19897
diff
changeset
|
823 |
if gen then map #1 binds ~~ Variable.exportT_terms ctxt' ctxt (map #2 binds) |
8616
90d2fed59be1
support Hindley-Milner polymorphisms in binds and facts;
wenzelm
parents:
8462
diff
changeset
|
824 |
else binds; |
15531 | 825 |
val binds'' = map (apsnd SOME) binds'; |
18310 | 826 |
val ctxt'' = |
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
827 |
tap (Variable.warn_extra_tfrees ctxt) |
18310 | 828 |
(if gen then |
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
829 |
ctxt (*sic!*) |> fold Variable.declare_term (map #2 binds') |> bind_terms binds'' |
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
830 |
else ctxt' |> bind_terms binds''); |
18310 | 831 |
in (ts, ctxt'') end; |
8096 | 832 |
|
833 |
in |
|
5935 | 834 |
|
24684 | 835 |
fun read_terms ctxt T = |
39288 | 836 |
map (Syntax.parse_term ctxt #> Type.constraint T) #> Syntax.check_terms ctxt; |
24684 | 837 |
|
838 |
val match_bind = gen_bind read_terms; |
|
839 |
val match_bind_i = gen_bind (fn ctxt => fn _ => map (cert_term ctxt)); |
|
8096 | 840 |
|
841 |
end; |
|
5935 | 842 |
|
843 |
||
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
844 |
(* propositions with patterns *) |
5935 | 845 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
846 |
local |
8096 | 847 |
|
45327 | 848 |
fun prep_propp mode prep_props args context = |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
849 |
let |
19585 | 850 |
fun prep (_, raw_pats) (ctxt, prop :: props) = |
24684 | 851 |
let val ctxt' = Variable.declare_term prop ctxt |
852 |
in ((prop, prep_props (set_mode mode_pattern ctxt') raw_pats), (ctxt', props)) end; |
|
853 |
||
45327 | 854 |
val (propp, (context', _)) = |
855 |
(fold_map o fold_map) prep args |
|
856 |
(context, prep_props (set_mode mode context) (maps (map fst) args)); |
|
857 |
in (propp, context') end; |
|
5935 | 858 |
|
45327 | 859 |
fun gen_bind_propp mode parse_prop raw_args ctxt = |
8096 | 860 |
let |
45327 | 861 |
val (args, ctxt') = prep_propp mode parse_prop raw_args ctxt; |
19585 | 862 |
val binds = flat (flat (map (map (simult_matches ctxt')) args)); |
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
863 |
val propss = map (map #1) args; |
45330
93b8e30a5d1f
more general Proof_Context.bind_propp, which allows outer parameters;
wenzelm
parents:
45327
diff
changeset
|
864 |
fun gen_binds ctxt0 = ctxt0 |
93b8e30a5d1f
more general Proof_Context.bind_propp, which allows outer parameters;
wenzelm
parents:
45327
diff
changeset
|
865 |
|> bind_terms (map #1 binds ~~ |
93b8e30a5d1f
more general Proof_Context.bind_propp, which allows outer parameters;
wenzelm
parents:
45327
diff
changeset
|
866 |
map (SOME o Term.close_schematic_term) (Variable.export_terms ctxt' ctxt0 (map #2 binds))); |
45327 | 867 |
in ((propss, gen_binds), ctxt' |> bind_terms (map (apsnd SOME) binds)) end; |
8096 | 868 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
869 |
in |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
870 |
|
24684 | 871 |
val read_propp = prep_propp mode_default Syntax.read_props; |
872 |
val cert_propp = prep_propp mode_default (map o cert_prop); |
|
873 |
val read_propp_schematic = prep_propp mode_schematic Syntax.read_props; |
|
874 |
val cert_propp_schematic = prep_propp mode_schematic (map o cert_prop); |
|
10554 | 875 |
|
24684 | 876 |
val bind_propp = gen_bind_propp mode_default Syntax.read_props; |
877 |
val bind_propp_i = gen_bind_propp mode_default (map o cert_prop); |
|
878 |
val bind_propp_schematic = gen_bind_propp mode_schematic Syntax.read_props; |
|
879 |
val bind_propp_schematic_i = gen_bind_propp mode_schematic (map o cert_prop); |
|
6789 | 880 |
|
10465
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
881 |
end; |
4aa6f8b5cdc4
added read_terms, read_props (simulataneous type-inference);
wenzelm
parents:
10381
diff
changeset
|
882 |
|
6789 | 883 |
|
5819 | 884 |
|
885 |
(** theorems **) |
|
886 |
||
18042 | 887 |
(* fact_tac *) |
888 |
||
52223
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
889 |
local |
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
890 |
|
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
891 |
fun comp_hhf_tac th i st = |
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
892 |
PRIMSEQ (Thm.bicompose {flatten = true, match = false, incremented = true} |
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
893 |
(false, Drule.lift_all (Thm.cprem_of st i) th, 0) i) st; |
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
894 |
|
27867 | 895 |
fun comp_incr_tac [] _ = no_tac |
896 |
| comp_incr_tac (th :: ths) i = |
|
52223
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
897 |
(fn st => comp_hhf_tac (Drule.incr_indexes st th) i st) APPEND comp_incr_tac ths i; |
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
898 |
|
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
899 |
in |
18042 | 900 |
|
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
901 |
fun fact_tac ctxt facts = Goal.norm_hhf_tac ctxt THEN' comp_incr_tac facts; |
18122 | 902 |
|
27867 | 903 |
fun potential_facts ctxt prop = |
904 |
Facts.could_unify (facts_of ctxt) (Term.strip_all_body prop); |
|
905 |
||
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
906 |
fun some_fact_tac ctxt = SUBGOAL (fn (goal, i) => fact_tac ctxt (potential_facts ctxt goal) i); |
18042 | 907 |
|
52223
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
908 |
end; |
5bb6ae8acb87
tuned signature -- more explicit flags for low-level Thm.bicompose;
wenzelm
parents:
52156
diff
changeset
|
909 |
|
18042 | 910 |
|
6091 | 911 |
(* get_thm(s) *) |
5819 | 912 |
|
26361 | 913 |
local |
914 |
||
26687 | 915 |
fun retrieve_thms pick ctxt (Facts.Fact s) = |
16501 | 916 |
let |
46849 | 917 |
val pos = Syntax.read_token_pos s; |
42502 | 918 |
val prop = |
919 |
Syntax.read_prop (ctxt |> set_mode mode_default |> allow_dummies) s |
|
24511
69d270cc7e4f
removed obsolete read/cert variations (cf. Syntax.read/check);
wenzelm
parents:
24505
diff
changeset
|
920 |
|> singleton (Variable.polymorphic ctxt); |
48992 | 921 |
fun err msg = error (msg ^ Position.here pos ^ ":\n" ^ Syntax.string_of_term ctxt prop); |
27867 | 922 |
|
42502 | 923 |
val (prop', _) = Term.replace_dummy_patterns prop (Variable.maxidx_of ctxt + 1); |
27867 | 924 |
fun prove_fact th = |
54742
7a86358a3c0b
proper context for basic Simplifier operations: rewrite_rule, rewrite_goals_rule, rewrite_goals_tac etc.;
wenzelm
parents:
54740
diff
changeset
|
925 |
Goal.prove ctxt [] [] prop' (K (ALLGOALS (fact_tac ctxt [th]))); |
42502 | 926 |
val results = map_filter (try prove_fact) (potential_facts ctxt prop'); |
27867 | 927 |
val res = |
42502 | 928 |
(case distinct Thm.eq_thm_prop results of |
929 |
[res] => res |
|
930 |
| [] => err "Failed to retrieve literal fact" |
|
931 |
| _ => err "Ambiguous specification of literal fact"); |
|
55740 | 932 |
in pick ("", Position.none) [res] end |
26687 | 933 |
| retrieve_thms pick ctxt xthmref = |
18042 | 934 |
let |
935 |
val thy = theory_of ctxt; |
|
26284 | 936 |
val local_facts = facts_of ctxt; |
26673 | 937 |
val thmref = Facts.map_name_of_ref (Facts.intern local_facts) xthmref; |
26336
a0e2b706ce73
renamed datatype thmref to Facts.ref, tuned interfaces;
wenzelm
parents:
26321
diff
changeset
|
938 |
val name = Facts.name_of_ref thmref; |
27821 | 939 |
val pos = Facts.pos_of_ref xthmref; |
24012 | 940 |
val thms = |
941 |
if name = "" then [Thm.transfer thy Drule.dummy_thm] |
|
942 |
else |
|
26393 | 943 |
(case Facts.lookup (Context.Proof ctxt) local_facts name of |
39507
839873937ddd
tuned signature of (Context_)Position.report variants;
wenzelm
parents:
39441
diff
changeset
|
944 |
SOME (_, ths) => |
42378 | 945 |
(Context_Position.report ctxt pos |
42379 | 946 |
(Name_Space.markup (Facts.space_of local_facts) name); |
42378 | 947 |
map (Thm.transfer thy) (Facts.select thmref ths)) |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
948 |
| NONE => Global_Theory.get_fact (Context.Proof ctxt) thy xthmref); |
55740 | 949 |
in pick (name, pos) thms end; |
5819 | 950 |
|
26361 | 951 |
in |
26346
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
952 |
|
26687 | 953 |
val get_fact = retrieve_thms (K I); |
954 |
val get_fact_single = retrieve_thms Facts.the_single; |
|
26346
17debd2fff8e
simplified get_thm(s): back to plain name argument;
wenzelm
parents:
26336
diff
changeset
|
955 |
|
26361 | 956 |
fun get_thms ctxt = get_fact ctxt o Facts.named; |
957 |
fun get_thm ctxt = get_fact_single ctxt o Facts.named; |
|
958 |
||
959 |
end; |
|
5819 | 960 |
|
961 |
||
26284 | 962 |
(* facts *) |
5819 | 963 |
|
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
964 |
local |
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
965 |
|
28965 | 966 |
fun update_thms _ (b, NONE) ctxt = ctxt |> map_facts (Facts.del (full_name ctxt b)) |
49747 | 967 |
| update_thms flags (b, SOME ths) ctxt = ctxt |> map_facts |
968 |
(Facts.add_static (Context.Proof ctxt) flags (b, ths) #> snd); |
|
5819 | 969 |
|
30761
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
wenzelm
parents:
30758
diff
changeset
|
970 |
in |
ac7570d80c3d
renamed ProofContext.note_thmss_i to ProofContext.note_thmss, eliminated obsolete external version;
wenzelm
parents:
30758
diff
changeset
|
971 |
|
46775
6287653e63ec
canonical argument order for attribute application;
wenzelm
parents:
45666
diff
changeset
|
972 |
fun note_thmss kind = fold_map (fn ((b, more_atts), raw_facts) => fn ctxt => |
5819 | 973 |
let |
28965 | 974 |
val name = full_name ctxt b; |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
975 |
val facts = Global_Theory.name_thmss false name raw_facts; |
46775
6287653e63ec
canonical argument order for attribute application;
wenzelm
parents:
45666
diff
changeset
|
976 |
fun app (ths, atts) = |
6287653e63ec
canonical argument order for attribute application;
wenzelm
parents:
45666
diff
changeset
|
977 |
fold_map (Thm.proof_attributes (surround (Thm.kind kind) (atts @ more_atts))) ths; |
21443
cc5095d57da4
added stmt mode, which affects naming/indexing of local facts;
wenzelm
parents:
21370
diff
changeset
|
978 |
val (res, ctxt') = fold_map app facts ctxt; |
39557
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents:
39508
diff
changeset
|
979 |
val thms = Global_Theory.name_thms false false name (flat res); |
24388
cf24894b81ff
added inner syntax mode, includes former type_mode and is_stmt;
wenzelm
parents:
24371
diff
changeset
|
980 |
val Mode {stmt, ...} = get_mode ctxt; |
49747 | 981 |
in ((name, thms), ctxt' |> update_thms {strict = false, index = stmt} (b, SOME thms)) end); |
12711 | 982 |
|
49747 | 983 |
fun put_thms index thms ctxt = ctxt |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
984 |
|> map_naming (K Name_Space.local_naming) |
33383 | 985 |
|> Context_Position.set_visible false |
49747 | 986 |
|> update_thms {strict = false, index = index} (apfst Binding.name thms) |
33383 | 987 |
|> Context_Position.restore_visible ctxt |
28417 | 988 |
|> restore_naming ctxt; |
28082
37350f301128
explicit type Name.binding for higher-specification elements;
wenzelm
parents:
28017
diff
changeset
|
989 |
|
12711 | 990 |
end; |
9196 | 991 |
|
5819 | 992 |
|
993 |
||
35680 | 994 |
(** basic logical entities **) |
17360
fa1f262dbc4e
added add_view, export_view (supercedes adhoc view arguments);
wenzelm
parents:
17221
diff
changeset
|
995 |
|
8096 | 996 |
(* variables *) |
997 |
||
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
998 |
fun declare_var (x, opt_T, mx) ctxt = |
42287
d98eb048a2e4
discontinued special treatment of structure Mixfix;
wenzelm
parents:
42267
diff
changeset
|
999 |
let val T = (case opt_T of SOME T => T | NONE => Mixfix.mixfixT mx) |
20163 | 1000 |
in ((x, T, mx), ctxt |> Variable.declare_constraints (Free (x, T))) end; |
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
1001 |
|
10381 | 1002 |
local |
1003 |
||
25353
17f04d987f37
removed unused read_termTs_schematic, read/cert_vars_legacy, add_fixes_legacy;
wenzelm
parents:
25345
diff
changeset
|
1004 |
fun prep_vars prep_typ internal = |
35129 | 1005 |
fold_map (fn (b, raw_T, mx) => fn ctxt => |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1006 |
let |
42494 | 1007 |
val x = Variable.check_name b; |
55949 | 1008 |
val check_name = if internal then Name.reject_skolem else Name.reject_internal; |
1009 |
val _ = |
|
1010 |
if can check_name (x, []) andalso Symbol_Pos.is_identifier x then () |
|
1011 |
else error ("Bad name: " ^ Binding.print b); |
|
12504 | 1012 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1013 |
fun cond_tvars T = |
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1014 |
if internal then T |
18678 | 1015 |
else Type.no_tvars T handle TYPE (msg, _, _) => error msg; |
24277 | 1016 |
val opt_T = Option.map (cond_tvars o cert_typ ctxt o prep_typ ctxt) raw_T; |
35129 | 1017 |
val (_, ctxt') = ctxt |> declare_var (x, opt_T, mx); |
1018 |
in ((b, opt_T, mx), ctxt') end); |
|
8096 | 1019 |
|
10381 | 1020 |
in |
1021 |
||
45427
fca432074fb2
sort assignment before simultaneous term_check, not isolated parse_term;
wenzelm
parents:
45330
diff
changeset
|
1022 |
val read_vars = prep_vars Syntax.read_typ false; |
25353
17f04d987f37
removed unused read_termTs_schematic, read/cert_vars_legacy, add_fixes_legacy;
wenzelm
parents:
25345
diff
changeset
|
1023 |
val cert_vars = prep_vars (K I) true; |
8096 | 1024 |
|
10381 | 1025 |
end; |
1026 |
||
8096 | 1027 |
|
21744 | 1028 |
(* notation *) |
1029 |
||
24949 | 1030 |
local |
1031 |
||
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35412
diff
changeset
|
1032 |
fun type_syntax (Type (c, args), mx) = |
42290
b1f544c84040
discontinued special treatment of structure Lexicon;
wenzelm
parents:
42287
diff
changeset
|
1033 |
SOME (Local_Syntax.Type, (Lexicon.mark_type c, Mixfix.make_type (length args), mx)) |
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1034 |
| type_syntax _ = NONE; |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1035 |
|
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1036 |
fun const_syntax _ (Free (x, T), mx) = SOME (Local_Syntax.Fixed, (x, T, mx)) |
24949 | 1037 |
| const_syntax ctxt (Const (c, _), mx) = |
35255 | 1038 |
(case try (Consts.type_scheme (consts_of ctxt)) c of |
42290
b1f544c84040
discontinued special treatment of structure Lexicon;
wenzelm
parents:
42287
diff
changeset
|
1039 |
SOME T => SOME (Local_Syntax.Const, (Lexicon.mark_const c, T, mx)) |
35255 | 1040 |
| NONE => NONE) |
24949 | 1041 |
| const_syntax _ _ = NONE; |
1042 |
||
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1043 |
fun gen_notation syntax add mode args ctxt = |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1044 |
ctxt |> map_syntax |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1045 |
(Local_Syntax.update_modesyntax (theory_of ctxt) add mode (map_filter (syntax ctxt) args)); |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1046 |
|
24949 | 1047 |
in |
21744 | 1048 |
|
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1049 |
val type_notation = gen_notation (K type_syntax); |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1050 |
val notation = gen_notation const_syntax; |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1051 |
|
47247 | 1052 |
fun generic_type_notation add mode args phi = |
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1053 |
let |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1054 |
val args' = args |> map_filter (fn (T, mx) => |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1055 |
let |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1056 |
val T' = Morphism.typ phi T; |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1057 |
val similar = (case (T, T') of (Type (c, _), Type (c', _)) => c = c' | _ => false); |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1058 |
in if similar then SOME (T', mx) else NONE end); |
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1059 |
in Context.mapping (Sign.type_notation add mode args') (type_notation add mode args') end; |
24949 | 1060 |
|
47247 | 1061 |
fun generic_notation add mode args phi = |
33537
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1062 |
let |
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1063 |
val args' = args |> map_filter (fn (t, mx) => |
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1064 |
let val t' = Morphism.term phi t |
06c87d2c5b5a
locale_const/target_notation: uniform use of Term.aconv_untyped;
wenzelm
parents:
33519
diff
changeset
|
1065 |
in if Term.aconv_untyped (t, t') then SOME (t', mx) else NONE end); |
24949 | 1066 |
in Context.mapping (Sign.notation add mode args') (notation add mode args') end; |
1067 |
||
35680 | 1068 |
end; |
35412
b8dead547d9e
more uniform treatment of syntax for types vs. consts;
wenzelm
parents:
35399
diff
changeset
|
1069 |
|
35680 | 1070 |
|
1071 |
(* aliases *) |
|
1072 |
||
36450 | 1073 |
fun class_alias b c ctxt = (map_tsig o apfst) (Type.class_alias (naming_of ctxt) b c) ctxt; |
1074 |
fun type_alias b c ctxt = (map_tsig o apfst) (Type.type_alias (naming_of ctxt) b c) ctxt; |
|
35680 | 1075 |
fun const_alias b c ctxt = (map_consts o apfst) (Consts.alias (naming_of ctxt) b c) ctxt; |
21744 | 1076 |
|
1077 |
||
24767 | 1078 |
(* local constants *) |
1079 |
||
1080 |
fun add_const_constraint (c, opt_T) ctxt = |
|
1081 |
let |
|
1082 |
fun prepT raw_T = |
|
1083 |
let val T = cert_typ ctxt raw_T |
|
1084 |
in cert_term ctxt (Const (c, T)); T end; |
|
25039 | 1085 |
in ctxt |> (map_consts o apfst) (Consts.constrain (c, Option.map prepT opt_T)) end; |
19001 | 1086 |
|
33173
b8ca12f6681a
eliminated obsolete tags for types/consts -- now handled via name space, in strongly typed fashion;
wenzelm
parents:
33165
diff
changeset
|
1087 |
fun add_abbrev mode (b, raw_t) ctxt = |
19001 | 1088 |
let |
24675
2be1253a20d3
removed obsolete set_expand_abbrevs (superceded by mode_abbrev);
wenzelm
parents:
24612
diff
changeset
|
1089 |
val t0 = cert_term (ctxt |> set_mode mode_abbrev) raw_t |
42381
309ec68442c6
added Binding.print convenience, which includes quote already;
wenzelm
parents:
42379
diff
changeset
|
1090 |
handle ERROR msg => cat_error msg ("in constant abbreviation " ^ Binding.print b); |
20008
8d9d770e1f06
add_abbrevs/polymorphic: Variable.exportT_terms avoids over-generalization;
wenzelm
parents:
19916
diff
changeset
|
1091 |
val [t] = Variable.exportT_terms (Variable.declare_term t0 ctxt) ctxt [t0]; |
21807
a59f083632a7
add_abbrev: removed Assumption.add_assms (danger of inconsistent naming);
wenzelm
parents:
21803
diff
changeset
|
1092 |
val ((lhs, rhs), consts') = consts_of ctxt |
47005
421760a1efe7
maintain generic context naming in structure Name_Space (NB: empty = default_naming, init = local_naming);
wenzelm
parents:
47001
diff
changeset
|
1093 |
|> Consts.abbreviate (Context.Proof ctxt) (tsig_of ctxt) mode (b, t); |
19001 | 1094 |
in |
1095 |
ctxt |
|
25039 | 1096 |
|> (map_consts o apfst) (K consts') |
21803 | 1097 |
|> Variable.declare_term rhs |
1098 |
|> pair (lhs, rhs) |
|
21704 | 1099 |
end; |
19001 | 1100 |
|
25052 | 1101 |
fun revert_abbrev mode c = (map_consts o apfst) (Consts.revert_abbrev mode c); |
1102 |
||
47275 | 1103 |
fun generic_add_abbrev mode arg = |
1104 |
Context.mapping_result (Sign.add_abbrev mode arg) (add_abbrev mode arg); |
|
1105 |
||
1106 |
fun generic_revert_abbrev mode arg = |
|
1107 |
Context.mapping (Sign.revert_abbrev mode arg) (revert_abbrev mode arg); |
|
1108 |
||
19001 | 1109 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1110 |
(* fixes *) |
5819 | 1111 |
|
30763
6976521b4263
renamed ProofContext.add_fixes_i to ProofContext.add_fixes, eliminated obsolete external version;
wenzelm
parents:
30761
diff
changeset
|
1112 |
fun add_fixes raw_vars ctxt = |
8096 | 1113 |
let |
42491
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1114 |
val thy = theory_of ctxt; |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1115 |
val vars = #1 (cert_vars raw_vars ctxt); |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1116 |
in |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1117 |
ctxt |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1118 |
|> Variable.add_fixes_binding (map #1 vars) |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1119 |
|-> (fn xs => |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1120 |
fold_map declare_var (map2 (fn x => fn (_, T, mx) => (x, T, mx)) xs vars) |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1121 |
#-> (map_syntax o Local_Syntax.add_syntax thy o map (pair Local_Syntax.Fixed)) |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1122 |
#> pair xs) |
4bb5de0aae66
more precise position information via Variable.add_fixes_binding;
wenzelm
parents:
42488
diff
changeset
|
1123 |
end; |
5819 | 1124 |
|
9291
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1125 |
|
23705d14be8f
"_i" arguments now expected to have skolems already internalized;
wenzelm
parents:
9274
diff
changeset
|
1126 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1127 |
(** assumptions **) |
18187 | 1128 |
|
20209 | 1129 |
local |
1130 |
||
1131 |
fun gen_assms prepp exp args ctxt = |
|
1132 |
let |
|
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1133 |
val cert = Thm.cterm_of (theory_of ctxt); |
45327 | 1134 |
val ((propss, _), ctxt1) = prepp (map snd args) ctxt; |
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1135 |
val _ = Variable.warn_extra_tfrees ctxt ctxt1; |
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1136 |
val (premss, ctxt2) = fold_burrow (Assumption.add_assms exp o map cert) propss ctxt1; |
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1137 |
in |
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1138 |
ctxt2 |
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1139 |
|> auto_bind_facts (flat propss) |
33644
5266a72e0889
eliminated slightly odd (unused) "axiom" and "assumption" -- collapsed to unspecific "";
wenzelm
parents:
33537
diff
changeset
|
1140 |
|> note_thmss "" (map fst args ~~ map (map (fn th => ([th], []))) premss) |
20234
7e0693474bcd
added legacy_pretty_thm (with fall-back on ProtoPure.thy);
wenzelm
parents:
20209
diff
changeset
|
1141 |
end; |
20209 | 1142 |
|
1143 |
in |
|
1144 |
||
45327 | 1145 |
val add_assms = gen_assms bind_propp; |
1146 |
val add_assms_i = gen_assms bind_propp_i; |
|
20209 | 1147 |
|
1148 |
end; |
|
1149 |
||
1150 |
||
5819 | 1151 |
|
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1152 |
(** cases **) |
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1153 |
|
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1154 |
fun dest_cases ctxt = |
56025 | 1155 |
Name_Space.fold_table (fn (a, (c, i)) => cons (i, (a, c))) (cases_of ctxt) [] |
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1156 |
|> sort (int_ord o pairself #1) |> map #2; |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1157 |
|
16147 | 1158 |
local |
1159 |
||
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1160 |
fun update_case _ _ ("", _) res = res |
56025 | 1161 |
| update_case _ _ (name, NONE) (cases, index) = |
1162 |
(Name_Space.del_table name cases, index) |
|
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1163 |
| update_case context is_proper (name, SOME c) (cases, index) = |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1164 |
let |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1165 |
val (_, cases') = cases |> Name_Space.define context false |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1166 |
(Binding.make (name, Position.none), ((c, is_proper), index)); |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1167 |
val index' = index + 1; |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1168 |
in (cases', index') end; |
18609 | 1169 |
|
42501
2b8c34f53388
eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents:
42496
diff
changeset
|
1170 |
fun fix (b, T) ctxt = |
2b8c34f53388
eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents:
42496
diff
changeset
|
1171 |
let val ([x], ctxt') = add_fixes [(b, SOME T, NoSyn)] ctxt |
2b8c34f53388
eliminated slightly odd Proof_Context.bind_fixes;
wenzelm
parents:
42496
diff
changeset
|
1172 |
in (Free (x, T), ctxt') end; |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1173 |
|
16147 | 1174 |
in |
1175 |
||
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1176 |
fun update_cases is_proper args ctxt = |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1177 |
let |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1178 |
val context = Context.Proof ctxt |> Name_Space.map_naming (K Name_Space.default_naming); |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1179 |
val cases = cases_of ctxt; |
56025 | 1180 |
val index = Name_Space.fold_table (fn _ => Integer.add 1) cases 0; |
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1181 |
val (cases', _) = fold (update_case context is_proper) args (cases, index); |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1182 |
in map_cases (K cases') ctxt end; |
18609 | 1183 |
|
1184 |
fun case_result c ctxt = |
|
1185 |
let |
|
33368 | 1186 |
val Rule_Cases.Case {fixes, ...} = c; |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1187 |
val (ts, ctxt') = ctxt |> fold_map fix fixes; |
33368 | 1188 |
val Rule_Cases.Case {assumes, binds, cases, ...} = Rule_Cases.apply ts c; |
18609 | 1189 |
in |
1190 |
ctxt' |
|
30757
2d2076300185
replaced add_binds(_i) by bind_terms -- internal version only;
wenzelm
parents:
30723
diff
changeset
|
1191 |
|> bind_terms (map drop_schematic binds) |
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1192 |
|> update_cases true (map (apsnd SOME) cases) |
18609 | 1193 |
|> pair (assumes, (binds, cases)) |
1194 |
end; |
|
1195 |
||
1196 |
val apply_case = apfst fst oo case_result; |
|
1197 |
||
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1198 |
fun check_case ctxt (name, pos) fxs = |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1199 |
let |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1200 |
val (_, ((Rule_Cases.Case {fixes, assumes, binds, cases}, _), _)) = |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1201 |
Name_Space.check (Context.Proof ctxt) (cases_of ctxt) (name, pos); |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1202 |
|
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1203 |
fun replace (opt_x :: xs) ((y, T) :: ys) = (the_default y opt_x, T) :: replace xs ys |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1204 |
| replace [] ys = ys |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1205 |
| replace (_ :: _) [] = |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1206 |
error ("Too many parameters for case " ^ quote name ^ Position.here pos); |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1207 |
val fixes' = replace fxs fixes; |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1208 |
val binds' = map drop_schematic binds; |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1209 |
in |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1210 |
if null (fold (Term.add_tvarsT o snd) fixes []) andalso |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1211 |
null (fold (fold Term.add_vars o snd) assumes []) then |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1212 |
Rule_Cases.Case {fixes = fixes', assumes = assumes, binds = binds', cases = cases} |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1213 |
else error ("Illegal schematic variable(s) in case " ^ quote name ^ Position.here pos) |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1214 |
end; |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1215 |
|
16147 | 1216 |
end; |
8373
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1217 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1218 |
|
e7237c8fe29e
handling of local contexts: print_cases, get_case, add_cases;
wenzelm
parents:
8186
diff
changeset
|
1219 |
|
10810 | 1220 |
(** print context information **) |
1221 |
||
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1222 |
(* local syntax *) |
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1223 |
|
12093 | 1224 |
val print_syntax = Syntax.print_syntax o syn_of; |
12072
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1225 |
|
4281198fb8cd
local syntax: add_syntax, proper read/pretty functions;
wenzelm
parents:
12066
diff
changeset
|
1226 |
|
21728 | 1227 |
(* abbreviations *) |
18971 | 1228 |
|
21728 | 1229 |
fun pretty_abbrevs show_globals ctxt = |
18971 | 1230 |
let |
56025 | 1231 |
val space = const_space ctxt; |
1232 |
val (constants, globals) = |
|
45650 | 1233 |
pairself (#constants o Consts.dest) (#consts (rep_data ctxt)); |
21803 | 1234 |
fun add_abbr (_, (_, NONE)) = I |
25406 | 1235 |
| add_abbr (c, (T, SOME t)) = |
21728 | 1236 |
if not show_globals andalso Symtab.defined globals c then I |
1237 |
else cons (c, Logic.mk_equals (Const (c, T), t)); |
|
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42357
diff
changeset
|
1238 |
val abbrevs = |
56025 | 1239 |
Name_Space.extern_table' ctxt space (Symtab.make (Symtab.fold add_abbr constants [])); |
18971 | 1240 |
in |
35141 | 1241 |
if null abbrevs then [] |
21728 | 1242 |
else [Pretty.big_list "abbreviations:" (map (pretty_term_abbrev ctxt o #2) abbrevs)] |
18971 | 1243 |
end; |
1244 |
||
21728 | 1245 |
val print_abbrevs = Pretty.writeln o Pretty.chunks o pretty_abbrevs true; |
1246 |
||
18971 | 1247 |
|
10810 | 1248 |
(* term bindings *) |
1249 |
||
16540 | 1250 |
fun pretty_binds ctxt = |
10810 | 1251 |
let |
19897
fe661eb3b0e7
ProofContext: moved variable operations to struct Variable;
wenzelm
parents:
19882
diff
changeset
|
1252 |
val binds = Variable.binds_of ctxt; |
21728 | 1253 |
fun prt_bind (xi, (T, t)) = pretty_term_abbrev ctxt (Logic.mk_equals (Var (xi, T), t)); |
10810 | 1254 |
in |
35141 | 1255 |
if Vartab.is_empty binds then [] |
15758
07e382399a96
binds/thms: do not store options, but delete from table;
wenzelm
parents:
15750
diff
changeset
|
1256 |
else [Pretty.big_list "term bindings:" (map prt_bind (Vartab.dest binds))] |
10810 | 1257 |
end; |
1258 |
||
1259 |
val print_binds = Pretty.writeln o Pretty.chunks o pretty_binds; |
|
1260 |
||
1261 |
||
1262 |
(* local theorems *) |
|
1263 |
||
16540 | 1264 |
fun pretty_lthms ctxt = |
20012 | 1265 |
let |
26284 | 1266 |
val local_facts = facts_of ctxt; |
1267 |
val props = Facts.props local_facts; |
|
26673 | 1268 |
val facts = |
35141 | 1269 |
(if null props then [] else [("<unnamed>", props)]) @ |
28212 | 1270 |
Facts.dest_static [] local_facts; |
20012 | 1271 |
in |
35141 | 1272 |
if null facts then [] |
28212 | 1273 |
else [Pretty.big_list "facts:" (map #1 (sort_wrt (#1 o #2) (map (`(pretty_fact ctxt)) facts)))] |
20012 | 1274 |
end; |
10810 | 1275 |
|
12057 | 1276 |
val print_lthms = Pretty.writeln o Pretty.chunks o pretty_lthms; |
10810 | 1277 |
|
1278 |
||
1279 |
(* local contexts *) |
|
1280 |
||
26722 | 1281 |
local |
1282 |
||
1283 |
fun pretty_case (name, (fixes, ((asms, (lets, cs)), ctxt))) = |
|
10810 | 1284 |
let |
24922 | 1285 |
val prt_term = Syntax.pretty_term ctxt; |
12057 | 1286 |
|
10810 | 1287 |
fun prt_let (xi, t) = Pretty.block |
10818 | 1288 |
[Pretty.quote (prt_term (Var (xi, Term.fastype_of t))), Pretty.str " =", Pretty.brk 1, |
10810 | 1289 |
Pretty.quote (prt_term t)]; |
1290 |
||
53380
08f3491c50bf
cases: formal binding of 'assumes', with position provided via invoke_case;
wenzelm
parents:
53378
diff
changeset
|
1291 |
fun prt_asm (b, ts) = Pretty.block (Pretty.breaks |
08f3491c50bf
cases: formal binding of 'assumes', with position provided via invoke_case;
wenzelm
parents:
53378
diff
changeset
|
1292 |
((if Binding.is_empty b then [] |
08f3491c50bf
cases: formal binding of 'assumes', with position provided via invoke_case;
wenzelm
parents:
53378
diff
changeset
|
1293 |
else [Binding.pretty b, Pretty.str ":"]) @ map (Pretty.quote o prt_term) ts)); |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1294 |
|
10810 | 1295 |
fun prt_sect _ _ _ [] = [] |
35141 | 1296 |
| prt_sect s sep prt xs = |
1297 |
[Pretty.block (Pretty.breaks (Pretty.str s :: |
|
1298 |
flat (separate sep (map (single o prt) xs))))]; |
|
26722 | 1299 |
in |
1300 |
Pretty.block (Pretty.fbreaks |
|
10810 | 1301 |
(Pretty.str (name ^ ":") :: |
42496 | 1302 |
prt_sect "fix" [] (Pretty.str o Binding.name_of o fst) fixes @ |
10810 | 1303 |
prt_sect "let" [Pretty.str "and"] prt_let |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19422
diff
changeset
|
1304 |
(map_filter (fn (xi, SOME t) => SOME (xi, t) | _ => NONE) lets) @ |
13425
119ae829ad9b
support for split assumptions in cases (hyps vs. prems);
wenzelm
parents:
13415
diff
changeset
|
1305 |
(if forall (null o #2) asms then [] |
18609 | 1306 |
else prt_sect "assume" [Pretty.str "and"] prt_asm asms) @ |
26722 | 1307 |
prt_sect "subcases:" [] (Pretty.str o fst) cs)) |
1308 |
end; |
|
16540 | 1309 |
|
26722 | 1310 |
in |
1311 |
||
1312 |
fun pretty_cases ctxt = |
|
1313 |
let |
|
53378
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1314 |
fun mk_case (_, (_, false)) = NONE |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1315 |
| mk_case (name, (c as Rule_Cases.Case {fixes, ...}, true)) = |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1316 |
SOME (name, (fixes, case_result c ctxt)); |
07990ba8c0ea
cases: more position information and PIDE markup;
wenzelm
parents:
52223
diff
changeset
|
1317 |
val cases = dest_cases ctxt |> map_filter mk_case; |
10810 | 1318 |
in |
35141 | 1319 |
if null cases then [] |
26722 | 1320 |
else [Pretty.big_list "cases:" (map pretty_case cases)] |
10810 | 1321 |
end; |
1322 |
||
1323 |
val print_cases = Pretty.writeln o Pretty.chunks o pretty_cases; |
|
1324 |
||
26722 | 1325 |
end; |
1326 |
||
10810 | 1327 |
|
12057 | 1328 |
(* core context *) |
10810 | 1329 |
|
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1330 |
val debug = Config.bool (Config.declare "Proof_Context.debug" (K (Config.Bool false))); |
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1331 |
val verbose = Config.bool (Config.declare "Proof_Context.verbose" (K (Config.Bool false))); |
10810 | 1332 |
|
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1333 |
fun pretty_ctxt ctxt = |
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1334 |
if not (Config.get ctxt debug) then [] |
20310 | 1335 |
else |
1336 |
let |
|
24922 | 1337 |
val prt_term = Syntax.pretty_term ctxt; |
12057 | 1338 |
|
20310 | 1339 |
(*structures*) |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35412
diff
changeset
|
1340 |
val {structs, ...} = Local_Syntax.idents_of (syntax_of ctxt); |
35139 | 1341 |
val prt_structs = |
1342 |
if null structs then [] |
|
20310 | 1343 |
else [Pretty.block (Pretty.str "structures:" :: Pretty.brk 1 :: |
1344 |
Pretty.commas (map Pretty.str structs))]; |
|
12093 | 1345 |
|
20310 | 1346 |
(*fixes*) |
1347 |
fun prt_fix (x, x') = |
|
1348 |
if x = x' then Pretty.str x |
|
1349 |
else Pretty.block [Pretty.str x, Pretty.str " =", Pretty.brk 1, prt_term (Syntax.free x')]; |
|
1350 |
val fixes = |
|
55948 | 1351 |
filter_out ((Name.is_internal orf member (op =) structs) o #1) |
42488
4638622bcaa1
reorganized fixes as specialized (global) name space;
wenzelm
parents:
42469
diff
changeset
|
1352 |
(Variable.dest_fixes ctxt); |
35139 | 1353 |
val prt_fixes = |
1354 |
if null fixes then [] |
|
20310 | 1355 |
else [Pretty.block (Pretty.str "fixed variables:" :: Pretty.brk 1 :: |
1356 |
Pretty.commas (map prt_fix fixes))]; |
|
12057 | 1357 |
|
20310 | 1358 |
(*prems*) |
35139 | 1359 |
val prt_prems = |
51584 | 1360 |
(case Assumption.all_prems_of ctxt of |
1361 |
[] => [] |
|
51601 | 1362 |
| prems => [Pretty.big_list "prems:" [pretty_fact ctxt ("", prems)]]); |
20310 | 1363 |
in prt_structs @ prt_fixes @ prt_prems end; |
10810 | 1364 |
|
1365 |
||
1366 |
(* main context *) |
|
1367 |
||
16540 | 1368 |
fun pretty_context ctxt = |
10810 | 1369 |
let |
42717
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1370 |
val verbose = Config.get ctxt verbose; |
0bbb56867091
proper configuration options Proof_Context.debug and Proof_Context.verbose;
wenzelm
parents:
42502
diff
changeset
|
1371 |
fun verb f x = if verbose then f (x ()) else []; |
35141 | 1372 |
|
24922 | 1373 |
val prt_term = Syntax.pretty_term ctxt; |
1374 |
val prt_typ = Syntax.pretty_typ ctxt; |
|
1375 |
val prt_sort = Syntax.pretty_sort ctxt; |
|
10810 | 1376 |
|
1377 |
(*theory*) |
|
12057 | 1378 |
val pretty_thy = Pretty.block |
17384 | 1379 |
[Pretty.str "theory:", Pretty.brk 1, Context.pretty_thy (theory_of ctxt)]; |
10810 | 1380 |
|
1381 |
(*defaults*) |
|
1382 |
fun prt_atom prt prtT (x, X) = Pretty.block |
|
1383 |
[prt x, Pretty.str " ::", Pretty.brk 1, prtT X]; |
|
1384 |
||
1385 |
fun prt_var (x, ~1) = prt_term (Syntax.free x) |
|
1386 |
| prt_var xi = prt_term (Syntax.var xi); |
|
1387 |
||
1388 |
fun prt_varT (x, ~1) = prt_typ (TFree (x, [])) |
|
1389 |
| prt_varT xi = prt_typ (TVar (xi, [])); |
|
1390 |
||
1391 |
val prt_defT = prt_atom prt_var prt_typ; |
|
1392 |
val prt_defS = prt_atom prt_varT prt_sort; |
|
16540 | 1393 |
|
20163 | 1394 |
val (types, sorts) = Variable.constraints_of ctxt; |
10810 | 1395 |
in |
18609 | 1396 |
verb single (K pretty_thy) @ |
18672
ac1a048ca7dd
uniform handling of fixes: read/cert_vars, add_fixes(_i), body flag;
wenzelm
parents:
18619
diff
changeset
|
1397 |
pretty_ctxt ctxt @ |
21728 | 1398 |
verb (pretty_abbrevs false) (K ctxt) @ |
10810 | 1399 |
verb pretty_binds (K ctxt) @ |
12057 | 1400 |
verb pretty_lthms (K ctxt) @ |
10810 | 1401 |
verb pretty_cases (K ctxt) @ |
18609 | 1402 |
verb single (fn () => Pretty.big_list "type constraints:" (map prt_defT (Vartab.dest types))) @ |
20163 | 1403 |
verb single (fn () => Pretty.big_list "default sorts:" (map prt_defS (Vartab.dest sorts))) |
10810 | 1404 |
end; |
1405 |
||
5819 | 1406 |
end; |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35412
diff
changeset
|
1407 |
|
42360 | 1408 |
val show_abbrevs = Proof_Context.show_abbrevs; |
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
39557
diff
changeset
|
1409 |