doc-src/IsarRef/syntax.tex
author wenzelm
Fri, 30 Jul 1999 15:40:54 +0200
changeset 7135 8eabfd7e6b9b
parent 7134 320b412e5800
child 7141 a67dde8820c0
permissions -rw-r--r--
more;
wenzelm@7050
     1
wenzelm@7050
     2
%FIXME
wenzelm@7050
     3
% - examples (!?)
wenzelm@7050
     4
wenzelm@7046
     5
wenzelm@7046
     6
\chapter{Isar document syntax}
wenzelm@7046
     7
wenzelm@7134
     8
FIXME shortcut
wenzelm@7134
     9
wenzelm@7050
    10
FIXME important note: inner versus outer syntax
wenzelm@7046
    11
wenzelm@7046
    12
\section{Lexical matters}
wenzelm@7046
    13
wenzelm@7046
    14
\section{Common syntax entities}
wenzelm@7046
    15
wenzelm@7050
    16
The Isar proof and theory language syntax has been carefully designed with
wenzelm@7134
    17
orthogonality in mind.  Subsequently, we introduce several basic syntactic
wenzelm@7134
    18
entities, such as names, terms, theorem specifications, which have been
wenzelm@7134
    19
factored out of the actual Isar language elements described later.
wenzelm@7134
    20
wenzelm@7134
    21
Some of the basic syntactic entities introduced below act much like tokens
wenzelm@7134
    22
rather than nonterminals, in particular for error messages are concerned.
wenzelm@7134
    23
E.g.\ syntax elements such as $\CONSTS$ referring to \railqtoken{name} or
wenzelm@7134
    24
\railqtoken{type} would really report a missing \railqtoken{name} or
wenzelm@7134
    25
\railqtoken{type} rather than any of its constituent primitive tokens
wenzelm@7134
    26
(\railtoken{ident}, \railtoken{string} etc.).
wenzelm@7046
    27
wenzelm@7050
    28
wenzelm@7050
    29
\subsection{Names}
wenzelm@7050
    30
wenzelm@7134
    31
Entity \railqtoken{name} usually refers to any name of types, constants,
wenzelm@7050
    32
theorems, etc.\ to be \emph{declared} or \emph{defined} (so qualified
wenzelm@7134
    33
identifiers are excluded).  Quoted strings provide an escape for
wenzelm@7134
    34
non-identifier names or those ruled out by outer syntax keywords (e.g.\ 
wenzelm@7134
    35
\verb|"let"|).  Already existing objects are usually referenced by
wenzelm@7134
    36
\railqtoken{nameref}.
wenzelm@7050
    37
wenzelm@7050
    38
\indexoutertoken{name}\indexoutertoken{nameref}
wenzelm@7046
    39
\begin{rail}
wenzelm@7046
    40
  name : ident | symident | string
wenzelm@7046
    41
  ;
wenzelm@7046
    42
  nameref : name | longident
wenzelm@7046
    43
  ;
wenzelm@7046
    44
\end{rail}
wenzelm@7046
    45
wenzelm@7050
    46
wenzelm@7046
    47
\subsection{Comments}
wenzelm@7046
    48
wenzelm@7134
    49
Large chunks of plain \railqtoken{text} are usually given \railtoken{verbatim},
wenzelm@7134
    50
i.e.\ enclosed in \verb|{*|\dots\verb|*}|.  For convenience, any of the
wenzelm@7134
    51
smaller text entities (\railtoken{ident}, \railtoken{string} etc.)  are
wenzelm@7134
    52
admitted as well.  Almost any of the Isar commands may be annotated by a
wenzelm@7134
    53
marginal \railnonterm{comment}: \texttt{--} \railqtoken{text}.  Note that this
wenzelm@7134
    54
kind of comment is actually part of the language, while source level comments
wenzelm@7134
    55
\verb|(*|\dots\verb|*)| are already stripped at the lexical level.  A few
wenzelm@7134
    56
commands such as $\PROOFNAME$ admit additional markup with a ``level of
wenzelm@7134
    57
interest'', currently only \texttt{\%} for ``boring, don't read this''.
wenzelm@7050
    58
wenzelm@7050
    59
\indexoutertoken{text}\indexouternonterm{comment}\indexouternonterm{interest}
wenzelm@7046
    60
\begin{rail}
wenzelm@7050
    61
  text : verbatim | nameref
wenzelm@7050
    62
  ;
wenzelm@7134
    63
  comment : '--' text
wenzelm@7046
    64
  ;
wenzelm@7134
    65
  interest : '\%'
wenzelm@7046
    66
  ;
wenzelm@7046
    67
\end{rail}
wenzelm@7046
    68
wenzelm@7046
    69
wenzelm@7046
    70
\subsection{Sorts and arities}
wenzelm@7046
    71
wenzelm@7050
    72
The syntax of sorts and arities is given directly at the outer level.  Note
wenzelm@7050
    73
that this in contrast to that types and terms (see below).  Only few commands
wenzelm@7050
    74
ever refer to sorts or arities explicitly.
wenzelm@7050
    75
wenzelm@7050
    76
\indexouternonterm{sort}\indexouternonterm{arity}\indexouternonterm{simplearity}
wenzelm@7135
    77
\indexouternonterm{classdecl}
wenzelm@7046
    78
\begin{rail}
wenzelm@7046
    79
  sort : nameref | lbrace (nameref * ',') rbrace
wenzelm@7046
    80
  ;
wenzelm@7046
    81
  arity : ( () | '(' (sort + ',') ')' ) sort
wenzelm@7046
    82
  ;
wenzelm@7050
    83
  simplearity : ( () | '(' (sort + ',') ')' ) nameref
wenzelm@7046
    84
  ;
wenzelm@7135
    85
  classdecl: name ('<' (nameref ',' +))? comment?
wenzelm@7046
    86
\end{rail}
wenzelm@7046
    87
wenzelm@7046
    88
wenzelm@7050
    89
\subsection{Types and terms}
wenzelm@7046
    90
wenzelm@7050
    91
The actual inner Isabelle syntax, i.e.\ that of types and terms, is far too
wenzelm@7050
    92
flexible in order to be modeled explicitly at the outer theory level.
wenzelm@7050
    93
Basically, any such entity would have to be quoted at the outer level to turn
wenzelm@7050
    94
it into a single token, with the actual parsing deferred to some functions
wenzelm@7134
    95
that read and type-check terms etc.\ (note that \railqtoken{prop}s will be
wenzelm@7134
    96
handled differently from plain \railqtoken{term}s here).  For convenience, the
wenzelm@7050
    97
quotes may be omitted for any \emph{atomic} term or type (e.g.\ a single
wenzelm@7050
    98
variable).
wenzelm@7050
    99
wenzelm@7050
   100
\indexoutertoken{type}\indexoutertoken{term}\indexoutertoken{prop}
wenzelm@7046
   101
\begin{rail}
wenzelm@7134
   102
  type : nameref | typefree | typevar
wenzelm@7050
   103
  ;
wenzelm@7134
   104
  term : nameref | var | textvar | nat
wenzelm@7050
   105
  ;
wenzelm@7050
   106
  prop : term
wenzelm@7050
   107
  ;
wenzelm@7046
   108
\end{rail}
wenzelm@7046
   109
wenzelm@7050
   110
Type definitions etc.\ usually refer to \railnonterm{typespec} on the
wenzelm@7050
   111
left-hand side.  This models basic type constructor application at the outer
wenzelm@7050
   112
syntax level.  Note that only plain postfix notation is available here, but no
wenzelm@7050
   113
infixes.
wenzelm@7050
   114
wenzelm@7050
   115
\indexouternonterm{typespec}
wenzelm@7050
   116
\begin{rail}
wenzelm@7050
   117
  typespec : (() | typefree | '(' ( typefree + ',' ) ')') name
wenzelm@7050
   118
  ;
wenzelm@7050
   119
\end{rail}
wenzelm@7050
   120
wenzelm@7050
   121
wenzelm@7050
   122
\subsection{Term patterns}
wenzelm@7050
   123
wenzelm@7050
   124
Statements like $\SHOWNAME$ involve propositions, some others like $\DEFNAME$
wenzelm@7050
   125
plain terms.  Any of these usually admit automatic binding of schematic text
wenzelm@7050
   126
variables by giving (optional) patterns $\IS{p@1 \dots p@n}$.  For
wenzelm@7134
   127
\railqtoken{prop}s the $\CONCLNAME$ part refers to the conclusion only, in case
wenzelm@7050
   128
actual rules are involved, rather than atomic propositions.
wenzelm@7050
   129
wenzelm@7050
   130
\indexouternonterm{termpat}\indexouternonterm{proppat}
wenzelm@7050
   131
\begin{rail}
wenzelm@7050
   132
  termpat : '(' (term + 'is' ) ')'
wenzelm@7050
   133
  ;
wenzelm@7050
   134
  proppat : '(' (() | (prop + 'is' )) (() | 'concl' (prop + 'is' )) ')'
wenzelm@7050
   135
  ;
wenzelm@7050
   136
\end{rail}
wenzelm@7050
   137
wenzelm@7050
   138
wenzelm@7046
   139
\subsection{Mixfix annotations}
wenzelm@7046
   140
wenzelm@7134
   141
Mixfix annotations specify concrete \emph{inner} syntax of Isabelle types and
wenzelm@7134
   142
terms.  Some commands such as $\TYPES$ admit infixes only, while $\CONSTS$
wenzelm@7134
   143
etc.\ support the full range of general mixfixes and binders.
wenzelm@7046
   144
wenzelm@7050
   145
\indexouternonterm{infix}\indexouternonterm{mixfix}
wenzelm@7050
   146
\begin{rail}
wenzelm@7050
   147
  infix : '(' ('infixl' | 'infixr') (() | string) nat ')'
wenzelm@7050
   148
  ;
wenzelm@7046
   149
wenzelm@7050
   150
  mixfix : infix | string (() | '[' (nat + ',') ']') (() | nat) |
wenzelm@7050
   151
  'binder' string (() | '[' (nat + ',') ']') nat
wenzelm@7050
   152
  ;
wenzelm@7050
   153
\end{rail}
wenzelm@7046
   154
wenzelm@7050
   155
wenzelm@7134
   156
\subsection{Attributes and theorems}\label{sec:syn-att}
wenzelm@7050
   157
wenzelm@7050
   158
Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
wenzelm@7050
   159
``semi-inner'' syntax, which does not have to be atomic at the outer level
wenzelm@7050
   160
unlike that of types and terms.  Instead, the attribute argument
wenzelm@7050
   161
specifications may be any sequence of atomic entities (identifiers, strings
wenzelm@7134
   162
etc.), or properly bracketed argument lists.  Below \railqtoken{atom} refers to
wenzelm@7050
   163
any atomic entity (\railtoken{ident}, \railtoken{longident},
wenzelm@7050
   164
\railtoken{symident} etc.), including keywords that conform to
wenzelm@7050
   165
\railtoken{symident}, but do not coincide with actual command names.
wenzelm@7050
   166
wenzelm@7050
   167
\indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
wenzelm@7050
   168
\begin{rail}
wenzelm@7134
   169
  atom : nameref | typefree | typevar | var | textvar | nat
wenzelm@7050
   170
  ;
wenzelm@7134
   171
  arg : atom | '(' args ')' | '[' args ']' | lbrace args rbrace
wenzelm@7134
   172
  ;
wenzelm@7134
   173
  args : arg *
wenzelm@7134
   174
  ;
wenzelm@7134
   175
  attributes : '[' (nameref args * ',') ']'
wenzelm@7050
   176
  ;
wenzelm@7050
   177
\end{rail}
wenzelm@7050
   178
wenzelm@7134
   179
Theorem specifications come in three flavors: \railnonterm{thmdecl} usually
wenzelm@7134
   180
refers to the result of an assumption or goal statement (e.g.\ $\SHOWNAME$),
wenzelm@7050
   181
\railnonterm{thmdef} collects lists of existing theorems (as in $\NOTENAME$),
wenzelm@7134
   182
\railnonterm{thmrefs} refers to any list of existing theorems (e.g.\ occurring
wenzelm@7050
   183
as proof method arguments).  Any of these may include lists of attributes,
wenzelm@7050
   184
which are applied to the preceding theorem or list of theorems.
wenzelm@7050
   185
wenzelm@7135
   186
\indexouternonterm{thmdecl}\indexouternonterm{axmdecl}
wenzelm@7135
   187
\indexouternonterm{thmdef}\indexouternonterm{thmrefs}
wenzelm@7050
   188
\begin{rail}
wenzelm@7134
   189
  thmname : name attributes | name | attributes
wenzelm@7050
   190
  ;
wenzelm@7135
   191
  axmdecl : name attributes? ':'
wenzelm@7135
   192
  ;
wenzelm@7134
   193
  thmdecl : thmname ':'
wenzelm@7050
   194
  ;
wenzelm@7134
   195
  thmdef : thmname '='
wenzelm@7134
   196
  ;
wenzelm@7134
   197
  thmrefs : nameref (() | attributes) +
wenzelm@7050
   198
  ;
wenzelm@7050
   199
\end{rail}
wenzelm@7050
   200
wenzelm@7050
   201
wenzelm@7050
   202
\subsection{Proof methods}\label{sec:syn-meth}
wenzelm@7050
   203
wenzelm@7050
   204
Proof methods are either basic ones, or expressions composed of methods via
wenzelm@7050
   205
``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternatives),
wenzelm@7050
   206
``\texttt{?}'' (try), ``\texttt{*}'' (repeat, ${} \ge 0$ times),
wenzelm@7134
   207
``\texttt{+}'' (repeat, ${} > 0$ times).  In practice, proof methods are very
wenzelm@7134
   208
often just a comma separated list of \railqtoken{nameref}~\railnonterm{args}
wenzelm@7050
   209
specifications.  Thus the syntax is similar to that of attributes, with plain
wenzelm@7050
   210
parentheses instead of square brackets (see also \S\ref{sec:syn-att}).  Note
wenzelm@7134
   211
that parentheses may be dropped for single method specifications without
wenzelm@7134
   212
arguments.
wenzelm@7050
   213
wenzelm@7050
   214
\indexouternonterm{method}
wenzelm@7050
   215
\begin{rail}
wenzelm@7134
   216
  method : (nameref | '(' methods ')') (() | '?' | '*' | '+')
wenzelm@7134
   217
  ;
wenzelm@7134
   218
  methods : (nameref args | method) + (',' | '|')
wenzelm@7050
   219
  ;
wenzelm@7050
   220
\end{rail}
wenzelm@7046
   221
wenzelm@7046
   222
wenzelm@7046
   223
%%% Local Variables: 
wenzelm@7046
   224
%%% mode: latex
wenzelm@7046
   225
%%% TeX-master: "isar-ref"
wenzelm@7046
   226
%%% End: