260 ; |
260 ; |
261 \end{rail} |
261 \end{rail} |
262 *} |
262 *} |
263 |
263 |
264 |
264 |
|
265 subsection {* Term patterns and declarations \label{sec:term-decls} *} |
|
266 |
|
267 text {* |
|
268 Wherever explicit propositions (or term fragments) occur in a proof |
|
269 text, casual binding of schematic term variables may be given |
|
270 specified via patterns of the form ``@{text "(\<IS> p\<^sub>1 \<dots> |
|
271 p\<^sub>n)"}''. This works both for \railqtok{term} and \railqtok{prop}. |
|
272 |
|
273 \indexouternonterm{termpat}\indexouternonterm{proppat} |
|
274 \begin{rail} |
|
275 termpat: '(' ('is' term +) ')' |
|
276 ; |
|
277 proppat: '(' ('is' prop +) ')' |
|
278 ; |
|
279 \end{rail} |
|
280 |
|
281 \medskip Declarations of local variables @{text "x :: \<tau>"} and |
|
282 logical propositions @{text "a : \<phi>"} represent different views on |
|
283 the same principle of introducing a local scope. In practice, one |
|
284 may usually omit the typing of \railnonterm{vars} (due to |
|
285 type-inference), and the naming of propositions (due to implicit |
|
286 references of current facts). In any case, Isar proof elements |
|
287 usually admit to introduce multiple such items simultaneously. |
|
288 |
|
289 \indexouternonterm{vars}\indexouternonterm{props} |
|
290 \begin{rail} |
|
291 vars: (name+) ('::' type)? |
|
292 ; |
|
293 props: thmdecl? (prop proppat? +) |
|
294 ; |
|
295 \end{rail} |
|
296 |
|
297 The treatment of multiple declarations corresponds to the |
|
298 complementary focus of \railnonterm{vars} versus |
|
299 \railnonterm{props}. In ``@{text "x\<^sub>1 \<dots> x\<^sub>n :: \<tau>"}'' |
|
300 the typing refers to all variables, while in @{text "a: \<phi>\<^sub>1 \<dots> |
|
301 \<phi>\<^sub>n"} the naming refers to all propositions collectively. |
|
302 Isar language elements that refer to \railnonterm{vars} or |
|
303 \railnonterm{props} typically admit separate typings or namings via |
|
304 another level of iteration, with explicit @{keyword_ref "and"} |
|
305 separators; e.g.\ see @{command "fix"} and @{command "assume"} in |
|
306 \secref{sec:proof-context}. |
|
307 *} |
|
308 |
|
309 |
265 subsection {* Mixfix annotations *} |
310 subsection {* Mixfix annotations *} |
266 |
311 |
267 text {* |
312 text {* |
268 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle |
313 Mixfix annotations specify concrete \emph{inner} syntax of Isabelle |
269 types and terms. Some commands such as @{command "types"} (see |
314 types and terms. Some commands such as @{command "types"} (see |
284 prios: '[' (nat + ',') ']' |
329 prios: '[' (nat + ',') ']' |
285 ; |
330 ; |
286 \end{rail} |
331 \end{rail} |
287 |
332 |
288 Here the \railtok{string} specifications refer to the actual mixfix |
333 Here the \railtok{string} specifications refer to the actual mixfix |
289 template (see also \cite{isabelle-ref}), which may include literal |
334 template, which may include literal text, spacing, blocks, and |
290 text, spacing, blocks, and arguments (denoted by ``@{text _}''); the |
335 arguments (denoted by ``@{text _}''); the special symbol |
291 special symbol ``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') |
336 ``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') represents an index |
292 represents an index argument that specifies an implicit structure |
337 argument that specifies an implicit structure reference (see also |
293 reference (see also \secref{sec:locale}). Infix and binder |
338 \secref{sec:locale}). Infix and binder declarations provide common |
294 declarations provide common abbreviations for particular mixfix |
339 abbreviations for particular mixfix declarations. So in practice, |
295 declarations. So in practice, mixfix templates mostly degenerate to |
340 mixfix templates mostly degenerate to literal text for concrete |
296 literal text for concrete syntax, such as ``@{verbatim "++"}'' for |
341 syntax, such as ``@{verbatim "++"}'' for an infix symbol. |
297 an infix symbol, or ``@{verbatim "++"}@{text "\<index>"}'' for an infix of |
342 |
298 an implicit structure. |
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}. |
299 *} |
418 *} |
300 |
419 |
301 |
420 |
302 subsection {* Proof methods \label{sec:syn-meth} *} |
421 subsection {* Proof methods \label{sec:syn-meth} *} |
303 |
422 |
422 selection: '(' ((nat | nat '-' nat?) + ',') ')' |
541 selection: '(' ((nat | nat '-' nat?) + ',') ')' |
423 ; |
542 ; |
424 \end{rail} |
543 \end{rail} |
425 *} |
544 *} |
426 |
545 |
427 |
|
428 subsection {* Term patterns and declarations \label{sec:term-decls} *} |
|
429 |
|
430 text {* |
|
431 Wherever explicit propositions (or term fragments) occur in a proof |
|
432 text, casual binding of schematic term variables may be given |
|
433 specified via patterns of the form ``@{text "(\<IS> p\<^sub>1 \<dots> |
|
434 p\<^sub>n)"}''. This works both for \railqtok{term} and \railqtok{prop}. |
|
435 |
|
436 \indexouternonterm{termpat}\indexouternonterm{proppat} |
|
437 \begin{rail} |
|
438 termpat: '(' ('is' term +) ')' |
|
439 ; |
|
440 proppat: '(' ('is' prop +) ')' |
|
441 ; |
|
442 \end{rail} |
|
443 |
|
444 \medskip Declarations of local variables @{text "x :: \<tau>"} and |
|
445 logical propositions @{text "a : \<phi>"} represent different views on |
|
446 the same principle of introducing a local scope. In practice, one |
|
447 may usually omit the typing of \railnonterm{vars} (due to |
|
448 type-inference), and the naming of propositions (due to implicit |
|
449 references of current facts). In any case, Isar proof elements |
|
450 usually admit to introduce multiple such items simultaneously. |
|
451 |
|
452 \indexouternonterm{vars}\indexouternonterm{props} |
|
453 \begin{rail} |
|
454 vars: (name+) ('::' type)? |
|
455 ; |
|
456 props: thmdecl? (prop proppat? +) |
|
457 ; |
|
458 \end{rail} |
|
459 |
|
460 The treatment of multiple declarations corresponds to the |
|
461 complementary focus of \railnonterm{vars} versus |
|
462 \railnonterm{props}. In ``@{text "x\<^sub>1 \<dots> x\<^sub>n :: \<tau>"}'' |
|
463 the typing refers to all variables, while in @{text "a: \<phi>\<^sub>1 \<dots> |
|
464 \<phi>\<^sub>n"} the naming refers to all propositions collectively. |
|
465 Isar language elements that refer to \railnonterm{vars} or |
|
466 \railnonterm{props} typically admit separate typings or namings via |
|
467 another level of iteration, with explicit @{keyword_ref "and"} |
|
468 separators; e.g.\ see @{command "fix"} and @{command "assume"} in |
|
469 \secref{sec:proof-context}. |
|
470 *} |
|
471 |
|
472 end |
546 end |