author | wenzelm |
Thu, 13 Nov 2008 21:50:57 +0100 | |
changeset 28765 | da8f6f4a74be |
parent 28763 | b5e6122ff575 |
child 28766 | accab7594b8e |
permissions | -rw-r--r-- |
28762 | 1 |
(* $Id$ *) |
2 |
||
3 |
theory Inner_Syntax |
|
4 |
imports Main |
|
5 |
begin |
|
6 |
||
7 |
chapter {* Inner syntax --- the term language *} |
|
8 |
||
9 |
section {* Printing logical entities *} |
|
10 |
||
11 |
subsection {* Diagnostic commands *} |
|
12 |
||
13 |
text {* |
|
14 |
\begin{matharray}{rcl} |
|
15 |
@{command_def "pr"}@{text "\<^sup>*"} & : & @{text "any \<rightarrow>"} \\ |
|
16 |
@{command_def "thm"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
17 |
@{command_def "term"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
18 |
@{command_def "prop"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
19 |
@{command_def "typ"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
20 |
@{command_def "prf"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
21 |
@{command_def "full_prf"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
22 |
\end{matharray} |
|
23 |
||
24 |
These diagnostic commands assist interactive development by printing |
|
25 |
internal logical entities in a human-readable fashion. |
|
26 |
||
27 |
\begin{rail} |
|
28 |
'pr' modes? nat? (',' nat)? |
|
29 |
; |
|
30 |
'thm' modes? thmrefs |
|
31 |
; |
|
32 |
'term' modes? term |
|
33 |
; |
|
34 |
'prop' modes? prop |
|
35 |
; |
|
36 |
'typ' modes? type |
|
37 |
; |
|
38 |
'prf' modes? thmrefs? |
|
39 |
; |
|
40 |
'full\_prf' modes? thmrefs? |
|
41 |
; |
|
42 |
||
43 |
modes: '(' (name + ) ')' |
|
44 |
; |
|
45 |
\end{rail} |
|
46 |
||
47 |
\begin{description} |
|
48 |
||
49 |
\item @{command "pr"}~@{text "goals, prems"} prints the current |
|
50 |
proof state (if present), including the proof context, current facts |
|
51 |
and goals. The optional limit arguments affect the number of goals |
|
52 |
and premises to be displayed, which is initially 10 for both. |
|
53 |
Omitting limit values leaves the current setting unchanged. |
|
54 |
||
55 |
\item @{command "thm"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} retrieves |
|
56 |
theorems from the current theory or proof context. Note that any |
|
57 |
attributes included in the theorem specifications are applied to a |
|
58 |
temporary context derived from the current theory or proof; the |
|
59 |
result is discarded, i.e.\ attributes involved in @{text "a\<^sub>1, |
|
60 |
\<dots>, a\<^sub>n"} do not have any permanent effect. |
|
61 |
||
62 |
\item @{command "term"}~@{text t} and @{command "prop"}~@{text \<phi>} |
|
63 |
read, type-check and print terms or propositions according to the |
|
64 |
current theory or proof context; the inferred type of @{text t} is |
|
65 |
output as well. Note that these commands are also useful in |
|
66 |
inspecting the current environment of term abbreviations. |
|
67 |
||
68 |
\item @{command "typ"}~@{text \<tau>} reads and prints types of the |
|
69 |
meta-logic according to the current theory or proof context. |
|
70 |
||
71 |
\item @{command "prf"} displays the (compact) proof term of the |
|
72 |
current proof state (if present), or of the given theorems. Note |
|
73 |
that this requires proof terms to be switched on for the current |
|
74 |
object logic (see the ``Proof terms'' section of the Isabelle |
|
75 |
reference manual for information on how to do this). |
|
76 |
||
77 |
\item @{command "full_prf"} is like @{command "prf"}, but displays |
|
78 |
the full proof term, i.e.\ also displays information omitted in the |
|
79 |
compact proof term, which is denoted by ``@{text _}'' placeholders |
|
80 |
there. |
|
81 |
||
82 |
\end{description} |
|
83 |
||
84 |
All of the diagnostic commands above admit a list of @{text modes} |
|
85 |
to be specified, which is appended to the current print mode (see |
|
86 |
also \cite{isabelle-ref}). Thus the output behavior may be modified |
|
87 |
according particular print mode features. For example, @{command |
|
88 |
"pr"}~@{text "(latex xsymbols)"} would print the current proof state |
|
89 |
with mathematical symbols and special characters represented in |
|
90 |
{\LaTeX} source, according to the Isabelle style |
|
91 |
\cite{isabelle-sys}. |
|
92 |
||
93 |
Note that antiquotations (cf.\ \secref{sec:antiq}) provide a more |
|
94 |
systematic way to include formal items into the printed text |
|
95 |
document. |
|
96 |
*} |
|
97 |
||
98 |
||
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
99 |
subsection {* Details of printed content *} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
100 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
101 |
text {* |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
102 |
\begin{mldecls} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
103 |
@{index_ML show_types: "bool ref"} & default @{ML false} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
104 |
@{index_ML show_sorts: "bool ref"} & default @{ML false} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
105 |
@{index_ML show_consts: "bool ref"} & default @{ML false} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
106 |
@{index_ML long_names: "bool ref"} & default @{ML false} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
107 |
@{index_ML short_names: "bool ref"} & default @{ML false} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
108 |
@{index_ML unique_names: "bool ref"} & default @{ML true} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
109 |
@{index_ML show_brackets: "bool ref"} & default @{ML false} \\ |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
110 |
@{index_ML eta_contract: "bool ref"} & default @{ML true} \\ |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
111 |
@{index_ML goals_limit: "int ref"} & default @{ML 10} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
112 |
@{index_ML Proof.show_main_goal: "bool ref"} & default @{ML false} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
113 |
@{index_ML show_hyps: "bool ref"} & default @{ML false} \\ |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
114 |
@{index_ML show_tags: "bool ref"} & default @{ML false} \\ |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
115 |
@{index_ML show_question_marks: "bool ref"} & default @{ML true} \\ |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
116 |
\end{mldecls} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
117 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
118 |
These global ML variables control the detail of information that is |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
119 |
displayed for types, terms, theorems, goals etc. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
120 |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
121 |
In interactive sessions, the user interface usually manages these |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
122 |
global parameters of the Isabelle process, even with some concept of |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
123 |
persistence. Nonetheless it is occasionally useful to manipulate ML |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
124 |
variables directly, e.g.\ using @{command "ML_val"} or @{command |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
125 |
"ML_command"}. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
126 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
127 |
Batch-mode logic sessions may be configured by putting appropriate |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
128 |
ML text directly into the @{verbatim ROOT.ML} file. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
129 |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
130 |
\begin{description} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
131 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
132 |
\item @{ML show_types} and @{ML show_sorts} control printing of type |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
133 |
constraints for term variables, and sort constraints for type |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
134 |
variables. By default, neither of these are shown in output. If |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
135 |
@{ML show_sorts} is set to @{ML true}, types are always shown as |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
136 |
well. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
137 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
138 |
Note that displaying types and sorts may explain why a polymorphic |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
139 |
inference rule fails to resolve with some goal, or why a rewrite |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
140 |
rule does not apply as expected. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
141 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
142 |
\item @{ML show_consts} controls printing of types of constants when |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
143 |
displaying a goal state. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
144 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
145 |
Note that the output can be enormous, because polymorphic constants |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
146 |
often occur at several different type instances. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
147 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
148 |
\item @{ML long_names}, @{ML short_names}, and @{ML unique_names} |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
149 |
control the way of printing fully qualified internal names in |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
150 |
external form. See also \secref{sec:antiq} for the document |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
151 |
antiquotation options of the same names. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
152 |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
153 |
\item @{ML show_brackets} controls bracketing in pretty printed |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
154 |
output. If set to @{ML true}, all sub-expressions of the pretty |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
155 |
printing tree will be parenthesized, even if this produces malformed |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
156 |
term syntax! This crude way of showing the internal structure of |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
157 |
pretty printed entities may occasionally help to diagnose problems |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
158 |
with operator priorities, for example. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
159 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
160 |
\item @{ML eta_contract} controls @{text "\<eta>"}-contracted printing of |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
161 |
terms. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
162 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
163 |
The @{text \<eta>}-contraction law asserts @{prop "(\<lambda>x. f x) \<equiv> f"}, |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
164 |
provided @{text x} is not free in @{text f}. It asserts |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
165 |
\emph{extensionality} of functions: @{prop "f \<equiv> g"} if @{prop "f x \<equiv> |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
166 |
g x"} for all @{text x}. Higher-order unification frequently puts |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
167 |
terms into a fully @{text \<eta>}-expanded form. For example, if @{text |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
168 |
F} has type @{text "(\<tau> \<Rightarrow> \<tau>) \<Rightarrow> \<tau>"} then its expanded form is @{term |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
169 |
"\<lambda>h. F (\<lambda>x. h x)"}. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
170 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
171 |
Setting @{ML eta_contract} makes Isabelle perform @{text |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
172 |
\<eta>}-contractions before printing, so that @{term "\<lambda>h. F (\<lambda>x. h x)"} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
173 |
appears simply as @{text F}. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
174 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
175 |
Note that the distinction between a term and its @{text \<eta>}-expanded |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
176 |
form occasionally matters. While higher-order resolution and |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
177 |
rewriting operate modulo @{text "\<alpha>\<beta>\<eta>"}-conversion, some other tools |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
178 |
might look at terms more discretely. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
179 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
180 |
\item @{ML goals_limit} controls the maximum number of subgoals to |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
181 |
be shown in goal output. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
182 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
183 |
\item @{ML Proof.show_main_goal} controls whether the main result to |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
184 |
be proven should be displayed. This information might be relevant |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
185 |
for schematic goals, to inspect the current claim that has been |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
186 |
synthesized so far. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
187 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
188 |
\item @{ML show_hyps} controls printing of implicit hypotheses of |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
189 |
local facts. Normally, only those hypotheses are displayed that are |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
190 |
\emph{not} covered by the assumptions of the current context: this |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
191 |
situation indicates a fault in some tool being used. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
192 |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
193 |
By setting @{ML show_hyps} to @{ML true}, output of \emph{all} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
194 |
hypotheses can be enforced, which is occasionally useful for |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
195 |
diagnostic purposes. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
196 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
197 |
\item @{ML show_tags} controls printing of extra annotations within |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
198 |
theorems, such as internal position information, or the case names |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
199 |
being attached by the attribute @{attribute case_names}. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
200 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
201 |
Note that the @{attribute tagged} and @{attribute untagged} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
202 |
attributes provide low-level access to the collection of tags |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
203 |
associated with a theorem. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
204 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
205 |
\item @{ML show_question_marks} controls printing of question marks |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
206 |
for schematic variables, such as @{text ?x}. Only the leading |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
207 |
question mark is affected, the remaining text is unchanged |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
208 |
(including proper markup for schematic variables that might be |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
209 |
relevant for user interfaces). |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
210 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
211 |
\end{description} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
212 |
*} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
213 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
214 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
215 |
subsection {* Printing limits *} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
216 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
217 |
text {* |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
218 |
\begin{mldecls} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
219 |
@{index_ML Pretty.setdepth: "int -> unit"} \\ |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
220 |
@{index_ML Pretty.setmargin: "int -> unit"} \\ |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
221 |
@{index_ML print_depth: "int -> unit"} \\ |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
222 |
\end{mldecls} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
223 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
224 |
These ML functions set limits for pretty printed text. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
225 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
226 |
\begin{description} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
227 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
228 |
\item @{ML Pretty.setdepth}~@{text d} tells the pretty printer to |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
229 |
limit the printing depth to @{text d}. This affects the display of |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
230 |
types, terms, theorems etc. The default value is 0, which permits |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
231 |
printing to an arbitrary depth. Other useful values for @{text d} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
232 |
are 10 and 20. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
233 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
234 |
\item @{ML Pretty.setmargin}~@{text m} tells the pretty printer to |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
235 |
assume a right margin (page width) of @{text m}. The initial margin |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
236 |
is 76, but user interfaces might adapt the margin automatically when |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
237 |
resizing windows. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
238 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
239 |
\item @{ML print_depth}~@{text n} limits the printing depth of the |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
240 |
ML toplevel pretty printer; the precise effect depends on the ML |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
241 |
compiler and run-time system. Typically @{text n} should be less |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
242 |
than 10. Bigger values such as 100--1000 are useful for debugging. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
243 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
244 |
\end{description} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
245 |
*} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
246 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
247 |
|
28762 | 248 |
section {* Mixfix annotations *} |
249 |
||
250 |
text {* Mixfix annotations specify concrete \emph{inner syntax} of |
|
251 |
Isabelle types and terms. Some commands such as @{command "types"} |
|
252 |
(see \secref{sec:types-pure}) admit infixes only, while @{command |
|
253 |
"consts"} (see \secref{sec:consts}) and @{command "syntax"} (see |
|
254 |
\secref{sec:syn-trans}) support the full range of general mixfixes |
|
255 |
and binders. |
|
256 |
||
257 |
\indexouternonterm{infix}\indexouternonterm{mixfix}\indexouternonterm{structmixfix} |
|
258 |
\begin{rail} |
|
259 |
infix: '(' ('infix' | 'infixl' | 'infixr') string nat ')' |
|
260 |
; |
|
261 |
mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')' |
|
262 |
; |
|
263 |
structmixfix: mixfix | '(' 'structure' ')' |
|
264 |
; |
|
265 |
||
266 |
prios: '[' (nat + ',') ']' |
|
267 |
; |
|
268 |
\end{rail} |
|
269 |
||
270 |
Here the \railtok{string} specifications refer to the actual mixfix |
|
271 |
template, which may include literal text, spacing, blocks, and |
|
272 |
arguments (denoted by ``@{text _}''); the special symbol |
|
273 |
``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') represents an index |
|
274 |
argument that specifies an implicit structure reference (see also |
|
275 |
\secref{sec:locale}). Infix and binder declarations provide common |
|
276 |
abbreviations for particular mixfix declarations. So in practice, |
|
277 |
mixfix templates mostly degenerate to literal text for concrete |
|
278 |
syntax, such as ``@{verbatim "++"}'' for an infix symbol. |
|
279 |
||
280 |
\medskip In full generality, mixfix declarations work as follows. |
|
281 |
Suppose a constant @{text "c :: \<tau>\<^sub>1 \<Rightarrow> \<dots> \<tau>\<^sub>n \<Rightarrow> \<tau>"} is |
|
282 |
annotated by @{text "(mixfix [p\<^sub>1, \<dots>, p\<^sub>n] p)"}, where @{text |
|
283 |
"mixfix"} is a string @{text "d\<^sub>0 _ d\<^sub>1 _ \<dots> _ d\<^sub>n"} consisting of |
|
284 |
delimiters that surround argument positions as indicated by |
|
285 |
underscores. |
|
286 |
||
287 |
Altogether this determines a production for a context-free priority |
|
288 |
grammar, where for each argument @{text "i"} the syntactic category |
|
289 |
is determined by @{text "\<tau>\<^sub>i"} (with priority @{text "p\<^sub>i"}), and |
|
290 |
the result category is determined from @{text "\<tau>"} (with |
|
291 |
priority @{text "p"}). Priority specifications are optional, with |
|
292 |
default 0 for arguments and 1000 for the result. |
|
293 |
||
294 |
Since @{text "\<tau>"} may be again a function type, the constant |
|
295 |
type scheme may have more argument positions than the mixfix |
|
296 |
pattern. Printing a nested application @{text "c t\<^sub>1 \<dots> t\<^sub>m"} for |
|
297 |
@{text "m > n"} works by attaching concrete notation only to the |
|
298 |
innermost part, essentially by printing @{text "(c t\<^sub>1 \<dots> t\<^sub>n) \<dots> t\<^sub>m"} |
|
299 |
instead. If a term has fewer arguments than specified in the mixfix |
|
300 |
template, the concrete syntax is ignored. |
|
301 |
||
302 |
\medskip A mixfix template may also contain additional directives |
|
303 |
for pretty printing, notably spaces, blocks, and breaks. The |
|
304 |
general template format is a sequence over any of the following |
|
305 |
entities. |
|
306 |
||
307 |
\begin{itemize} |
|
308 |
||
309 |
\item @{text "\<^bold>d"} is a delimiter, namely a non-empty |
|
310 |
sequence of characters other than the special characters @{text "'"} |
|
311 |
(single quote), @{text "_"} (underscore), @{text "\<index>"} (index |
|
312 |
symbol), @{text "/"} (slash), @{text "("} and @{text ")"} |
|
313 |
(parentheses). |
|
314 |
||
315 |
A single quote escapes the special meaning of these meta-characters, |
|
316 |
producing a literal version of the following character, unless that |
|
317 |
is a blank. A single quote followed by a blank separates |
|
318 |
delimiters, without affecting printing, but input tokens may have |
|
319 |
additional white space here. |
|
320 |
||
321 |
\item @{text "_"} is an argument position, which stands for a |
|
322 |
certain syntactic category in the underlying grammar. |
|
323 |
||
324 |
\item @{text "\<index>"} is an indexed argument position; this is |
|
325 |
the place where implicit structure arguments can be attached. |
|
326 |
||
327 |
\item @{text "\<^bold>s"} is a non-empty sequence of spaces for |
|
328 |
printing. This and the following specifications do not affect |
|
329 |
parsing at all. |
|
330 |
||
331 |
\item @{text "(\<^bold>n"} opens a pretty printing block. The |
|
332 |
optional number specifies how much indentation to add when a line |
|
333 |
break occurs within the block. If the parenthesis is not followed |
|
334 |
by digits, the indentation defaults to 0. A block specified via |
|
335 |
@{text "(00"} is unbreakable. |
|
336 |
||
337 |
\item @{text ")"} closes a pretty printing block. |
|
338 |
||
339 |
\item @{text "//"} forces a line break. |
|
340 |
||
341 |
\item @{text "/\<^bold>s"} allows a line break. Here @{text |
|
342 |
"\<^bold>s"} stands for the string of spaces (zero or more) right |
|
343 |
after the slash. These spaces are printed if the break is |
|
344 |
\emph{not} taken. |
|
345 |
||
346 |
\end{itemize} |
|
347 |
||
348 |
For example, the template @{text "(_ +/ _)"} specifies an infix |
|
349 |
operator. There are two argument positions; the delimiter @{text |
|
350 |
"+"} is preceded by a space and followed by a space or line break; |
|
351 |
the entire phrase is a pretty printing block. |
|
352 |
||
353 |
The general idea of pretty printing with blocks and breaks is also |
|
354 |
described in \cite{paulson-ml2}. |
|
355 |
*} |
|
356 |
||
357 |
||
358 |
section {* Additional term notation *} |
|
359 |
||
360 |
text {* |
|
361 |
\begin{matharray}{rcll} |
|
362 |
@{command_def "notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
363 |
@{command_def "no_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
364 |
\end{matharray} |
|
365 |
||
366 |
\begin{rail} |
|
367 |
('notation' | 'no\_notation') target? mode? (nameref structmixfix + 'and') |
|
368 |
; |
|
369 |
\end{rail} |
|
370 |
||
371 |
\begin{description} |
|
372 |
||
373 |
\item @{command "notation"}~@{text "c (mx)"} associates mixfix |
|
374 |
syntax with an existing constant or fixed variable. This is a |
|
375 |
robust interface to the underlying @{command "syntax"} primitive |
|
376 |
(\secref{sec:syn-trans}). Type declaration and internal syntactic |
|
377 |
representation of the given entity is retrieved from the context. |
|
378 |
||
379 |
\item @{command "no_notation"} is similar to @{command "notation"}, |
|
380 |
but removes the specified syntax annotation from the present |
|
381 |
context. |
|
382 |
||
383 |
\end{description} |
|
384 |
*} |
|
385 |
||
386 |
section {* Syntax and translations \label{sec:syn-trans} *} |
|
387 |
||
388 |
text {* |
|
389 |
\begin{matharray}{rcl} |
|
390 |
@{command_def "nonterminals"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
391 |
@{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
392 |
@{command_def "no_syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
393 |
@{command_def "translations"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
394 |
@{command_def "no_translations"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
395 |
\end{matharray} |
|
396 |
||
397 |
\begin{rail} |
|
398 |
'nonterminals' (name +) |
|
399 |
; |
|
400 |
('syntax' | 'no\_syntax') mode? (constdecl +) |
|
401 |
; |
|
402 |
('translations' | 'no\_translations') (transpat ('==' | '=>' | '<=' | rightleftharpoons | rightharpoonup | leftharpoondown) transpat +) |
|
403 |
; |
|
404 |
||
405 |
mode: ('(' ( name | 'output' | name 'output' ) ')') |
|
406 |
; |
|
407 |
transpat: ('(' nameref ')')? string |
|
408 |
; |
|
409 |
\end{rail} |
|
410 |
||
411 |
\begin{description} |
|
412 |
||
413 |
\item @{command "nonterminals"}~@{text c} declares a type |
|
414 |
constructor @{text c} (without arguments) to act as purely syntactic |
|
415 |
type: a nonterminal symbol of the inner syntax. |
|
416 |
||
417 |
\item @{command "syntax"}~@{text "(mode) decls"} is similar to |
|
418 |
@{command "consts"}~@{text decls}, except that the actual logical |
|
419 |
signature extension is omitted. Thus the context free grammar of |
|
420 |
Isabelle's inner syntax may be augmented in arbitrary ways, |
|
421 |
independently of the logic. The @{text mode} argument refers to the |
|
422 |
print mode that the grammar rules belong; unless the @{keyword_ref |
|
423 |
"output"} indicator is given, all productions are added both to the |
|
424 |
input and output grammar. |
|
425 |
||
426 |
\item @{command "no_syntax"}~@{text "(mode) decls"} removes grammar |
|
427 |
declarations (and translations) resulting from @{text decls}, which |
|
428 |
are interpreted in the same manner as for @{command "syntax"} above. |
|
429 |
||
430 |
\item @{command "translations"}~@{text rules} specifies syntactic |
|
431 |
translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}), |
|
432 |
parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}). |
|
433 |
Translation patterns may be prefixed by the syntactic category to be |
|
434 |
used for parsing; the default is @{text logic}. |
|
435 |
||
436 |
\item @{command "no_translations"}~@{text rules} removes syntactic |
|
437 |
translation rules, which are interpreted in the same manner as for |
|
438 |
@{command "translations"} above. |
|
439 |
||
440 |
\end{description} |
|
441 |
*} |
|
442 |
||
443 |
||
444 |
section {* Syntax translation functions *} |
|
445 |
||
446 |
text {* |
|
447 |
\begin{matharray}{rcl} |
|
448 |
@{command_def "parse_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
449 |
@{command_def "parse_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
450 |
@{command_def "print_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
451 |
@{command_def "typed_print_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
452 |
@{command_def "print_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
453 |
\end{matharray} |
|
454 |
||
455 |
\begin{rail} |
|
456 |
( 'parse\_ast\_translation' | 'parse\_translation' | 'print\_translation' | |
|
457 |
'typed\_print\_translation' | 'print\_ast\_translation' ) ('(advanced)')? text |
|
458 |
; |
|
459 |
\end{rail} |
|
460 |
||
461 |
Syntax translation functions written in ML admit almost arbitrary |
|
462 |
manipulations of Isabelle's inner syntax. Any of the above commands |
|
463 |
have a single \railqtok{text} argument that refers to an ML |
|
464 |
expression of appropriate type, which are as follows by default: |
|
465 |
||
466 |
%FIXME proper antiquotations |
|
467 |
\begin{ttbox} |
|
468 |
val parse_ast_translation : (string * (ast list -> ast)) list |
|
469 |
val parse_translation : (string * (term list -> term)) list |
|
470 |
val print_translation : (string * (term list -> term)) list |
|
471 |
val typed_print_translation : |
|
472 |
(string * (bool -> typ -> term list -> term)) list |
|
473 |
val print_ast_translation : (string * (ast list -> ast)) list |
|
474 |
\end{ttbox} |
|
475 |
||
476 |
If the @{text "(advanced)"} option is given, the corresponding |
|
477 |
translation functions may depend on the current theory or proof |
|
478 |
context. This allows to implement advanced syntax mechanisms, as |
|
479 |
translations functions may refer to specific theory declarations or |
|
480 |
auxiliary proof data. |
|
481 |
||
482 |
See also \cite[\S8]{isabelle-ref} for more information on the |
|
483 |
general concept of syntax transformations in Isabelle. |
|
484 |
||
485 |
%FIXME proper antiquotations |
|
486 |
\begin{ttbox} |
|
487 |
val parse_ast_translation: |
|
488 |
(string * (Proof.context -> ast list -> ast)) list |
|
489 |
val parse_translation: |
|
490 |
(string * (Proof.context -> term list -> term)) list |
|
491 |
val print_translation: |
|
492 |
(string * (Proof.context -> term list -> term)) list |
|
493 |
val typed_print_translation: |
|
494 |
(string * (Proof.context -> bool -> typ -> term list -> term)) list |
|
495 |
val print_ast_translation: |
|
496 |
(string * (Proof.context -> ast list -> ast)) list |
|
497 |
\end{ttbox} |
|
498 |
*} |
|
499 |
||
500 |
end |