doc-src/IsarRef/syntax.tex
author wenzelm
Mon, 12 Feb 2001 20:44:02 +0100
changeset 11100 34d58b1818f4
parent 10858 479dad7b3b41
child 11651 201b3f76c7b7
permissions -rw-r--r--
\<subseteq> syntax for classes/classrel/axclass/instance;
wenzelm@7046
     1
wenzelm@7895
     2
\chapter{Isar Syntax Primitives}
wenzelm@7046
     3
wenzelm@7315
     4
We give a complete reference of all basic syntactic entities underlying the
wenzelm@7335
     5
Isabelle/Isar document syntax.  Actual theory and proof commands will be
wenzelm@7335
     6
introduced later on.
wenzelm@7134
     7
wenzelm@7315
     8
\medskip
wenzelm@7046
     9
wenzelm@7315
    10
In order to get started with writing well-formed Isabelle/Isar documents, the
wenzelm@7315
    11
most important aspect to be noted is the difference of \emph{inner} versus
wenzelm@7315
    12
\emph{outer} syntax.  Inner syntax is that of Isabelle types and terms of the
wenzelm@7895
    13
logic, while outer syntax is that of Isabelle/Isar theories (including
wenzelm@7895
    14
proofs).  As a general rule, inner syntax entities may occur only as
wenzelm@7895
    15
\emph{atomic entities} within outer syntax.  For example, the string
wenzelm@7895
    16
\texttt{"x + y"} and identifier \texttt{z} are legal term specifications
wenzelm@7895
    17
within a theory, while \texttt{x + y} is not.
wenzelm@7315
    18
wenzelm@7315
    19
\begin{warn}
wenzelm@8378
    20
  Note that classic Isabelle theories used to fake parts of the inner syntax
wenzelm@8378
    21
  of types, with rather complicated rules when quotes may be omitted.  Despite
wenzelm@7981
    22
  the minor drawback of requiring quotes more often, the syntax of
wenzelm@8548
    23
  Isabelle/Isar is much simpler and more robust in that respect.
wenzelm@7315
    24
\end{warn}
wenzelm@7315
    25
wenzelm@7466
    26
\medskip
wenzelm@7466
    27
wenzelm@9601
    28
Isabelle/Isar input may contain any number of input termination characters
wenzelm@9601
    29
``\texttt{;}'' (semicolon) to separate commands explicitly.  This may be
wenzelm@9601
    30
particularly useful in interactive shell sessions to make clear where the
wenzelm@9601
    31
current command is intended to end.  Otherwise, the interactive loop will
wenzelm@10858
    32
continue until end-of-command is clearly indicated from the input syntax,
wenzelm@9601
    33
e.g.\ encounter of the next command keyword.
wenzelm@9601
    34
wenzelm@9601
    35
Advanced interfaces such as Proof~General \cite{proofgeneral} do not require
wenzelm@9601
    36
explicit semicolons, the amount of input text is determined automatically by
wenzelm@9601
    37
inspecting the Emacs text buffer.  Also note that in the presentation of
wenzelm@9601
    38
Isabelle/Isar documents, semicolons are omitted in any case to gain
wenzelm@7981
    39
readability.
wenzelm@7466
    40
wenzelm@7315
    41
wenzelm@7315
    42
\section{Lexical matters}\label{sec:lex-syntax}
wenzelm@7315
    43
wenzelm@7315
    44
The Isabelle/Isar outer syntax provides token classes as presented below.
wenzelm@7895
    45
Note that some of these coincide (by full intention) with the inner lexical
wenzelm@7895
    46
syntax as presented in \cite{isabelle-ref}.  These different levels of syntax
wenzelm@7895
    47
should not be confused, though.
wenzelm@7315
    48
wenzelm@7335
    49
%FIXME keyword, command
wenzelm@9617
    50
\indexoutertoken{ident}\indexoutertoken{longident}\indexoutertoken{symident}
wenzelm@9617
    51
\indexoutertoken{nat}\indexoutertoken{var}\indexoutertoken{typefree}
wenzelm@9617
    52
\indexoutertoken{typevar}\indexoutertoken{string}\indexoutertoken{verbatim}
wenzelm@7315
    53
\begin{matharray}{rcl}
wenzelm@7315
    54
  ident & = & letter~quasiletter^* \\
wenzelm@7315
    55
  longident & = & ident\verb,.,ident~\dots~ident \\
wenzelm@8548
    56
  symident & = & sym^+ ~|~ symbol \\
wenzelm@7315
    57
  nat & = & digit^+ \\
wenzelm@7315
    58
  var & = & \verb,?,ident ~|~ \verb,?,ident\verb,.,nat \\
wenzelm@7315
    59
  typefree & = & \verb,',ident \\
wenzelm@7315
    60
  typevar & = & \verb,?,typefree ~|~ \verb,?,typefree\verb,.,nat \\
wenzelm@7315
    61
  string & = & \verb,", ~\dots~ \verb,", \\
wenzelm@7319
    62
  verbatim & = & \verb,{*, ~\dots~ \verb,*}, \\
wenzelm@7319
    63
\end{matharray}
wenzelm@7319
    64
\begin{matharray}{rcl}
wenzelm@7315
    65
  letter & = & \verb,a, ~|~ \dots ~|~ \verb,z, ~|~ \verb,A, ~|~ \dots ~|~ \verb,Z, \\
wenzelm@7315
    66
  digit & = & \verb,0, ~|~ \dots ~|~ \verb,9, \\
wenzelm@7315
    67
  quasiletter & = & letter ~|~ digit ~|~ \verb,_, ~|~ \verb,', \\
wenzelm@7315
    68
  sym & = & \verb,!, ~|~ \verb,#, ~|~ \verb,$, ~|~ \verb,%, ~|~ \verb,&, ~|~  %$
wenzelm@10160
    69
   \verb,*, ~|~ \verb,+, ~|~ \verb,-, ~|~ \verb,/, ~|~ \verb,:, ~|~ \\
wenzelm@10160
    70
  & & \verb,<, ~|~ \verb,=, ~|~ \verb,>, ~|~ \verb,?, ~|~ \texttt{\at} ~|~
wenzelm@10160
    71
  \verb,^, ~|~ \verb,_, ~|~ \verb,`, ~|~ \verb,|, ~|~ \verb,~, \\
wenzelm@8548
    72
  symbol & = & {\forall} ~|~ {\exists} ~|~ \dots
wenzelm@7315
    73
\end{matharray}
wenzelm@7315
    74
wenzelm@7315
    75
The syntax of \texttt{string} admits any characters, including newlines;
wenzelm@7895
    76
``\verb|"|'' (double-quote) and ``\verb|\|'' (backslash) have to be escaped by
wenzelm@9051
    77
a backslash; newlines need not be escaped.  Note that ML-style control
wenzelm@9051
    78
characters are \emph{not} supported.  The body of \texttt{verbatim} may
wenzelm@9051
    79
consist of any text not containing ``\verb|*}|''.
wenzelm@7315
    80
wenzelm@7895
    81
Comments take the form \texttt{(*~\dots~*)} and may be
wenzelm@8378
    82
nested\footnote{Proof~General may occasionally get confused by nested
wenzelm@8378
    83
  comments.}, just as in ML. Note that these are \emph{source} comments only,
wenzelm@8378
    84
which are stripped after lexical analysis of the input.  The Isar document
wenzelm@8378
    85
syntax also provides \emph{formal comments} that are actually part of the text
wenzelm@8378
    86
(see \S\ref{sec:comments}).
wenzelm@7315
    87
wenzelm@10160
    88
Mathematical symbols such as ``$\forall$'' are represented in plain ASCII as
wenzelm@10160
    89
``\verb,\<forall>,''.
wenzelm@10160
    90
wenzelm@7046
    91
wenzelm@7046
    92
\section{Common syntax entities}
wenzelm@7046
    93
wenzelm@7335
    94
Subsequently, we introduce several basic syntactic entities, such as names,
wenzelm@7895
    95
terms, and theorem specifications, which have been factored out of the actual
wenzelm@7895
    96
Isar language elements to be described later.
wenzelm@7134
    97
wenzelm@7981
    98
Note that some of the basic syntactic entities introduced below (e.g.\ 
wenzelm@7895
    99
\railqtoken{name}) act much like tokens rather than plain nonterminals (e.g.\ 
wenzelm@7895
   100
\railnonterm{sort}), especially for the sake of error messages.  E.g.\ syntax
wenzelm@7895
   101
elements such as $\CONSTS$ referring to \railqtoken{name} or \railqtoken{type}
wenzelm@7895
   102
would really report a missing name or type rather than any of the constituent
wenzelm@7895
   103
primitive tokens such as \railtoken{ident} or \railtoken{string}.
wenzelm@7046
   104
wenzelm@7050
   105
wenzelm@7050
   106
\subsection{Names}
wenzelm@7050
   107
wenzelm@7134
   108
Entity \railqtoken{name} usually refers to any name of types, constants,
wenzelm@7167
   109
theorems etc.\ that are to be \emph{declared} or \emph{defined} (so qualified
wenzelm@8548
   110
identifiers are excluded here).  Quoted strings provide an escape for
wenzelm@7134
   111
non-identifier names or those ruled out by outer syntax keywords (e.g.\ 
wenzelm@7134
   112
\verb|"let"|).  Already existing objects are usually referenced by
wenzelm@7134
   113
\railqtoken{nameref}.
wenzelm@7050
   114
wenzelm@7141
   115
\indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
wenzelm@9617
   116
\indexoutertoken{int}
wenzelm@7046
   117
\begin{rail}
wenzelm@8145
   118
  name: ident | symident | string | nat
wenzelm@7046
   119
  ;
wenzelm@7167
   120
  parname: '(' name ')'
wenzelm@7141
   121
  ;
wenzelm@7167
   122
  nameref: name | longident
wenzelm@7046
   123
  ;
wenzelm@9617
   124
  int: nat | '-' nat
wenzelm@9617
   125
  ;
wenzelm@7046
   126
\end{rail}
wenzelm@7046
   127
wenzelm@7050
   128
wenzelm@7315
   129
\subsection{Comments}\label{sec:comments}
wenzelm@7046
   130
wenzelm@7167
   131
Large chunks of plain \railqtoken{text} are usually given
wenzelm@7895
   132
\railtoken{verbatim}, i.e.\ enclosed in \verb|{*|~\dots~\verb|*}|.  For
wenzelm@7175
   133
convenience, any of the smaller text units conforming to \railqtoken{nameref}
wenzelm@8102
   134
are admitted as well.  Almost any of the Isar commands may be annotated by
wenzelm@7466
   135
marginal \railnonterm{comment} of the form \texttt{--} \railqtoken{text}.
wenzelm@7466
   136
Note that the latter kind of comment is actually part of the language, while
wenzelm@7895
   137
source level comments \verb|(*|~\dots~\verb|*)| are stripped at the lexical
wenzelm@7466
   138
level.  A few commands such as $\PROOFNAME$ admit additional markup with a
wenzelm@7466
   139
``level of interest'': \texttt{\%} followed by an optional number $n$ (default
wenzelm@7466
   140
$n = 1$) indicates that the respective part of the document becomes $n$ levels
wenzelm@7466
   141
more obscure; \texttt{\%\%} means that interest drops by $\infty$ --- abandon
wenzelm@7466
   142
every hope, who enter here.
wenzelm@7050
   143
wenzelm@7050
   144
\indexoutertoken{text}\indexouternonterm{comment}\indexouternonterm{interest}
wenzelm@7046
   145
\begin{rail}
wenzelm@7167
   146
  text: verbatim | nameref
wenzelm@7050
   147
  ;
wenzelm@8102
   148
  comment: ('--' text +)
wenzelm@7046
   149
  ;
wenzelm@7167
   150
  interest: percent nat? | ppercent
wenzelm@7046
   151
  ;
wenzelm@7046
   152
\end{rail}
wenzelm@7046
   153
wenzelm@7046
   154
wenzelm@7335
   155
\subsection{Type classes, sorts and arities}
wenzelm@7046
   156
wenzelm@8896
   157
Classes are specified by plain names.  Sorts have a very simple inner syntax,
wenzelm@8896
   158
which is either a single class name $c$ or a list $\{c@1, \dots, c@n\}$
wenzelm@8896
   159
referring to the intersection of these classes.  The syntax of type arities is
wenzelm@8896
   160
given directly at the outer level.
wenzelm@7050
   161
wenzelm@11100
   162
\railalias{subseteq}{\isasymsubseteq}
wenzelm@11100
   163
\railterm{subseteq}
wenzelm@11100
   164
wenzelm@7050
   165
\indexouternonterm{sort}\indexouternonterm{arity}\indexouternonterm{simplearity}
wenzelm@7135
   166
\indexouternonterm{classdecl}
wenzelm@7046
   167
\begin{rail}
wenzelm@11100
   168
  classdecl: name (('<' | subseteq) (nameref + ','))?
wenzelm@7046
   169
  ;
wenzelm@8896
   170
  sort: nameref
wenzelm@7046
   171
  ;
wenzelm@7167
   172
  arity: ('(' (sort + ',') ')')? sort
wenzelm@7046
   173
  ;
wenzelm@7167
   174
  simplearity: ('(' (sort + ',') ')')? nameref
wenzelm@7167
   175
  ;
wenzelm@7046
   176
\end{rail}
wenzelm@7046
   177
wenzelm@7046
   178
wenzelm@7167
   179
\subsection{Types and terms}\label{sec:types-terms}
wenzelm@7046
   180
wenzelm@7167
   181
The actual inner Isabelle syntax, that of types and terms of the logic, is far
wenzelm@7895
   182
too sophisticated in order to be modelled explicitly at the outer theory
wenzelm@8548
   183
level.  Basically, any such entity has to be quoted to turn it into a single
wenzelm@8548
   184
token (the parsing and type-checking is performed internally later).  For
wenzelm@8548
   185
convenience, a slightly more liberal convention is adopted: quotes may be
wenzelm@7895
   186
omitted for any type or term that is already \emph{atomic} at the outer level.
wenzelm@7895
   187
For example, one may write just \texttt{x} instead of \texttt{"x"}.  Note that
wenzelm@8548
   188
symbolic identifiers (e.g.\ \texttt{++} or $\forall$) are available as well,
wenzelm@8548
   189
provided these are not superseded by commands or keywords (e.g.\ \texttt{+}).
wenzelm@7050
   190
wenzelm@7050
   191
\indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
wenzelm@7046
   192
\begin{rail}
wenzelm@7167
   193
  type: nameref | typefree | typevar
wenzelm@7050
   194
  ;
wenzelm@8593
   195
  term: nameref | var
wenzelm@7050
   196
  ;
wenzelm@7167
   197
  prop: term
wenzelm@7050
   198
  ;
wenzelm@7046
   199
\end{rail}
wenzelm@7046
   200
wenzelm@8690
   201
Positional instantiations are indicated by giving a sequence of terms, or the
wenzelm@8690
   202
placeholder ``$\_$'' (underscore), which means to skip a position.
wenzelm@8690
   203
wenzelm@8690
   204
\indexoutertoken{inst}\indexoutertoken{insts}
wenzelm@8690
   205
\begin{rail}
wenzelm@8690
   206
  inst: underscore | term
wenzelm@8690
   207
  ;
wenzelm@8690
   208
  insts: (inst *)
wenzelm@8690
   209
  ;
wenzelm@8690
   210
\end{rail}
wenzelm@8690
   211
wenzelm@7167
   212
Type declarations and definitions usually refer to \railnonterm{typespec} on
wenzelm@7167
   213
the left-hand side.  This models basic type constructor application at the
wenzelm@7167
   214
outer syntax level.  Note that only plain postfix notation is available here,
wenzelm@7167
   215
but no infixes.
wenzelm@7050
   216
wenzelm@7050
   217
\indexouternonterm{typespec}
wenzelm@7050
   218
\begin{rail}
wenzelm@7167
   219
  typespec: (() | typefree | '(' ( typefree + ',' ) ')') name
wenzelm@7050
   220
  ;
wenzelm@7050
   221
\end{rail}
wenzelm@7050
   222
wenzelm@7050
   223
wenzelm@7315
   224
\subsection{Term patterns}\label{sec:term-pats}
wenzelm@7050
   225
wenzelm@7895
   226
Assumptions and goal statements usually admit casual binding of schematic term
wenzelm@7981
   227
variables by giving (optional) patterns of the form $\ISS{p@1\;\dots}{p@n}$.
wenzelm@7167
   228
There are separate versions available for \railqtoken{term}s and
wenzelm@7167
   229
\railqtoken{prop}s.  The latter provides a $\CONCLNAME$ part with patterns
wenzelm@7167
   230
referring the (atomic) conclusion of a rule.
wenzelm@7050
   231
wenzelm@7050
   232
\indexouternonterm{termpat}\indexouternonterm{proppat}
wenzelm@7050
   233
\begin{rail}
wenzelm@7167
   234
  termpat: '(' ('is' term +) ')'
wenzelm@7050
   235
  ;
wenzelm@7167
   236
  proppat: '(' (('is' prop +) | 'concl' ('is' prop +) | ('is' prop +) 'concl' ('is' prop +)) ')'
wenzelm@7050
   237
  ;
wenzelm@7050
   238
\end{rail}
wenzelm@7050
   239
wenzelm@7050
   240
wenzelm@7046
   241
\subsection{Mixfix annotations}
wenzelm@7046
   242
wenzelm@7134
   243
Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
wenzelm@8548
   244
terms (see also \cite{isabelle-ref}).  Some commands such as $\TYPES$ (see
wenzelm@8548
   245
\S\ref{sec:types-pure}) admit infixes only, while $\CONSTS$ (see
wenzelm@8548
   246
\S\ref{sec:consts}) and $\isarkeyword{syntax}$ (see \S\ref{sec:syn-trans})
wenzelm@8548
   247
support the full range of general mixfixes and binders.
wenzelm@7046
   248
wenzelm@7050
   249
\indexouternonterm{infix}\indexouternonterm{mixfix}
wenzelm@7050
   250
\begin{rail}
wenzelm@7167
   251
  infix: '(' ('infixl' | 'infixr') string? nat ')'
wenzelm@7167
   252
  ;
wenzelm@7175
   253
  mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')'
wenzelm@7050
   254
  ;
wenzelm@7046
   255
wenzelm@7175
   256
  prios: '[' (nat + ',') ']'
wenzelm@7050
   257
  ;
wenzelm@7050
   258
\end{rail}
wenzelm@7046
   259
wenzelm@7050
   260
wenzelm@7134
   261
\subsection{Attributes and theorems}\label{sec:syn-att}
wenzelm@7050
   262
wenzelm@7050
   263
Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
wenzelm@7335
   264
``semi-inner'' syntax, in the sense that input conforming to
wenzelm@7335
   265
\railnonterm{args} below is parsed by the attribute a second time.  The
wenzelm@7335
   266
attribute argument specifications may be any sequence of atomic entities
wenzelm@7335
   267
(identifiers, strings etc.), or properly bracketed argument lists.  Below
wenzelm@7981
   268
\railqtoken{atom} refers to any atomic entity, including any
wenzelm@7981
   269
\railtoken{keyword} conforming to \railtoken{symident}.
wenzelm@7050
   270
wenzelm@7050
   271
\indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
wenzelm@7050
   272
\begin{rail}
wenzelm@7466
   273
  atom: nameref | typefree | typevar | var | nat | keyword
wenzelm@7050
   274
  ;
wenzelm@8896
   275
  arg: atom | '(' args ')' | '[' args ']'
wenzelm@7134
   276
  ;
wenzelm@7167
   277
  args: arg *
wenzelm@7134
   278
  ;
wenzelm@7167
   279
  attributes: '[' (nameref args * ',') ']'
wenzelm@7050
   280
  ;
wenzelm@7050
   281
\end{rail}
wenzelm@7050
   282
wenzelm@7895
   283
Theorem specifications come in several flavors: \railnonterm{axmdecl} and
wenzelm@7175
   284
\railnonterm{thmdecl} usually refer to axioms, assumptions or results of goal
wenzelm@7981
   285
statements, while \railnonterm{thmdef} collects lists of existing theorems.
wenzelm@7981
   286
Existing theorems are given by \railnonterm{thmref} and \railnonterm{thmrefs},
wenzelm@7981
   287
the former requires an actual singleton result.  Any of these theorem
wenzelm@7175
   288
specifications may include lists of attributes both on the left and right hand
wenzelm@7466
   289
sides; attributes are applied to any immediately preceding theorem.  If names
wenzelm@7981
   290
are omitted, the theorems are not stored within the theorem database of the
wenzelm@7981
   291
theory or proof context; any given attributes are still applied, though.
wenzelm@7050
   292
wenzelm@7135
   293
\indexouternonterm{thmdecl}\indexouternonterm{axmdecl}
wenzelm@7135
   294
\indexouternonterm{thmdef}\indexouternonterm{thmrefs}
wenzelm@7050
   295
\begin{rail}
wenzelm@7167
   296
  axmdecl: name attributes? ':'
wenzelm@7050
   297
  ;
wenzelm@9200
   298
  thmdecl: thmbind ':'
wenzelm@7135
   299
  ;
wenzelm@9200
   300
  thmdef: thmbind '='
wenzelm@7050
   301
  ;
wenzelm@7175
   302
  thmref: nameref attributes?
wenzelm@7175
   303
  ;
wenzelm@7175
   304
  thmrefs: thmref +
wenzelm@7134
   305
  ;
wenzelm@7167
   306
wenzelm@9200
   307
  thmbind: name attributes | name | attributes
wenzelm@7050
   308
  ;
wenzelm@7050
   309
\end{rail}
wenzelm@7050
   310
wenzelm@7050
   311
wenzelm@7050
   312
\subsection{Proof methods}\label{sec:syn-meth}
wenzelm@7050
   313
wenzelm@7050
   314
Proof methods are either basic ones, or expressions composed of methods via
wenzelm@7175
   315
``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternative choices),
wenzelm@7981
   316
``\texttt{?}'' (try), ``\texttt{+}'' (repeat at least once).  In practice,
wenzelm@7981
   317
proof methods are usually just a comma separated list of
wenzelm@7981
   318
\railqtoken{nameref}~\railnonterm{args} specifications.  Note that parentheses
wenzelm@7981
   319
may be dropped for single method specifications (with no arguments).
wenzelm@7050
   320
wenzelm@7050
   321
\indexouternonterm{method}
wenzelm@7050
   322
\begin{rail}
wenzelm@7430
   323
  method: (nameref | '(' methods ')') (() | '?' | '+')
wenzelm@7134
   324
  ;
wenzelm@7167
   325
  methods: (nameref args | method) + (',' | '|')
wenzelm@7050
   326
  ;
wenzelm@7050
   327
\end{rail}
wenzelm@7046
   328
wenzelm@8532
   329
Proper use of Isar proof methods does \emph{not} involve goal addressing.
wenzelm@8532
   330
Nevertheless, specifying goal ranges may occasionally come in handy in
wenzelm@8532
   331
emulating tactic scripts.  Note that $[n-]$ refers to all goals, starting from
wenzelm@8548
   332
$n$.  All goals may be specified by $[!]$, which is the same as $[1-]$.
wenzelm@8532
   333
wenzelm@8532
   334
\indexouternonterm{goalspec}
wenzelm@8532
   335
\begin{rail}
wenzelm@8548
   336
  goalspec: '[' (nat '-' nat | nat '-' | nat | '!' ) ']'
wenzelm@8532
   337
  ;
wenzelm@8532
   338
\end{rail}
wenzelm@8532
   339
wenzelm@7046
   340
wenzelm@9200
   341
\subsection{Antiquotations}\label{sec:antiq}
wenzelm@9200
   342
wenzelm@10336
   343
\begin{matharray}{rcl}
wenzelm@10336
   344
  thm & : & \isarantiq \\
wenzelm@10336
   345
  prop & : & \isarantiq \\
wenzelm@10336
   346
  term & : & \isarantiq \\
wenzelm@10336
   347
  typ & : & \isarantiq \\
wenzelm@10336
   348
  text & : & \isarantiq \\
wenzelm@10336
   349
  goals & : & \isarantiq \\
nipkow@10351
   350
  subgoals & : & \isarantiq \\
wenzelm@10336
   351
\end{matharray}
wenzelm@10336
   352
wenzelm@9200
   353
The text body of formal comments (see also \S\ref{sec:comments}) may contain
wenzelm@9200
   354
antiquotations of logical entities, such as theorems, terms and types, which
wenzelm@9200
   355
are to be presented in the final output produced by the Isabelle document
wenzelm@9200
   356
preparation system (see also \S\ref{sec:document-prep}).
wenzelm@9200
   357
wenzelm@9601
   358
Thus embedding of
wenzelm@10160
   359
\texttt{{\at}{\ttlbrace}term~[show_types]~"f(x)~=~a~+~x"{\ttrbrace}} within a
wenzelm@9601
   360
text block would cause
wenzelm@9200
   361
\isa{(f{\isasymColon}'a~{\isasymRightarrow}~'a)~(x{\isasymColon}'a)~=~(a{\isasymColon}'a)~+~x}
wenzelm@10160
   362
to appear in the final {\LaTeX} document.  Also note that theorem
wenzelm@10160
   363
antiquotations may involve attributes as well.  For example,
wenzelm@10160
   364
\texttt{{\at}{\ttlbrace}thm~sym~[no_vars]{\ttrbrace}} would print the
wenzelm@10160
   365
statement where all schematic variables have been replaced by fixed ones,
wenzelm@10160
   366
which are better readable.
wenzelm@9200
   367
wenzelm@9728
   368
\indexisarant{thm}\indexisarant{prop}\indexisarant{term}
wenzelm@10355
   369
\indexisarant{typ}\indexisarant{text}\indexisarant{goals}\indexisarant{subgoals}
wenzelm@9200
   370
\begin{rail}
wenzelm@9200
   371
  atsign lbrace antiquotation rbrace
wenzelm@9200
   372
  ;
wenzelm@9200
   373
wenzelm@9200
   374
  antiquotation:
wenzelm@9200
   375
    'thm' options thmrefs |
wenzelm@9200
   376
    'prop' options prop |
wenzelm@9200
   377
    'term' options term |
wenzelm@9728
   378
    'typ' options type |
wenzelm@10319
   379
    'text' options name |
wenzelm@10355
   380
    'goals' options |
wenzelm@10355
   381
    'subgoals' options
wenzelm@9200
   382
  ;
wenzelm@9200
   383
  options: '[' (option * ',') ']'
wenzelm@9200
   384
  ;
wenzelm@9200
   385
  option: name | name '=' name
wenzelm@9200
   386
  ;
wenzelm@9200
   387
\end{rail}
wenzelm@9200
   388
wenzelm@9200
   389
Note that the syntax of antiquotations may \emph{not} include source comments
wenzelm@9200
   390
\texttt{(*~\dots~*)} or verbatim text \verb|{*|~\dots~\verb|*}|.
wenzelm@9200
   391
wenzelm@10319
   392
\begin{descr}
wenzelm@10336
   393
\item [$\at\{thm~\vec a\}$] prints theorems $\vec a$. Note that attribute
wenzelm@10336
   394
  specifications may be included as well (see also \S\ref{sec:syn-att}); the
wenzelm@10336
   395
  $no_vars$ operation (see \S\ref{sec:misc-methods}) would be particularly
wenzelm@10336
   396
  useful to suppress printing of schematic variables.
wenzelm@10336
   397
\item [$\at\{prop~\phi\}$] prints a well-typed proposition $\phi$.
wenzelm@10336
   398
\item [$\at\{term~t\}$] prints a well-typed term $t$.
wenzelm@10336
   399
\item [$\at\{typ~\tau\}$] prints a well-formed type $\tau$.
wenzelm@10336
   400
\item [$\at\{text~s\}$] prints uninterpreted source text $s$.  This is
wenzelm@10336
   401
  particularly useful to print portions of text according to the Isabelle
wenzelm@10336
   402
  {\LaTeX} output style, without demanding well-formedness (e.g.\ small pieces
wenzelm@10336
   403
  of terms that cannot be parsed or type-checked yet).
wenzelm@10336
   404
\item [$\at\{goals\}$] prints the current \emph{dynamic} goal state.  This is
wenzelm@10336
   405
  only for support of tactic-emulation scripts within Isar --- presentation of
wenzelm@10336
   406
  goal states does not conform to actual human-readable proof documents.
wenzelm@10319
   407
  
wenzelm@10319
   408
  Please do not include goal states into document output unless you really
wenzelm@10319
   409
  know what you are doing!
wenzelm@10355
   410
\item [$\at\{subgoals\}$] behaves almost like $goals$, except that it does not
wenzelm@10355
   411
  print the main goal.
wenzelm@10319
   412
\end{descr}
wenzelm@10319
   413
wenzelm@9200
   414
\medskip
wenzelm@9200
   415
wenzelm@10336
   416
The following options are available to tune the output.  Note that most of
wenzelm@9233
   417
these coincide with ML flags of the same names (see also \cite{isabelle-ref}).
wenzelm@9200
   418
\begin{descr}
wenzelm@9233
   419
\item[$show_types = bool$ and $show_sorts = bool$] control printing of
wenzelm@9234
   420
  explicit type and sort constraints.
wenzelm@9233
   421
\item[$long_names = bool$] forces names of types and constants etc.\ to be
wenzelm@9233
   422
  printed in their fully qualified internal form.
wenzelm@9233
   423
\item[$eta_contract = bool$] prints terms in $\eta$-contracted form.
wenzelm@9200
   424
\item[$display = bool$] indicates if the text is to be output as multi-line
wenzelm@9200
   425
  ``display material'', rather than a small piece of text without line breaks
wenzelm@9200
   426
  (which is the default).
wenzelm@9200
   427
\item[$quotes = bool$] indicates if the output should be enclosed in double
wenzelm@9200
   428
  quotes.
wenzelm@9233
   429
\item[$mode = name$] adds $name$ to the print mode to be used for presentation
wenzelm@9233
   430
  (see also \cite{isabelle-ref}).  Note that the standard setup for {\LaTeX}
wenzelm@9233
   431
  output is already present by default, including the modes ``$latex$'',
wenzelm@9233
   432
  ``$xsymbols$'', ``$symbols$''.
wenzelm@9728
   433
\item[$margin = nat$ and $indent = nat$] change the margin or indentation for
wenzelm@9728
   434
  pretty printing of display material.
wenzelm@9752
   435
\item[$source = bool$] prints the source text of the antiquotation arguments,
wenzelm@9752
   436
  rather than the actual value.  Note that this does not affect
wenzelm@9752
   437
  well-formedness checks of $thm$, $term$, etc. (only the $text$ antiquotation
wenzelm@9752
   438
  admits arbitrary output).
wenzelm@10319
   439
\item[$goals_limit = nat$] determines the maximum number of goals to be
wenzelm@10319
   440
  printed.
wenzelm@9200
   441
\end{descr}
wenzelm@9200
   442
wenzelm@9200
   443
For boolean flags, ``$name = true$'' may be abbreviated as ``$name$''.  All of
wenzelm@9200
   444
the above flags are disabled by default, unless changed from ML.
wenzelm@9200
   445
wenzelm@10336
   446
\medskip Note that antiquotations do not only spare the author from tedious
wenzelm@10336
   447
typing, but also achieve some degree of consistency-checking of informal
wenzelm@10336
   448
explanations with formal developments, since well-formedness of terms and
wenzelm@10336
   449
types with respect to the current theory or proof context can be ensured.
wenzelm@9200
   450
wenzelm@7046
   451
%%% Local Variables: 
wenzelm@7046
   452
%%% mode: latex
wenzelm@7046
   453
%%% TeX-master: "isar-ref"
wenzelm@7046
   454
%%% End: