| author | wenzelm |
| Sun, 29 Sep 2024 15:00:20 +0200 | |
| changeset 80999 | 7f9e8516ca05 |
| parent 80759 | 4641f0fdaa59 |
| child 81589 | fcf44ef51057 |
| 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 |
|
| 42204 | 16 |
val translations: (xstring * string) Syntax.trrule list -> theory -> theory |
17 |
val no_translations: (xstring * string) Syntax.trrule list -> theory -> theory |
|
| 80752 | 18 |
val syntax_consts: ((string * Position.T) list * (xstring * Position.T) list) list -> |
19 |
theory -> theory |
|
20 |
val syntax_types: ((string * Position.T) list * (xstring * Position.T) list) list -> |
|
21 |
theory -> theory |
|
| 59064 | 22 |
val oracle: bstring * Position.range -> Input.source -> theory -> theory |
23 |
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
|
24 |
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
|
25 |
val terminal_proof: Method.text_range * Method.text_range option -> |
| 21350 | 26 |
Toplevel.transition -> Toplevel.transition |
27 |
val default_proof: Toplevel.transition -> Toplevel.transition |
|
28 |
val immediate_proof: Toplevel.transition -> Toplevel.transition |
|
29 |
val done_proof: Toplevel.transition -> Toplevel.transition |
|
30 |
val skip_proof: Toplevel.transition -> Toplevel.transition |
|
| 59064 | 31 |
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
|
32 |
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
|
33 |
val diag_goal: Proof.context -> {context: Proof.context, facts: thm list, goal: thm}
|
| 57605 | 34 |
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
|
35 |
val print_stmts: string list * (Facts.ref * Token.src list) list |
| 19268 | 36 |
-> Toplevel.transition -> Toplevel.transition |
|
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57934
diff
changeset
|
37 |
val print_thms: string list * (Facts.ref * Token.src list) list |
| 10581 | 38 |
-> Toplevel.transition -> Toplevel.transition |
|
58011
bc6bced136e5
tuned signature -- moved type src to Token, without aliases;
wenzelm
parents:
57934
diff
changeset
|
39 |
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
|
40 |
-> Toplevel.transition -> Toplevel.transition |
|
12876
a70df1e5bf10
got rid of explicit marginal comments (now stripped earlier from input);
wenzelm
parents:
12758
diff
changeset
|
41 |
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
|
42 |
val print_term: (string list * string) -> Toplevel.transition -> Toplevel.transition |
| 48792 | 43 |
val print_type: (string list * (string * string option)) -> |
44 |
Toplevel.transition -> Toplevel.transition |
|
| 5831 | 45 |
end; |
46 |
||
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
37198
diff
changeset
|
47 |
structure Isar_Cmd: ISAR_CMD = |
| 5831 | 48 |
struct |
49 |
||
50 |
||
|
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
51 |
(** theory declarations **) |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
52 |
|
| 30461 | 53 |
(* generic setup *) |
|
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
54 |
|
| 59930 | 55 |
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
|
56 |
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
|
57 |
(ML_Lex.read "Theory.setup (" @ ML_Lex.read_source source @ ML_Lex.read ")")
|
| 26435 | 58 |
|> Context.theory_map; |
|
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
59 |
|
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
(ML_Lex.read "Theory.local_setup (" @ ML_Lex.read_source source @ ML_Lex.read ")")
|
| 30461 | 63 |
|> Context.proof_map; |
64 |
||
|
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
65 |
|
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
66 |
(* translation functions *) |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
67 |
|
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
(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
|
71 |
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
|
72 |
|> Context.theory_map; |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
73 |
|
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
(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
|
77 |
ML_Lex.read_source source @ ML_Lex.read "))") |
| 52143 | 78 |
|> Context.theory_map; |
79 |
||
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
80 |
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
|
81 |
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
|
82 |
(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
|
83 |
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
|
84 |
|> Context.theory_map; |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
85 |
|
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
86 |
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
|
87 |
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
|
88 |
(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
|
89 |
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
|
90 |
|> Context.theory_map; |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
91 |
|
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
(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
|
95 |
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
|
96 |
|> Context.theory_map; |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
97 |
|
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
98 |
|
| 42204 | 99 |
(* translation rules *) |
100 |
||
101 |
fun read_trrules thy raw_rules = |
|
102 |
let |
|
| 42360 | 103 |
val ctxt = Proof_Context.init_global thy; |
| 56006 | 104 |
val read_root = |
| 80632 | 105 |
dest_Type_name o Proof_Context.read_type_name {proper = true, strict = false} ctxt;
|
| 42204 | 106 |
in |
| 56006 | 107 |
raw_rules |
108 |
|> map (Syntax.map_trrule (fn (r, s) => Syntax_Phases.parse_ast_pattern ctxt (read_root r, s))) |
|
| 42204 | 109 |
end; |
110 |
||
111 |
fun translations args thy = Sign.add_trrules (read_trrules thy args) thy; |
|
112 |
fun no_translations args thy = Sign.del_trrules (read_trrules thy args) thy; |
|
113 |
||
114 |
||
| 80750 | 115 |
(* syntax consts/types (after translation) *) |
116 |
||
117 |
local |
|
118 |
||
119 |
fun syntax_deps_cmd f args thy = |
|
120 |
let |
|
121 |
val ctxt = Proof_Context.init_global thy; |
|
| 80752 | 122 |
|
123 |
val check_lhs = Proof_Context.check_syntax_const ctxt; |
|
| 80750 | 124 |
fun check_rhs (b: xstring, pos: Position.T) = |
125 |
let |
|
| 80752 | 126 |
val (c: string, reports) = f ctxt (b, pos); |
| 80750 | 127 |
val _ = Context_Position.reports ctxt reports; |
128 |
in c end; |
|
| 80752 | 129 |
|
130 |
fun check (raw_lhs, raw_rhs) = |
|
131 |
let |
|
132 |
val lhs = map check_lhs raw_lhs; |
|
133 |
val rhs = map check_rhs raw_rhs; |
|
134 |
in map (fn l => (l, rhs)) lhs end; |
|
135 |
in Sign.syntax_deps (maps check args) thy end; |
|
| 80750 | 136 |
|
137 |
fun check_const ctxt (s, pos) = |
|
|
80759
4641f0fdaa59
proper flags (amending 1319c729c65d): abbrevs are allowed, free variables are disallowed;
wenzelm
parents:
80752
diff
changeset
|
138 |
Proof_Context.check_const {proper = true, strict = false} ctxt (s, [pos])
|
| 80750 | 139 |
|>> (Term.dest_Const_name #> Lexicon.mark_const); |
140 |
||
141 |
fun check_type_name ctxt arg = |
|
|
80759
4641f0fdaa59
proper flags (amending 1319c729c65d): abbrevs are allowed, free variables are disallowed;
wenzelm
parents:
80752
diff
changeset
|
142 |
Proof_Context.check_type_name {proper = true, strict = false} ctxt arg
|
| 80750 | 143 |
|>> (Term.dest_Type_name #> Lexicon.mark_type); |
144 |
||
145 |
in |
|
146 |
||
147 |
val syntax_consts = syntax_deps_cmd check_const; |
|
148 |
val syntax_types = syntax_deps_cmd check_type_name; |
|
149 |
||
150 |
end; |
|
151 |
||
152 |
||
|
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
153 |
(* oracles *) |
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
154 |
|
|
59029
c907cbe36713
more careful ML source positions, for improved PIDE markup;
wenzelm
parents:
58991
diff
changeset
|
155 |
fun oracle (name, range) source = |
| 69263 | 156 |
ML_Context.expression (Input.pos_of source) |
157 |
(ML_Lex.read "val " @ |
|
|
73549
a2c589d5e1e4
clarified signature: more detailed token positions for antiquotations;
wenzelm
parents:
70839
diff
changeset
|
158 |
ML_Lex.read_range range name @ |
| 69263 | 159 |
ML_Lex.read |
|
78795
f7e972d567f3
clarified signature: more concise variations on implicit theory setup;
wenzelm
parents:
78792
diff
changeset
|
160 |
(" = snd (Theory.setup_result (Thm.add_oracle (" ^
|
| 69263 | 161 |
ML_Syntax.make_binding (name, #1 range) ^ ", ") @ |
|
78795
f7e972d567f3
clarified signature: more concise variations on implicit theory setup;
wenzelm
parents:
78792
diff
changeset
|
162 |
ML_Lex.read_source source @ ML_Lex.read ")))") |
| 69263 | 163 |
|> Context.theory_map; |
|
22116
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
164 |
|
|
6917be2e647d
added various ML setup functions (from sign.ML, pure_thy.ML);
wenzelm
parents:
22087
diff
changeset
|
165 |
|
| 22087 | 166 |
(* declarations *) |
167 |
||
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
(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
|
171 |
("Theory.local_setup (Local_Theory.declaration {syntax = " ^
|
| 78095 | 172 |
Bool.toString syntax ^ ", pervasive = " ^ Bool.toString pervasive ^ |
173 |
", 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
|
174 |
ML_Lex.read_source source @ ML_Lex.read "))") |
|
26385
ae7564661e76
ML runtime compilation: pass position, tuned signature;
wenzelm
parents:
26336
diff
changeset
|
175 |
|> Context.proof_map; |
| 22087 | 176 |
|
177 |
||
| 21350 | 178 |
(* local endings *) |
179 |
||
| 29383 | 180 |
fun local_qed m = Toplevel.proof (Proof.local_qed (m, true)); |
| 60403 | 181 |
val local_terminal_proof = Toplevel.proof o Proof.local_future_terminal_proof; |
| 29383 | 182 |
val local_default_proof = Toplevel.proof Proof.local_default_proof; |
183 |
val local_immediate_proof = Toplevel.proof Proof.local_immediate_proof; |
|
184 |
val local_done_proof = Toplevel.proof Proof.local_done_proof; |
|
185 |
val local_skip_proof = Toplevel.proof' Proof.local_skip_proof; |
|
| 21350 | 186 |
|
187 |
||
188 |
(* global endings *) |
|
189 |
||
190 |
fun global_qed m = Toplevel.end_proof (K (Proof.global_qed (m, true))); |
|
| 60403 | 191 |
val global_terminal_proof = Toplevel.end_proof o K o Proof.global_future_terminal_proof; |
| 21350 | 192 |
val global_default_proof = Toplevel.end_proof (K Proof.global_default_proof); |
193 |
val global_immediate_proof = Toplevel.end_proof (K Proof.global_immediate_proof); |
|
194 |
val global_skip_proof = Toplevel.end_proof Proof.global_skip_proof; |
|
195 |
val global_done_proof = Toplevel.end_proof (K Proof.global_done_proof); |
|
196 |
||
197 |
||
198 |
(* common endings *) |
|
199 |
||
|
60693
044f8bb3dd30
more accurate skip_proofs nesting, e.g. relevant for 'subgoal' command;
wenzelm
parents:
60405
diff
changeset
|
200 |
fun qed m = local_qed m o global_qed m; |
| 21350 | 201 |
fun terminal_proof m = local_terminal_proof m o global_terminal_proof m; |
202 |
val default_proof = local_default_proof o global_default_proof; |
|
203 |
val immediate_proof = local_immediate_proof o global_immediate_proof; |
|
204 |
val done_proof = local_done_proof o global_done_proof; |
|
205 |
val skip_proof = local_skip_proof o global_skip_proof; |
|
206 |
||
207 |
||
| 26489 | 208 |
(* diagnostic ML evaluation *) |
| 5831 | 209 |
|
|
37305
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
210 |
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
|
211 |
( |
| 69883 | 212 |
type T = Toplevel.state option; |
213 |
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
|
214 |
); |
|
9763792e4ac7
diagnostic commands 'ML_val' and 'ML_command' may refer to antiquotations @{Isar.state} and @{Isar.goal};
wenzelm
parents:
37216
diff
changeset
|
215 |
|
|
55828
42ac3cfb89f6
clarified language markup: added "delimited" property;
wenzelm
parents:
53171
diff
changeset
|
216 |
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
|
217 |
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
|
218 |
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
|
219 |
try Toplevel.generic_theory_of state |
| 69883 | 220 |
|> 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
|
221 |
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
|
222 |
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
|
223 |
|
| 69883 | 224 |
fun diag_state ctxt = |
225 |
(case Diag_State.get ctxt of |
|
226 |
SOME st => st |
|
| 76415 | 227 |
| NONE => Toplevel.make_state NONE); |
| 69883 | 228 |
|
| 60094 | 229 |
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
|
230 |
|
| 53171 | 231 |
val _ = Theory.setup |
| 67147 | 232 |
(ML_Antiquotation.value (Binding.qualify true "Isar" \<^binding>\<open>state\<close>) |
| 53171 | 233 |
(Scan.succeed "Isar_Cmd.diag_state ML_context") #> |
| 67147 | 234 |
ML_Antiquotation.value (Binding.qualify true "Isar" \<^binding>\<open>goal\<close>) |
| 53171 | 235 |
(Scan.succeed "Isar_Cmd.diag_goal ML_context")); |
| 5831 | 236 |
|
237 |
||
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
238 |
(* theorems of theory or proof context *) |
| 17066 | 239 |
|
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
240 |
fun pretty_theorems verbose st = |
|
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
241 |
if Toplevel.is_proof st then |
|
59917
9830c944670f
more uniform "verbose" option to print name space;
wenzelm
parents:
59210
diff
changeset
|
242 |
Proof_Context.pretty_local_facts verbose (Toplevel.context_of st) |
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
243 |
else |
|
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
244 |
let |
| 61266 | 245 |
val ctxt = Toplevel.context_of st; |
|
56868
b5fb264d53ba
clarified print operations for "terms" and "theorems";
wenzelm
parents:
56334
diff
changeset
|
246 |
val prev_thys = |
| 67391 | 247 |
(case Toplevel.previous_theory_of st of |
248 |
SOME thy => [thy] |
|
| 61266 | 249 |
| NONE => Theory.parents_of (Proof_Context.theory_of ctxt)); |
250 |
in Proof_Display.pretty_theorems_diff verbose prev_thys ctxt end; |
|
| 9513 | 251 |
|
| 12060 | 252 |
|
| 19268 | 253 |
(* print theorems, terms, types etc. *) |
254 |
||
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
255 |
local |
|
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
256 |
|
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
257 |
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
|
258 |
Attrib.eval_thms ctxt args |
|
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
259 |
|> map (Element.pretty_statement ctxt Thm.theoremK) |
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
260 |
|> Pretty.chunks2 |> Pretty.string_of; |
| 5880 | 261 |
|
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
262 |
fun string_of_thms ctxt args = |
| 51583 | 263 |
Pretty.string_of (Proof_Context.pretty_fact ctxt ("", Attrib.eval_thms ctxt args));
|
| 5895 | 264 |
|
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
(case arg of |
| 15531 | 268 |
NONE => |
|
12125
316d11f760f7
Commands prf and full_prf can now also be used to display proof term
berghofe
parents:
12069
diff
changeset
|
269 |
let |
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
270 |
val {context = ctxt, goal = thm} = Proof.simple_goal (Toplevel.proof_of state);
|
| 70449 | 271 |
val thy = Proof_Context.theory_of ctxt; |
| 28814 | 272 |
val prf = Thm.proof_of thm; |
| 17066 | 273 |
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
|
274 |
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
|
275 |
in |
| 33388 | 276 |
Proof_Syntax.pretty_proof ctxt |
| 70449 | 277 |
(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
|
278 |
end |
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
279 |
| SOME srcs => |
|
63624
994d1a1105ef
more informative 'prf' and 'full_prf', based on HOL/Proofs/ex/XML_Data.thy;
wenzelm
parents:
62922
diff
changeset
|
280 |
let |
|
994d1a1105ef
more informative 'prf' and 'full_prf', based on HOL/Proofs/ex/XML_Data.thy;
wenzelm
parents:
62922
diff
changeset
|
281 |
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
|
282 |
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
|
283 |
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
|
284 |
|
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
285 |
fun string_of_prop ctxt s = |
| 5831 | 286 |
let |
|
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24314
diff
changeset
|
287 |
val prop = Syntax.read_prop ctxt s; |
| 70308 | 288 |
val ctxt' = Proof_Context.augment prop ctxt; |
|
26704
51ee753cc2e3
token translations: context dependent, result Pretty.T;
wenzelm
parents:
26694
diff
changeset
|
289 |
in Pretty.string_of (Pretty.quote (Syntax.pretty_term ctxt' prop)) end; |
| 5831 | 290 |
|
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
291 |
fun string_of_term ctxt s = |
| 5831 | 292 |
let |
|
24508
c8b82fec6447
replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents:
24314
diff
changeset
|
293 |
val t = Syntax.read_term ctxt s; |
| 5831 | 294 |
val T = Term.type_of t; |
| 70308 | 295 |
val ctxt' = Proof_Context.augment t ctxt; |
| 5831 | 296 |
in |
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
297 |
Pretty.string_of |
|
26704
51ee753cc2e3
token translations: context dependent, result Pretty.T;
wenzelm
parents:
26694
diff
changeset
|
298 |
(Pretty.block [Pretty.quote (Syntax.pretty_term ctxt' t), Pretty.fbrk, |
|
51ee753cc2e3
token translations: context dependent, result Pretty.T;
wenzelm
parents:
26694
diff
changeset
|
299 |
Pretty.str "::", Pretty.brk 1, Pretty.quote (Syntax.pretty_typ ctxt' T)]) |
| 9128 | 300 |
end; |
| 5831 | 301 |
|
| 48792 | 302 |
fun string_of_type ctxt (s, NONE) = |
303 |
let val T = Syntax.read_typ ctxt s |
|
304 |
in Pretty.string_of (Pretty.quote (Syntax.pretty_typ ctxt T)) end |
|
305 |
| string_of_type ctxt (s1, SOME s2) = |
|
306 |
let |
|
307 |
val ctxt' = Config.put show_sorts true ctxt; |
|
308 |
val raw_T = Syntax.parse_typ ctxt' s1; |
|
309 |
val S = Syntax.read_sort ctxt' s2; |
|
310 |
val T = |
|
311 |
Syntax.check_term ctxt' |
|
312 |
(Logic.mk_type raw_T |> Type.constraint (Term.itselfT (Type_Infer.anyT S))) |
|
313 |
|> Logic.dest_type; |
|
314 |
in Pretty.string_of (Pretty.quote (Syntax.pretty_typ ctxt' T)) end; |
|
| 9128 | 315 |
|
| 23935 | 316 |
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
|
317 |
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
|
318 |
|
|
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
319 |
in |
| 9128 | 320 |
|
|
38331
6e72f31999ac
prefer plain Attrib.eval_thms with plain Proof.context instead of Proof.state;
wenzelm
parents:
38139
diff
changeset
|
321 |
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
|
322 |
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
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
val print_type = print_item (string_of_type o Toplevel.context_of); |
| 5831 | 327 |
|
|
19385
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
328 |
end; |
|
c0f2f8224ea8
print_term etc.: actually observe print mode in final output;
wenzelm
parents:
19268
diff
changeset
|
329 |
|
| 5831 | 330 |
end; |