260 ; |
260 ; |
261 \end{rail} |
261 \end{rail} |
262 *} |
262 *} |
263 |
263 |
264 |
264 |
265 subsection {* Mixfix annotations *} |
|
266 |
|
267 text {* |
|
268 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle |
|
269 types and terms. Some commands such as @{command "types"} (see |
|
270 \secref{sec:types-pure}) admit infixes only, while @{command |
|
271 "consts"} (see \secref{sec:consts}) and @{command "syntax"} (see |
|
272 \secref{sec:syn-trans}) support the full range of general mixfixes |
|
273 and binders. |
|
274 |
|
275 \indexouternonterm{infix}\indexouternonterm{mixfix}\indexouternonterm{structmixfix} |
|
276 \begin{rail} |
|
277 infix: '(' ('infix' | 'infixl' | 'infixr') string nat ')' |
|
278 ; |
|
279 mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')' |
|
280 ; |
|
281 structmixfix: mixfix | '(' 'structure' ')' |
|
282 ; |
|
283 |
|
284 prios: '[' (nat + ',') ']' |
|
285 ; |
|
286 \end{rail} |
|
287 |
|
288 Here the \railtok{string} specifications refer to the actual mixfix |
|
289 template, which may include literal text, spacing, blocks, and |
|
290 arguments (denoted by ``@{text _}''); the special symbol |
|
291 ``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') represents an index |
|
292 argument that specifies an implicit structure reference (see also |
|
293 \secref{sec:locale}). Infix and binder declarations provide common |
|
294 abbreviations for particular mixfix declarations. So in practice, |
|
295 mixfix templates mostly degenerate to literal text for concrete |
|
296 syntax, such as ``@{verbatim "++"}'' for an infix symbol. |
|
297 |
|
298 \medskip In full generality, mixfix declarations work as follows. |
|
299 Suppose a constant @{text "c :: \<tau>\<^sub>1 \<Rightarrow> \<dots> \<tau>\<^sub>n \<Rightarrow> \<tau>"} is |
|
300 annotated by @{text "(mixfix [p\<^sub>1, \<dots>, p\<^sub>n] p)"}, where @{text |
|
301 "mixfix"} is a string @{text "d\<^sub>0 _ d\<^sub>1 _ \<dots> _ d\<^sub>n"} consisting of |
|
302 delimiters that surround argument positions as indicated by |
|
303 underscores. |
|
304 |
|
305 Altogether this determines a production for a context-free priority |
|
306 grammar, where for each argument @{text "i"} the syntactic category |
|
307 is determined by @{text "\<tau>\<^sub>i"} (with priority @{text "p\<^sub>i"}), and |
|
308 the result category is determined from @{text "\<tau>"} (with |
|
309 priority @{text "p"}). Priority specifications are optional, with |
|
310 default 0 for arguments and 1000 for the result. |
|
311 |
|
312 Since @{text "\<tau>"} may be again a function type, the constant |
|
313 type scheme may have more argument positions than the mixfix |
|
314 pattern. Printing a nested application @{text "c t\<^sub>1 \<dots> t\<^sub>m"} for |
|
315 @{text "m > n"} works by attaching concrete notation only to the |
|
316 innermost part, essentially by printing @{text "(c t\<^sub>1 \<dots> t\<^sub>n) \<dots> t\<^sub>m"} |
|
317 instead. If a term has fewer argument than specified in the mixfix |
|
318 template, the concrete syntax is ignored. |
|
319 |
|
320 \medskip A mixfix template may also contain additional directives |
|
321 for pretty printing, notably spaces, blocks, and breaks. The |
|
322 general template format is a sequence over any of the following |
|
323 entities. |
|
324 |
|
325 \begin{itemize} |
|
326 |
|
327 \item @{text "\<^bold>d"} is a delimiter, namely a non-empty |
|
328 sequence of characters other than the special characters @{text "'"} |
|
329 (single quote), @{text "_"} (underscore), @{text "\<index>"} (index |
|
330 symbol), @{text "/"} (slash), @{text "("} and @{text ")"} |
|
331 (parentheses). |
|
332 |
|
333 A single quote escapes the special meaning of these meta-characters, |
|
334 producing a literal version of the following character, unless that |
|
335 is a blank. A single quote followed by a blank separates |
|
336 delimiters, without affecting printing, but input tokens may have |
|
337 additional white space here. |
|
338 |
|
339 \item @{text "_"} is an argument position, which stands for a |
|
340 certain syntactic category in the underlying grammar. |
|
341 |
|
342 \item @{text "\<index>"} is an indexed argument position; this is |
|
343 the place where implicit structure arguments can be attached. |
|
344 |
|
345 \item @{text "\<^bold>s"} is a non-empty sequence of spaces for |
|
346 printing. This and the following specifications do not affect |
|
347 parsing at all. |
|
348 |
|
349 \item @{text "(\<^bold>n"} opens a pretty printing block. The |
|
350 optional number specifies how much indentation to add when a line |
|
351 break occurs within the block. If the parenthesis is not followed |
|
352 by digits, the indentation defaults to 0. A block specified via |
|
353 @{text "(00"} is unbreakable. |
|
354 |
|
355 \item @{text ")"} closes a pretty printing block. |
|
356 |
|
357 \item @{text "//"} forces a line break. |
|
358 |
|
359 \item @{text "/\<^bold>s"} allows a line break. Here @{text |
|
360 "\<^bold>s"} stands for the string of spaces (zero or more) right |
|
361 after the slash. These spaces are printed if the break is |
|
362 \emph{not} taken. |
|
363 |
|
364 \end{itemize} |
|
365 |
|
366 For example, the template @{text "(_ +/ _)"} specifies an infix |
|
367 operator. There are two argument positions; the delimiter @{text |
|
368 "+"} is preceded by a space and followed by a space or line break; |
|
369 the entire phrase is a pretty printing block. |
|
370 |
|
371 The general idea of pretty printing with blocks and breaks is also |
|
372 described in \cite{paulson-ml2}. |
|
373 *} |
|
374 |
|
375 |
|
376 subsection {* Proof methods \label{sec:syn-meth} *} |
|
377 |
|
378 text {* |
|
379 Proof methods are either basic ones, or expressions composed of |
|
380 methods via ``@{verbatim ","}'' (sequential composition), |
|
381 ``@{verbatim "|"}'' (alternative choices), ``@{verbatim "?"}'' |
|
382 (try), ``@{verbatim "+"}'' (repeat at least once), ``@{verbatim |
|
383 "["}@{text n}@{verbatim "]"}'' (restriction to first @{text n} |
|
384 sub-goals, with default @{text "n = 1"}). In practice, proof |
|
385 methods are usually just a comma separated list of |
|
386 \railqtok{nameref}~\railnonterm{args} specifications. Note that |
|
387 parentheses may be dropped for single method specifications (with no |
|
388 arguments). |
|
389 |
|
390 \indexouternonterm{method} |
|
391 \begin{rail} |
|
392 method: (nameref | '(' methods ')') (() | '?' | '+' | '[' nat? ']') |
|
393 ; |
|
394 methods: (nameref args | method) + (',' | '|') |
|
395 ; |
|
396 \end{rail} |
|
397 |
|
398 Proper Isar proof methods do \emph{not} admit arbitrary goal |
|
399 addressing, but refer either to the first sub-goal or all sub-goals |
|
400 uniformly. The goal restriction operator ``@{text "[n]"}'' |
|
401 evaluates a method expression within a sandbox consisting of the |
|
402 first @{text n} sub-goals (which need to exist). For example, the |
|
403 method ``@{text "simp_all[3]"}'' simplifies the first three |
|
404 sub-goals, while ``@{text "(rule foo, simp_all)[]"}'' simplifies all |
|
405 new goals that emerge from applying rule @{text "foo"} to the |
|
406 originally first one. |
|
407 |
|
408 Improper methods, notably tactic emulations, offer a separate |
|
409 low-level goal addressing scheme as explicit argument to the |
|
410 individual tactic being involved. Here ``@{text "[!]"}'' refers to |
|
411 all goals, and ``@{text "[n-]"}'' to all goals starting from @{text |
|
412 "n"}. |
|
413 |
|
414 \indexouternonterm{goalspec} |
|
415 \begin{rail} |
|
416 goalspec: '[' (nat '-' nat | nat '-' | nat | '!' ) ']' |
|
417 ; |
|
418 \end{rail} |
|
419 *} |
|
420 |
|
421 |
|
422 subsection {* Attributes and theorems \label{sec:syn-att} *} |
|
423 |
|
424 text {* |
|
425 Attributes (and proof methods, see \secref{sec:syn-meth}) have their |
|
426 own ``semi-inner'' syntax, in the sense that input conforming to |
|
427 \railnonterm{args} below is parsed by the attribute a second time. |
|
428 The attribute argument specifications may be any sequence of atomic |
|
429 entities (identifiers, strings etc.), or properly bracketed argument |
|
430 lists. Below \railqtok{atom} refers to any atomic entity, including |
|
431 any \railtok{keyword} conforming to \railtok{symident}. |
|
432 |
|
433 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes} |
|
434 \begin{rail} |
|
435 atom: nameref | typefree | typevar | var | nat | keyword |
|
436 ; |
|
437 arg: atom | '(' args ')' | '[' args ']' |
|
438 ; |
|
439 args: arg * |
|
440 ; |
|
441 attributes: '[' (nameref args * ',') ']' |
|
442 ; |
|
443 \end{rail} |
|
444 |
|
445 Theorem specifications come in several flavors: |
|
446 \railnonterm{axmdecl} and \railnonterm{thmdecl} usually refer to |
|
447 axioms, assumptions or results of goal statements, while |
|
448 \railnonterm{thmdef} collects lists of existing theorems. Existing |
|
449 theorems are given by \railnonterm{thmref} and |
|
450 \railnonterm{thmrefs}, the former requires an actual singleton |
|
451 result. |
|
452 |
|
453 There are three forms of theorem references: |
|
454 \begin{enumerate} |
|
455 |
|
456 \item named facts @{text "a"}, |
|
457 |
|
458 \item selections from named facts @{text "a(i)"} or @{text "a(j - k)"}, |
|
459 |
|
460 \item literal fact propositions using @{syntax_ref altstring} syntax |
|
461 @{verbatim "`"}@{text "\<phi>"}@{verbatim "`"} (see also method |
|
462 @{method_ref fact} in \secref{sec:pure-meth-att}). |
|
463 |
|
464 \end{enumerate} |
|
465 |
|
466 Any kind of theorem specification may include lists of attributes |
|
467 both on the left and right hand sides; attributes are applied to any |
|
468 immediately preceding fact. If names are omitted, the theorems are |
|
469 not stored within the theorem database of the theory or proof |
|
470 context, but any given attributes are applied nonetheless. |
|
471 |
|
472 An extra pair of brackets around attributes (like ``@{text |
|
473 "[[simproc a]]"}'') abbreviates a theorem reference involving an |
|
474 internal dummy fact, which will be ignored later on. So only the |
|
475 effect of the attribute on the background context will persist. |
|
476 This form of in-place declarations is particularly useful with |
|
477 commands like @{command "declare"} and @{command "using"}. |
|
478 |
|
479 \indexouternonterm{axmdecl}\indexouternonterm{thmdecl} |
|
480 \indexouternonterm{thmdef}\indexouternonterm{thmref} |
|
481 \indexouternonterm{thmrefs}\indexouternonterm{selection} |
|
482 \begin{rail} |
|
483 axmdecl: name attributes? ':' |
|
484 ; |
|
485 thmdecl: thmbind ':' |
|
486 ; |
|
487 thmdef: thmbind '=' |
|
488 ; |
|
489 thmref: (nameref selection? | altstring) attributes? | '[' attributes ']' |
|
490 ; |
|
491 thmrefs: thmref + |
|
492 ; |
|
493 |
|
494 thmbind: name attributes | name | attributes |
|
495 ; |
|
496 selection: '(' ((nat | nat '-' nat?) + ',') ')' |
|
497 ; |
|
498 \end{rail} |
|
499 *} |
|
500 |
|
501 |
|
502 subsection {* Term patterns and declarations \label{sec:term-decls} *} |
265 subsection {* Term patterns and declarations \label{sec:term-decls} *} |
503 |
266 |
504 text {* |
267 text {* |
505 Wherever explicit propositions (or term fragments) occur in a proof |
268 Wherever explicit propositions (or term fragments) occur in a proof |
506 text, casual binding of schematic term variables may be given |
269 text, casual binding of schematic term variables may be given |
541 another level of iteration, with explicit @{keyword_ref "and"} |
304 another level of iteration, with explicit @{keyword_ref "and"} |
542 separators; e.g.\ see @{command "fix"} and @{command "assume"} in |
305 separators; e.g.\ see @{command "fix"} and @{command "assume"} in |
543 \secref{sec:proof-context}. |
306 \secref{sec:proof-context}. |
544 *} |
307 *} |
545 |
308 |
|
309 |
|
310 subsection {* Mixfix annotations *} |
|
311 |
|
312 text {* |
|
313 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle |
|
314 types and terms. Some commands such as @{command "types"} (see |
|
315 \secref{sec:types-pure}) admit infixes only, while @{command |
|
316 "consts"} (see \secref{sec:consts}) and @{command "syntax"} (see |
|
317 \secref{sec:syn-trans}) support the full range of general mixfixes |
|
318 and binders. |
|
319 |
|
320 \indexouternonterm{infix}\indexouternonterm{mixfix}\indexouternonterm{structmixfix} |
|
321 \begin{rail} |
|
322 infix: '(' ('infix' | 'infixl' | 'infixr') string nat ')' |
|
323 ; |
|
324 mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')' |
|
325 ; |
|
326 structmixfix: mixfix | '(' 'structure' ')' |
|
327 ; |
|
328 |
|
329 prios: '[' (nat + ',') ']' |
|
330 ; |
|
331 \end{rail} |
|
332 |
|
333 Here the \railtok{string} specifications refer to the actual mixfix |
|
334 template, which may include literal text, spacing, blocks, and |
|
335 arguments (denoted by ``@{text _}''); the special symbol |
|
336 ``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') represents an index |
|
337 argument that specifies an implicit structure reference (see also |
|
338 \secref{sec:locale}). Infix and binder declarations provide common |
|
339 abbreviations for particular mixfix declarations. So in practice, |
|
340 mixfix templates mostly degenerate to literal text for concrete |
|
341 syntax, such as ``@{verbatim "++"}'' for an infix symbol. |
|
342 |
|
343 \medskip In full generality, mixfix declarations work as follows. |
|
344 Suppose a constant @{text "c :: \<tau>\<^sub>1 \<Rightarrow> \<dots> \<tau>\<^sub>n \<Rightarrow> \<tau>"} is |
|
345 annotated by @{text "(mixfix [p\<^sub>1, \<dots>, p\<^sub>n] p)"}, where @{text |
|
346 "mixfix"} is a string @{text "d\<^sub>0 _ d\<^sub>1 _ \<dots> _ d\<^sub>n"} consisting of |
|
347 delimiters that surround argument positions as indicated by |
|
348 underscores. |
|
349 |
|
350 Altogether this determines a production for a context-free priority |
|
351 grammar, where for each argument @{text "i"} the syntactic category |
|
352 is determined by @{text "\<tau>\<^sub>i"} (with priority @{text "p\<^sub>i"}), and |
|
353 the result category is determined from @{text "\<tau>"} (with |
|
354 priority @{text "p"}). Priority specifications are optional, with |
|
355 default 0 for arguments and 1000 for the result. |
|
356 |
|
357 Since @{text "\<tau>"} may be again a function type, the constant |
|
358 type scheme may have more argument positions than the mixfix |
|
359 pattern. Printing a nested application @{text "c t\<^sub>1 \<dots> t\<^sub>m"} for |
|
360 @{text "m > n"} works by attaching concrete notation only to the |
|
361 innermost part, essentially by printing @{text "(c t\<^sub>1 \<dots> t\<^sub>n) \<dots> t\<^sub>m"} |
|
362 instead. If a term has fewer arguments than specified in the mixfix |
|
363 template, the concrete syntax is ignored. |
|
364 |
|
365 \medskip A mixfix template may also contain additional directives |
|
366 for pretty printing, notably spaces, blocks, and breaks. The |
|
367 general template format is a sequence over any of the following |
|
368 entities. |
|
369 |
|
370 \begin{itemize} |
|
371 |
|
372 \item @{text "\<^bold>d"} is a delimiter, namely a non-empty |
|
373 sequence of characters other than the special characters @{text "'"} |
|
374 (single quote), @{text "_"} (underscore), @{text "\<index>"} (index |
|
375 symbol), @{text "/"} (slash), @{text "("} and @{text ")"} |
|
376 (parentheses). |
|
377 |
|
378 A single quote escapes the special meaning of these meta-characters, |
|
379 producing a literal version of the following character, unless that |
|
380 is a blank. A single quote followed by a blank separates |
|
381 delimiters, without affecting printing, but input tokens may have |
|
382 additional white space here. |
|
383 |
|
384 \item @{text "_"} is an argument position, which stands for a |
|
385 certain syntactic category in the underlying grammar. |
|
386 |
|
387 \item @{text "\<index>"} is an indexed argument position; this is |
|
388 the place where implicit structure arguments can be attached. |
|
389 |
|
390 \item @{text "\<^bold>s"} is a non-empty sequence of spaces for |
|
391 printing. This and the following specifications do not affect |
|
392 parsing at all. |
|
393 |
|
394 \item @{text "(\<^bold>n"} opens a pretty printing block. The |
|
395 optional number specifies how much indentation to add when a line |
|
396 break occurs within the block. If the parenthesis is not followed |
|
397 by digits, the indentation defaults to 0. A block specified via |
|
398 @{text "(00"} is unbreakable. |
|
399 |
|
400 \item @{text ")"} closes a pretty printing block. |
|
401 |
|
402 \item @{text "//"} forces a line break. |
|
403 |
|
404 \item @{text "/\<^bold>s"} allows a line break. Here @{text |
|
405 "\<^bold>s"} stands for the string of spaces (zero or more) right |
|
406 after the slash. These spaces are printed if the break is |
|
407 \emph{not} taken. |
|
408 |
|
409 \end{itemize} |
|
410 |
|
411 For example, the template @{text "(_ +/ _)"} specifies an infix |
|
412 operator. There are two argument positions; the delimiter @{text |
|
413 "+"} is preceded by a space and followed by a space or line break; |
|
414 the entire phrase is a pretty printing block. |
|
415 |
|
416 The general idea of pretty printing with blocks and breaks is also |
|
417 described in \cite{paulson-ml2}. |
|
418 *} |
|
419 |
|
420 |
|
421 subsection {* Attributes and theorems \label{sec:syn-att} *} |
|
422 |
|
423 text {* Attributes have their own ``semi-inner'' syntax, in the sense |
|
424 that input conforming to \railnonterm{args} below is parsed by the |
|
425 attribute a second time. The attribute argument specifications may |
|
426 be any sequence of atomic entities (identifiers, strings etc.), or |
|
427 properly bracketed argument lists. Below \railqtok{atom} refers to |
|
428 any atomic entity, including any \railtok{keyword} conforming to |
|
429 \railtok{symident}. |
|
430 |
|
431 \indexoutertoken{atom}\indexouternonterm{args}\indexouternonterm{attributes} |
|
432 \begin{rail} |
|
433 atom: nameref | typefree | typevar | var | nat | keyword |
|
434 ; |
|
435 arg: atom | '(' args ')' | '[' args ']' |
|
436 ; |
|
437 args: arg * |
|
438 ; |
|
439 attributes: '[' (nameref args * ',') ']' |
|
440 ; |
|
441 \end{rail} |
|
442 |
|
443 Theorem specifications come in several flavors: |
|
444 \railnonterm{axmdecl} and \railnonterm{thmdecl} usually refer to |
|
445 axioms, assumptions or results of goal statements, while |
|
446 \railnonterm{thmdef} collects lists of existing theorems. Existing |
|
447 theorems are given by \railnonterm{thmref} and |
|
448 \railnonterm{thmrefs}, the former requires an actual singleton |
|
449 result. |
|
450 |
|
451 There are three forms of theorem references: |
|
452 \begin{enumerate} |
|
453 |
|
454 \item named facts @{text "a"}, |
|
455 |
|
456 \item selections from named facts @{text "a(i)"} or @{text "a(j - k)"}, |
|
457 |
|
458 \item literal fact propositions using @{syntax_ref altstring} syntax |
|
459 @{verbatim "`"}@{text "\<phi>"}@{verbatim "`"} (see also method |
|
460 @{method_ref fact}). |
|
461 |
|
462 \end{enumerate} |
|
463 |
|
464 Any kind of theorem specification may include lists of attributes |
|
465 both on the left and right hand sides; attributes are applied to any |
|
466 immediately preceding fact. If names are omitted, the theorems are |
|
467 not stored within the theorem database of the theory or proof |
|
468 context, but any given attributes are applied nonetheless. |
|
469 |
|
470 An extra pair of brackets around attributes (like ``@{text |
|
471 "[[simproc a]]"}'') abbreviates a theorem reference involving an |
|
472 internal dummy fact, which will be ignored later on. So only the |
|
473 effect of the attribute on the background context will persist. |
|
474 This form of in-place declarations is particularly useful with |
|
475 commands like @{command "declare"} and @{command "using"}. |
|
476 |
|
477 \indexouternonterm{axmdecl}\indexouternonterm{thmdecl} |
|
478 \indexouternonterm{thmdef}\indexouternonterm{thmref} |
|
479 \indexouternonterm{thmrefs}\indexouternonterm{selection} |
|
480 \begin{rail} |
|
481 axmdecl: name attributes? ':' |
|
482 ; |
|
483 thmdecl: thmbind ':' |
|
484 ; |
|
485 thmdef: thmbind '=' |
|
486 ; |
|
487 thmref: (nameref selection? | altstring) attributes? | '[' attributes ']' |
|
488 ; |
|
489 thmrefs: thmref + |
|
490 ; |
|
491 |
|
492 thmbind: name attributes | name | attributes |
|
493 ; |
|
494 selection: '(' ((nat | nat '-' nat?) + ',') ')' |
|
495 ; |
|
496 \end{rail} |
|
497 *} |
|
498 |
546 end |
499 end |