doc-src/IsarRef/syntax.tex
changeset 13048 8b2eb3b78cc3
parent 13039 cfcc1f6f21df
child 13827 c690cb885db4
equal deleted inserted replaced
13047:f27cc0a43feb 13048:8b2eb3b78cc3
     1 
     1 
     2 \chapter{Syntax Primitives}
     2 \chapter{Syntax primitives}
     3 
     3 
     4 The rather generic framework of Isabelle/Isar syntax emerges from three main
     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
     5 syntactic categories: \emph{commands} of the top-level Isar engine (covering
     6 theory and proof elements), \emph{methods} for general goal refinements
     6 theory and proof elements), \emph{methods} for general goal refinements
     7 (analogous to traditional ``tactics''), and \emph{attributes} for operations
     7 (analogous to traditional ``tactics''), and \emph{attributes} for operations
   128 Subsequently, we introduce several basic syntactic entities, such as names,
   128 Subsequently, we introduce several basic syntactic entities, such as names,
   129 terms, and theorem specifications, which have been factored out of the actual
   129 terms, and theorem specifications, which have been factored out of the actual
   130 Isar language elements to be described later.
   130 Isar language elements to be described later.
   131 
   131 
   132 Note that some of the basic syntactic entities introduced below (e.g.\ 
   132 Note that some of the basic syntactic entities introduced below (e.g.\ 
   133 \railqtoken{name}) act much like tokens rather than plain nonterminals (e.g.\ 
   133 \railqtok{name}) act much like tokens rather than plain nonterminals (e.g.\ 
   134 \railnonterm{sort}), especially for the sake of error messages.  E.g.\ syntax
   134 \railnonterm{sort}), especially for the sake of error messages.  E.g.\ syntax
   135 elements like $\CONSTS$ referring to \railqtoken{name} or \railqtoken{type}
   135 elements like $\CONSTS$ referring to \railqtok{name} or \railqtok{type} would
   136 would really report a missing name or type rather than any of the constituent
   136 really report a missing name or type rather than any of the constituent
   137 primitive tokens such as \railtoken{ident} or \railtoken{string}.
   137 primitive tokens such as \railtok{ident} or \railtok{string}.
   138 
   138 
   139 
   139 
   140 \subsection{Names}
   140 \subsection{Names}
   141 
   141 
   142 Entity \railqtoken{name} usually refers to any name of types, constants,
   142 Entity \railqtok{name} usually refers to any name of types, constants,
   143 theorems etc.\ that are to be \emph{declared} or \emph{defined} (so qualified
   143 theorems etc.\ that are to be \emph{declared} or \emph{defined} (so qualified
   144 identifiers are excluded here).  Quoted strings provide an escape for
   144 identifiers are excluded here).  Quoted strings provide an escape for
   145 non-identifier names or those ruled out by outer syntax keywords (e.g.\ 
   145 non-identifier names or those ruled out by outer syntax keywords (e.g.\ 
   146 \verb|"let"|).  Already existing objects are usually referenced by
   146 \verb|"let"|).  Already existing objects are usually referenced by
   147 \railqtoken{nameref}.
   147 \railqtok{nameref}.
   148 
   148 
   149 \indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
   149 \indexoutertoken{name}\indexoutertoken{parname}\indexoutertoken{nameref}
   150 \indexoutertoken{int}
   150 \indexoutertoken{int}
   151 \begin{rail}
   151 \begin{rail}
   152   name: ident | symident | string | nat
   152   name: ident | symident | string | nat
   160 \end{rail}
   160 \end{rail}
   161 
   161 
   162 
   162 
   163 \subsection{Comments}\label{sec:comments}
   163 \subsection{Comments}\label{sec:comments}
   164 
   164 
   165 Large chunks of plain \railqtoken{text} are usually given
   165 Large chunks of plain \railqtok{text} are usually given \railtok{verbatim},
   166 \railtoken{verbatim}, i.e.\ enclosed in \verb|{*|~\dots~\verb|*}|.  For
   166 i.e.\ enclosed in \verb|{*|~\dots~\verb|*}|.  For convenience, any of the
   167 convenience, any of the smaller text units conforming to \railqtoken{nameref}
   167 smaller text units conforming to \railqtok{nameref} are admitted as well.  A
   168 are admitted as well.  A marginal \railnonterm{comment} is of the form
   168 marginal \railnonterm{comment} is of the form \texttt{--} \railqtok{text}.
   169 \texttt{--} \railqtoken{text}.  Any number of these may occur within
   169 Any number of these may occur within Isabelle/Isar commands.
   170 Isabelle/Isar commands.
       
   171 
   170 
   172 \indexoutertoken{text}\indexouternonterm{comment}
   171 \indexoutertoken{text}\indexouternonterm{comment}
   173 \begin{rail}
   172 \begin{rail}
   174   text: verbatim | nameref
   173   text: verbatim | nameref
   175   ;
   174   ;
   267 
   266 
   268   prios: '[' (nat + ',') ']'
   267   prios: '[' (nat + ',') ']'
   269   ;
   268   ;
   270 \end{rail}
   269 \end{rail}
   271 
   270 
   272 Here the \railtoken{string} specifications refer to the actual mixfix template
   271 Here the \railtok{string} specifications refer to the actual mixfix template
   273 (see also \cite{isabelle-ref}), which may include literal text, spacing,
   272 (see also \cite{isabelle-ref}), which may include literal text, spacing,
   274 blocks, and arguments (denoted by ``$_$''); the special symbol \verb,\<index>,
   273 blocks, and arguments (denoted by ``$_$''); the special symbol \verb,\<index>,
   275 (printed as ``\i'') represents an index argument that specifies an implicit
   274 (printed as ``\i'') represents an index argument that specifies an implicit
   276 structure reference (see also \S\ref{sec:locale}).  Infix and binder
   275 structure reference (see also \S\ref{sec:locale}).  Infix and binder
   277 declarations provide common abbreviations for particular mixfix declarations.
   276 declarations provide common abbreviations for particular mixfix declarations.
   285 
   284 
   286 Proof methods are either basic ones, or expressions composed of methods via
   285 Proof methods are either basic ones, or expressions composed of methods via
   287 ``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternative choices),
   286 ``\texttt{,}'' (sequential composition), ``\texttt{|}'' (alternative choices),
   288 ``\texttt{?}'' (try), ``\texttt{+}'' (repeat at least once).  In practice,
   287 ``\texttt{?}'' (try), ``\texttt{+}'' (repeat at least once).  In practice,
   289 proof methods are usually just a comma separated list of
   288 proof methods are usually just a comma separated list of
   290 \railqtoken{nameref}~\railnonterm{args} specifications.  Note that parentheses
   289 \railqtok{nameref}~\railnonterm{args} specifications.  Note that parentheses
   291 may be dropped for single method specifications (with no arguments).
   290 may be dropped for single method specifications (with no arguments).
   292 
   291 
   293 \indexouternonterm{method}
   292 \indexouternonterm{method}
   294 \begin{rail}
   293 \begin{rail}
   295   method: (nameref | '(' methods ')') (() | '?' | '+')
   294   method: (nameref | '(' methods ')') (() | '?' | '+')
   315 Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
   314 Attributes (and proof methods, see \S\ref{sec:syn-meth}) have their own
   316 ``semi-inner'' syntax, in the sense that input conforming to
   315 ``semi-inner'' syntax, in the sense that input conforming to
   317 \railnonterm{args} below is parsed by the attribute a second time.  The
   316 \railnonterm{args} below is parsed by the attribute a second time.  The
   318 attribute argument specifications may be any sequence of atomic entities
   317 attribute argument specifications may be any sequence of atomic entities
   319 (identifiers, strings etc.), or properly bracketed argument lists.  Below
   318 (identifiers, strings etc.), or properly bracketed argument lists.  Below
   320 \railqtoken{atom} refers to any atomic entity, including any
   319 \railqtok{atom} refers to any atomic entity, including any \railtok{keyword}
   321 \railtoken{keyword} conforming to \railtoken{symident}.
   320 conforming to \railtok{symident}.
   322 
   321 
   323 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
   322 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes}
   324 \begin{rail}
   323 \begin{rail}
   325   atom: nameref | typefree | typevar | var | nat | keyword
   324   atom: nameref | typefree | typevar | var | nat | keyword
   326   ;
   325   ;
   364 \subsection{Term patterns and declarations}\label{sec:term-decls}
   363 \subsection{Term patterns and declarations}\label{sec:term-decls}
   365 
   364 
   366 Wherever explicit propositions (or term fragments) occur in a proof text,
   365 Wherever explicit propositions (or term fragments) occur in a proof text,
   367 casual binding of schematic term variables may be given specified via patterns
   366 casual binding of schematic term variables may be given specified via patterns
   368 of the form ``$\ISS{p@1\;\dots}{p@n}$''.  There are separate versions
   367 of the form ``$\ISS{p@1\;\dots}{p@n}$''.  There are separate versions
   369 available for \railqtoken{term}s and \railqtoken{prop}s.  The latter provides
   368 available for \railqtok{term}s and \railqtok{prop}s.  The latter provides a
   370 a $\CONCLNAME$ part with patterns referring the (atomic) conclusion of a rule.
   369 $\CONCLNAME$ part with patterns referring the (atomic) conclusion of a rule.
   371 
   370 
   372 \indexouternonterm{termpat}\indexouternonterm{proppat}
   371 \indexouternonterm{termpat}\indexouternonterm{proppat}
   373 \begin{rail}
   372 \begin{rail}
   374   termpat: '(' ('is' term +) ')'
   373   termpat: '(' ('is' term +) ')'
   375   ;
   374   ;