author | wenzelm |
Sat, 14 Dec 2024 17:35:53 +0100 | |
changeset 81590 | e656c5edc352 |
parent 81589 | fcf44ef51057 |
child 81594 | 7e1b66416b7f |
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 -> |
18 |
theory -> theory |
|
19 |
val syntax_types: ((string * Position.T) list * (xstring * Position.T) list) list -> |
|
20 |
theory -> 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 |
||
111 |
fun syntax_deps_cmd f args thy = |
|
112 |
let |
|
113 |
val ctxt = Proof_Context.init_global thy; |
|
80752 | 114 |
|
115 |
val check_lhs = Proof_Context.check_syntax_const ctxt; |
|
80750 | 116 |
fun check_rhs (b: xstring, pos: Position.T) = |
117 |
let |
|
80752 | 118 |
val (c: string, reports) = f ctxt (b, pos); |
80750 | 119 |
val _ = Context_Position.reports ctxt reports; |
120 |
in c end; |
|
80752 | 121 |
|
122 |
fun check (raw_lhs, raw_rhs) = |
|
123 |
let |
|
124 |
val lhs = map check_lhs raw_lhs; |
|
125 |
val rhs = map check_rhs raw_rhs; |
|
126 |
in map (fn l => (l, rhs)) lhs end; |
|
127 |
in Sign.syntax_deps (maps check args) thy end; |
|
80750 | 128 |
|
129 |
fun check_const ctxt (s, pos) = |
|
80759
4641f0fdaa59
proper flags (amending 1319c729c65d): abbrevs are allowed, free variables are disallowed;
wenzelm
parents:
80752
diff
changeset
|
130 |
Proof_Context.check_const {proper = true, strict = false} ctxt (s, [pos]) |
80750 | 131 |
|>> (Term.dest_Const_name #> Lexicon.mark_const); |
132 |
||
133 |
fun check_type_name ctxt arg = |
|
80759
4641f0fdaa59
proper flags (amending 1319c729c65d): abbrevs are allowed, free variables are disallowed;
wenzelm
parents:
80752
diff
changeset
|
134 |
Proof_Context.check_type_name {proper = true, strict = false} ctxt arg |
80750 | 135 |
|>> (Term.dest_Type_name #> Lexicon.mark_type); |
136 |
||
137 |
in |
|
138 |
||
139 |
val syntax_consts = syntax_deps_cmd check_const; |
|
140 |
val syntax_types = syntax_deps_cmd check_type_name; |
|
141 |
||
142 |
end; |
|
143 |
||
144 |
||
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
145 |
(* oracles *) |
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
146 |
|
59029
c907cbe36713
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58991
diff
changeset
|
147 |
fun oracle (name, range) source = |
69263 | 148 |
ML_Context.expression (Input.pos_of source) |
149 |
(ML_Lex.read "val " @ |
|
73549
a2c589d5e1e4
clarified signature: more detailed token positions for antiquotations;
wenzelm
parents:
70839
diff
changeset
|
150 |
ML_Lex.read_range range name @ |
69263 | 151 |
ML_Lex.read |
78795
f7e972d567f3
clarified signature: more concise variations on implicit theory setup;
wenzelm
parents:
78792
diff
changeset
|
152 |
(" = snd (Theory.setup_result (Thm.add_oracle (" ^ |
69263 | 153 |
ML_Syntax.make_binding (name, #1 range) ^ ", ") @ |
78795
f7e972d567f3
clarified signature: more concise variations on implicit theory setup;
wenzelm
parents:
78792
diff
changeset
|
154 |
ML_Lex.read_source source @ ML_Lex.read ")))") |
69263 | 155 |
|> Context.theory_map; |
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
156 |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
157 |
|
22087 | 158 |
(* declarations *) |
159 |
||
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
160 |
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
|
161 |
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
|
162 |
(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
|
163 |
("Theory.local_setup (Local_Theory.declaration {syntax = " ^ |
78095 | 164 |
Bool.toString syntax ^ ", pervasive = " ^ Bool.toString pervasive ^ |
165 |
", 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
|
166 |
ML_Lex.read_source source @ ML_Lex.read "))") |
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26336
diff
changeset
|
167 |
|> Context.proof_map; |
22087 | 168 |
|
169 |
||
21350 | 170 |
(* local endings *) |
171 |
||
29383 | 172 |
fun local_qed m = Toplevel.proof (Proof.local_qed (m, true)); |
60403 | 173 |
val local_terminal_proof = Toplevel.proof o Proof.local_future_terminal_proof; |
29383 | 174 |
val local_default_proof = Toplevel.proof Proof.local_default_proof; |
175 |
val local_immediate_proof = Toplevel.proof Proof.local_immediate_proof; |
|
176 |
val local_done_proof = Toplevel.proof Proof.local_done_proof; |
|
177 |
val local_skip_proof = Toplevel.proof' Proof.local_skip_proof; |
|
21350 | 178 |
|
179 |
||
180 |
(* global endings *) |
|
181 |
||
182 |
fun global_qed m = Toplevel.end_proof (K (Proof.global_qed (m, true))); |
|
60403 | 183 |
val global_terminal_proof = Toplevel.end_proof o K o Proof.global_future_terminal_proof; |
21350 | 184 |
val global_default_proof = Toplevel.end_proof (K Proof.global_default_proof); |
185 |
val global_immediate_proof = Toplevel.end_proof (K Proof.global_immediate_proof); |
|
186 |
val global_skip_proof = Toplevel.end_proof Proof.global_skip_proof; |
|
187 |
val global_done_proof = Toplevel.end_proof (K Proof.global_done_proof); |
|
188 |
||
189 |
||
190 |
(* common endings *) |
|
191 |
||
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60405
diff
changeset
|
192 |
fun qed m = local_qed m o global_qed m; |
21350 | 193 |
fun terminal_proof m = local_terminal_proof m o global_terminal_proof m; |
194 |
val default_proof = local_default_proof o global_default_proof; |
|
195 |
val immediate_proof = local_immediate_proof o global_immediate_proof; |
|
196 |
val done_proof = local_done_proof o global_done_proof; |
|
197 |
val skip_proof = local_skip_proof o global_skip_proof; |
|
198 |
||
199 |
||
26489 | 200 |
(* diagnostic ML evaluation *) |
5831 | 201 |
|
37305
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
202 |
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
|
203 |
( |
69883 | 204 |
type T = Toplevel.state option; |
205 |
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
|
206 |
); |
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
207 |
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
208 |
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
|
209 |
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
|
210 |
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
|
211 |
try Toplevel.generic_theory_of state |
69883 | 212 |
|> 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
|
213 |
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
|
214 |
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
|
215 |
|
69883 | 216 |
fun diag_state ctxt = |
217 |
(case Diag_State.get ctxt of |
|
218 |
SOME st => st |
|
76415 | 219 |
| NONE => Toplevel.make_state NONE); |
69883 | 220 |
|
60094 | 221 |
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
|
222 |
|
53171 | 223 |
val _ = Theory.setup |
67147 | 224 |
(ML_Antiquotation.value (Binding.qualify true "Isar" \<^binding>\<open>state\<close>) |
53171 | 225 |
(Scan.succeed "Isar_Cmd.diag_state ML_context") #> |
67147 | 226 |
ML_Antiquotation.value (Binding.qualify true "Isar" \<^binding>\<open>goal\<close>) |
53171 | 227 |
(Scan.succeed "Isar_Cmd.diag_goal ML_context")); |
5831 | 228 |
|
229 |
||
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
230 |
(* theorems of theory or proof context *) |
17066 | 231 |
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
232 |
fun pretty_theorems verbose st = |
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
233 |
if Toplevel.is_proof st then |
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59210
diff
changeset
|
234 |
Proof_Context.pretty_local_facts verbose (Toplevel.context_of st) |
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
235 |
else |
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
236 |
let |
61266 | 237 |
val ctxt = Toplevel.context_of st; |
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
238 |
val prev_thys = |
67391 | 239 |
(case Toplevel.previous_theory_of st of |
240 |
SOME thy => [thy] |
|
61266 | 241 |
| NONE => Theory.parents_of (Proof_Context.theory_of ctxt)); |
242 |
in Proof_Display.pretty_theorems_diff verbose prev_thys ctxt end; |
|
9513 | 243 |
|
12060 | 244 |
|
19268 | 245 |
(* print theorems, terms, types etc. *) |
246 |
||
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
247 |
local |
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
248 |
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
249 |
fun string_of_stmts ctxt args = |
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
250 |
Attrib.eval_thms ctxt args |
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
251 |
|> map (Element.pretty_statement ctxt Thm.theoremK) |
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
252 |
|> Pretty.chunks2 |> Pretty.string_of; |
5880 | 253 |
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
254 |
fun string_of_thms ctxt args = |
51583 | 255 |
Pretty.string_of (Proof_Context.pretty_fact ctxt ("", Attrib.eval_thms ctxt args)); |
5895 | 256 |
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
257 |
fun string_of_prfs full state arg = |
32859
204f749f35a9
replaced Proof.get_goal state by Proof.flat_goal state, which provides the standard view on goals for (semi)automated tools;
wenzelm
parents:
32804
diff
changeset
|
258 |
Pretty.string_of |
204f749f35a9
replaced Proof.get_goal state by Proof.flat_goal state, which provides the standard view on goals for (semi)automated tools;
wenzelm
parents:
32804
diff
changeset
|
259 |
(case arg of |
15531 | 260 |
NONE => |
12125
316d11f760f7
Commands prf and full_prf can now also be used to display proof term
berghofe
parents:
12069
diff
changeset
|
261 |
let |
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
262 |
val {context = ctxt, goal = thm} = Proof.simple_goal (Toplevel.proof_of state); |
70449 | 263 |
val thy = Proof_Context.theory_of ctxt; |
28814 | 264 |
val prf = Thm.proof_of thm; |
17066 | 265 |
val prop = Thm.full_prop_of thm; |
32859
204f749f35a9
replaced Proof.get_goal state by Proof.flat_goal state, which provides the standard view on goals for (semi)automated tools;
wenzelm
parents:
32804
diff
changeset
|
266 |
val prf' = Proofterm.rewrite_proof_notypes ([], []) prf; |
12125
316d11f760f7
Commands prf and full_prf can now also be used to display proof term
berghofe
parents:
12069
diff
changeset
|
267 |
in |
33388 | 268 |
Proof_Syntax.pretty_proof ctxt |
70449 | 269 |
(if full then Proofterm.reconstruct_proof thy prop prf' else prf') |
12125
316d11f760f7
Commands prf and full_prf can now also be used to display proof term
berghofe
parents:
12069
diff
changeset
|
270 |
end |
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
271 |
| SOME srcs => |
63624
994d1a1105ef
more informative 'prf' and 'full_prf', based on HOL/Proofs/ex/XML_Data.thy;
wenzelm
parents:
62922
diff
changeset
|
272 |
let |
994d1a1105ef
more informative 'prf' and 'full_prf', based on HOL/Proofs/ex/XML_Data.thy;
wenzelm
parents:
62922
diff
changeset
|
273 |
val ctxt = Toplevel.context_of state; |
70839
2136e4670ad2
clarified standard_proof_of: prefer expand_proof over somewhat adhoc strip_thm_proof;
wenzelm
parents:
70449
diff
changeset
|
274 |
val pretty_proof = Proof_Syntax.pretty_standard_proof_of ctxt full; |
63624
994d1a1105ef
more informative 'prf' and 'full_prf', based on HOL/Proofs/ex/XML_Data.thy;
wenzelm
parents:
62922
diff
changeset
|
275 |
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
|
276 |
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
277 |
fun string_of_prop ctxt s = |
5831 | 278 |
let |
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24314
diff
changeset
|
279 |
val prop = Syntax.read_prop ctxt s; |
70308 | 280 |
val ctxt' = Proof_Context.augment prop ctxt; |
26704
51ee753cc2e3
token translations: context dependent, result Pretty.T;
wenzelm
parents:
26694
diff
changeset
|
281 |
in Pretty.string_of (Pretty.quote (Syntax.pretty_term ctxt' prop)) end; |
5831 | 282 |
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
283 |
fun string_of_term ctxt s = |
5831 | 284 |
let |
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24314
diff
changeset
|
285 |
val t = Syntax.read_term ctxt s; |
5831 | 286 |
val T = Term.type_of t; |
70308 | 287 |
val ctxt' = Proof_Context.augment t ctxt; |
5831 | 288 |
in |
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
289 |
Pretty.string_of |
26704
51ee753cc2e3
token translations: context dependent, result Pretty.T;
wenzelm
parents:
26694
diff
changeset
|
290 |
(Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t), Pretty.fbrk, |
51ee753cc2e3
token translations: context dependent, result Pretty.T;
wenzelm
parents:
26694
diff
changeset
|
291 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' T)]) |
9128 | 292 |
end; |
5831 | 293 |
|
48792 | 294 |
fun string_of_type ctxt (s, NONE) = |
295 |
let val T = Syntax.read_typ ctxt s |
|
296 |
in Pretty.string_of (Pretty.quote (Syntax.pretty_typ ctxt T)) end |
|
297 |
| string_of_type ctxt (s1, SOME s2) = |
|
298 |
let |
|
299 |
val ctxt' = Config.put show_sorts true ctxt; |
|
300 |
val raw_T = Syntax.parse_typ ctxt' s1; |
|
301 |
val S = Syntax.read_sort ctxt' s2; |
|
302 |
val T = |
|
303 |
Syntax.check_term ctxt' |
|
304 |
(Logic.mk_type raw_T |> Type.constraint (Term.itselfT (Type_Infer.anyT S))) |
|
305 |
|> Logic.dest_type; |
|
306 |
in Pretty.string_of (Pretty.quote (Syntax.pretty_typ ctxt' T)) end; |
|
9128 | 307 |
|
23935 | 308 |
fun print_item string_of (modes, arg) = Toplevel.keep (fn state => |
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
309 |
Print_Mode.with_modes modes (fn () => writeln (string_of state arg)) ()); |
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
310 |
|
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
311 |
in |
9128 | 312 |
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
313 |
val print_stmts = print_item (string_of_stmts o Toplevel.context_of); |
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
314 |
val print_thms = print_item (string_of_thms o Toplevel.context_of); |
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
315 |
val print_prfs = print_item o string_of_prfs; |
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
316 |
val print_prop = print_item (string_of_prop o Toplevel.context_of); |
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
317 |
val print_term = print_item (string_of_term o Toplevel.context_of); |
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
318 |
val print_type = print_item (string_of_type o Toplevel.context_of); |
5831 | 319 |
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
320 |
end; |
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
321 |
|
5831 | 322 |
end; |