author | wenzelm |
Sat, 04 Feb 2012 18:33:04 +0100 | |
changeset 46290 | 465851ba524e |
parent 46289 | d0199d9f9c5b |
child 46291 | a1827b8b45ae |
permissions | -rw-r--r-- |
28762 | 1 |
theory Inner_Syntax |
42651 | 2 |
imports Base Main |
28762 | 3 |
begin |
4 |
||
28778 | 5 |
chapter {* Inner syntax --- the term language \label{ch:inner-syntax} *} |
28762 | 6 |
|
46282 | 7 |
text {* The inner syntax of Isabelle provides concrete notation for |
8 |
the main entities of the logical framework, notably @{text |
|
9 |
"\<lambda>"}-terms with types and type classes. Applications may either |
|
10 |
extend existing syntactic categories by additional notation, or |
|
11 |
define new sub-languages that are linked to the standard term |
|
12 |
language via some explicit markers. For example @{verbatim |
|
13 |
FOO}~@{text "foo"} could embed the syntax corresponding for some |
|
14 |
user-defined nonterminal @{text "foo"} --- within the bounds of the |
|
15 |
given lexical syntax of Isabelle/Pure. |
|
16 |
||
17 |
The most basic way to specify concrete syntax for logical entities |
|
18 |
works via mixfix annotations (\secref{sec:mixfix}), which may be |
|
19 |
usually given as part of the original declaration or via explicit |
|
20 |
notation commands later on (\secref{sec:notation}). This already |
|
21 |
covers many needs of concrete syntax without having to understand |
|
22 |
the full complexity of inner syntax layers. |
|
23 |
||
24 |
Further details of the syntax engine involves the classical |
|
25 |
distinction of lexical language versus context-free grammar (see |
|
26 |
\secref{sec:pure-syntax}), and various mechanisms for \emph{syntax |
|
27 |
translations} --- either as rewrite systems on first-order ASTs |
|
28 |
(\secref{sec:syn-trans}) or ML functions on ASTs or @{text |
|
29 |
"\<lambda>"}-terms that represent parse trees (\secref{sec:tr-funs}). |
|
30 |
*} |
|
31 |
||
32 |
||
28762 | 33 |
section {* Printing logical entities *} |
34 |
||
46284 | 35 |
subsection {* Diagnostic commands \label{sec:print-diag} *} |
28762 | 36 |
|
37 |
text {* |
|
38 |
\begin{matharray}{rcl} |
|
28766
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
39 |
@{command_def "typ"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
28762 | 40 |
@{command_def "term"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
41 |
@{command_def "prop"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
28766
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
42 |
@{command_def "thm"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
28762 | 43 |
@{command_def "prf"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
44 |
@{command_def "full_prf"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
28766
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
45 |
@{command_def "pr"}@{text "\<^sup>*"} & : & @{text "any \<rightarrow>"} \\ |
28762 | 46 |
\end{matharray} |
47 |
||
48 |
These diagnostic commands assist interactive development by printing |
|
49 |
internal logical entities in a human-readable fashion. |
|
50 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
51 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
52 |
@@{command typ} @{syntax modes}? @{syntax type} |
28762 | 53 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
54 |
@@{command term} @{syntax modes}? @{syntax term} |
28762 | 55 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
56 |
@@{command prop} @{syntax modes}? @{syntax prop} |
28762 | 57 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
58 |
@@{command thm} @{syntax modes}? @{syntax thmrefs} |
28762 | 59 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
60 |
( @@{command prf} | @@{command full_prf} ) @{syntax modes}? @{syntax thmrefs}? |
28762 | 61 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
62 |
@@{command pr} @{syntax modes}? @{syntax nat}? |
28762 | 63 |
; |
64 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
65 |
@{syntax_def modes}: '(' (@{syntax name} + ) ')' |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
66 |
"} |
28762 | 67 |
|
68 |
\begin{description} |
|
69 |
||
28766
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
70 |
\item @{command "typ"}~@{text \<tau>} reads and prints types of the |
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
71 |
meta-logic according to the current theory or proof context. |
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
72 |
|
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
73 |
\item @{command "term"}~@{text t} and @{command "prop"}~@{text \<phi>} |
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
74 |
read, type-check and print terms or propositions according to the |
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
75 |
current theory or proof context; the inferred type of @{text t} is |
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
76 |
output as well. Note that these commands are also useful in |
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
77 |
inspecting the current environment of term abbreviations. |
28762 | 78 |
|
79 |
\item @{command "thm"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} retrieves |
|
80 |
theorems from the current theory or proof context. Note that any |
|
81 |
attributes included in the theorem specifications are applied to a |
|
82 |
temporary context derived from the current theory or proof; the |
|
83 |
result is discarded, i.e.\ attributes involved in @{text "a\<^sub>1, |
|
84 |
\<dots>, a\<^sub>n"} do not have any permanent effect. |
|
85 |
||
86 |
\item @{command "prf"} displays the (compact) proof term of the |
|
87 |
current proof state (if present), or of the given theorems. Note |
|
88 |
that this requires proof terms to be switched on for the current |
|
89 |
object logic (see the ``Proof terms'' section of the Isabelle |
|
90 |
reference manual for information on how to do this). |
|
91 |
||
92 |
\item @{command "full_prf"} is like @{command "prf"}, but displays |
|
93 |
the full proof term, i.e.\ also displays information omitted in the |
|
94 |
compact proof term, which is denoted by ``@{text _}'' placeholders |
|
95 |
there. |
|
96 |
||
39165 | 97 |
\item @{command "pr"}~@{text "goals"} prints the current proof state |
98 |
(if present), including current facts and goals. The optional limit |
|
99 |
arguments affect the number of goals to be displayed, which is |
|
100 |
initially 10. Omitting limit value leaves the current setting |
|
101 |
unchanged. |
|
28766
accab7594b8e
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28765
diff
changeset
|
102 |
|
28762 | 103 |
\end{description} |
104 |
||
105 |
All of the diagnostic commands above admit a list of @{text modes} |
|
42926 | 106 |
to be specified, which is appended to the current print mode; see |
46284 | 107 |
also \secref{sec:print-modes}. Thus the output behavior may be |
108 |
modified according particular print mode features. For example, |
|
109 |
@{command "pr"}~@{text "(latex xsymbols)"} would print the current |
|
110 |
proof state with mathematical symbols and special characters |
|
111 |
represented in {\LaTeX} source, according to the Isabelle style |
|
28762 | 112 |
\cite{isabelle-sys}. |
113 |
||
114 |
Note that antiquotations (cf.\ \secref{sec:antiq}) provide a more |
|
115 |
systematic way to include formal items into the printed text |
|
116 |
document. |
|
117 |
*} |
|
118 |
||
119 |
||
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
120 |
subsection {* Details of printed content *} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
121 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
122 |
text {* |
42655 | 123 |
\begin{tabular}{rcll} |
124 |
@{attribute_def show_types} & : & @{text attribute} & default @{text false} \\ |
|
125 |
@{attribute_def show_sorts} & : & @{text attribute} & default @{text false} \\ |
|
126 |
@{attribute_def show_consts} & : & @{text attribute} & default @{text false} \\ |
|
127 |
@{attribute_def show_abbrevs} & : & @{text attribute} & default @{text true} \\ |
|
128 |
@{attribute_def show_brackets} & : & @{text attribute} & default @{text false} \\ |
|
42669
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42655
diff
changeset
|
129 |
@{attribute_def names_long} & : & @{text attribute} & default @{text false} \\ |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42655
diff
changeset
|
130 |
@{attribute_def names_short} & : & @{text attribute} & default @{text false} \\ |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42655
diff
changeset
|
131 |
@{attribute_def names_unique} & : & @{text attribute} & default @{text true} \\ |
42655 | 132 |
@{attribute_def eta_contract} & : & @{text attribute} & default @{text true} \\ |
133 |
@{attribute_def goals_limit} & : & @{text attribute} & default @{text 10} \\ |
|
134 |
@{attribute_def show_main_goal} & : & @{text attribute} & default @{text false} \\ |
|
135 |
@{attribute_def show_hyps} & : & @{text attribute} & default @{text false} \\ |
|
136 |
@{attribute_def show_tags} & : & @{text attribute} & default @{text false} \\ |
|
137 |
@{attribute_def show_question_marks} & : & @{text attribute} & default @{text true} \\ |
|
138 |
\end{tabular} |
|
139 |
\medskip |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
140 |
|
42655 | 141 |
These configuration options control the detail of information that |
142 |
is displayed for types, terms, theorems, goals etc. See also |
|
143 |
\secref{sec:config}. |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
144 |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
145 |
\begin{description} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
146 |
|
42655 | 147 |
\item @{attribute show_types} and @{attribute show_sorts} control |
148 |
printing of type constraints for term variables, and sort |
|
149 |
constraints for type variables. By default, neither of these are |
|
150 |
shown in output. If @{attribute show_sorts} is enabled, types are |
|
151 |
always shown as well. |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
152 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
153 |
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
|
154 |
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
|
155 |
rule does not apply as expected. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
156 |
|
42655 | 157 |
\item @{attribute show_consts} controls printing of types of |
158 |
constants when displaying a goal state. |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
159 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
160 |
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
|
161 |
often occur at several different type instances. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
162 |
|
42655 | 163 |
\item @{attribute show_abbrevs} controls folding of constant |
164 |
abbreviations. |
|
40879
ca132ef44944
configuration option "show_abbrevs" supersedes print mode "no_abbrevs", with inverted meaning;
wenzelm
parents:
40255
diff
changeset
|
165 |
|
42655 | 166 |
\item @{attribute show_brackets} controls bracketing in pretty |
167 |
printed output. If enabled, all sub-expressions of the pretty |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
168 |
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
|
169 |
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
|
170 |
pretty printed entities may occasionally help to diagnose problems |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
171 |
with operator priorities, for example. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
172 |
|
42669
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42655
diff
changeset
|
173 |
\item @{attribute names_long}, @{attribute names_short}, and |
04dfffda5671
more conventional naming scheme: names_long, names_short, names_unique;
wenzelm
parents:
42655
diff
changeset
|
174 |
@{attribute names_unique} control the way of printing fully |
42358
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42279
diff
changeset
|
175 |
qualified internal names in external form. See also |
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42279
diff
changeset
|
176 |
\secref{sec:antiq} for the document antiquotation options of the |
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42279
diff
changeset
|
177 |
same names. |
b47d41d9f4b5
Name_Space: proper configuration options long_names, short_names, unique_names instead of former unsynchronized references;
wenzelm
parents:
42279
diff
changeset
|
178 |
|
42655 | 179 |
\item @{attribute eta_contract} controls @{text "\<eta>"}-contracted |
180 |
printing of terms. |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
181 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
182 |
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
|
183 |
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
|
184 |
\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
|
185 |
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
|
186 |
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
|
187 |
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
|
188 |
"\<lambda>h. F (\<lambda>x. h x)"}. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
189 |
|
42655 | 190 |
Enabling @{attribute eta_contract} makes Isabelle perform @{text |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
191 |
\<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
|
192 |
appears simply as @{text F}. |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
193 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
194 |
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
|
195 |
form occasionally matters. While higher-order resolution and |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
196 |
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
|
197 |
might look at terms more discretely. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
198 |
|
42655 | 199 |
\item @{attribute goals_limit} controls the maximum number of |
39130 | 200 |
subgoals to be shown in goal output. |
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
201 |
|
42655 | 202 |
\item @{attribute show_main_goal} controls whether the main result |
203 |
to be proven should be displayed. This information might be |
|
39130 | 204 |
relevant for schematic goals, to inspect the current claim that has |
205 |
been synthesized so far. |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
206 |
|
42655 | 207 |
\item @{attribute show_hyps} controls printing of implicit |
208 |
hypotheses of local facts. Normally, only those hypotheses are |
|
209 |
displayed that are \emph{not} covered by the assumptions of the |
|
210 |
current context: this situation indicates a fault in some tool being |
|
211 |
used. |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
212 |
|
42655 | 213 |
By enabling @{attribute show_hyps}, output of \emph{all} hypotheses |
214 |
can be enforced, which is occasionally useful for diagnostic |
|
215 |
purposes. |
|
28763
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
216 |
|
42655 | 217 |
\item @{attribute show_tags} controls printing of extra annotations |
218 |
within theorems, such as internal position information, or the case |
|
219 |
names being attached by the attribute @{attribute case_names}. |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
220 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
221 |
Note that the @{attribute tagged} and @{attribute untagged} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
222 |
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
|
223 |
associated with a theorem. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
224 |
|
42655 | 225 |
\item @{attribute show_question_marks} controls printing of question |
226 |
marks for schematic variables, such as @{text ?x}. Only the leading |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
227 |
question mark is affected, the remaining text is unchanged |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
228 |
(including proper markup for schematic variables that might be |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
229 |
relevant for user interfaces). |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
230 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
231 |
\end{description} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
232 |
*} |
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 |
|
46284 | 235 |
subsection {* Alternative print modes \label{sec:print-modes} *} |
236 |
||
237 |
text {* |
|
238 |
\begin{mldecls} |
|
239 |
@{index_ML print_mode_value: "unit -> string list"} \\ |
|
240 |
@{index_ML Print_Mode.with_modes: "string list -> ('a -> 'b) -> 'a -> 'b"} \\ |
|
241 |
\end{mldecls} |
|
242 |
||
243 |
The \emph{print mode} facility allows to modify various operations |
|
244 |
for printing. Commands like @{command typ}, @{command term}, |
|
245 |
@{command thm} (see \secref{sec:print-diag}) take additional print |
|
246 |
modes as optional argument. The underlying ML operations are as |
|
247 |
follows. |
|
248 |
||
249 |
\begin{description} |
|
250 |
||
251 |
\item @{ML "print_mode_value ()"} yields the list of currently |
|
252 |
active print mode names. This should be understood as symbolic |
|
253 |
representation of certain individual features for printing (with |
|
254 |
precedence from left to right). |
|
255 |
||
256 |
\item @{ML Print_Mode.with_modes}~@{text "modes f x"} evaluates |
|
257 |
@{text "f x"} in an execution context where the print mode is |
|
258 |
prepended by the given @{text "modes"}. This provides a thread-safe |
|
259 |
way to augment print modes. It is also monotonic in the set of mode |
|
260 |
names: it retains the default print mode that certain |
|
261 |
user-interfaces might have installed for their proper functioning! |
|
262 |
||
263 |
\end{description} |
|
264 |
||
265 |
\begin{warn} |
|
266 |
The old global reference @{ML print_mode} should never be used |
|
267 |
directly in applications. Its main reason for being publicly |
|
268 |
accessible is to support historic versions of Proof~General. |
|
269 |
\end{warn} |
|
270 |
||
271 |
\medskip The pretty printer for inner syntax maintains alternative |
|
272 |
mixfix productions for any print mode name invented by the user, say |
|
273 |
in commands like @{command notation} or @{command abbreviation}. |
|
274 |
Mode names can be arbitrary, but the following ones have a specific |
|
275 |
meaning by convention: |
|
276 |
||
277 |
\begin{itemize} |
|
278 |
||
279 |
\item @{verbatim "\"\""} (the empty string): default mode; |
|
280 |
implicitly active as last element in the list of modes. |
|
281 |
||
282 |
\item @{verbatim input}: dummy print mode that is never active; may |
|
283 |
be used to specify notation that is only available for input. |
|
284 |
||
285 |
\item @{verbatim internal} dummy print mode that is never active; |
|
286 |
used internally in Isabelle/Pure. |
|
287 |
||
288 |
\item @{verbatim xsymbols}: enable proper mathematical symbols |
|
289 |
instead of ASCII art.\footnote{This traditional mode name stems from |
|
290 |
the ``X-Symbol'' package for old versions Proof~General with XEmacs, |
|
291 |
although that package has been superseded by Unicode in recent |
|
292 |
years.} |
|
293 |
||
294 |
\item @{verbatim HTML}: additional mode that is active in HTML |
|
295 |
presentation of Isabelle theory sources; allows to provide |
|
296 |
alternative output notation. |
|
297 |
||
298 |
\item @{verbatim latex}: additional mode that is active in {\LaTeX} |
|
299 |
document preparation of Isabelle theory sources; allows to provide |
|
300 |
alternative output notation. |
|
301 |
||
302 |
\end{itemize} |
|
303 |
*} |
|
304 |
||
305 |
||
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
306 |
subsection {* Printing limits *} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
307 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
308 |
text {* |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
309 |
\begin{mldecls} |
36745 | 310 |
@{index_ML Pretty.margin_default: "int Unsynchronized.ref"} \\ |
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
311 |
@{index_ML print_depth: "int -> unit"} \\ |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
312 |
\end{mldecls} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
313 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
314 |
These ML functions set limits for pretty printed text. |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
315 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
316 |
\begin{description} |
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
317 |
|
36745 | 318 |
\item @{ML Pretty.margin_default} indicates the global default for |
319 |
the right margin of the built-in pretty printer, with initial value |
|
320 |
76. Note that user-interfaces typically control margins |
|
321 |
automatically when resizing windows, or even bypass the formatting |
|
322 |
engine of Isabelle/ML altogether and do it within the front end via |
|
323 |
Isabelle/Scala. |
|
28765
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
324 |
|
da8f6f4a74be
misc tuning and rearrangement of section "Printing logical entities";
wenzelm
parents:
28763
diff
changeset
|
325 |
\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
|
326 |
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
|
327 |
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
|
328 |
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
|
329 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
330 |
\end{description} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
331 |
*} |
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
332 |
|
b5e6122ff575
added pretty printing options (from old ref manual);
wenzelm
parents:
28762
diff
changeset
|
333 |
|
46282 | 334 |
section {* Mixfix annotations \label{sec:mixfix} *} |
28762 | 335 |
|
336 |
text {* Mixfix annotations specify concrete \emph{inner syntax} of |
|
35351
7425aece4ee3
allow general mixfix syntax for type constructors;
wenzelm
parents:
32833
diff
changeset
|
337 |
Isabelle types and terms. Locally fixed parameters in toplevel |
46290 | 338 |
theorem statements, locale and class specifications also admit |
339 |
mixfix annotations in a fairly uniform manner. A mixfix annotation |
|
340 |
describes describes the concrete syntax, the translation to abstract |
|
341 |
syntax, and the pretty printing. Special case annotations provide a |
|
342 |
simple means of specifying infix operators and binders. |
|
343 |
||
344 |
Isabelle mixfix syntax is inspired by {\OBJ} \cite{OBJ}. It allows |
|
345 |
to specify any context-free priority grammar, which is more general |
|
346 |
than the fixity declarations of ML and Prolog. |
|
28762 | 347 |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
348 |
@{rail " |
46289 | 349 |
@{syntax_def mixfix}: '(' mfix ')' |
28762 | 350 |
; |
46289 | 351 |
@{syntax_def struct_mixfix}: '(' ( mfix | @'structure' ) ')' |
28762 | 352 |
; |
353 |
||
46290 | 354 |
mfix: @{syntax template} prios? @{syntax nat}? | |
355 |
(@'infix' | @'infixl' | @'infixr') @{syntax template} @{syntax nat} | |
|
356 |
@'binder' @{syntax template} prios? @{syntax nat} |
|
357 |
; |
|
358 |
template: string |
|
46289 | 359 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
360 |
prios: '[' (@{syntax nat} + ',') ']' |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
361 |
"} |
28762 | 362 |
|
46290 | 363 |
The string given as @{text template} may include literal text, |
364 |
spacing, blocks, and arguments (denoted by ``@{text _}''); the |
|
365 |
special symbol ``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') |
|
366 |
represents an index argument that specifies an implicit structure |
|
367 |
reference (see also \secref{sec:locale}). Infix and binder |
|
368 |
declarations provide common abbreviations for particular mixfix |
|
369 |
declarations. So in practice, mixfix templates mostly degenerate to |
|
370 |
literal text for concrete syntax, such as ``@{verbatim "++"}'' for |
|
371 |
an infix symbol. |
|
372 |
*} |
|
28762 | 373 |
|
46290 | 374 |
|
375 |
subsection {* The general mixfix form *} |
|
376 |
||
377 |
text {* In full generality, mixfix declarations work as follows. |
|
378 |
Suppose a constant @{text "c :: \<tau>\<^sub>1 \<Rightarrow> \<dots> \<tau>\<^sub>n \<Rightarrow> \<tau>"} is annotated by |
|
379 |
@{text "(mixfix [p\<^sub>1, \<dots>, p\<^sub>n] p)"}, where @{text "mixfix"} is a string |
|
380 |
@{text "d\<^sub>0 _ d\<^sub>1 _ \<dots> _ d\<^sub>n"} consisting of delimiters that surround |
|
381 |
argument positions as indicated by underscores. |
|
28762 | 382 |
|
383 |
Altogether this determines a production for a context-free priority |
|
384 |
grammar, where for each argument @{text "i"} the syntactic category |
|
385 |
is determined by @{text "\<tau>\<^sub>i"} (with priority @{text "p\<^sub>i"}), and |
|
386 |
the result category is determined from @{text "\<tau>"} (with |
|
387 |
priority @{text "p"}). Priority specifications are optional, with |
|
388 |
default 0 for arguments and 1000 for the result. |
|
389 |
||
390 |
Since @{text "\<tau>"} may be again a function type, the constant |
|
391 |
type scheme may have more argument positions than the mixfix |
|
392 |
pattern. Printing a nested application @{text "c t\<^sub>1 \<dots> t\<^sub>m"} for |
|
393 |
@{text "m > n"} works by attaching concrete notation only to the |
|
394 |
innermost part, essentially by printing @{text "(c t\<^sub>1 \<dots> t\<^sub>n) \<dots> t\<^sub>m"} |
|
395 |
instead. If a term has fewer arguments than specified in the mixfix |
|
396 |
template, the concrete syntax is ignored. |
|
397 |
||
398 |
\medskip A mixfix template may also contain additional directives |
|
399 |
for pretty printing, notably spaces, blocks, and breaks. The |
|
400 |
general template format is a sequence over any of the following |
|
401 |
entities. |
|
402 |
||
28778 | 403 |
\begin{description} |
28762 | 404 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
405 |
\item @{text "d"} is a delimiter, namely a non-empty sequence of |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
406 |
characters other than the following special characters: |
28762 | 407 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
408 |
\smallskip |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
409 |
\begin{tabular}{ll} |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
410 |
@{verbatim "'"} & single quote \\ |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
411 |
@{verbatim "_"} & underscore \\ |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
412 |
@{text "\<index>"} & index symbol \\ |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
413 |
@{verbatim "("} & open parenthesis \\ |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
414 |
@{verbatim ")"} & close parenthesis \\ |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
415 |
@{verbatim "/"} & slash \\ |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
416 |
\end{tabular} |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
417 |
\medskip |
28762 | 418 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
419 |
\item @{verbatim "'"} escapes the special meaning of these |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
420 |
meta-characters, producing a literal version of the following |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
421 |
character, unless that is a blank. |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
422 |
|
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
423 |
A single quote followed by a blank separates delimiters, without |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
424 |
affecting printing, but input tokens may have additional white space |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
425 |
here. |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
426 |
|
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
427 |
\item @{verbatim "_"} is an argument position, which stands for a |
28762 | 428 |
certain syntactic category in the underlying grammar. |
429 |
||
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
430 |
\item @{text "\<index>"} is an indexed argument position; this is the place |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
431 |
where implicit structure arguments can be attached. |
28762 | 432 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
433 |
\item @{text "s"} is a non-empty sequence of spaces for printing. |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
434 |
This and the following specifications do not affect parsing at all. |
28762 | 435 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
436 |
\item @{verbatim "("}@{text n} opens a pretty printing block. The |
28762 | 437 |
optional number specifies how much indentation to add when a line |
438 |
break occurs within the block. If the parenthesis is not followed |
|
439 |
by digits, the indentation defaults to 0. A block specified via |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
440 |
@{verbatim "(00"} is unbreakable. |
28762 | 441 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
442 |
\item @{verbatim ")"} closes a pretty printing block. |
28762 | 443 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
444 |
\item @{verbatim "//"} forces a line break. |
28762 | 445 |
|
28771
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
446 |
\item @{verbatim "/"}@{text s} allows a line break. Here @{text s} |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
447 |
stands for the string of spaces (zero or more) right after the |
4510201c6aaf
mixfix annotations: verbatim for special symbols;
wenzelm
parents:
28770
diff
changeset
|
448 |
slash. These spaces are printed if the break is \emph{not} taken. |
28762 | 449 |
|
28778 | 450 |
\end{description} |
28762 | 451 |
|
452 |
The general idea of pretty printing with blocks and breaks is also |
|
46286 | 453 |
described in \cite{paulson-ml2}; it goes back to \cite{Oppen:1980}. |
28762 | 454 |
*} |
455 |
||
456 |
||
46290 | 457 |
subsection {* Infixes *} |
458 |
||
459 |
text {* Infix operators are specified by convenient short forms that |
|
460 |
abbreviate general mixfix annotations as follows: |
|
461 |
||
462 |
\begin{center} |
|
463 |
\begin{tabular}{lll} |
|
464 |
||
465 |
@{verbatim "("}@{keyword "infix"}~@{verbatim "\""}@{text sy}@{verbatim "\""} @{text "p"}@{verbatim ")"} |
|
466 |
& @{text "\<mapsto>"} & |
|
467 |
@{verbatim "(\"(_ "}@{text sy}@{verbatim "/ _)\" ["}@{text "p + 1"}@{verbatim ", "}@{text "p + 1"}@{verbatim "]"}@{text " p"}@{verbatim ")"} \\ |
|
468 |
@{verbatim "("}@{keyword "infixl"}~@{verbatim "\""}@{text sy}@{verbatim "\""} @{text "p"}@{verbatim ")"} |
|
469 |
& @{text "\<mapsto>"} & |
|
470 |
@{verbatim "(\"(_ "}@{text sy}@{verbatim "/ _)\" ["}@{text "p"}@{verbatim ", "}@{text "p + 1"}@{verbatim "]"}@{text " p"}@{verbatim ")"} \\ |
|
471 |
@{verbatim "("}@{keyword "infixr"}~@{verbatim "\""}@{text sy}@{verbatim "\""} @{text "p"}@{verbatim ")"} |
|
472 |
& @{text "\<mapsto>"} & |
|
473 |
@{verbatim "(\"(_ "}@{text sy}@{verbatim "/ _)\" ["}@{text "p + 1"}@{verbatim ", "}@{text "p"}@{verbatim "]"}@{text " p"}@{verbatim ")"} \\ |
|
474 |
||
475 |
\end{tabular} |
|
476 |
\end{center} |
|
477 |
||
478 |
The mixfix template @{verbatim "\"(_ "}@{text sy}@{verbatim "/ |
|
479 |
_)\""} specifies two argument positions; the delimiter is preceded |
|
480 |
by a space and followed by a space or line break; the entire phrase |
|
481 |
is a pretty printing block. |
|
482 |
||
483 |
The alternative notation @{verbatim "op"}~@{text sy} is introduced |
|
484 |
in addition. Thus any infix operator may be written in prefix form |
|
485 |
(as in ML), independently of the number of arguments in the term. |
|
486 |
*} |
|
487 |
||
488 |
||
489 |
subsection {* Binders *} |
|
490 |
||
491 |
text {* A \emph{binder} is a variable-binding construct such as a |
|
492 |
quantifier. The idea to formalize @{text "\<forall>x. b"} as @{text "All |
|
493 |
(\<lambda>x. b)"} for @{text "All :: ('a \<Rightarrow> bool) \<Rightarrow> bool"} already goes back |
|
494 |
to \cite{church40}. Isabelle declarations of certain higher-order |
|
495 |
operators may be annotated with @{keyword "binder"} annotations as |
|
496 |
follows: |
|
497 |
||
498 |
\begin{center} |
|
499 |
@{text "c :: "}@{verbatim "\""}@{text "(\<tau>\<^sub>1 \<Rightarrow> \<tau>\<^sub>2) \<Rightarrow> \<tau>\<^sub>3"}@{verbatim "\" ("}@{keyword "binder"}@{verbatim " \""}@{text "sy"}@{verbatim "\" ["}@{text "p"}@{verbatim "] "}@{text "q"}@{verbatim ")"} |
|
500 |
\end{center} |
|
501 |
||
502 |
This introduces concrete binder syntax @{text "sy x. b"}, where |
|
503 |
@{text x} is a bound variable of type @{text "\<tau>\<^sub>1"}, the body @{text |
|
504 |
b} has type @{text "\<tau>\<^sub>2"} and the whole term has type @{text "\<tau>\<^sub>3"}. |
|
505 |
The optional integer @{text p} specifies the syntactic priority of |
|
506 |
the body; the default is @{text "q"}, which is also the priority of |
|
507 |
the whole construct. |
|
508 |
||
509 |
Internally, the binder syntax is expanded to something like this: |
|
510 |
\begin{center} |
|
511 |
@{text "c_binder :: "}@{verbatim "\""}@{text "idts \<Rightarrow> \<tau>\<^sub>2 \<Rightarrow> \<tau>\<^sub>3"}@{verbatim "\" (\"(3"}@{text sy}@{verbatim "_./ _)\" [0, "}@{text "p"}@{verbatim "] "}@{text "q"}@{verbatim ")"} |
|
512 |
\end{center} |
|
513 |
||
514 |
Here @{syntax (inner) idts} is the nonterminal symbol for a list of |
|
515 |
identifiers with optional type constraints (see also |
|
516 |
\secref{sec:pure-grammar}). The mixfix template @{verbatim |
|
517 |
"\"(3"}@{text sy}@{verbatim "_./ _)\""} defines argument positions |
|
518 |
for the bound identifiers and the body, separated by a dot with |
|
519 |
optional line break; the entire phrase is a pretty printing block of |
|
520 |
indentation level 3. Note that there is no extra space after @{text |
|
521 |
"sy"}, so it needs to be included user specification if the binder |
|
522 |
syntax ends with a token that may be continued by an identifier |
|
523 |
token at the start of @{syntax (inner) idts}. |
|
524 |
||
525 |
Furthermore, a syntax translation to transforms @{text "c_binder x\<^sub>1 |
|
526 |
\<dots> x\<^sub>n b"} into iterated application @{text "c (\<lambda>x\<^sub>1. \<dots> c (\<lambda>x\<^sub>n. b)\<dots>)"}. |
|
527 |
This works in both directions, for parsing and printing. *} |
|
528 |
||
529 |
||
46282 | 530 |
section {* Explicit notation \label{sec:notation} *} |
28762 | 531 |
|
532 |
text {* |
|
533 |
\begin{matharray}{rcll} |
|
35413 | 534 |
@{command_def "type_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
535 |
@{command_def "no_type_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
28762 | 536 |
@{command_def "notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
537 |
@{command_def "no_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
|
36508
03d2a2d0ee4a
allow concrete syntax for local entities within a proof body, either via regular mixfix annotations to 'fix' etc. or the separate 'write' command;
wenzelm
parents:
35413
diff
changeset
|
538 |
@{command_def "write"} & : & @{text "proof(state) \<rightarrow> proof(state)"} \\ |
28762 | 539 |
\end{matharray} |
540 |
||
46288 | 541 |
Commands that introduce new logical entities (terms or types) |
542 |
usually allow to provide mixfix annotations on the spot, which is |
|
543 |
convenient for default notation. Nonetheless, the syntax may be |
|
544 |
modified later on by declarations for explicit notation. This |
|
545 |
allows to add or delete mixfix annotations for of existing logical |
|
546 |
entities within the current context. |
|
547 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
548 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
549 |
(@@{command type_notation} | @@{command no_type_notation}) @{syntax target}? |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
550 |
@{syntax mode}? \\ (@{syntax nameref} @{syntax mixfix} + @'and') |
35413 | 551 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
552 |
(@@{command notation} | @@{command no_notation}) @{syntax target}? @{syntax mode}? \\ |
42705 | 553 |
(@{syntax nameref} @{syntax struct_mixfix} + @'and') |
28762 | 554 |
; |
42705 | 555 |
@@{command write} @{syntax mode}? (@{syntax nameref} @{syntax struct_mixfix} + @'and') |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
556 |
"} |
28762 | 557 |
|
558 |
\begin{description} |
|
559 |
||
35413 | 560 |
\item @{command "type_notation"}~@{text "c (mx)"} associates mixfix |
561 |
syntax with an existing type constructor. The arity of the |
|
562 |
constructor is retrieved from the context. |
|
46282 | 563 |
|
35413 | 564 |
\item @{command "no_type_notation"} is similar to @{command |
565 |
"type_notation"}, but removes the specified syntax annotation from |
|
566 |
the present context. |
|
567 |
||
28762 | 568 |
\item @{command "notation"}~@{text "c (mx)"} associates mixfix |
35413 | 569 |
syntax with an existing constant or fixed variable. The type |
570 |
declaration of the given entity is retrieved from the context. |
|
46282 | 571 |
|
28762 | 572 |
\item @{command "no_notation"} is similar to @{command "notation"}, |
573 |
but removes the specified syntax annotation from the present |
|
574 |
context. |
|
575 |
||
36508
03d2a2d0ee4a
allow concrete syntax for local entities within a proof body, either via regular mixfix annotations to 'fix' etc. or the separate 'write' command;
wenzelm
parents:
35413
diff
changeset
|
576 |
\item @{command "write"} is similar to @{command "notation"}, but |
03d2a2d0ee4a
allow concrete syntax for local entities within a proof body, either via regular mixfix annotations to 'fix' etc. or the separate 'write' command;
wenzelm
parents:
35413
diff
changeset
|
577 |
works within an Isar proof body. |
03d2a2d0ee4a
allow concrete syntax for local entities within a proof body, either via regular mixfix annotations to 'fix' etc. or the separate 'write' command;
wenzelm
parents:
35413
diff
changeset
|
578 |
|
28762 | 579 |
\end{description} |
580 |
*} |
|
581 |
||
28778 | 582 |
|
583 |
section {* The Pure syntax \label{sec:pure-syntax} *} |
|
28769
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
584 |
|
46282 | 585 |
subsection {* Lexical matters \label{sec:inner-lex} *} |
586 |
||
587 |
text {* The inner lexical syntax vaguely resembles the outer one |
|
588 |
(\secref{sec:outer-lex}), but some details are different. There are |
|
589 |
two main categories of inner syntax tokens: |
|
590 |
||
591 |
\begin{enumerate} |
|
592 |
||
593 |
\item \emph{delimiters} --- the literal tokens occurring in |
|
594 |
productions of the given priority grammar (cf.\ |
|
595 |
\secref{sec:priority-grammar}); |
|
596 |
||
597 |
\item \emph{named tokens} --- various categories of identifiers etc. |
|
598 |
||
599 |
\end{enumerate} |
|
600 |
||
601 |
Delimiters override named tokens and may thus render certain |
|
602 |
identifiers inaccessible. Sometimes the logical context admits |
|
603 |
alternative ways to refer to the same entity, potentially via |
|
604 |
qualified names. |
|
605 |
||
606 |
\medskip The categories for named tokens are defined once and for |
|
607 |
all as follows, reusing some categories of the outer token syntax |
|
608 |
(\secref{sec:outer-lex}). |
|
609 |
||
610 |
\begin{center} |
|
611 |
\begin{supertabular}{rcl} |
|
612 |
@{syntax_def (inner) id} & = & @{syntax_ref ident} \\ |
|
613 |
@{syntax_def (inner) longid} & = & @{syntax_ref longident} \\ |
|
614 |
@{syntax_def (inner) var} & = & @{syntax_ref var} \\ |
|
615 |
@{syntax_def (inner) tid} & = & @{syntax_ref typefree} \\ |
|
616 |
@{syntax_def (inner) tvar} & = & @{syntax_ref typevar} \\ |
|
617 |
@{syntax_def (inner) num_token} & = & @{syntax_ref nat}@{text " | "}@{verbatim "-"}@{syntax_ref nat} \\ |
|
618 |
@{syntax_def (inner) float_token} & = & @{syntax_ref nat}@{verbatim "."}@{syntax_ref nat}@{text " | "}@{verbatim "-"}@{syntax_ref nat}@{verbatim "."}@{syntax_ref nat} \\ |
|
619 |
@{syntax_def (inner) xnum_token} & = & @{verbatim "#"}@{syntax_ref nat}@{text " | "}@{verbatim "#-"}@{syntax_ref nat} \\ |
|
620 |
||
621 |
@{syntax_def (inner) xstr} & = & @{verbatim "''"} @{text "\<dots>"} @{verbatim "''"} \\ |
|
622 |
\end{supertabular} |
|
623 |
\end{center} |
|
624 |
||
625 |
The token categories @{syntax (inner) num_token}, @{syntax (inner) |
|
626 |
float_token}, @{syntax (inner) xnum_token}, and @{syntax (inner) |
|
627 |
xstr} are not used in Pure. Object-logics may implement numerals |
|
628 |
and string constants by adding appropriate syntax declarations, |
|
629 |
together with some translation functions (e.g.\ see Isabelle/HOL). |
|
630 |
||
631 |
The derived categories @{syntax_def (inner) num_const}, @{syntax_def |
|
632 |
(inner) float_const}, and @{syntax_def (inner) num_const} provide |
|
633 |
robust access to the respective tokens: the syntax tree holds a |
|
634 |
syntactic constant instead of a free variable. |
|
635 |
*} |
|
636 |
||
637 |
||
28777 | 638 |
subsection {* Priority grammars \label{sec:priority-grammar} *} |
28769
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
639 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
640 |
text {* A context-free grammar consists of a set of \emph{terminal |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
641 |
symbols}, a set of \emph{nonterminal symbols} and a set of |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
642 |
\emph{productions}. Productions have the form @{text "A = \<gamma>"}, |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
643 |
where @{text A} is a nonterminal and @{text \<gamma>} is a string of |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
644 |
terminals and nonterminals. One designated nonterminal is called |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
645 |
the \emph{root symbol}. The language defined by the grammar |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
646 |
consists of all strings of terminals that can be derived from the |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
647 |
root symbol by applying productions as rewrite rules. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
648 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
649 |
The standard Isabelle parser for inner syntax uses a \emph{priority |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
650 |
grammar}. Each nonterminal is decorated by an integer priority: |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
651 |
@{text "A\<^sup>(\<^sup>p\<^sup>)"}. In a derivation, @{text "A\<^sup>(\<^sup>p\<^sup>)"} may be rewritten |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
652 |
using a production @{text "A\<^sup>(\<^sup>q\<^sup>) = \<gamma>"} only if @{text "p \<le> q"}. Any |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
653 |
priority grammar can be translated into a normal context-free |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
654 |
grammar by introducing new nonterminals and productions. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
655 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
656 |
\medskip Formally, a set of context free productions @{text G} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
657 |
induces a derivation relation @{text "\<longrightarrow>\<^sub>G"} as follows. Let @{text |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
658 |
\<alpha>} and @{text \<beta>} denote strings of terminal or nonterminal symbols. |
28774 | 659 |
Then @{text "\<alpha> A\<^sup>(\<^sup>p\<^sup>) \<beta> \<longrightarrow>\<^sub>G \<alpha> \<gamma> \<beta>"} holds if and only if @{text G} |
660 |
contains some production @{text "A\<^sup>(\<^sup>q\<^sup>) = \<gamma>"} for @{text "p \<le> q"}. |
|
28769
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
661 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
662 |
\medskip The following grammar for arithmetic expressions |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
663 |
demonstrates how binding power and associativity of operators can be |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
664 |
enforced by priorities. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
665 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
666 |
\begin{center} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
667 |
\begin{tabular}{rclr} |
28774 | 668 |
@{text "A\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} & @{text "="} & @{verbatim "("} @{text "A\<^sup>(\<^sup>0\<^sup>)"} @{verbatim ")"} \\ |
28769
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
669 |
@{text "A\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} & @{text "="} & @{verbatim 0} \\ |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
670 |
@{text "A\<^sup>(\<^sup>0\<^sup>)"} & @{text "="} & @{text "A\<^sup>(\<^sup>0\<^sup>)"} @{verbatim "+"} @{text "A\<^sup>(\<^sup>1\<^sup>)"} \\ |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
671 |
@{text "A\<^sup>(\<^sup>2\<^sup>)"} & @{text "="} & @{text "A\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "*"} @{text "A\<^sup>(\<^sup>2\<^sup>)"} \\ |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
672 |
@{text "A\<^sup>(\<^sup>3\<^sup>)"} & @{text "="} & @{verbatim "-"} @{text "A\<^sup>(\<^sup>3\<^sup>)"} \\ |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
673 |
\end{tabular} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
674 |
\end{center} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
675 |
The choice of priorities determines that @{verbatim "-"} binds |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
676 |
tighter than @{verbatim "*"}, which binds tighter than @{verbatim |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
677 |
"+"}. Furthermore @{verbatim "+"} associates to the left and |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
678 |
@{verbatim "*"} to the right. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
679 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
680 |
\medskip For clarity, grammars obey these conventions: |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
681 |
\begin{itemize} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
682 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
683 |
\item All priorities must lie between 0 and 1000. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
684 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
685 |
\item Priority 0 on the right-hand side and priority 1000 on the |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
686 |
left-hand side may be omitted. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
687 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
688 |
\item The production @{text "A\<^sup>(\<^sup>p\<^sup>) = \<alpha>"} is written as @{text "A = \<alpha> |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
689 |
(p)"}, i.e.\ the priority of the left-hand side actually appears in |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
690 |
a column on the far right. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
691 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
692 |
\item Alternatives are separated by @{text "|"}. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
693 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
694 |
\item Repetition is indicated by dots @{text "(\<dots>)"} in an informal |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
695 |
but obvious way. |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
696 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
697 |
\end{itemize} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
698 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
699 |
Using these conventions, the example grammar specification above |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
700 |
takes the form: |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
701 |
\begin{center} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
702 |
\begin{tabular}{rclc} |
28774 | 703 |
@{text A} & @{text "="} & @{verbatim "("} @{text A} @{verbatim ")"} \\ |
704 |
& @{text "|"} & @{verbatim 0} & \qquad\qquad \\ |
|
28769
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
705 |
& @{text "|"} & @{text A} @{verbatim "+"} @{text "A\<^sup>(\<^sup>1\<^sup>)"} & @{text "(0)"} \\ |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
706 |
& @{text "|"} & @{text "A\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "*"} @{text "A\<^sup>(\<^sup>2\<^sup>)"} & @{text "(2)"} \\ |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
707 |
& @{text "|"} & @{verbatim "-"} @{text "A\<^sup>(\<^sup>3\<^sup>)"} & @{text "(3)"} \\ |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
708 |
\end{tabular} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
709 |
\end{center} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
710 |
*} |
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
711 |
|
8fc228f21861
added section "Priority grammars" (variant from old ref manual);
wenzelm
parents:
28767
diff
changeset
|
712 |
|
46290 | 713 |
subsection {* The Pure grammar \label{sec:pure-grammar} *} |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
714 |
|
46287 | 715 |
text {* The priority grammar of the @{text "Pure"} theory is defined |
716 |
approximately like this: |
|
28774 | 717 |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
718 |
\begin{center} |
28773 | 719 |
\begin{supertabular}{rclr} |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
720 |
|
28778 | 721 |
@{syntax_def (inner) any} & = & @{text "prop | logic"} \\\\ |
28772 | 722 |
|
28778 | 723 |
@{syntax_def (inner) prop} & = & @{verbatim "("} @{text prop} @{verbatim ")"} \\ |
28772 | 724 |
& @{text "|"} & @{text "prop\<^sup>(\<^sup>4\<^sup>)"} @{verbatim "::"} @{text type} & @{text "(3)"} \\ |
725 |
& @{text "|"} & @{text "any\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "=="} @{text "any\<^sup>(\<^sup>2\<^sup>)"} & @{text "(2)"} \\ |
|
28773 | 726 |
& @{text "|"} & @{text "any\<^sup>(\<^sup>3\<^sup>)"} @{text "\<equiv>"} @{text "any\<^sup>(\<^sup>2\<^sup>)"} & @{text "(2)"} \\ |
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28779
diff
changeset
|
727 |
& @{text "|"} & @{text "prop\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "&&&"} @{text "prop\<^sup>(\<^sup>2\<^sup>)"} & @{text "(2)"} \\ |
28772 | 728 |
& @{text "|"} & @{text "prop\<^sup>(\<^sup>2\<^sup>)"} @{verbatim "==>"} @{text "prop\<^sup>(\<^sup>1\<^sup>)"} & @{text "(1)"} \\ |
28773 | 729 |
& @{text "|"} & @{text "prop\<^sup>(\<^sup>2\<^sup>)"} @{text "\<Longrightarrow>"} @{text "prop\<^sup>(\<^sup>1\<^sup>)"} & @{text "(1)"} \\ |
28772 | 730 |
& @{text "|"} & @{verbatim "[|"} @{text prop} @{verbatim ";"} @{text "\<dots>"} @{verbatim ";"} @{text prop} @{verbatim "|]"} @{verbatim "==>"} @{text "prop\<^sup>(\<^sup>1\<^sup>)"} & @{text "(1)"} \\ |
28773 | 731 |
& @{text "|"} & @{text "\<lbrakk>"} @{text prop} @{verbatim ";"} @{text "\<dots>"} @{verbatim ";"} @{text prop} @{text "\<rbrakk>"} @{text "\<Longrightarrow>"} @{text "prop\<^sup>(\<^sup>1\<^sup>)"} & @{text "(1)"} \\ |
28772 | 732 |
& @{text "|"} & @{verbatim "!!"} @{text idts} @{verbatim "."} @{text prop} & @{text "(0)"} \\ |
28773 | 733 |
& @{text "|"} & @{text "\<And>"} @{text idts} @{verbatim "."} @{text prop} & @{text "(0)"} \\ |
734 |
& @{text "|"} & @{verbatim OFCLASS} @{verbatim "("} @{text type} @{verbatim ","} @{text logic} @{verbatim ")"} \\ |
|
735 |
& @{text "|"} & @{verbatim SORT_CONSTRAINT} @{verbatim "("} @{text type} @{verbatim ")"} \\ |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28779
diff
changeset
|
736 |
& @{text "|"} & @{verbatim TERM} @{text logic} \\ |
28773 | 737 |
& @{text "|"} & @{verbatim PROP} @{text aprop} \\\\ |
28772 | 738 |
|
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28779
diff
changeset
|
739 |
@{syntax_def (inner) aprop} & = & @{verbatim "("} @{text aprop} @{verbatim ")"} \\ |
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28779
diff
changeset
|
740 |
& @{text "|"} & @{text "id | longid | var | "}@{verbatim "_"}@{text " | "}@{verbatim "..."} \\ |
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28779
diff
changeset
|
741 |
& @{text "|"} & @{verbatim CONST} @{text "id | "}@{verbatim CONST} @{text "longid"} \\ |
46287 | 742 |
& @{text "|"} & @{verbatim XCONST} @{text "id | "}@{verbatim XCONST} @{text "longid"} \\ |
28773 | 743 |
& @{text "|"} & @{text "logic\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>) any\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>) \<dots> any\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} & @{text "(999)"} \\\\ |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
744 |
|
28778 | 745 |
@{syntax_def (inner) logic} & = & @{verbatim "("} @{text logic} @{verbatim ")"} \\ |
28772 | 746 |
& @{text "|"} & @{text "logic\<^sup>(\<^sup>4\<^sup>)"} @{verbatim "::"} @{text type} & @{text "(3)"} \\ |
28773 | 747 |
& @{text "|"} & @{text "id | longid | var | "}@{verbatim "_"}@{text " | "}@{verbatim "..."} \\ |
28856
5e009a80fe6d
Pure syntax: more coherent treatment of aprop, permanent TERM and &&&;
wenzelm
parents:
28779
diff
changeset
|
748 |
& @{text "|"} & @{verbatim CONST} @{text "id | "}@{verbatim CONST} @{text "longid"} \\ |
46287 | 749 |
& @{text "|"} & @{verbatim XCONST} @{text "id | "}@{verbatim XCONST} @{text "longid"} \\ |
28773 | 750 |
& @{text "|"} & @{text "logic\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>) any\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>) \<dots> any\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} & @{text "(999)"} \\ |
46287 | 751 |
& @{text "|"} & @{text "\<struct> index\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} \\ |
28772 | 752 |
& @{text "|"} & @{verbatim "%"} @{text pttrns} @{verbatim "."} @{text "any\<^sup>(\<^sup>3\<^sup>)"} & @{text "(3)"} \\ |
28773 | 753 |
& @{text "|"} & @{text \<lambda>} @{text pttrns} @{verbatim "."} @{text "any\<^sup>(\<^sup>3\<^sup>)"} & @{text "(3)"} \\ |
46287 | 754 |
& @{text "|"} & @{verbatim op} @{verbatim "=="}@{text " | "}@{verbatim op} @{text "\<equiv>"}@{text " | "}@{verbatim op} @{verbatim "&&&"} \\ |
755 |
& @{text "|"} & @{verbatim op} @{verbatim "==>"}@{text " | "}@{verbatim op} @{text "\<Longrightarrow>"} \\ |
|
28772 | 756 |
& @{text "|"} & @{verbatim TYPE} @{verbatim "("} @{text type} @{verbatim ")"} \\\\ |
757 |
||
28778 | 758 |
@{syntax_def (inner) idt} & = & @{verbatim "("} @{text idt} @{verbatim ")"}@{text " | id | "}@{verbatim "_"} \\ |
28773 | 759 |
& @{text "|"} & @{text id} @{verbatim "::"} @{text type} & @{text "(0)"} \\ |
760 |
& @{text "|"} & @{verbatim "_"} @{verbatim "::"} @{text type} & @{text "(0)"} \\\\ |
|
28772 | 761 |
|
46287 | 762 |
@{syntax_def (inner) index} & = & @{verbatim "\<^bsub>"} @{text "logic\<^sup>(\<^sup>0\<^sup>)"} @{verbatim "\<^esub>"}@{text " | | \<index>"} \\\\ |
763 |
||
28778 | 764 |
@{syntax_def (inner) idts} & = & @{text "idt | idt\<^sup>(\<^sup>1\<^sup>) idts"} & @{text "(0)"} \\\\ |
28772 | 765 |
|
28778 | 766 |
@{syntax_def (inner) pttrn} & = & @{text idt} \\\\ |
28772 | 767 |
|
28778 | 768 |
@{syntax_def (inner) pttrns} & = & @{text "pttrn | pttrn\<^sup>(\<^sup>1\<^sup>) pttrns"} & @{text "(0)"} \\\\ |
28774 | 769 |
|
28778 | 770 |
@{syntax_def (inner) type} & = & @{verbatim "("} @{text type} @{verbatim ")"} \\ |
28773 | 771 |
& @{text "|"} & @{text "tid | tvar | "}@{verbatim "_"} \\ |
772 |
& @{text "|"} & @{text "tid"} @{verbatim "::"} @{text "sort | tvar "}@{verbatim "::"} @{text "sort | "}@{verbatim "_"} @{verbatim "::"} @{text "sort"} \\ |
|
46287 | 773 |
& @{text "|"} & @{text "type_name | type\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>) type_name"} \\ |
774 |
& @{text "|"} & @{verbatim "("} @{text type} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text type} @{verbatim ")"} @{text type_name} \\ |
|
28772 | 775 |
& @{text "|"} & @{text "type\<^sup>(\<^sup>1\<^sup>)"} @{verbatim "=>"} @{text type} & @{text "(0)"} \\ |
28773 | 776 |
& @{text "|"} & @{text "type\<^sup>(\<^sup>1\<^sup>)"} @{text "\<Rightarrow>"} @{text type} & @{text "(0)"} \\ |
777 |
& @{text "|"} & @{verbatim "["} @{text type} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text type} @{verbatim "]"} @{verbatim "=>"} @{text type} & @{text "(0)"} \\ |
|
46287 | 778 |
& @{text "|"} & @{verbatim "["} @{text type} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text type} @{verbatim "]"} @{text "\<Rightarrow>"} @{text type} & @{text "(0)"} \\ |
779 |
@{syntax_def (inner) type_name} & = & @{text "id | longid"} \\\\ |
|
28772 | 780 |
|
46287 | 781 |
@{syntax_def (inner) sort} & = & @{syntax class_name}~@{text " | "}@{verbatim "{}"} \\ |
782 |
& @{text "|"} & @{verbatim "{"} @{syntax class_name} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{syntax class_name} @{verbatim "}"} \\ |
|
783 |
@{syntax_def (inner) class_name} & = & @{text "id | longid"} \\ |
|
28773 | 784 |
\end{supertabular} |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
785 |
\end{center} |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
786 |
|
28774 | 787 |
\medskip Here literal terminals are printed @{verbatim "verbatim"}; |
788 |
see also \secref{sec:inner-lex} for further token categories of the |
|
789 |
inner syntax. The meaning of the nonterminals defined by the above |
|
790 |
grammar is as follows: |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
791 |
|
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
792 |
\begin{description} |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
793 |
|
28778 | 794 |
\item @{syntax_ref (inner) any} denotes any term. |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
795 |
|
28778 | 796 |
\item @{syntax_ref (inner) prop} denotes meta-level propositions, |
797 |
which are terms of type @{typ prop}. The syntax of such formulae of |
|
798 |
the meta-logic is carefully distinguished from usual conventions for |
|
799 |
object-logics. In particular, plain @{text "\<lambda>"}-term notation is |
|
800 |
\emph{not} recognized as @{syntax (inner) prop}. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
801 |
|
28778 | 802 |
\item @{syntax_ref (inner) aprop} denotes atomic propositions, which |
803 |
are embedded into regular @{syntax (inner) prop} by means of an |
|
804 |
explicit @{verbatim PROP} token. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
805 |
|
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
806 |
Terms of type @{typ prop} with non-constant head, e.g.\ a plain |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
807 |
variable, are printed in this form. Constants that yield type @{typ |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
808 |
prop} are expected to provide their own concrete syntax; otherwise |
28778 | 809 |
the printed version will appear like @{syntax (inner) logic} and |
810 |
cannot be parsed again as @{syntax (inner) prop}. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
811 |
|
28778 | 812 |
\item @{syntax_ref (inner) logic} denotes arbitrary terms of a |
813 |
logical type, excluding type @{typ prop}. This is the main |
|
814 |
syntactic category of object-logic entities, covering plain @{text |
|
815 |
\<lambda>}-term notation (variables, abstraction, application), plus |
|
816 |
anything defined by the user. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
817 |
|
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
818 |
When specifying notation for logical entities, all logical types |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
819 |
(excluding @{typ prop}) are \emph{collapsed} to this single category |
28778 | 820 |
of @{syntax (inner) logic}. |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
821 |
|
46287 | 822 |
\item @{syntax_ref (inner) index} denotes an optional index term for |
823 |
indexed syntax. If omitted, it refers to the first @{keyword |
|
824 |
"structure"} variable in the context. The special dummy ``@{text |
|
825 |
"\<index>"}'' serves as pattern variable in mixfix annotations that |
|
826 |
introduce indexed notation. |
|
827 |
||
28778 | 828 |
\item @{syntax_ref (inner) idt} denotes identifiers, possibly |
829 |
constrained by types. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
830 |
|
28778 | 831 |
\item @{syntax_ref (inner) idts} denotes a sequence of @{syntax_ref |
832 |
(inner) idt}. This is the most basic category for variables in |
|
833 |
iterated binders, such as @{text "\<lambda>"} or @{text "\<And>"}. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
834 |
|
28778 | 835 |
\item @{syntax_ref (inner) pttrn} and @{syntax_ref (inner) pttrns} |
836 |
denote patterns for abstraction, cases bindings etc. In Pure, these |
|
837 |
categories start as a merely copy of @{syntax (inner) idt} and |
|
838 |
@{syntax (inner) idts}, respectively. Object-logics may add |
|
839 |
additional productions for binding forms. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
840 |
|
28778 | 841 |
\item @{syntax_ref (inner) type} denotes types of the meta-logic. |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
842 |
|
28778 | 843 |
\item @{syntax_ref (inner) sort} denotes meta-level sorts. |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
844 |
|
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
845 |
\end{description} |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
846 |
|
28774 | 847 |
Here are some further explanations of certain syntax features. |
28773 | 848 |
|
849 |
\begin{itemize} |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
850 |
|
28778 | 851 |
\item In @{syntax (inner) idts}, note that @{text "x :: nat y"} is |
852 |
parsed as @{text "x :: (nat y)"}, treating @{text y} like a type |
|
853 |
constructor applied to @{text nat}. To avoid this interpretation, |
|
854 |
write @{text "(x :: nat) y"} with explicit parentheses. |
|
28773 | 855 |
|
856 |
\item Similarly, @{text "x :: nat y :: nat"} is parsed as @{text "x :: |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
857 |
(nat y :: nat)"}. The correct form is @{text "(x :: nat) (y :: |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
858 |
nat)"}, or @{text "(x :: nat) y :: nat"} if @{text y} is last in the |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
859 |
sequence of identifiers. |
28773 | 860 |
|
861 |
\item Type constraints for terms bind very weakly. For example, |
|
862 |
@{text "x < y :: nat"} is normally parsed as @{text "(x < y) :: |
|
863 |
nat"}, unless @{text "<"} has a very low priority, in which case the |
|
864 |
input is likely to be ambiguous. The correct form is @{text "x < (y |
|
865 |
:: nat)"}. |
|
866 |
||
867 |
\item Constraints may be either written with two literal colons |
|
868 |
``@{verbatim "::"}'' or the double-colon symbol @{verbatim "\<Colon>"}, |
|
28774 | 869 |
which actually looks exactly the same in some {\LaTeX} styles. |
28773 | 870 |
|
28774 | 871 |
\item Dummy variables (written as underscore) may occur in different |
872 |
roles. |
|
28773 | 873 |
|
874 |
\begin{description} |
|
875 |
||
28774 | 876 |
\item A type ``@{text "_"}'' or ``@{text "_ :: sort"}'' acts like an |
877 |
anonymous inference parameter, which is filled-in according to the |
|
878 |
most general type produced by the type-checking phase. |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
879 |
|
28774 | 880 |
\item A bound ``@{text "_"}'' refers to a vacuous abstraction, where |
881 |
the body does not refer to the binding introduced here. As in the |
|
882 |
term @{term "\<lambda>x _. x"}, which is @{text "\<alpha>"}-equivalent to @{text |
|
883 |
"\<lambda>x y. x"}. |
|
28773 | 884 |
|
28774 | 885 |
\item A free ``@{text "_"}'' refers to an implicit outer binding. |
886 |
Higher definitional packages usually allow forms like @{text "f x _ |
|
887 |
= x"}. |
|
28773 | 888 |
|
28774 | 889 |
\item A schematic ``@{text "_"}'' (within a term pattern, see |
890 |
\secref{sec:term-decls}) refers to an anonymous variable that is |
|
891 |
implicitly abstracted over its context of locally bound variables. |
|
892 |
For example, this allows pattern matching of @{text "{x. f x = g |
|
893 |
x}"} against @{text "{x. _ = _}"}, or even @{text "{_. _ = _}"} by |
|
894 |
using both bound and schematic dummies. |
|
28773 | 895 |
|
896 |
\end{description} |
|
897 |
||
28774 | 898 |
\item The three literal dots ``@{verbatim "..."}'' may be also |
899 |
written as ellipsis symbol @{verbatim "\<dots>"}. In both cases this |
|
900 |
refers to a special schematic variable, which is bound in the |
|
901 |
context. This special term abbreviation works nicely with |
|
902 |
calculational reasoning (\secref{sec:calculation}). |
|
903 |
||
46287 | 904 |
\item @{verbatim CONST} ensures that the given identifier is treated |
905 |
as constant term, and passed through the parse tree in fully |
|
906 |
internalized form. This is particularly relevant for translation |
|
907 |
rules (\secref{sec:syn-trans}), notably on the RHS. |
|
908 |
||
909 |
\item @{verbatim XCONST} is similar to @{verbatim CONST}, but |
|
910 |
retains the constant name as given. This is only relevant to |
|
911 |
translation rules (\secref{sec:syn-trans}), notably on the LHS. |
|
912 |
||
28773 | 913 |
\end{itemize} |
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
914 |
*} |
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
915 |
|
28777 | 916 |
|
46282 | 917 |
subsection {* Inspecting the syntax *} |
28777 | 918 |
|
46282 | 919 |
text {* |
920 |
\begin{matharray}{rcl} |
|
921 |
@{command_def "print_syntax"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
|
922 |
\end{matharray} |
|
28777 | 923 |
|
46282 | 924 |
\begin{description} |
925 |
||
926 |
\item @{command "print_syntax"} prints the inner syntax of the |
|
927 |
current context. The output can be quite large; the most important |
|
928 |
sections are explained below. |
|
28777 | 929 |
|
46282 | 930 |
\begin{description} |
28777 | 931 |
|
46282 | 932 |
\item @{text "lexicon"} lists the delimiters of the inner token |
933 |
language; see \secref{sec:inner-lex}. |
|
28777 | 934 |
|
46282 | 935 |
\item @{text "prods"} lists the productions of the underlying |
936 |
priority grammar; see \secref{sec:priority-grammar}. |
|
28777 | 937 |
|
46282 | 938 |
The nonterminal @{text "A\<^sup>(\<^sup>p\<^sup>)"} is rendered in plain text as @{text |
939 |
"A[p]"}; delimiters are quoted. Many productions have an extra |
|
940 |
@{text "\<dots> => name"}. These names later become the heads of parse |
|
941 |
trees; they also guide the pretty printer. |
|
28777 | 942 |
|
46282 | 943 |
Productions without such parse tree names are called \emph{copy |
944 |
productions}. Their right-hand side must have exactly one |
|
945 |
nonterminal symbol (or named token). The parser does not create a |
|
946 |
new parse tree node for copy productions, but simply returns the |
|
947 |
parse tree of the right-hand symbol. |
|
948 |
||
949 |
If the right-hand side of a copy production consists of a single |
|
950 |
nonterminal without any delimiters, then it is called a \emph{chain |
|
951 |
production}. Chain productions act as abbreviations: conceptually, |
|
952 |
they are removed from the grammar by adding new productions. |
|
953 |
Priority information attached to chain productions is ignored; only |
|
954 |
the dummy value @{text "-1"} is displayed. |
|
955 |
||
956 |
\item @{text "print modes"} lists the alternative print modes |
|
957 |
provided by this grammar; see \secref{sec:print-modes}. |
|
28777 | 958 |
|
46282 | 959 |
\item @{text "parse_rules"} and @{text "print_rules"} relate to |
960 |
syntax translations (macros); see \secref{sec:syn-trans}. |
|
961 |
||
962 |
\item @{text "parse_ast_translation"} and @{text |
|
963 |
"print_ast_translation"} list sets of constants that invoke |
|
964 |
translation functions for abstract syntax trees, which are only |
|
965 |
required in very special situations; see \secref{sec:tr-funs}. |
|
28777 | 966 |
|
46282 | 967 |
\item @{text "parse_translation"} and @{text "print_translation"} |
968 |
list the sets of constants that invoke regular translation |
|
969 |
functions; see \secref{sec:tr-funs}. |
|
29157 | 970 |
|
46282 | 971 |
\end{description} |
972 |
||
973 |
\end{description} |
|
28777 | 974 |
*} |
28774 | 975 |
|
28770
93a372e2dc7a
added section "The Pure grammar" (incomplete version, based on old ref manual);
wenzelm
parents:
28769
diff
changeset
|
976 |
|
46282 | 977 |
section {* Raw syntax and translations \label{sec:syn-trans} *} |
28762 | 978 |
|
979 |
text {* |
|
980 |
\begin{matharray}{rcl} |
|
41229
d797baa3d57c
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents:
40879
diff
changeset
|
981 |
@{command_def "nonterminal"} & : & @{text "theory \<rightarrow> theory"} \\ |
28762 | 982 |
@{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |
983 |
@{command_def "no_syntax"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
984 |
@{command_def "translations"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
985 |
@{command_def "no_translations"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
986 |
\end{matharray} |
|
987 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
988 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
989 |
@@{command nonterminal} (@{syntax name} + @'and') |
28762 | 990 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
991 |
(@@{command syntax} | @@{command no_syntax}) @{syntax mode}? (@{syntax constdecl} +) |
28762 | 992 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
993 |
(@@{command translations} | @@{command no_translations}) |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
994 |
(transpat ('==' | '=>' | '<=' | '\<rightleftharpoons>' | '\<rightharpoonup>' | '\<leftharpoondown>') transpat +) |
28762 | 995 |
; |
996 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
997 |
mode: ('(' ( @{syntax name} | @'output' | @{syntax name} @'output' ) ')') |
28762 | 998 |
; |
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
999 |
transpat: ('(' @{syntax nameref} ')')? @{syntax string} |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
1000 |
"} |
28762 | 1001 |
|
1002 |
\begin{description} |
|
46282 | 1003 |
|
41229
d797baa3d57c
replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents:
40879
diff
changeset
|
1004 |
\item @{command "nonterminal"}~@{text c} declares a type |
28762 | 1005 |
constructor @{text c} (without arguments) to act as purely syntactic |
1006 |
type: a nonterminal symbol of the inner syntax. |
|
1007 |
||
1008 |
\item @{command "syntax"}~@{text "(mode) decls"} is similar to |
|
1009 |
@{command "consts"}~@{text decls}, except that the actual logical |
|
1010 |
signature extension is omitted. Thus the context free grammar of |
|
1011 |
Isabelle's inner syntax may be augmented in arbitrary ways, |
|
1012 |
independently of the logic. The @{text mode} argument refers to the |
|
1013 |
print mode that the grammar rules belong; unless the @{keyword_ref |
|
1014 |
"output"} indicator is given, all productions are added both to the |
|
1015 |
input and output grammar. |
|
46282 | 1016 |
|
28762 | 1017 |
\item @{command "no_syntax"}~@{text "(mode) decls"} removes grammar |
1018 |
declarations (and translations) resulting from @{text decls}, which |
|
1019 |
are interpreted in the same manner as for @{command "syntax"} above. |
|
46282 | 1020 |
|
28762 | 1021 |
\item @{command "translations"}~@{text rules} specifies syntactic |
1022 |
translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}), |
|
1023 |
parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}). |
|
1024 |
Translation patterns may be prefixed by the syntactic category to be |
|
1025 |
used for parsing; the default is @{text logic}. |
|
46282 | 1026 |
|
28762 | 1027 |
\item @{command "no_translations"}~@{text rules} removes syntactic |
1028 |
translation rules, which are interpreted in the same manner as for |
|
1029 |
@{command "translations"} above. |
|
1030 |
||
1031 |
\end{description} |
|
1032 |
*} |
|
1033 |
||
1034 |
||
28779
698960f08652
separate section "Inspecting the syntax" for print_syntax;
wenzelm
parents:
28778
diff
changeset
|
1035 |
section {* Syntax translation functions \label{sec:tr-funs} *} |
28762 | 1036 |
|
1037 |
text {* |
|
1038 |
\begin{matharray}{rcl} |
|
1039 |
@{command_def "parse_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1040 |
@{command_def "parse_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1041 |
@{command_def "print_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1042 |
@{command_def "typed_print_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1043 |
@{command_def "print_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\ |
|
1044 |
\end{matharray} |
|
1045 |
||
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
1046 |
@{rail " |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
1047 |
( @@{command parse_ast_translation} | @@{command parse_translation} | |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
1048 |
@@{command print_translation} | @@{command typed_print_translation} | |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
1049 |
@@{command print_ast_translation}) ('(' @'advanced' ')')? @{syntax text} |
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
1050 |
"} |
28762 | 1051 |
|
1052 |
Syntax translation functions written in ML admit almost arbitrary |
|
1053 |
manipulations of Isabelle's inner syntax. Any of the above commands |
|
42596
6c621a9d612a
modernized rail diagrams using @{rail} antiquotation;
wenzelm
parents:
42358
diff
changeset
|
1054 |
have a single @{syntax text} argument that refers to an ML |
28762 | 1055 |
expression of appropriate type, which are as follows by default: |
1056 |
||
1057 |
%FIXME proper antiquotations |
|
1058 |
\begin{ttbox} |
|
1059 |
val parse_ast_translation : (string * (ast list -> ast)) list |
|
1060 |
val parse_translation : (string * (term list -> term)) list |
|
1061 |
val print_translation : (string * (term list -> term)) list |
|
42247
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
wenzelm
parents:
41229
diff
changeset
|
1062 |
val typed_print_translation : (string * (typ -> term list -> term)) list |
28762 | 1063 |
val print_ast_translation : (string * (ast list -> ast)) list |
1064 |
\end{ttbox} |
|
1065 |
||
1066 |
If the @{text "(advanced)"} option is given, the corresponding |
|
1067 |
translation functions may depend on the current theory or proof |
|
1068 |
context. This allows to implement advanced syntax mechanisms, as |
|
1069 |
translations functions may refer to specific theory declarations or |
|
1070 |
auxiliary proof data. |
|
1071 |
||
30397 | 1072 |
See also \cite{isabelle-ref} for more information on the general |
1073 |
concept of syntax transformations in Isabelle. |
|
28762 | 1074 |
|
1075 |
%FIXME proper antiquotations |
|
1076 |
\begin{ttbox} |
|
1077 |
val parse_ast_translation: |
|
1078 |
(string * (Proof.context -> ast list -> ast)) list |
|
1079 |
val parse_translation: |
|
1080 |
(string * (Proof.context -> term list -> term)) list |
|
1081 |
val print_translation: |
|
1082 |
(string * (Proof.context -> term list -> term)) list |
|
1083 |
val typed_print_translation: |
|
42247
12fe41a92cd5
typed_print_translation: discontinued show_sorts argument;
wenzelm
parents:
41229
diff
changeset
|
1084 |
(string * (Proof.context -> typ -> term list -> term)) list |
28762 | 1085 |
val print_ast_translation: |
1086 |
(string * (Proof.context -> ast list -> ast)) list |
|
1087 |
\end{ttbox} |
|
1088 |
*} |
|
1089 |
||
1090 |
end |