author | haftmann |
Sat, 19 Jul 2025 18:41:55 +0200 | |
changeset 82886 | 8d1e295aab70 |
parent 82582 | bcee022fbe30 |
permissions | -rw-r--r-- |
5831 | 1 |
(* Title: Pure/Isar/isar_cmd.ML |
80750 | 2 |
Author: Makarius |
5831 | 3 |
|
30805 | 4 |
Miscellaneous Isar commands. |
5831 | 5 |
*) |
6 |
||
7 |
signature ISAR_CMD = |
|
8 |
sig |
|
59930 | 9 |
val setup: Input.source -> theory -> theory |
59064 | 10 |
val local_setup: Input.source -> Proof.context -> Proof.context |
11 |
val parse_ast_translation: Input.source -> theory -> theory |
|
12 |
val parse_translation: Input.source -> theory -> theory |
|
13 |
val print_translation: Input.source -> theory -> theory |
|
14 |
val typed_print_translation: Input.source -> theory -> theory |
|
15 |
val print_ast_translation: Input.source -> theory -> theory |
|
81590 | 16 |
val translations: bool -> (string * string) Syntax.trrule list -> theory -> theory |
80752 | 17 |
val syntax_consts: ((string * Position.T) list * (xstring * Position.T) list) list -> |
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
18 |
local_theory -> local_theory |
80752 | 19 |
val syntax_types: ((string * Position.T) list * (xstring * Position.T) list) list -> |
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
20 |
local_theory -> local_theory |
59064 | 21 |
val oracle: bstring * Position.range -> Input.source -> theory -> theory |
22 |
val declaration: {syntax: bool, pervasive: bool} -> Input.source -> local_theory -> local_theory |
|
49889
00ea087e83d8
more method position information, notably finished_pos after end of previous text;
wenzelm
parents:
49866
diff
changeset
|
23 |
val qed: Method.text_range option -> Toplevel.transition -> Toplevel.transition |
00ea087e83d8
more method position information, notably finished_pos after end of previous text;
wenzelm
parents:
49866
diff
changeset
|
24 |
val terminal_proof: Method.text_range * Method.text_range option -> |
21350 | 25 |
Toplevel.transition -> Toplevel.transition |
26 |
val default_proof: Toplevel.transition -> Toplevel.transition |
|
27 |
val immediate_proof: Toplevel.transition -> Toplevel.transition |
|
28 |
val done_proof: Toplevel.transition -> Toplevel.transition |
|
29 |
val skip_proof: Toplevel.transition -> Toplevel.transition |
|
59064 | 30 |
val ml_diag: bool -> Input.source -> Toplevel.transition -> Toplevel.transition |
48776
37cd53e69840
faster compilation of ML with antiquotations: static ML_context is bound once in auxiliary structure Isabelle;
wenzelm
parents:
47815
diff
changeset
|
31 |
val diag_state: Proof.context -> Toplevel.state |
37cd53e69840
faster compilation of ML with antiquotations: static ML_context is bound once in auxiliary structure Isabelle;
wenzelm
parents:
47815
diff
changeset
|
32 |
val diag_goal: Proof.context -> {context: Proof.context, facts: thm list, goal: thm} |
57605 | 33 |
val pretty_theorems: bool -> Toplevel.state -> Pretty.T list |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57934
diff
changeset
|
34 |
val print_stmts: string list * (Facts.ref * Token.src list) list |
19268 | 35 |
-> Toplevel.transition -> Toplevel.transition |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57934
diff
changeset
|
36 |
val print_thms: string list * (Facts.ref * Token.src list) list |
10581 | 37 |
-> Toplevel.transition -> Toplevel.transition |
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57934
diff
changeset
|
38 |
val print_prfs: bool -> string list * (Facts.ref * Token.src list) list option |
11524
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11017
diff
changeset
|
39 |
-> Toplevel.transition -> Toplevel.transition |
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12758
diff
changeset
|
40 |
val print_prop: (string list * string) -> Toplevel.transition -> Toplevel.transition |
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12758
diff
changeset
|
41 |
val print_term: (string list * string) -> Toplevel.transition -> Toplevel.transition |
48792 | 42 |
val print_type: (string list * (string * string option)) -> |
43 |
Toplevel.transition -> Toplevel.transition |
|
5831 | 44 |
end; |
45 |
||
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
37198
diff
changeset
|
46 |
structure Isar_Cmd: ISAR_CMD = |
5831 | 47 |
struct |
48 |
||
49 |
||
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
50 |
(** theory declarations **) |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
51 |
|
30461 | 52 |
(* generic setup *) |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
53 |
|
59930 | 54 |
fun setup source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
55 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
56 |
(ML_Lex.read "Theory.setup (" @ ML_Lex.read_source source @ ML_Lex.read ")") |
26435 | 57 |
|> Context.theory_map; |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
58 |
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
59 |
fun local_setup source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
60 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
61 |
(ML_Lex.read "Theory.local_setup (" @ ML_Lex.read_source source @ ML_Lex.read ")") |
30461 | 62 |
|> Context.proof_map; |
63 |
||
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
64 |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
65 |
(* translation functions *) |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
66 |
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
67 |
fun parse_ast_translation source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
68 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
69 |
(ML_Lex.read "Theory.setup (Sign.parse_ast_translation (" @ |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
70 |
ML_Lex.read_source source @ ML_Lex.read "))") |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
71 |
|> Context.theory_map; |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
72 |
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
73 |
fun parse_translation source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
74 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
75 |
(ML_Lex.read "Theory.setup (Sign.parse_translation (" @ |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
76 |
ML_Lex.read_source source @ ML_Lex.read "))") |
52143 | 77 |
|> Context.theory_map; |
78 |
||
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
79 |
fun print_translation source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
80 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
81 |
(ML_Lex.read "Theory.setup (Sign.print_translation (" @ |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
82 |
ML_Lex.read_source source @ ML_Lex.read "))") |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
83 |
|> Context.theory_map; |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
84 |
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
85 |
fun typed_print_translation source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
86 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
87 |
(ML_Lex.read "Theory.setup (Sign.typed_print_translation (" @ |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
88 |
ML_Lex.read_source source @ ML_Lex.read "))") |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
89 |
|> Context.theory_map; |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
90 |
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
91 |
fun print_ast_translation source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
92 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
93 |
(ML_Lex.read "Theory.setup (Sign.print_ast_translation (" @ |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
94 |
ML_Lex.read_source source @ ML_Lex.read "))") |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
95 |
|> Context.theory_map; |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
96 |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
97 |
|
42204 | 98 |
(* translation rules *) |
99 |
||
81590 | 100 |
fun translations add raw_rules thy = |
101 |
let |
|
102 |
val thy_ctxt = Proof_Context.init_global thy; |
|
103 |
val rules = map (Syntax.parse_trrule thy_ctxt) raw_rules; |
|
104 |
in Sign.translations_global add rules thy end; |
|
42204 | 105 |
|
106 |
||
80750 | 107 |
(* syntax consts/types (after translation) *) |
108 |
||
109 |
local |
|
110 |
||
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
111 |
fun syntax_deps_cmd f args lthy = |
80750 | 112 |
let |
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
113 |
val check_lhs = Proof_Context.check_syntax_const lthy; |
80750 | 114 |
fun check_rhs (b: xstring, pos: Position.T) = |
115 |
let |
|
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
116 |
val (c: string, reports) = f lthy (b, pos); |
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
117 |
val _ = Context_Position.reports lthy reports; |
80750 | 118 |
in c end; |
80752 | 119 |
|
120 |
fun check (raw_lhs, raw_rhs) = |
|
121 |
let |
|
122 |
val lhs = map check_lhs raw_lhs; |
|
123 |
val rhs = map check_rhs raw_rhs; |
|
124 |
in map (fn l => (l, rhs)) lhs end; |
|
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
125 |
in Local_Theory.syntax_deps (maps check args) lthy end; |
80750 | 126 |
|
127 |
fun check_const ctxt (s, pos) = |
|
80759
4641f0fdaa59
proper flags (amending 1319c729c65d): abbrevs are allowed, free variables are disallowed;
wenzelm
parents:
80752
diff
changeset
|
128 |
Proof_Context.check_const {proper = true, strict = false} ctxt (s, [pos]) |
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
129 |
|>> (Term.dest_Const_name #> Lexicon.mark_const #> tap (Sign.check_syntax_dep ctxt)); |
80750 | 130 |
|
131 |
fun check_type_name ctxt arg = |
|
80759
4641f0fdaa59
proper flags (amending 1319c729c65d): abbrevs are allowed, free variables are disallowed;
wenzelm
parents:
80752
diff
changeset
|
132 |
Proof_Context.check_type_name {proper = true, strict = false} ctxt arg |
81594
7e1b66416b7f
commands 'syntax_types' and 'syntax_consts' now work in a local theory context;
wenzelm
parents:
81590
diff
changeset
|
133 |
|>> (Term.dest_Type_name #> Lexicon.mark_type #> tap (Sign.check_syntax_dep ctxt)); |
80750 | 134 |
|
135 |
in |
|
136 |
||
137 |
val syntax_consts = syntax_deps_cmd check_const; |
|
138 |
val syntax_types = syntax_deps_cmd check_type_name; |
|
139 |
||
140 |
end; |
|
141 |
||
142 |
||
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
143 |
(* oracles *) |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
144 |
|
59029
c907cbe36713
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58991
diff
changeset
|
145 |
fun oracle (name, range) source = |
69263 | 146 |
ML_Context.expression (Input.pos_of source) |
147 |
(ML_Lex.read "val " @ |
|
73549
a2c589d5e1e4
clarified signature: more detailed token positions for antiquotations;
wenzelm
parents:
70839
diff
changeset
|
148 |
ML_Lex.read_range range name @ |
69263 | 149 |
ML_Lex.read |
78795
f7e972d567f3
clarified signature: more concise variations on implicit theory setup;
wenzelm
parents:
78792
diff
changeset
|
150 |
(" = snd (Theory.setup_result (Thm.add_oracle (" ^ |
69263 | 151 |
ML_Syntax.make_binding (name, #1 range) ^ ", ") @ |
78795
f7e972d567f3
clarified signature: more concise variations on implicit theory setup;
wenzelm
parents:
78792
diff
changeset
|
152 |
ML_Lex.read_source source @ ML_Lex.read ")))") |
69263 | 153 |
|> Context.theory_map; |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
154 |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
155 |
|
22087 | 156 |
(* declarations *) |
157 |
||
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
158 |
fun declaration {syntax, pervasive} source = |
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
159 |
ML_Context.expression (Input.pos_of source) |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
160 |
(ML_Lex.read |
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
161 |
("Theory.local_setup (Local_Theory.declaration {syntax = " ^ |
78095 | 162 |
Bool.toString syntax ^ ", pervasive = " ^ Bool.toString pervasive ^ |
163 |
", pos = " ^ ML_Syntax.print_position (Position.thread_data ()) ^ "} (") @ |
|
69216
1a52baa70aed
clarified ML_Context.expression: it is a closed expression, not a let-declaration -- thus source positions are more accurate (amending d8849cfad60f, 162a4c2e97bc);
wenzelm
parents:
69187
diff
changeset
|
164 |
ML_Lex.read_source source @ ML_Lex.read "))") |
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26336
diff
changeset
|
165 |
|> Context.proof_map; |
22087 | 166 |
|
167 |
||
21350 | 168 |
(* local endings *) |
169 |
||
29383 | 170 |
fun local_qed m = Toplevel.proof (Proof.local_qed (m, true)); |
60403 | 171 |
val local_terminal_proof = Toplevel.proof o Proof.local_future_terminal_proof; |
29383 | 172 |
val local_default_proof = Toplevel.proof Proof.local_default_proof; |
173 |
val local_immediate_proof = Toplevel.proof Proof.local_immediate_proof; |
|
174 |
val local_done_proof = Toplevel.proof Proof.local_done_proof; |
|
175 |
val local_skip_proof = Toplevel.proof' Proof.local_skip_proof; |
|
21350 | 176 |
|
177 |
||
178 |
(* global endings *) |
|
179 |
||
180 |
fun global_qed m = Toplevel.end_proof (K (Proof.global_qed (m, true))); |
|
60403 | 181 |
val global_terminal_proof = Toplevel.end_proof o K o Proof.global_future_terminal_proof; |
21350 | 182 |
val global_default_proof = Toplevel.end_proof (K Proof.global_default_proof); |
183 |
val global_immediate_proof = Toplevel.end_proof (K Proof.global_immediate_proof); |
|
184 |
val global_skip_proof = Toplevel.end_proof Proof.global_skip_proof; |
|
185 |
val global_done_proof = Toplevel.end_proof (K Proof.global_done_proof); |
|
186 |
||
187 |
||
188 |
(* common endings *) |
|
189 |
||
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60405
diff
changeset
|
190 |
fun qed m = local_qed m o global_qed m; |
21350 | 191 |
fun terminal_proof m = local_terminal_proof m o global_terminal_proof m; |
192 |
val default_proof = local_default_proof o global_default_proof; |
|
193 |
val immediate_proof = local_immediate_proof o global_immediate_proof; |
|
194 |
val done_proof = local_done_proof o global_done_proof; |
|
195 |
val skip_proof = local_skip_proof o global_skip_proof; |
|
196 |
||
197 |
||
26489 | 198 |
(* diagnostic ML evaluation *) |
5831 | 199 |
|
37305
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
200 |
structure Diag_State = Proof_Data |
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
201 |
( |
69883 | 202 |
type T = Toplevel.state option; |
203 |
fun init _ = NONE; |
|
37305
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
204 |
); |
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
205 |
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
206 |
fun ml_diag verbose source = Toplevel.keep (fn state => |
56304
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
wenzelm
parents:
56278
diff
changeset
|
207 |
let |
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
wenzelm
parents:
56278
diff
changeset
|
208 |
val opt_ctxt = |
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
wenzelm
parents:
56278
diff
changeset
|
209 |
try Toplevel.generic_theory_of state |
69883 | 210 |
|> Option.map (Context.proof_of #> Diag_State.put (SOME state)); |
56304
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
wenzelm
parents:
56278
diff
changeset
|
211 |
val flags = ML_Compiler.verbose verbose ML_Compiler.flags; |
40274e4f5ebf
redirect ML_Compiler reports more directly: only the (big) parse tree report is deferred via Execution.print (NB: this does not work for asynchronous "diag" commands);
wenzelm
parents:
56278
diff
changeset
|
212 |
in ML_Context.eval_source_in opt_ctxt flags source end); |
37305
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
213 |
|
69883 | 214 |
fun diag_state ctxt = |
215 |
(case Diag_State.get ctxt of |
|
216 |
SOME st => st |
|
76415 | 217 |
| NONE => Toplevel.make_state NONE); |
69883 | 218 |
|
60094 | 219 |
val diag_goal = Proof.goal o Toplevel.proof_of o diag_state; |
37305
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
220 |
|
53171 | 221 |
val _ = Theory.setup |
67147 | 222 |
(ML_Antiquotation.value (Binding.qualify true "Isar" \<^binding>\<open>state\<close>) |
53171 | 223 |
(Scan.succeed "Isar_Cmd.diag_state ML_context") #> |
67147 | 224 |
ML_Antiquotation.value (Binding.qualify true "Isar" \<^binding>\<open>goal\<close>) |
53171 | 225 |
(Scan.succeed "Isar_Cmd.diag_goal ML_context")); |
5831 | 226 |
|
227 |
||
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
228 |
(* theorems of theory or proof context *) |
17066 | 229 |
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
230 |
fun pretty_theorems verbose st = |
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
231 |
if Toplevel.is_proof st then |
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59210
diff
changeset
|
232 |
Proof_Context.pretty_local_facts verbose (Toplevel.context_of st) |
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
233 |
else |
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
234 |
let |
61266 | 235 |
val ctxt = Toplevel.context_of st; |
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
236 |
val prev_thys = |
67391 | 237 |
(case Toplevel.previous_theory_of st of |
238 |
SOME thy => [thy] |
|
61266 | 239 |
| NONE => Theory.parents_of (Proof_Context.theory_of ctxt)); |
240 |
in Proof_Display.pretty_theorems_diff verbose prev_thys ctxt end; |
|
9513 | 241 |
|
12060 | 242 |
|
19268 | 243 |
(* print theorems, terms, types etc. *) |
244 |
||
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
245 |
local |
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
246 |
|
82582 | 247 |
fun pretty_stmts ctxt args = |
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
248 |
Attrib.eval_thms ctxt args |
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
249 |
|> map (Element.pretty_statement ctxt Thm.theoremK) |
82582 | 250 |
|> Pretty.chunks2; |
5880 | 251 |
|
82582 | 252 |
fun pretty_thms ctxt args = |
253 |
Proof_Context.pretty_fact ctxt ("", Attrib.eval_thms ctxt args); |
|
5895 | 254 |
|
82582 | 255 |
fun pretty_prfs full state arg = |
256 |
(case arg of |
|
257 |
NONE => |
|
258 |
let |
|
259 |
val {context = ctxt, goal = thm} = Proof.simple_goal (Toplevel.proof_of state); |
|
260 |
val thy = Proof_Context.theory_of ctxt; |
|
261 |
val prf = Thm.proof_of thm; |
|
262 |
val prop = Thm.full_prop_of thm; |
|
263 |
val prf' = Proofterm.rewrite_proof_notypes ([], []) prf; |
|
264 |
in |
|
265 |
Proof_Syntax.pretty_proof ctxt |
|
266 |
(if full then Proofterm.reconstruct_proof thy prop prf' else prf') |
|
267 |
end |
|
268 |
| SOME srcs => |
|
269 |
let |
|
270 |
val ctxt = Toplevel.context_of state; |
|
271 |
val pretty_proof = Proof_Syntax.pretty_standard_proof_of ctxt full; |
|
272 |
in Pretty.chunks (map pretty_proof (Attrib.eval_thms ctxt srcs)) end); |
|
11524
197f2e14a714
Added functions for printing primitive proof terms.
berghofe
parents:
11017
diff
changeset
|
273 |
|
82582 | 274 |
fun pretty_prop ctxt s = |
5831 | 275 |
let |
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24314
diff
changeset
|
276 |
val prop = Syntax.read_prop ctxt s; |
70308 | 277 |
val ctxt' = Proof_Context.augment prop ctxt; |
82582 | 278 |
in Pretty.quote (Syntax.pretty_term ctxt' prop) end; |
5831 | 279 |
|
82582 | 280 |
fun pretty_term ctxt s = |
5831 | 281 |
let |
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24314
diff
changeset
|
282 |
val t = Syntax.read_term ctxt s; |
5831 | 283 |
val T = Term.type_of t; |
70308 | 284 |
val ctxt' = Proof_Context.augment t ctxt; |
5831 | 285 |
in |
82582 | 286 |
Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t), Pretty.fbrk, |
287 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' T)] |
|
9128 | 288 |
end; |
5831 | 289 |
|
82582 | 290 |
fun pretty_type ctxt (s, NONE) = |
48792 | 291 |
let val T = Syntax.read_typ ctxt s |
82582 | 292 |
in Pretty.quote (Syntax.pretty_typ ctxt T) end |
293 |
| pretty_type ctxt (s1, SOME s2) = |
|
48792 | 294 |
let |
295 |
val ctxt' = Config.put show_sorts true ctxt; |
|
296 |
val raw_T = Syntax.parse_typ ctxt' s1; |
|
297 |
val S = Syntax.read_sort ctxt' s2; |
|
298 |
val T = |
|
299 |
Syntax.check_term ctxt' |
|
300 |
(Logic.mk_type raw_T |> Type.constraint (Term.itselfT (Type_Infer.anyT S))) |
|
301 |
|> Logic.dest_type; |
|
82582 | 302 |
in Pretty.quote (Syntax.pretty_typ ctxt' T) end; |
9128 | 303 |
|
82582 | 304 |
fun print_item pretty (modes, arg) = Toplevel.keep (fn state => |
305 |
Print_Mode.with_modes modes (fn () => Pretty.writeln (pretty state arg)) ()); |
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
306 |
|
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
307 |
in |
9128 | 308 |
|
82582 | 309 |
val print_stmts = print_item (pretty_stmts o Toplevel.context_of); |
310 |
val print_thms = print_item (pretty_thms o Toplevel.context_of); |
|
311 |
val print_prfs = print_item o pretty_prfs; |
|
312 |
val print_prop = print_item (pretty_prop o Toplevel.context_of); |
|
313 |
val print_term = print_item (pretty_term o Toplevel.context_of); |
|
314 |
val print_type = print_item (pretty_type o Toplevel.context_of); |
|
5831 | 315 |
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
316 |
end; |
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
317 |
|
5831 | 318 |
end; |