doc-src/IsarRef/Thy/Outer_Syntax.thy
author wenzelm
Tue, 18 Nov 2008 18:25:10 +0100
changeset 28838 d5db6dfcb34a
parent 28778 a25630deacaf
child 30045 d2597c4f7e5c
child 30240 5b25fee0362c
permissions -rw-r--r--
moved table of standard Isabelle symbols to isar-ref manual;
wenzelm@27037
     1
(* $Id$ *)
wenzelm@27037
     2
wenzelm@27037
     3
theory Outer_Syntax
wenzelm@27050
     4
imports Main
wenzelm@27037
     5
begin
wenzelm@27037
     6
wenzelm@27040
     7
chapter {* Outer syntax *}
wenzelm@27037
     8
wenzelm@27037
     9
text {*
wenzelm@27037
    10
  The rather generic framework of Isabelle/Isar syntax emerges from
wenzelm@27037
    11
  three main syntactic categories: \emph{commands} of the top-level
wenzelm@27037
    12
  Isar engine (covering theory and proof elements), \emph{methods} for
wenzelm@27037
    13
  general goal refinements (analogous to traditional ``tactics''), and
wenzelm@27037
    14
  \emph{attributes} for operations on facts (within a certain
wenzelm@27037
    15
  context).  Subsequently we give a reference of basic syntactic
wenzelm@27037
    16
  entities underlying Isabelle/Isar syntax in a bottom-up manner.
wenzelm@27037
    17
  Concrete theory and proof language elements will be introduced later
wenzelm@27037
    18
  on.
wenzelm@27037
    19
wenzelm@27037
    20
  \medskip In order to get started with writing well-formed
wenzelm@27037
    21
  Isabelle/Isar documents, the most important aspect to be noted is
wenzelm@27037
    22
  the difference of \emph{inner} versus \emph{outer} syntax.  Inner
wenzelm@27037
    23
  syntax is that of Isabelle types and terms of the logic, while outer
wenzelm@27037
    24
  syntax is that of Isabelle/Isar theory sources (specifications and
wenzelm@27037
    25
  proofs).  As a general rule, inner syntax entities may occur only as
wenzelm@27037
    26
  \emph{atomic entities} within outer syntax.  For example, the string
wenzelm@27037
    27
  @{verbatim "\"x + y\""} and identifier @{verbatim z} are legal term
wenzelm@27037
    28
  specifications within a theory, while @{verbatim "x + y"} without
wenzelm@27037
    29
  quotes is not.
wenzelm@27037
    30
wenzelm@27037
    31
  Printed theory documents usually omit quotes to gain readability
wenzelm@27037
    32
  (this is a matter of {\LaTeX} macro setup, say via @{verbatim
wenzelm@27037
    33
  "\\isabellestyle"}, see also \cite{isabelle-sys}).  Experienced
wenzelm@27037
    34
  users of Isabelle/Isar may easily reconstruct the lost technical
wenzelm@27037
    35
  information, while mere readers need not care about quotes at all.
wenzelm@27037
    36
wenzelm@27037
    37
  \medskip Isabelle/Isar input may contain any number of input
wenzelm@27037
    38
  termination characters ``@{verbatim ";"}'' (semicolon) to separate
wenzelm@27037
    39
  commands explicitly.  This is particularly useful in interactive
wenzelm@27037
    40
  shell sessions to make clear where the current command is intended
wenzelm@27037
    41
  to end.  Otherwise, the interpreter loop will continue to issue a
wenzelm@27037
    42
  secondary prompt ``@{verbatim "#"}'' until an end-of-command is
wenzelm@27037
    43
  clearly recognized from the input syntax, e.g.\ encounter of the
wenzelm@27037
    44
  next command keyword.
wenzelm@27037
    45
wenzelm@27037
    46
  More advanced interfaces such as Proof~General \cite{proofgeneral}
wenzelm@27037
    47
  do not require explicit semicolons, the amount of input text is
wenzelm@27037
    48
  determined automatically by inspecting the present content of the
wenzelm@27037
    49
  Emacs text buffer.  In the printed presentation of Isabelle/Isar
wenzelm@27037
    50
  documents semicolons are omitted altogether for readability.
wenzelm@27037
    51
wenzelm@27037
    52
  \begin{warn}
wenzelm@27037
    53
    Proof~General requires certain syntax classification tables in
wenzelm@27037
    54
    order to achieve properly synchronized interaction with the
wenzelm@27037
    55
    Isabelle/Isar process.  These tables need to be consistent with
wenzelm@27037
    56
    the Isabelle version and particular logic image to be used in a
wenzelm@27037
    57
    running session (common object-logics may well change the outer
wenzelm@27037
    58
    syntax).  The standard setup should work correctly with any of the
wenzelm@27037
    59
    ``official'' logic images derived from Isabelle/HOL (including
wenzelm@27037
    60
    HOLCF etc.).  Users of alternative logics may need to tell
wenzelm@27037
    61
    Proof~General explicitly, e.g.\ by giving an option @{verbatim "-k ZF"}
wenzelm@27037
    62
    (in conjunction with @{verbatim "-l ZF"}, to specify the default
wenzelm@27037
    63
    logic image).  Note that option @{verbatim "-L"} does both
wenzelm@27037
    64
    of this at the same time.
wenzelm@27037
    65
  \end{warn}
wenzelm@27037
    66
*}
wenzelm@27037
    67
wenzelm@27037
    68
wenzelm@28774
    69
section {* Lexical matters \label{sec:outer-lex} *}
wenzelm@27037
    70
wenzelm@28775
    71
text {* The outer lexical syntax consists of three main categories of
wenzelm@28776
    72
  syntax tokens:
wenzelm@27037
    73
wenzelm@28775
    74
  \begin{enumerate}
wenzelm@27037
    75
wenzelm@28775
    76
  \item \emph{major keywords} --- the command names that are available
wenzelm@28775
    77
  in the present logic session;
wenzelm@28775
    78
wenzelm@28775
    79
  \item \emph{minor keywords} --- additional literal tokens required
wenzelm@28775
    80
  by the syntax of commands;
wenzelm@28775
    81
wenzelm@28776
    82
  \item \emph{named tokens} --- various categories of identifiers etc.
wenzelm@28775
    83
wenzelm@28775
    84
  \end{enumerate}
wenzelm@28775
    85
wenzelm@28776
    86
  Major keywords and minor keywords are guaranteed to be disjoint.
wenzelm@28775
    87
  This helps user-interfaces to determine the overall structure of a
wenzelm@28775
    88
  theory text, without knowing the full details of command syntax.
wenzelm@28776
    89
  Internally, there is some additional information about the kind of
wenzelm@28776
    90
  major keywords, which approximates the command type (theory command,
wenzelm@28776
    91
  proof command etc.).
wenzelm@28775
    92
wenzelm@28775
    93
  Keywords override named tokens.  For example, the presence of a
wenzelm@28775
    94
  command called @{verbatim term} inhibits the identifier @{verbatim
wenzelm@28775
    95
  term}, but the string @{verbatim "\"term\""} can be used instead.
wenzelm@28775
    96
  By convention, the outer syntax always allows quoted strings in
wenzelm@28775
    97
  addition to identifiers, wherever a named entity is expected.
wenzelm@28775
    98
wenzelm@28776
    99
  When tokenizing a given input sequence, the lexer repeatedly takes
wenzelm@28776
   100
  the longest prefix of the input that forms a valid token.  Spaces,
wenzelm@28776
   101
  tabs, newlines and formfeeds between tokens serve as explicit
wenzelm@28776
   102
  separators.
wenzelm@28776
   103
wenzelm@28775
   104
  \medskip The categories for named tokens are defined once and for
wenzelm@28775
   105
  all as follows.
wenzelm@28775
   106
wenzelm@28776
   107
  \begin{center}
wenzelm@28775
   108
  \begin{supertabular}{rcl}
wenzelm@28775
   109
    @{syntax_def ident} & = & @{text "letter quasiletter\<^sup>*"} \\
wenzelm@28775
   110
    @{syntax_def longident} & = & @{text "ident("}@{verbatim "."}@{text "ident)\<^sup>+"} \\
wenzelm@28775
   111
    @{syntax_def symident} & = & @{text "sym\<^sup>+  |  "}@{verbatim "\\"}@{verbatim "<"}@{text ident}@{verbatim ">"} \\
wenzelm@28775
   112
    @{syntax_def nat} & = & @{text "digit\<^sup>+"} \\
wenzelm@28775
   113
    @{syntax_def var} & = & @{verbatim "?"}@{text "ident  |  "}@{verbatim "?"}@{text ident}@{verbatim "."}@{text nat} \\
wenzelm@28775
   114
    @{syntax_def typefree} & = & @{verbatim "'"}@{text ident} \\
wenzelm@28775
   115
    @{syntax_def typevar} & = & @{verbatim "?"}@{text "typefree  |  "}@{verbatim "?"}@{text typefree}@{verbatim "."}@{text nat} \\
wenzelm@28775
   116
    @{syntax_def string} & = & @{verbatim "\""} @{text "\<dots>"} @{verbatim "\""} \\
wenzelm@28775
   117
    @{syntax_def altstring} & = & @{verbatim "`"} @{text "\<dots>"} @{verbatim "`"} \\
wenzelm@28775
   118
    @{syntax_def verbatim} & = & @{verbatim "{*"} @{text "\<dots>"} @{verbatim "*"}@{verbatim "}"} \\[1ex]
wenzelm@28775
   119
wenzelm@28775
   120
    @{text letter} & = & @{text "latin  |  "}@{verbatim "\\"}@{verbatim "<"}@{text latin}@{verbatim ">"}@{text "  |  "}@{verbatim "\\"}@{verbatim "<"}@{text "latin latin"}@{verbatim ">"}@{text "  |  greek  |"} \\
wenzelm@28775
   121
          &   & @{verbatim "\<^isub>"}@{text "  |  "}@{verbatim "\<^isup>"} \\
wenzelm@28775
   122
    @{text quasiletter} & = & @{text "letter  |  digit  |  "}@{verbatim "_"}@{text "  |  "}@{verbatim "'"} \\
wenzelm@28775
   123
    @{text latin} & = & @{verbatim a}@{text "  | \<dots> |  "}@{verbatim z}@{text "  |  "}@{verbatim A}@{text "  |  \<dots> |  "}@{verbatim Z} \\
wenzelm@28775
   124
    @{text digit} & = & @{verbatim "0"}@{text "  |  \<dots> |  "}@{verbatim "9"} \\
wenzelm@28775
   125
    @{text sym} & = & @{verbatim "!"}@{text "  |  "}@{verbatim "#"}@{text "  |  "}@{verbatim "$"}@{text "  |  "}@{verbatim "%"}@{text "  |  "}@{verbatim "&"}@{text "  |  "}@{verbatim "*"}@{text "  |  "}@{verbatim "+"}@{text "  |  "}@{verbatim "-"}@{text "  |  "}@{verbatim "/"}@{text "  |"} \\
wenzelm@28775
   126
    & & @{verbatim "<"}@{text "  |  "}@{verbatim "="}@{text "  |  "}@{verbatim ">"}@{text "  |  "}@{verbatim "?"}@{text "  |  "}@{verbatim "@"}@{text "  |  "}@{verbatim "^"}@{text "  |  "}@{verbatim "_"}@{text "  |  "}@{verbatim "|"}@{text "  |  "}@{verbatim "~"} \\
wenzelm@28775
   127
    @{text greek} & = & @{verbatim "\<alpha>"}@{text "  |  "}@{verbatim "\<beta>"}@{text "  |  "}@{verbatim "\<gamma>"}@{text "  |  "}@{verbatim "\<delta>"}@{text "  |"} \\
wenzelm@28775
   128
          &   & @{verbatim "\<epsilon>"}@{text "  |  "}@{verbatim "\<zeta>"}@{text "  |  "}@{verbatim "\<eta>"}@{text "  |  "}@{verbatim "\<theta>"}@{text "  |"} \\
wenzelm@28775
   129
          &   & @{verbatim "\<iota>"}@{text "  |  "}@{verbatim "\<kappa>"}@{text "  |  "}@{verbatim "\<mu>"}@{text "  |  "}@{verbatim "\<nu>"}@{text "  |"} \\
wenzelm@28775
   130
          &   & @{verbatim "\<xi>"}@{text "  |  "}@{verbatim "\<pi>"}@{text "  |  "}@{verbatim "\<rho>"}@{text "  |  "}@{verbatim "\<sigma>"}@{text "  |  "}@{verbatim "\<tau>"}@{text "  |"} \\
wenzelm@28775
   131
          &   & @{verbatim "\<upsilon>"}@{text "  |  "}@{verbatim "\<phi>"}@{text "  |  "}@{verbatim "\<chi>"}@{text "  |  "}@{verbatim "\<psi>"}@{text "  |"} \\
wenzelm@28775
   132
          &   & @{verbatim "\<omega>"}@{text "  |  "}@{verbatim "\<Gamma>"}@{text "  |  "}@{verbatim "\<Delta>"}@{text "  |  "}@{verbatim "\<Theta>"}@{text "  |"} \\
wenzelm@28775
   133
          &   & @{verbatim "\<Lambda>"}@{text "  |  "}@{verbatim "\<Xi>"}@{text "  |  "}@{verbatim "\<Pi>"}@{text "  |  "}@{verbatim "\<Sigma>"}@{text "  |"} \\
wenzelm@28775
   134
          &   & @{verbatim "\<Upsilon>"}@{text "  |  "}@{verbatim "\<Phi>"}@{text "  |  "}@{verbatim "\<Psi>"}@{text "  |  "}@{verbatim "\<Omega>"} \\
wenzelm@28775
   135
  \end{supertabular}
wenzelm@28776
   136
  \end{center}
wenzelm@27037
   137
wenzelm@28778
   138
  A @{syntax_ref var} or @{syntax_ref typevar} describes an unknown,
wenzelm@28778
   139
  which is internally a pair of base name and index (ML type @{ML_type
wenzelm@28778
   140
  indexname}).  These components are either separated by a dot as in
wenzelm@28778
   141
  @{text "?x.1"} or @{text "?x7.3"} or run together as in @{text
wenzelm@28778
   142
  "?x1"}.  The latter form is possible if the base name does not end
wenzelm@28778
   143
  with digits.  If the index is 0, it may be dropped altogether:
wenzelm@28778
   144
  @{text "?x"} and @{text "?x0"} and @{text "?x.0"} all refer to the
wenzelm@28778
   145
  same unknown, with basename @{text "x"} and index 0.
wenzelm@28778
   146
wenzelm@28778
   147
  The syntax of @{syntax_ref string} admits any characters, including
wenzelm@27037
   148
  newlines; ``@{verbatim "\""}'' (double-quote) and ``@{verbatim
wenzelm@27037
   149
  "\\"}'' (backslash) need to be escaped by a backslash; arbitrary
wenzelm@27037
   150
  character codes may be specified as ``@{verbatim "\\"}@{text ddd}'',
wenzelm@27037
   151
  with three decimal digits.  Alternative strings according to
wenzelm@28778
   152
  @{syntax_ref altstring} are analogous, using single back-quotes
wenzelm@28778
   153
  instead.
wenzelm@28778
   154
wenzelm@28778
   155
  The body of @{syntax_ref verbatim} may consist of any text not
wenzelm@27037
   156
  containing ``@{verbatim "*"}@{verbatim "}"}''; this allows
wenzelm@28778
   157
  convenient inclusion of quotes without further escapes.  There is no
wenzelm@28778
   158
  way to escape ``@{verbatim "*"}@{verbatim "}"}''.  If the quoted
wenzelm@28778
   159
  text is {\LaTeX} source, one may usually add some blank or comment
wenzelm@28778
   160
  to avoid the critical character sequence.
wenzelm@28778
   161
wenzelm@28778
   162
  Source comments take the form @{verbatim "(*"}~@{text
wenzelm@28778
   163
  "\<dots>"}~@{verbatim "*)"} and may be nested, although the user-interface
wenzelm@28778
   164
  might prevent this.  Note that this form indicates source comments
wenzelm@28778
   165
  only, which are stripped after lexical analysis of the input.  The
wenzelm@28778
   166
  Isar syntax also provides proper \emph{document comments} that are
wenzelm@28778
   167
  considered as part of the text (see \secref{sec:comments}).
wenzelm@27037
   168
wenzelm@27037
   169
  Common mathematical symbols such as @{text \<forall>} are represented in
wenzelm@27037
   170
  Isabelle as @{verbatim \<forall>}.  There are infinitely many Isabelle
wenzelm@27037
   171
  symbols like this, although proper presentation is left to front-end
wenzelm@27037
   172
  tools such as {\LaTeX} or Proof~General with the X-Symbol package.
wenzelm@27037
   173
  A list of standard Isabelle symbols that work well with these tools
wenzelm@28838
   174
  is given in \appref{app:symbols}.  Note that @{verbatim "\<lambda>"} does
wenzelm@28838
   175
  not belong to the @{text letter} category, since it is already used
wenzelm@28838
   176
  differently in the Pure term language.
wenzelm@27037
   177
*}
wenzelm@27037
   178
wenzelm@27037
   179
wenzelm@27037
   180
section {* Common syntax entities *}
wenzelm@27037
   181
wenzelm@27037
   182
text {*
wenzelm@27037
   183
  We now introduce several basic syntactic entities, such as names,
wenzelm@27037
   184
  terms, and theorem specifications, which are factored out of the
wenzelm@27037
   185
  actual Isar language elements to be described later.
wenzelm@27037
   186
*}
wenzelm@27037
   187
wenzelm@27037
   188
wenzelm@27037
   189
subsection {* Names *}
wenzelm@27037
   190
wenzelm@27037
   191
text {*
wenzelm@27037
   192
  Entity \railqtok{name} usually refers to any name of types,
wenzelm@27037
   193
  constants, theorems etc.\ that are to be \emph{declared} or
wenzelm@27037
   194
  \emph{defined} (so qualified identifiers are excluded here).  Quoted
wenzelm@27037
   195
  strings provide an escape for non-identifier names or those ruled
wenzelm@27037
   196
  out by outer syntax keywords (e.g.\ quoted @{verbatim "\"let\""}).
wenzelm@27037
   197
  Already existing objects are usually referenced by
wenzelm@27037
   198
  \railqtok{nameref}.
wenzelm@27037
   199
wenzelm@27037
   200
  \indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
wenzelm@27037
   201
  \indexoutertoken{int}
wenzelm@27037
   202
  \begin{rail}
wenzelm@27037
   203
    name: ident | symident | string | nat
wenzelm@27037
   204
    ;
wenzelm@27037
   205
    parname: '(' name ')'
wenzelm@27037
   206
    ;
wenzelm@27037
   207
    nameref: name | longident
wenzelm@27037
   208
    ;
wenzelm@27037
   209
    int: nat | '-' nat
wenzelm@27037
   210
    ;
wenzelm@27037
   211
  \end{rail}
wenzelm@27037
   212
*}
wenzelm@27037
   213
wenzelm@27037
   214
wenzelm@27037
   215
subsection {* Comments \label{sec:comments} *}
wenzelm@27037
   216
wenzelm@27037
   217
text {*
wenzelm@27037
   218
  Large chunks of plain \railqtok{text} are usually given
wenzelm@27037
   219
  \railtok{verbatim}, i.e.\ enclosed in @{verbatim "{"}@{verbatim
wenzelm@27037
   220
  "*"}~@{text "\<dots>"}~@{verbatim "*"}@{verbatim "}"}.  For convenience,
wenzelm@27037
   221
  any of the smaller text units conforming to \railqtok{nameref} are
wenzelm@27037
   222
  admitted as well.  A marginal \railnonterm{comment} is of the form
wenzelm@27037
   223
  @{verbatim "--"} \railqtok{text}.  Any number of these may occur
wenzelm@27037
   224
  within Isabelle/Isar commands.
wenzelm@27037
   225
wenzelm@27037
   226
  \indexoutertoken{text}\indexouternonterm{comment}
wenzelm@27037
   227
  \begin{rail}
wenzelm@27037
   228
    text: verbatim | nameref
wenzelm@27037
   229
    ;
wenzelm@27037
   230
    comment: '--' text
wenzelm@27037
   231
    ;
wenzelm@27037
   232
  \end{rail}
wenzelm@27037
   233
*}
wenzelm@27037
   234
wenzelm@27037
   235
wenzelm@27037
   236
subsection {* Type classes, sorts and arities *}
wenzelm@27037
   237
wenzelm@27037
   238
text {*
wenzelm@27037
   239
  Classes are specified by plain names.  Sorts have a very simple
wenzelm@27037
   240
  inner syntax, which is either a single class name @{text c} or a
wenzelm@27037
   241
  list @{text "{c\<^sub>1, \<dots>, c\<^sub>n}"} referring to the
wenzelm@27037
   242
  intersection of these classes.  The syntax of type arities is given
wenzelm@27037
   243
  directly at the outer level.
wenzelm@27037
   244
wenzelm@27037
   245
  \indexouternonterm{sort}\indexouternonterm{arity}
wenzelm@27037
   246
  \indexouternonterm{classdecl}
wenzelm@27037
   247
  \begin{rail}
wenzelm@27037
   248
    classdecl: name (('<' | subseteq) (nameref + ','))?
wenzelm@27037
   249
    ;
wenzelm@27037
   250
    sort: nameref
wenzelm@27037
   251
    ;
wenzelm@27037
   252
    arity: ('(' (sort + ',') ')')? sort
wenzelm@27037
   253
    ;
wenzelm@27037
   254
  \end{rail}
wenzelm@27037
   255
*}
wenzelm@27037
   256
wenzelm@27037
   257
wenzelm@27037
   258
subsection {* Types and terms \label{sec:types-terms} *}
wenzelm@27037
   259
wenzelm@27037
   260
text {*
wenzelm@27037
   261
  The actual inner Isabelle syntax, that of types and terms of the
wenzelm@27037
   262
  logic, is far too sophisticated in order to be modelled explicitly
wenzelm@27037
   263
  at the outer theory level.  Basically, any such entity has to be
wenzelm@27037
   264
  quoted to turn it into a single token (the parsing and type-checking
wenzelm@27037
   265
  is performed internally later).  For convenience, a slightly more
wenzelm@27037
   266
  liberal convention is adopted: quotes may be omitted for any type or
wenzelm@27037
   267
  term that is already atomic at the outer level.  For example, one
wenzelm@27037
   268
  may just write @{verbatim x} instead of quoted @{verbatim "\"x\""}.
wenzelm@27037
   269
  Note that symbolic identifiers (e.g.\ @{verbatim "++"} or @{text
wenzelm@27037
   270
  "\<forall>"} are available as well, provided these have not been superseded
wenzelm@27037
   271
  by commands or other keywords already (such as @{verbatim "="} or
wenzelm@27037
   272
  @{verbatim "+"}).
wenzelm@27037
   273
wenzelm@27037
   274
  \indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
wenzelm@27037
   275
  \begin{rail}
wenzelm@27037
   276
    type: nameref | typefree | typevar
wenzelm@27037
   277
    ;
wenzelm@27037
   278
    term: nameref | var
wenzelm@27037
   279
    ;
wenzelm@27037
   280
    prop: term
wenzelm@27037
   281
    ;
wenzelm@27037
   282
  \end{rail}
wenzelm@27037
   283
wenzelm@27037
   284
  Positional instantiations are indicated by giving a sequence of
wenzelm@27037
   285
  terms, or the placeholder ``@{text _}'' (underscore), which means to
wenzelm@27037
   286
  skip a position.
wenzelm@27037
   287
wenzelm@27037
   288
  \indexoutertoken{inst}\indexoutertoken{insts}
wenzelm@27037
   289
  \begin{rail}
wenzelm@27037
   290
    inst: underscore | term
wenzelm@27037
   291
    ;
wenzelm@27037
   292
    insts: (inst *)
wenzelm@27037
   293
    ;
wenzelm@27037
   294
  \end{rail}
wenzelm@27037
   295
wenzelm@27037
   296
  Type declarations and definitions usually refer to
wenzelm@27037
   297
  \railnonterm{typespec} on the left-hand side.  This models basic
wenzelm@27037
   298
  type constructor application at the outer syntax level.  Note that
wenzelm@27037
   299
  only plain postfix notation is available here, but no infixes.
wenzelm@27037
   300
wenzelm@27037
   301
  \indexouternonterm{typespec}
wenzelm@27037
   302
  \begin{rail}
wenzelm@27037
   303
    typespec: (() | typefree | '(' ( typefree + ',' ) ')') name
wenzelm@27037
   304
    ;
wenzelm@27037
   305
  \end{rail}
wenzelm@27037
   306
*}
wenzelm@27037
   307
wenzelm@27037
   308
wenzelm@28754
   309
subsection {* Term patterns and declarations \label{sec:term-decls} *}
wenzelm@28754
   310
wenzelm@28754
   311
text {*
wenzelm@28754
   312
  Wherever explicit propositions (or term fragments) occur in a proof
wenzelm@28754
   313
  text, casual binding of schematic term variables may be given
wenzelm@28754
   314
  specified via patterns of the form ``@{text "(\<IS> p\<^sub>1 \<dots>
wenzelm@28754
   315
  p\<^sub>n)"}''.  This works both for \railqtok{term} and \railqtok{prop}.
wenzelm@28754
   316
wenzelm@28754
   317
  \indexouternonterm{termpat}\indexouternonterm{proppat}
wenzelm@28754
   318
  \begin{rail}
wenzelm@28754
   319
    termpat: '(' ('is' term +) ')'
wenzelm@28754
   320
    ;
wenzelm@28754
   321
    proppat: '(' ('is' prop +) ')'
wenzelm@28754
   322
    ;
wenzelm@28754
   323
  \end{rail}
wenzelm@28754
   324
wenzelm@28754
   325
  \medskip Declarations of local variables @{text "x :: \<tau>"} and
wenzelm@28754
   326
  logical propositions @{text "a : \<phi>"} represent different views on
wenzelm@28754
   327
  the same principle of introducing a local scope.  In practice, one
wenzelm@28754
   328
  may usually omit the typing of \railnonterm{vars} (due to
wenzelm@28754
   329
  type-inference), and the naming of propositions (due to implicit
wenzelm@28754
   330
  references of current facts).  In any case, Isar proof elements
wenzelm@28754
   331
  usually admit to introduce multiple such items simultaneously.
wenzelm@28754
   332
wenzelm@28754
   333
  \indexouternonterm{vars}\indexouternonterm{props}
wenzelm@28754
   334
  \begin{rail}
wenzelm@28754
   335
    vars: (name+) ('::' type)?
wenzelm@28754
   336
    ;
wenzelm@28754
   337
    props: thmdecl? (prop proppat? +)
wenzelm@28754
   338
    ;
wenzelm@28754
   339
  \end{rail}
wenzelm@28754
   340
wenzelm@28754
   341
  The treatment of multiple declarations corresponds to the
wenzelm@28754
   342
  complementary focus of \railnonterm{vars} versus
wenzelm@28754
   343
  \railnonterm{props}.  In ``@{text "x\<^sub>1 \<dots> x\<^sub>n :: \<tau>"}''
wenzelm@28754
   344
  the typing refers to all variables, while in @{text "a: \<phi>\<^sub>1 \<dots>
wenzelm@28754
   345
  \<phi>\<^sub>n"} the naming refers to all propositions collectively.
wenzelm@28754
   346
  Isar language elements that refer to \railnonterm{vars} or
wenzelm@28754
   347
  \railnonterm{props} typically admit separate typings or namings via
wenzelm@28754
   348
  another level of iteration, with explicit @{keyword_ref "and"}
wenzelm@28754
   349
  separators; e.g.\ see @{command "fix"} and @{command "assume"} in
wenzelm@28754
   350
  \secref{sec:proof-context}.
wenzelm@28754
   351
*}
wenzelm@28754
   352
wenzelm@28754
   353
wenzelm@27037
   354
subsection {* Attributes and theorems \label{sec:syn-att} *}
wenzelm@27037
   355
wenzelm@28754
   356
text {* Attributes have their own ``semi-inner'' syntax, in the sense
wenzelm@28754
   357
  that input conforming to \railnonterm{args} below is parsed by the
wenzelm@28754
   358
  attribute a second time.  The attribute argument specifications may
wenzelm@28754
   359
  be any sequence of atomic entities (identifiers, strings etc.), or
wenzelm@28754
   360
  properly bracketed argument lists.  Below \railqtok{atom} refers to
wenzelm@28754
   361
  any atomic entity, including any \railtok{keyword} conforming to
wenzelm@28754
   362
  \railtok{symident}.
wenzelm@27037
   363
wenzelm@27037
   364
  \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
wenzelm@27037
   365
  \begin{rail}
wenzelm@27037
   366
    atom: nameref | typefree | typevar | var | nat | keyword
wenzelm@27037
   367
    ;
wenzelm@27037
   368
    arg: atom | '(' args ')' | '[' args ']'
wenzelm@27037
   369
    ;
wenzelm@27037
   370
    args: arg *
wenzelm@27037
   371
    ;
wenzelm@27037
   372
    attributes: '[' (nameref args * ',') ']'
wenzelm@27037
   373
    ;
wenzelm@27037
   374
  \end{rail}
wenzelm@27037
   375
wenzelm@27037
   376
  Theorem specifications come in several flavors:
wenzelm@27037
   377
  \railnonterm{axmdecl} and \railnonterm{thmdecl} usually refer to
wenzelm@27037
   378
  axioms, assumptions or results of goal statements, while
wenzelm@27037
   379
  \railnonterm{thmdef} collects lists of existing theorems.  Existing
wenzelm@27037
   380
  theorems are given by \railnonterm{thmref} and
wenzelm@27037
   381
  \railnonterm{thmrefs}, the former requires an actual singleton
wenzelm@27037
   382
  result.
wenzelm@27037
   383
wenzelm@27037
   384
  There are three forms of theorem references:
wenzelm@27037
   385
  \begin{enumerate}
wenzelm@27037
   386
  
wenzelm@27037
   387
  \item named facts @{text "a"},
wenzelm@27037
   388
wenzelm@27037
   389
  \item selections from named facts @{text "a(i)"} or @{text "a(j - k)"},
wenzelm@27037
   390
wenzelm@27037
   391
  \item literal fact propositions using @{syntax_ref altstring} syntax
wenzelm@27037
   392
  @{verbatim "`"}@{text "\<phi>"}@{verbatim "`"} (see also method
wenzelm@28754
   393
  @{method_ref fact}).
wenzelm@27037
   394
wenzelm@27037
   395
  \end{enumerate}
wenzelm@27037
   396
wenzelm@27037
   397
  Any kind of theorem specification may include lists of attributes
wenzelm@27037
   398
  both on the left and right hand sides; attributes are applied to any
wenzelm@27037
   399
  immediately preceding fact.  If names are omitted, the theorems are
wenzelm@27037
   400
  not stored within the theorem database of the theory or proof
wenzelm@27037
   401
  context, but any given attributes are applied nonetheless.
wenzelm@27037
   402
wenzelm@27037
   403
  An extra pair of brackets around attributes (like ``@{text
wenzelm@27037
   404
  "[[simproc a]]"}'') abbreviates a theorem reference involving an
wenzelm@27037
   405
  internal dummy fact, which will be ignored later on.  So only the
wenzelm@27037
   406
  effect of the attribute on the background context will persist.
wenzelm@27037
   407
  This form of in-place declarations is particularly useful with
wenzelm@27037
   408
  commands like @{command "declare"} and @{command "using"}.
wenzelm@27037
   409
wenzelm@27037
   410
  \indexouternonterm{axmdecl}\indexouternonterm{thmdecl}
wenzelm@27037
   411
  \indexouternonterm{thmdef}\indexouternonterm{thmref}
wenzelm@27037
   412
  \indexouternonterm{thmrefs}\indexouternonterm{selection}
wenzelm@27037
   413
  \begin{rail}
wenzelm@27037
   414
    axmdecl: name attributes? ':'
wenzelm@27037
   415
    ;
wenzelm@27037
   416
    thmdecl: thmbind ':'
wenzelm@27037
   417
    ;
wenzelm@27037
   418
    thmdef: thmbind '='
wenzelm@27037
   419
    ;
wenzelm@27037
   420
    thmref: (nameref selection? | altstring) attributes? | '[' attributes ']'
wenzelm@27037
   421
    ;
wenzelm@27037
   422
    thmrefs: thmref +
wenzelm@27037
   423
    ;
wenzelm@27037
   424
wenzelm@27037
   425
    thmbind: name attributes | name | attributes
wenzelm@27037
   426
    ;
wenzelm@27037
   427
    selection: '(' ((nat | nat '-' nat?) + ',') ')'
wenzelm@27037
   428
    ;
wenzelm@27037
   429
  \end{rail}
wenzelm@27037
   430
*}
wenzelm@27037
   431
wenzelm@27037
   432
end