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 Some of the basic syntactic entities introduced below act much like tokens
22 rather than nonterminals, in particular for error messages are concerned.
23 E.g.\ syntax elements such as $\CONSTS$ referring to \railqtoken{name} or
24 \railqtoken{type} would really report a missing \railqtoken{name} or
25 \railqtoken{type} rather than any of its constituent primitive tokens
26 (\railtoken{ident}, \railtoken{string} etc.).
31 Entity \railqtoken{name} usually refers to any name of types, constants,
32 theorems, etc.\ 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{nameref}
40 name : ident | symident | string
42 nameref : name | longident
49 Large chunks of plain \railqtoken{text} are usually given \railtoken{verbatim},
50 i.e.\ enclosed in \verb|{*|\dots\verb|*}|. For convenience, any of the
51 smaller text entities (\railtoken{ident}, \railtoken{string} etc.) are
52 admitted as well. Almost any of the Isar commands may be annotated by a
53 marginal \railnonterm{comment}: \texttt{--} \railqtoken{text}. Note that this
54 kind of comment is actually part of the language, while source level comments
55 \verb|(*|\dots\verb|*)| are already stripped at the lexical level. A few
56 commands such as $\PROOFNAME$ admit additional markup with a ``level of
57 interest'', currently only \texttt{\%} for ``boring, don't read this''.
59 \indexoutertoken{text}\indexouternonterm{comment}\indexouternonterm{interest}
61 text : verbatim | nameref
70 \subsection{Sorts and arities}
72 The syntax of sorts and arities is given directly at the outer level. Note
73 that this in contrast to that types and terms (see below). Only few commands
74 ever refer to sorts or arities explicitly.
76 \indexouternonterm{sort}\indexouternonterm{arity}\indexouternonterm{simplearity}
78 sort : nameref | lbrace (nameref * ',') rbrace
80 arity : ( () | '(' (sort + ',') ')' ) sort
82 simplearity : ( () | '(' (sort + ',') ')' ) nameref
87 \subsection{Types and terms}
89 The actual inner Isabelle syntax, i.e.\ that of types and terms, is far too
90 flexible in order to be modeled explicitly at the outer theory level.
91 Basically, any such entity would have to be quoted at the outer level to turn
92 it into a single token, with the actual parsing deferred to some functions
93 that read and type-check terms etc.\ (note that \railqtoken{prop}s will be
94 handled differently from plain \railqtoken{term}s here). For convenience, the
95 quotes may be omitted for any \emph{atomic} term or type (e.g.\ a single
98 \indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
100 type : nameref | typefree | typevar
102 term : nameref | var | textvar | nat
108 Type definitions etc.\ usually refer to \railnonterm{typespec} on the
109 left-hand side. This models basic type constructor application at the outer
110 syntax level. Note that only plain postfix notation is available here, but no
113 \indexouternonterm{typespec}
115 typespec : (() | typefree | '(' ( typefree + ',' ) ')') name
120 \subsection{Term patterns}
122 Statements like $\SHOWNAME$ involve propositions, some others like $\DEFNAME$
123 plain terms. Any of these usually admit automatic binding of schematic text
124 variables by giving (optional) patterns $\IS{p@1 \dots p@n}$. For
125 \railqtoken{prop}s the $\CONCLNAME$ part refers to the conclusion only, in case
126 actual rules are involved, rather than atomic propositions.
128 \indexouternonterm{termpat}\indexouternonterm{proppat}
130 termpat : '(' (term + 'is' ) ')'
132 proppat : '(' (() | (prop + 'is' )) (() | 'concl' (prop + 'is' )) ')'
137 \subsection{Mixfix annotations}
139 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
140 terms. Some commands such as $\TYPES$ admit infixes only, while $\CONSTS$
141 etc.\ support the full range of general mixfixes and binders.
143 \indexouternonterm{infix}\indexouternonterm{mixfix}
145 infix : '(' ('infixl' | 'infixr') (() | string) nat ')'
148 mixfix : infix | string (() | '[' (nat + ',') ']') (() | nat) |
149 'binder' string (() | '[' (nat + ',') ']') nat
154 \subsection{Attributes and theorems}\label{sec:syn-att}
156 Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
157 ``semi-inner'' syntax, which does not have to be atomic at the outer level
158 unlike that of types and terms. Instead, the attribute argument
159 specifications may be any sequence of atomic entities (identifiers, strings
160 etc.), or properly bracketed argument lists. Below \railqtoken{atom} refers to
161 any atomic entity (\railtoken{ident}, \railtoken{longident},
162 \railtoken{symident} etc.), including keywords that conform to
163 \railtoken{symident}, but do not coincide with actual command names.
165 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
167 atom : nameref | typefree | typevar | var | textvar | nat
169 arg : atom | '(' args ')' | '[' args ']' | lbrace args rbrace
173 attributes : '[' (nameref args * ',') ']'
177 Theorem specifications come in three flavors: \railnonterm{thmdecl} usually
178 refers to the result of an assumption or goal statement (e.g.\ $\SHOWNAME$),
179 \railnonterm{thmdef} collects lists of existing theorems (as in $\NOTENAME$),
180 \railnonterm{thmrefs} refers to any list of existing theorems (e.g.\ occurring
181 as proof method arguments). Any of these may include lists of attributes,
182 which are applied to the preceding theorem or list of theorems.
184 \indexouternonterm{thmdecl}\indexouternonterm{thmdef}\indexouternonterm{thmrefs}
186 thmname : name attributes | name | attributes
188 thmdecl : thmname ':'
192 thmrefs : nameref (() | attributes) +
197 \subsection{Proof methods}\label{sec:syn-meth}
199 Proof methods are either basic ones, or expressions composed of methods via
200 ``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternatives),
201 ``\texttt{?}'' (try), ``\texttt{*}'' (repeat, ${} \ge 0$ times),
202 ``\texttt{+}'' (repeat, ${} > 0$ times). In practice, proof methods are very
203 often just a comma separated list of \railqtoken{nameref}~\railnonterm{args}
204 specifications. Thus the syntax is similar to that of attributes, with plain
205 parentheses instead of square brackets (see also \S\ref{sec:syn-att}). Note
206 that parentheses may be dropped for single method specifications without
209 \indexouternonterm{method}
211 method : (nameref | '(' methods ')') (() | '?' | '*' | '+')
213 methods : (nameref args | method) + (',' | '|')
220 %%% TeX-master: "isar-ref"