doc-src/IsarRef/syntax.tex
author haftmann
Fri Dec 29 12:11:04 2006 +0100 (2006-12-29)
changeset 21927 9677abe5d374
parent 21717 410ca6910f6f
child 24016 cf022cc710ae
permissions -rw-r--r--
added handling for explicit classrel witnesses
     1 
     2 \chapter{Syntax primitives}
     3 
     4 The rather generic framework of Isabelle/Isar syntax emerges from three main
     5 syntactic categories: \emph{commands} of the top-level Isar engine (covering
     6 theory and proof elements), \emph{methods} for general goal refinements
     7 (analogous to traditional ``tactics''), and \emph{attributes} for operations
     8 on facts (within a certain context).  Here we give a reference of basic
     9 syntactic entities underlying Isabelle/Isar syntax in a bottom-up manner.
    10 Concrete theory and proof language elements will be introduced later on.
    11 
    12 \medskip
    13 
    14 In order to get started with writing well-formed Isabelle/Isar documents, the
    15 most important aspect to be noted is the difference of \emph{inner} versus
    16 \emph{outer} syntax.  Inner syntax is that of Isabelle types and terms of the
    17 logic, while outer syntax is that of Isabelle/Isar theory sources (including
    18 proofs).  As a general rule, inner syntax entities may occur only as
    19 \emph{atomic entities} within outer syntax.  For example, the string
    20 \texttt{"x + y"} and identifier \texttt{z} are legal term specifications
    21 within a theory, while \texttt{x + y} is not.
    22 
    23 \begin{warn}
    24   Old-style Isabelle theories used to fake parts of the inner syntax of types,
    25   with rather complicated rules when quotes may be omitted.  Despite the minor
    26   drawback of requiring quotes more often, the syntax of Isabelle/Isar is
    27   somewhat simpler and more robust in that respect.
    28 \end{warn}
    29 
    30 Printed theory documents usually omit quotes to gain readability (this is a
    31 matter of {\LaTeX} macro setup, say via \verb,\isabellestyle,, see also
    32 \cite{isabelle-sys}).  Experienced users of Isabelle/Isar may easily
    33 reconstruct the lost technical information, while mere readers need not care
    34 about quotes at all.
    35 
    36 \medskip
    37 
    38 Isabelle/Isar input may contain any number of input termination characters
    39 ``\texttt{;}'' (semicolon) to separate commands explicitly.  This is
    40 particularly useful in interactive shell sessions to make clear where the
    41 current command is intended to end.  Otherwise, the interpreter loop will
    42 continue to issue a secondary prompt ``\verb,#,'' until an end-of-command is
    43 clearly recognized from the input syntax, e.g.\ encounter of the next command
    44 keyword.
    45 
    46 Advanced interfaces such as Proof~General \cite{proofgeneral} do not require
    47 explicit semicolons, the amount of input text is determined automatically by
    48 inspecting the present content of the Emacs text buffer.  In the printed
    49 presentation of Isabelle/Isar documents semicolons are omitted altogether for
    50 readability.
    51 
    52 \begin{warn}
    53   Proof~General requires certain syntax classification tables in order to
    54   achieve properly synchronized interaction with the Isabelle/Isar process.
    55   These tables need to be consistent with the Isabelle version and particular
    56   logic image to be used in a running session (common object-logics may well
    57   change the outer syntax).  The standard setup should work correctly with any
    58   of the ``official'' logic images derived from Isabelle/HOL (including HOLCF
    59   etc.).  Users of alternative logics may need to tell Proof~General
    60   explicitly, e.g.\ by giving an option \verb,-k ZF, (in conjunction with
    61   \verb,-l ZF, to specify the default logic image).
    62 \end{warn}
    63 
    64 \section{Lexical matters}\label{sec:lex-syntax}
    65 
    66 The Isabelle/Isar outer syntax provides token classes as presented below; most
    67 of these coincide with the inner lexical syntax as presented in
    68 \cite{isabelle-ref}.
    69 
    70 \indexoutertoken{ident}\indexoutertoken{longident}\indexoutertoken{symident}
    71 \indexoutertoken{nat}\indexoutertoken{var}\indexoutertoken{typefree}
    72 \indexoutertoken{typevar}\indexoutertoken{string}\indexoutertoken{altstring}
    73 \indexoutertoken{verbatim}
    74 \begin{matharray}{rcl}
    75   ident & = & letter\,quasiletter^* \\
    76   longident & = & ident (\verb,.,ident)^+ \\
    77   symident & = & sym^+ ~|~ \verb,\<,ident\verb,>, \\
    78   nat & = & digit^+ \\
    79   var & = & ident ~|~ \verb,?,ident ~|~ \verb,?,ident\verb,.,nat \\
    80   typefree & = & \verb,',ident \\
    81   typevar & = & typefree ~|~ \verb,?,typefree ~|~ \verb,?,typefree\verb,.,nat \\
    82   string & = & \verb,", ~\dots~ \verb,", \\
    83   altstring & = & \backquote ~\dots~ \backquote \\
    84   verbatim & = & \verb,{*, ~\dots~ \verb,*}, \\[1ex]
    85 
    86   letter & = & latin ~|~ \verb,\<,latin\verb,>, ~|~ \verb,\<,latin\,latin\verb,>, ~|~ greek ~|~ \\
    87          &   & \verb,\<^isub>, ~|~ \verb,\<^isup>, \\
    88   quasiletter & = & letter ~|~ digit ~|~ \verb,_, ~|~ \verb,', \\
    89   latin & = & \verb,a, ~|~ \dots ~|~ \verb,z, ~|~ \verb,A, ~|~ \dots ~|~ \verb,Z, \\
    90   digit & = & \verb,0, ~|~ \dots ~|~ \verb,9, \\
    91   sym & = & \verb,!, ~|~ \verb,#, ~|~ \verb,$, ~|~ \verb,%, ~|~ \verb,&, ~|~  %$
    92    \verb,*, ~|~ \verb,+, ~|~ \verb,-, ~|~ \verb,/, ~|~ \\
    93   & & \verb,<, ~|~ \verb,=, ~|~ \verb,>, ~|~ \verb,?, ~|~ \texttt{\at} ~|~
    94   \verb,^, ~|~ \verb,_, ~|~ \verb,|, ~|~ \verb,~, \\
    95 greek & = & \verb,\<alpha>, ~|~ \verb,\<beta>, ~|~ \verb,\<gamma>, ~|~ \verb,\<delta>, ~| \\
    96       &   & \verb,\<epsilon>, ~|~ \verb,\<zeta>, ~|~ \verb,\<eta>, ~|~ \verb,\<theta>, ~| \\
    97       &   & \verb,\<iota>, ~|~ \verb,\<kappa>, ~|~ \verb,\<mu>, ~|~ \verb,\<nu>, ~| \\
    98       &   & \verb,\<xi>, ~|~ \verb,\<pi>, ~|~ \verb,\<rho>, ~|~ \verb,\<sigma>, ~| \\
    99       &   & \verb,\<tau>, ~|~ \verb,\<upsilon>, ~|~ \verb,\<phi>, ~|~ \verb,\<psi>, ~| \\
   100       &   & \verb,\<omega>, ~|~ \verb,\<Gamma>, ~|~ \verb,\<Delta>, ~|~ \verb,\<Theta>, ~| \\
   101       &   & \verb,\<Lambda>, ~|~ \verb,\<Xi>, ~|~ \verb,\<Pi>, ~|~ \verb,\<Sigma>, ~| \\
   102       &   & \verb,\<Upsilon>, ~|~ \verb,\<Phi>, ~|~ \verb,\<Psi>, ~|~ \verb,\<Omega>, \\
   103 \end{matharray}
   104 
   105 The syntax of $string$ admits any characters, including newlines; ``\verb|"|''
   106 (double-quote) and ``\verb|\|'' (backslash) need to be escaped by a backslash.
   107 Alternative strings according to $altstring$ are analogous, using single
   108 back-quotes instead.  The body of $verbatim$ may consist of any text not
   109 containing ``\verb|*}|''; this allows convenient inclusion of quotes without
   110 further escapes.  The greek letters do \emph{not} include \verb,\<lambda>,,
   111 which is already used differently in the meta-logic.
   112 
   113 Common mathematical symbols such as $\forall$ are represented in Isabelle as
   114 \verb,\<forall>,.  There are infinitely many legal symbols like this, although
   115 proper presentation is left to front-end tools such as {\LaTeX} or
   116 Proof~General with the X-Symbol package.  A list of standard Isabelle symbols
   117 that work well with these tools is given in \cite[appendix~A]{isabelle-sys}.
   118 
   119 Comments take the form \texttt{(*~\dots~*)} and may be nested, although
   120 user-interface tools may prevent this.  Note that \texttt{(*~\dots~*)}
   121 indicate source comments only, which are stripped after lexical analysis of
   122 the input.  The Isar document syntax also provides formal comments that are
   123 considered as part of the text (see \S\ref{sec:comments}).
   124 
   125 \begin{warn}
   126   Proof~General does not handle nested comments properly; it is also unable to
   127   keep \verb,(*,\,/\,\verb,{*, and \verb,*),\,/\,\verb,*}, apart, despite
   128   their rather different meaning.  These are inherent problems of Emacs
   129   legacy.  Users should not be overly aggressive about nesting or alternating
   130   these delimiters.
   131 \end{warn}
   132 
   133 
   134 \section{Common syntax entities}
   135 
   136 Subsequently, we introduce several basic syntactic entities, such as names,
   137 terms, and theorem specifications, which have been factored out of the actual
   138 Isar language elements to be described later.
   139 
   140 Note that some of the basic syntactic entities introduced below (e.g.\
   141 \railqtok{name}) act much like tokens rather than plain nonterminals (e.g.\
   142 \railnonterm{sort}), especially for the sake of error messages.  E.g.\ syntax
   143 elements like $\CONSTS$ referring to \railqtok{name} or \railqtok{type} would
   144 really report a missing name or type rather than any of the constituent
   145 primitive tokens such as \railtok{ident} or \railtok{string}.
   146 
   147 
   148 \subsection{Names}
   149 
   150 Entity \railqtok{name} usually refers to any name of types, constants,
   151 theorems etc.\ that are to be \emph{declared} or \emph{defined} (so qualified
   152 identifiers are excluded here).  Quoted strings provide an escape for
   153 non-identifier names or those ruled out by outer syntax keywords (e.g.\
   154 \verb|"let"|).  Already existing objects are usually referenced by
   155 \railqtok{nameref}.
   156 
   157 \indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
   158 \indexoutertoken{int}
   159 \begin{rail}
   160   name: ident | symident | string | nat
   161   ;
   162   parname: '(' name ')'
   163   ;
   164   nameref: name | longident
   165   ;
   166   int: nat | '-' nat
   167   ;
   168 \end{rail}
   169 
   170 
   171 \subsection{Comments}\label{sec:comments}
   172 
   173 Large chunks of plain \railqtok{text} are usually given \railtok{verbatim},
   174 i.e.\ enclosed in \verb|{*|~\dots~\verb|*}|.  For convenience, any of the
   175 smaller text units conforming to \railqtok{nameref} are admitted as well.  A
   176 marginal \railnonterm{comment} is of the form \texttt{--} \railqtok{text}.
   177 Any number of these may occur within Isabelle/Isar commands.
   178 
   179 \indexoutertoken{text}\indexouternonterm{comment}
   180 \begin{rail}
   181   text: verbatim | nameref
   182   ;
   183   comment: '--' text
   184   ;
   185 \end{rail}
   186 
   187 
   188 \subsection{Type classes, sorts and arities}
   189 
   190 Classes are specified by plain names.  Sorts have a very simple inner syntax,
   191 which is either a single class name $c$ or a list $\{c@1, \dots, c@n\}$
   192 referring to the intersection of these classes.  The syntax of type arities is
   193 given directly at the outer level.
   194 
   195 \railalias{subseteq}{\isasymsubseteq}
   196 \railterm{subseteq}
   197 
   198 \indexouternonterm{sort}\indexouternonterm{arity}
   199 \indexouternonterm{classdecl}
   200 \begin{rail}
   201   classdecl: name (('<' | subseteq) (nameref + ','))?
   202   ;
   203   sort: nameref
   204   ;
   205   arity: ('(' (sort + ',') ')')? sort
   206   ;
   207 \end{rail}
   208 
   209 
   210 \subsection{Types and terms}\label{sec:types-terms}
   211 
   212 The actual inner Isabelle syntax, that of types and terms of the logic, is far
   213 too sophisticated in order to be modelled explicitly at the outer theory
   214 level.  Basically, any such entity has to be quoted to turn it into a single
   215 token (the parsing and type-checking is performed internally later).  For
   216 convenience, a slightly more liberal convention is adopted: quotes may be
   217 omitted for any type or term that is already atomic at the outer level.  For
   218 example, one may just write \texttt{x} instead of \texttt{"x"}.  Note that
   219 symbolic identifiers (e.g.\ \texttt{++} or $\forall$) are available as well,
   220 provided these have not been superseded by commands or other keywords already
   221 (e.g.\ \texttt{=} or \texttt{+}).
   222 
   223 \indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
   224 \begin{rail}
   225   type: nameref | typefree | typevar
   226   ;
   227   term: nameref | var
   228   ;
   229   prop: term
   230   ;
   231 \end{rail}
   232 
   233 Positional instantiations are indicated by giving a sequence of terms, or the
   234 placeholder ``$\_$'' (underscore), which means to skip a position.
   235 
   236 \indexoutertoken{inst}\indexoutertoken{insts}
   237 \begin{rail}
   238   inst: underscore | term
   239   ;
   240   insts: (inst *)
   241   ;
   242 \end{rail}
   243 
   244 Type declarations and definitions usually refer to \railnonterm{typespec} on
   245 the left-hand side.  This models basic type constructor application at the
   246 outer syntax level.  Note that only plain postfix notation is available here,
   247 but no infixes.
   248 
   249 \indexouternonterm{typespec}
   250 \begin{rail}
   251   typespec: (() | typefree | '(' ( typefree + ',' ) ')') name
   252   ;
   253 \end{rail}
   254 
   255 
   256 \subsection{Mixfix annotations}
   257 
   258 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
   259 terms.  Some commands such as $\TYPES$ (see \S\ref{sec:types-pure}) admit
   260 infixes only, while $\CONSTS$ (see \S\ref{sec:consts}) and
   261 $\isarkeyword{syntax}$ (see \S\ref{sec:syn-trans}) support the full range of
   262 general mixfixes and binders.
   263 
   264 \indexouternonterm{infix}\indexouternonterm{mixfix}\indexouternonterm{structmixfix}
   265 \begin{rail}
   266   infix: '(' ('infix' | 'infixl' | 'infixr') string? nat ')'
   267   ;
   268   mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')'
   269   ;
   270   structmixfix: mixfix | '(' 'structure' ')'
   271   ;
   272 
   273   prios: '[' (nat + ',') ']'
   274   ;
   275 \end{rail}
   276 
   277 Here the \railtok{string} specifications refer to the actual mixfix template
   278 (see also \cite{isabelle-ref}), which may include literal text, spacing,
   279 blocks, and arguments (denoted by ``$_$''); the special symbol \verb,\<index>,
   280 (printed as ``\i'') represents an index argument that specifies an implicit
   281 structure reference (see also \S\ref{sec:locale}).  Infix and binder
   282 declarations provide common abbreviations for particular mixfix declarations.
   283 So in practice, mixfix templates mostly degenerate to literal text for
   284 concrete syntax, such as ``\verb,++,'' for an infix symbol, or ``\verb,++,\i''
   285 for an infix of an implicit structure.
   286 
   287 
   288 
   289 \subsection{Proof methods}\label{sec:syn-meth}
   290 
   291 Proof methods are either basic ones, or expressions composed of
   292 methods via ``\texttt{,}'' (sequential composition), ``\texttt{|}''
   293 (alternative choices), ``\texttt{?}'' (try), ``\texttt{+}'' (repeat at
   294 least once), ``\texttt{[$n$]}'' (restriction to first $n$ sub-goals,
   295 default $n = 1$).  In practice, proof methods are usually just a comma
   296 separated list of \railqtok{nameref}~\railnonterm{args}
   297 specifications.  Note that parentheses may be dropped for single
   298 method specifications (with no arguments).
   299 
   300 \indexouternonterm{method}
   301 \begin{rail}
   302   method: (nameref | '(' methods ')') (() | '?' | '+' | '[' nat? ']')
   303   ;
   304   methods: (nameref args | method) + (',' | '|')
   305   ;
   306 \end{rail}
   307 
   308 Proper Isar proof methods do \emph{not} admit arbitrary goal
   309 addressing, but refer either to the first sub-goal or all sub-goals
   310 uniformly.  The goal restriction operator ``\texttt{[$n$]}'' evaluates
   311 a method expression within a sandbox consisting of the first $n$
   312 sub-goals (which need to exist).  For example,
   313 $simp_all\mbox{\tt[}3\mbox{\tt]}$ simplifies the first three
   314 sub-goals, while $(rule~foo, simp_all)\mbox{\tt[]}$ simplifies all new
   315 goals that emerge from applying rule $foo$ to the originally first
   316 one.
   317 
   318 Improper methods, notably tactic emulations, offer a separate
   319 low-level goal addressing scheme as explicit argument to the
   320 individual tactic being involved.  Here $[!]$ refers to all goals, and
   321 $[n-]$ to all goals starting from $n$,
   322 
   323 \indexouternonterm{goalspec}
   324 \begin{rail}
   325   goalspec: '[' (nat '-' nat | nat '-' | nat | '!' ) ']'
   326   ;
   327 \end{rail}
   328 
   329 
   330 \subsection{Attributes and theorems}\label{sec:syn-att}
   331 
   332 Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
   333 ``semi-inner'' syntax, in the sense that input conforming to
   334 \railnonterm{args} below is parsed by the attribute a second time.  The
   335 attribute argument specifications may be any sequence of atomic entities
   336 (identifiers, strings etc.), or properly bracketed argument lists.  Below
   337 \railqtok{atom} refers to any atomic entity, including any \railtok{keyword}
   338 conforming to \railtok{symident}.
   339 
   340 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
   341 \begin{rail}
   342   atom: nameref | typefree | typevar | var | nat | keyword
   343   ;
   344   arg: atom | '(' args ')' | '[' args ']'
   345   ;
   346   args: arg *
   347   ;
   348   attributes: '[' (nameref args * ',') ']'
   349   ;
   350 \end{rail}
   351 
   352 Theorem specifications come in several flavors: \railnonterm{axmdecl} and
   353 \railnonterm{thmdecl} usually refer to axioms, assumptions or results of goal
   354 statements, while \railnonterm{thmdef} collects lists of existing theorems.
   355 Existing theorems are given by \railnonterm{thmref} and \railnonterm{thmrefs},
   356 the former requires an actual singleton result.  There are three forms of
   357 theorem references: (1) named facts $a$, (2) selections from named facts $a(i,
   358 j - k)$, or (3) literal fact propositions using $altstring$ syntax
   359 $\backquote\phi\backquote$, (see also method $fact$ in
   360 \S\ref{sec:pure-meth-att}).
   361 
   362 Any kind of theorem specification may include lists of attributes both on the
   363 left and right hand sides; attributes are applied to any immediately preceding
   364 fact.  If names are omitted, the theorems are not stored within the theorem
   365 database of the theory or proof context, but any given attributes are applied
   366 nonetheless.
   367 
   368 \indexouternonterm{axmdecl}\indexouternonterm{thmdecl}
   369 \indexouternonterm{thmdef}\indexouternonterm{thmref}
   370 \indexouternonterm{thmrefs}\indexouternonterm{selection}
   371 \begin{rail}
   372   axmdecl: name attributes? ':'
   373   ;
   374   thmdecl: thmbind ':'
   375   ;
   376   thmdef: thmbind '='
   377   ;
   378   thmref: (nameref selection? | altstring) attributes?
   379   ;
   380   thmrefs: thmref +
   381   ;
   382 
   383   thmbind: name attributes | name | attributes
   384   ;
   385   selection: '(' ((nat | nat '-' nat?) + ',') ')'
   386   ;
   387 \end{rail}
   388 
   389 
   390 \subsection{Term patterns and declarations}\label{sec:term-decls}
   391 
   392 Wherever explicit propositions (or term fragments) occur in a proof text,
   393 casual binding of schematic term variables may be given specified via patterns
   394 of the form ``$\ISS{p@1\;\dots}{p@n}$''.  There are separate versions
   395 available for \railqtok{term}s and \railqtok{prop}s.  The latter provides a
   396 $\CONCLNAME$ part with patterns referring the (atomic) conclusion of a rule.
   397 
   398 \indexouternonterm{termpat}\indexouternonterm{proppat}
   399 \begin{rail}
   400   termpat: '(' ('is' term +) ')'
   401   ;
   402   proppat: '(' ('is' prop +) ')'
   403   ;
   404 \end{rail}
   405 
   406 Declarations of local variables $x :: \tau$ and logical propositions $a :
   407 \phi$ represent different views on the same principle of introducing a local
   408 scope.  In practice, one may usually omit the typing of $vars$ (due to
   409 type-inference), and the naming of propositions (due to implicit references of
   410 current facts).  In any case, Isar proof elements usually admit to introduce
   411 multiple such items simultaneously.
   412 
   413 \indexouternonterm{vars}\indexouternonterm{props}
   414 \begin{rail}
   415   vars: (name+) ('::' type)?
   416   ;
   417   props: thmdecl? (prop proppat? +)
   418   ;
   419 \end{rail}
   420 
   421 The treatment of multiple declarations corresponds to the complementary focus
   422 of $vars$ versus $props$: in ``$x@1~\dots~x@n :: \tau$'' the typing refers to
   423 all variables, while in $a\colon \phi@1~\dots~\phi@n$ the naming refers to all
   424 propositions collectively.  Isar language elements that refer to $vars$ or
   425 $props$ typically admit separate typings or namings via another level of
   426 iteration, with explicit $\AND$ separators; e.g.\ see $\FIXNAME$ and
   427 $\ASSUMENAME$ in \S\ref{sec:proof-context}.
   428 
   429 
   430 \subsection{Antiquotations}\label{sec:antiq}
   431 
   432 \begin{matharray}{rcl}
   433   theory & : & \isarantiq \\
   434   thm & : & \isarantiq \\
   435   prop & : & \isarantiq \\
   436   term & : & \isarantiq \\
   437   const & : & \isarantiq \\
   438   abbrev & : & \isarantiq \\
   439   typeof & : & \isarantiq \\
   440   typ & : & \isarantiq \\
   441   thm_style & : & \isarantiq \\
   442   term_style & : & \isarantiq \\
   443   text & : & \isarantiq \\
   444   goals & : & \isarantiq \\
   445   subgoals & : & \isarantiq \\
   446   prf & : & \isarantiq \\
   447   full_prf & : & \isarantiq \\
   448   ML & : & \isarantiq \\
   449   ML_type & : & \isarantiq \\
   450   ML_struct & : & \isarantiq \\
   451 \end{matharray}
   452 
   453 The text body of formal comments (see also \S\ref{sec:comments}) may contain
   454 antiquotations of logical entities, such as theorems, terms and types, which
   455 are to be presented in the final output produced by the Isabelle document
   456 preparation system (see also \S\ref{sec:document-prep}).
   457 
   458 Thus embedding of
   459 ``\texttt{{\at}{\ttlbrace}term~[show_types]~"f(x)~=~a~+~x"{\ttrbrace}}''
   460 within a text block would cause
   461 \isa{(f{\isasymColon}'a~{\isasymRightarrow}~'a)~(x{\isasymColon}'a)~=~(a{\isasymColon}'a)~+~x}
   462 to appear in the final {\LaTeX} document.  Also note that theorem
   463 antiquotations may involve attributes as well.  For example,
   464 \texttt{{\at}{\ttlbrace}thm~sym~[no_vars]{\ttrbrace}} would print the
   465 statement where all schematic variables have been replaced by fixed ones,
   466 which are easier to read.
   467 
   468 \indexisarant{theory}\indexisarant{thm}\indexisarant{prop}\indexisarant{term}\indexisarant{const}
   469 \indexisarant{abbrev}\indexisarant{typeof}\indexisarant{typ}\indexisarant{thm-style}
   470 \indexisarant{term-style}\indexisarant{text}\indexisarant{goals}
   471 \indexisarant{subgoals}\indexisarant{prf}\indexisarant{full-prf}\indexisarant{ML}
   472 \indexisarant{ML-type}\indexisarant{ML-struct}
   473 
   474 \begin{rail}
   475   atsign lbrace antiquotation rbrace
   476   ;
   477 
   478   antiquotation:
   479     'theory' options name |
   480     'thm' options thmrefs |
   481     'prop' options prop |
   482     'term' options term |
   483     'const' options term |
   484     'abbrev' options term |
   485     'typeof' options term |
   486     'typ' options type |
   487     'thm\_style' options name thmref |
   488     'term\_style' options name term |
   489     'text' options name |
   490     'goals' options |
   491     'subgoals' options |
   492     'prf' options thmrefs |
   493     'full\_prf' options thmrefs |
   494     'ML' options name |
   495     'ML\_type' options name |
   496     'ML\_struct' options name
   497   ;
   498   options: '[' (option * ',') ']'
   499   ;
   500   option: name | name '=' name
   501   ;
   502 \end{rail}
   503 
   504 Note that the syntax of antiquotations may \emph{not} include source comments
   505 \texttt{(*~\dots~*)} or verbatim text \verb|{*|~\dots~\verb|*}|.
   506 
   507 \begin{descr}
   508   
   509 \item [$\at\{theory~A\}$] prints the name $A$, which is guaranteed to
   510   refer to a valid ancestor theory in the current context.
   511 
   512 \item [$\at\{thm~\vec a\}$] prints theorems $\vec a$. Note that attribute
   513   specifications may be included as well (see also \S\ref{sec:syn-att}); the
   514   $no_vars$ operation (see \S\ref{sec:misc-meth-att}) would be particularly
   515   useful to suppress printing of schematic variables.
   516 
   517 \item [$\at\{prop~\phi\}$] prints a well-typed proposition $\phi$.
   518 
   519 \item [$\at\{term~t\}$] prints a well-typed term $t$.
   520 
   521 \item [$\at\{const~c\}$] prints a well-defined constant $c$.
   522   
   523 \item [$\at\{abbrev~c\,\vec x\}$] prints a constant abbreviation
   524   $c\,\vec x \equiv rhs$ as defined in the current context.
   525 
   526 \item [$\at\{typeof~t\}$] prints the type of a well-typed term $t$.
   527 
   528 \item [$\at\{typ~\tau\}$] prints a well-formed type $\tau$.
   529   
   530 \item [$\at\{thm_style~s~a\}$] prints theorem $a$, previously applying a style
   531   $s$ to it (see below).
   532   
   533 \item [$\at\{term_style~s~t\}$] prints a well-typed term $t$ after applying a
   534   style $s$ to it (see below).
   535 
   536 \item [$\at\{text~s\}$] prints uninterpreted source text $s$.  This is
   537   particularly useful to print portions of text according to the Isabelle
   538   {\LaTeX} output style, without demanding well-formedness (e.g.\ small pieces
   539   of terms that should not be parsed or type-checked yet).
   540 
   541 \item [$\at\{goals\}$] prints the current \emph{dynamic} goal state.  This is
   542   mainly for support of tactic-emulation scripts within Isar --- presentation
   543   of goal states does not conform to actual human-readable proof documents.
   544   Please do not include goal states into document output unless you really
   545   know what you are doing!
   546   
   547 \item [$\at\{subgoals\}$] is similar to $goals$, but does not print the main
   548   goal.
   549   
   550 \item [$\at\{prf~\vec a\}$] prints the (compact) proof terms corresponding to
   551   the theorems $\vec a$. Note that this requires proof terms to be switched on
   552   for the current object logic (see the ``Proof terms'' section of the
   553   Isabelle reference manual for information on how to do this).
   554   
   555 \item [$\at\{full_prf~\vec a\}$] is like $\at\{prf~\vec a\}$, but displays the
   556   full proof terms, i.e.\ also displays information omitted in the compact
   557   proof term, which is denoted by ``$_$'' placeholders there.
   558   
   559 \item [$\at\{ML~s\}$, $\at\{ML_type~s\}$, and $\at\{ML_struct~s\}$] check text
   560   $s$ as ML value, type, and structure, respectively.  If successful, the
   561   source is displayed verbatim.
   562 
   563 \end{descr}
   564 
   565 \medskip
   566 
   567 The following standard styles for use with $thm_style$ and $term_style$ are
   568 available:
   569 
   570 \begin{descr}
   571   
   572 \item [$lhs$] extracts the first argument of any application form with at
   573   least two arguments -- typically meta-level or object-level equality, or any
   574   other binary relation.
   575   
   576 \item [$rhs$] is like $lhs$, but extracts the second argument.
   577   
   578 \item [$concl$] extracts the conclusion $C$ from a nested meta-level
   579   implication $A@1 \Imp \cdots A@n \Imp C$.
   580   
   581 \item [$prem1$, \dots, $prem9$] extract premise number $1$, \dots, $9$,
   582   respectively, from a nested meta-level implication $A@1 \Imp \cdots A@n \Imp
   583   C$.
   584 
   585 \end{descr}
   586 
   587 \medskip
   588 
   589 The following options are available to tune the output.  Note that most of
   590 these coincide with ML flags of the same names (see also \cite{isabelle-ref}).
   591 \begin{descr}
   592 \item[$show_types = bool$ and $show_sorts = bool$] control printing of
   593   explicit type and sort constraints.
   594 \item[$show_structs = bool$] controls printing of implicit structures.
   595 \item[$long_names = bool$] forces names of types and constants etc.\ to be
   596   printed in their fully qualified internal form.
   597 \item[$short_names = bool$] forces names of types and constants etc.\ to be
   598   printed unqualified.  Note that internalizing the output again in the
   599   current context may well yield a different result.
   600 \item[$unique_names = bool$] determines whether the printed version of
   601   qualified names should be made sufficiently long to avoid overlap with names
   602   declared further back.  Set to $false$ for more concise output.
   603 \item[$eta_contract = bool$] prints terms in $\eta$-contracted form.
   604 \item[$display = bool$] indicates if the text is to be output as multi-line
   605   ``display material'', rather than a small piece of text without line breaks
   606   (which is the default).
   607 \item[$breaks = bool$] controls line breaks in non-display material.
   608 \item[$quotes = bool$] indicates if the output should be enclosed in double
   609   quotes.
   610 \item[$mode = name$] adds $name$ to the print mode to be used for presentation
   611   (see also \cite{isabelle-ref}).  Note that the standard setup for {\LaTeX}
   612   output is already present by default, including the modes ``$latex$'',
   613   ``$xsymbols$'', ``$symbols$''.
   614 \item[$margin = nat$ and $indent = nat$] change the margin or indentation for
   615   pretty printing of display material.
   616 \item[$source = bool$] prints the source text of the antiquotation arguments,
   617   rather than the actual value.  Note that this does not affect
   618   well-formedness checks of $thm$, $term$, etc. (only the $text$ antiquotation
   619   admits arbitrary output).
   620 \item[$goals_limit = nat$] determines the maximum number of goals to be
   621   printed.
   622 \item[$locale = name$] specifies an alternative context used for evaluating
   623   and printing the subsequent argument.
   624 \end{descr}
   625 
   626 For boolean flags, ``$name = true$'' may be abbreviated as ``$name$''.  All of
   627 the above flags are disabled by default, unless changed from ML.
   628 
   629 \medskip Note that antiquotations do not only spare the author from tedious
   630 typing of logical entities, but also achieve some degree of
   631 consistency-checking of informal explanations with formal developments:
   632 well-formedness of terms and types with respect to the current theory or proof
   633 context is ensured here.
   634 
   635 
   636 \subsection{Tagged commands}\label{sec:tags}
   637 
   638 Each Isabelle/Isar command may be decorated by presentation tags:
   639 
   640 \indexouternonterm{tags}
   641 \begin{rail}
   642   tags: ( tag * )
   643   ;
   644   tag: '\%' (ident | string)
   645 \end{rail}
   646 
   647 The tags $theory$, $proof$, $ML$ are already pre-declared for certain classes
   648 of commands:
   649 
   650 \medskip
   651 
   652 \begin{tabular}{ll}
   653   $theory$ & theory begin and end \\
   654   $proof$ & all proof commands \\
   655   $ML$ & all commands involving ML code \\
   656 \end{tabular}
   657 
   658 \medskip The Isabelle document preparation system (see also
   659 \cite{isabelle-sys}) allows tagged command regions to be presented
   660 specifically, e.g.\ to fold proof texts, or drop parts of the text completely.
   661 
   662 For example ``$\BYNAME~\%invisible~(auto)$'' would cause that piece of proof
   663 to be treated as $invisible$ instead of $proof$ (the default), which may be
   664 either show or hidden depending on the document setup.  In contrast,
   665 ``$\BYNAME~\%visible~(auto)$'' would force this text to be shown invariably.
   666 
   667 Explicit tag specifications within a proof apply to all subsequent commands of
   668 the same level of nesting.  For example,
   669 ``$\PROOFNAME~\%visible~\dots\QEDNAME$'' would force the whole sub-proof to be
   670 typeset as $visible$ (unless some of its parts are tagged differently).
   671 
   672 %%% Local Variables:
   673 %%% mode: latex
   674 %%% TeX-master: "isar-ref"
   675 %%% End: