6 \chapter{Isar document syntax}
10 FIXME important note: inner versus outer syntax
12 \section{Lexical matters}
14 \section{Common syntax entities}
16 The Isar proof and theory language syntax has been carefully designed with
17 orthogonality in mind. Subsequently, we introduce several basic syntactic
18 entities, such as names, terms, theorem specifications, which have been
19 factored out of the actual Isar language elements described later.
21 Note that some of the basic syntactic entities introduced below act much like
22 tokens rather than nonterminals, in particular for the sake of error messages.
23 E.g.\ syntax elements such as $\CONSTS$ referring to \railqtoken{name} or
24 \railqtoken{type} would really report a missing name or type rather than any
25 of the constituent primitive tokens such as \railtoken{ident} or
31 Entity \railqtoken{name} usually refers to any name of types, constants,
32 theorems etc.\ that are to be \emph{declared} or \emph{defined} (so qualified
33 identifiers are excluded). Quoted strings provide an escape for
34 non-identifier names or those ruled out by outer syntax keywords (e.g.\
35 \verb|"let"|). Already existing objects are usually referenced by
38 \indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
40 name: ident | symident | string
44 nameref: name | longident
51 Large chunks of plain \railqtoken{text} are usually given
52 \railtoken{verbatim}, i.e.\ enclosed in \verb|{*|\dots\verb|*}|. For
53 convenience, any of the smaller text conforming to \railqtoken{nameref} are
54 admitted as well. Almost any of the Isar commands may be annotated by some
55 marginal \railnonterm{comment} of the form \texttt{--} \railqtoken{text}.
56 Note that this kind of comment is actually part of the language, while source
57 level comments \verb|(*|\dots\verb|*)| are already stripped at the lexical
58 level. A few commands such as $\PROOFNAME$ admit additional markup with a
59 ``level of interest'': \texttt{\%} followed by an optional number $n$ (default
60 $n = 1$) indicates that the respective part of the document becomes $n$ levels
61 more boring or obscure; \texttt{\%\%} means that the interest drops by
62 $\infty$ --- abandon every hope, who enter here.
64 \indexoutertoken{text}\indexouternonterm{comment}\indexouternonterm{interest}
66 text: verbatim | nameref
70 interest: percent nat? | ppercent
75 \subsection{Sorts and arities}
77 The syntax of sorts and arities is given directly at the outer level. Note
78 that this is in contrast to that types and terms (see \ref{sec:types-terms}).
80 \indexouternonterm{sort}\indexouternonterm{arity}\indexouternonterm{simplearity}
81 \indexouternonterm{classdecl}
83 classdecl: name ('<' (nameref ',' +))?
85 sort: nameref | lbrace (nameref * ',') rbrace
87 arity: ('(' (sort + ',') ')')? sort
89 simplearity: ('(' (sort + ',') ')')? nameref
94 \subsection{Types and terms}\label{sec:types-terms}
96 The actual inner Isabelle syntax, that of types and terms of the logic, is far
97 too flexible in order to be modeled explicitly at the outer theory level.
98 Basically, any such entity has to be quoted at the outer level to turn it into
99 a single token, with the actual parsing deferred to some functions for reading
100 and type-checking. For convenience, a more liberal convention is adopted:
101 quotes may be omitted for any type or term that is already \emph{atomic} at
102 the outer level. E.g.\ one may write \texttt{x} instead of \texttt{"x"}.
104 \indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
106 type: nameref | typefree | typevar
108 term: nameref | var | textvar | nat
114 Type declarations and definitions usually refer to \railnonterm{typespec} on
115 the left-hand side. This models basic type constructor application at the
116 outer syntax level. Note that only plain postfix notation is available here,
119 \indexouternonterm{typespec}
121 typespec: (() | typefree | '(' ( typefree + ',' ) ')') name
126 \subsection{Term patterns}
128 Assumptions and goal statements usually admit automatic binding of schematic
129 text variables by giving (optional) patterns of the form $\IS{p@1 \dots p@n}$.
130 There are separate versions available for \railqtoken{term}s and
131 \railqtoken{prop}s. The latter provides a $\CONCLNAME$ part with patterns
132 referring the (atomic) conclusion of a rule.
134 \indexouternonterm{termpat}\indexouternonterm{proppat}
136 termpat: '(' ('is' term +) ')'
138 proppat: '(' (('is' prop +) | 'concl' ('is' prop +) | ('is' prop +) 'concl' ('is' prop +)) ')'
143 \subsection{Mixfix annotations}
145 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
146 terms. Some commands such as $\TYPES$ admit infixes only, while $\CONSTS$ and
147 $\isarkeyword{syntax}$ support the full range of general mixfixes and binders.
149 \indexouternonterm{infix}\indexouternonterm{mixfix}
151 infix: '(' ('infixl' | 'infixr') string? nat ')'
153 mixfix: infix | '(' string pris? nat? ')' | '(' 'binder' string pris? nat ')'
156 pris: '[' (nat + ',') ']'
161 \subsection{Attributes and theorems}\label{sec:syn-att}
163 Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
164 ``semi-inner'' syntax, which does not have to be atomic at the outer level
165 unlike that of types and terms. Instead, the attribute argument
166 specifications may be any sequence of atomic entities (identifiers, strings
167 etc.), or properly bracketed argument lists. Below \railqtoken{atom} refers
168 to any atomic entity, including keywords that conform to \railtoken{symident}.
170 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
172 atom: nameref | typefree | typevar | var | textvar | nat | keyword
174 arg: atom | '(' args ')' | '[' args ']' | lbrace args rbrace
178 attributes: '[' (nameref args * ',') ']'
182 Theorem specifications come in several flavors: \railnonterm{axmdecl} and
183 \railnonterm{thmdecl} usually refer to assumptions or results of goal
184 statements, \railnonterm{thmdef} collects lists of existing theorems,
185 \railnonterm{thmrefs} refers to any lists of existing theorems. Any of these
186 may include lists of attributes, which are applied to the preceding theorem or
189 \indexouternonterm{thmdecl}\indexouternonterm{axmdecl}
190 \indexouternonterm{thmdef}\indexouternonterm{thmrefs}
192 axmdecl: name attributes? ':'
198 thmrefs: nameref attributes? +
201 thmname: name attributes | name | attributes
206 \subsection{Proof methods}\label{sec:syn-meth}
208 Proof methods are either basic ones, or expressions composed of methods via
209 ``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternatives),
210 ``\texttt{?}'' (try), ``\texttt{*}'' (repeat ${} \ge 0$ times), ``\texttt{+}''
211 (repeat ${} > 0$ times). In practice, proof methods are usually just a comma
212 separated list of \railqtoken{nameref}~\railnonterm{args} specifications.
213 Thus the syntax is similar to that of attributes, with plain parentheses
214 instead of square brackets (see also \S\ref{sec:syn-att}). Note that
215 parentheses may be dropped for single method specifications without arguments.
217 \indexouternonterm{method}
219 method: (nameref | '(' methods ')') (() | '?' | '*' | '+')
221 methods: (nameref args | method) + (',' | '|')
228 %%% TeX-master: "isar-ref"