doc-src/IsarRef/Thy/Inner_Syntax.thy
author wenzelm
Thu, 13 Nov 2008 21:57:20 +0100
changeset 28772 3f6bc48ebb9b
parent 28771 4510201c6aaf
child 28773 39b4cedb8433
permissions -rw-r--r--
added Pure grammer (from old ref manual);
wenzelm@28762
     1
(* $Id$ *)
wenzelm@28762
     2
wenzelm@28762
     3
theory Inner_Syntax
wenzelm@28762
     4
imports Main
wenzelm@28762
     5
begin
wenzelm@28762
     6
wenzelm@28762
     7
chapter {* Inner syntax --- the term language *}
wenzelm@28762
     8
wenzelm@28762
     9
section {* Printing logical entities *}
wenzelm@28762
    10
wenzelm@28762
    11
subsection {* Diagnostic commands *}
wenzelm@28762
    12
wenzelm@28762
    13
text {*
wenzelm@28762
    14
  \begin{matharray}{rcl}
wenzelm@28766
    15
    @{command_def "typ"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    16
    @{command_def "term"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    17
    @{command_def "prop"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28766
    18
    @{command_def "thm"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    19
    @{command_def "prf"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    20
    @{command_def "full_prf"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28766
    21
    @{command_def "pr"}@{text "\<^sup>*"} & : & @{text "any \<rightarrow>"} \\
wenzelm@28762
    22
  \end{matharray}
wenzelm@28762
    23
wenzelm@28762
    24
  These diagnostic commands assist interactive development by printing
wenzelm@28762
    25
  internal logical entities in a human-readable fashion.
wenzelm@28762
    26
wenzelm@28762
    27
  \begin{rail}
wenzelm@28766
    28
    'typ' modes? type
wenzelm@28762
    29
    ;
wenzelm@28762
    30
    'term' modes? term
wenzelm@28762
    31
    ;
wenzelm@28762
    32
    'prop' modes? prop
wenzelm@28762
    33
    ;
wenzelm@28766
    34
    'thm' modes? thmrefs
wenzelm@28762
    35
    ;
wenzelm@28766
    36
    ( 'prf' | 'full\_prf' ) modes? thmrefs?
wenzelm@28762
    37
    ;
wenzelm@28766
    38
    'pr' modes? nat? (',' nat)?
wenzelm@28762
    39
    ;
wenzelm@28762
    40
wenzelm@28762
    41
    modes: '(' (name + ) ')'
wenzelm@28762
    42
    ;
wenzelm@28762
    43
  \end{rail}
wenzelm@28762
    44
wenzelm@28762
    45
  \begin{description}
wenzelm@28762
    46
wenzelm@28766
    47
  \item @{command "typ"}~@{text \<tau>} reads and prints types of the
wenzelm@28766
    48
  meta-logic according to the current theory or proof context.
wenzelm@28766
    49
wenzelm@28766
    50
  \item @{command "term"}~@{text t} and @{command "prop"}~@{text \<phi>}
wenzelm@28766
    51
  read, type-check and print terms or propositions according to the
wenzelm@28766
    52
  current theory or proof context; the inferred type of @{text t} is
wenzelm@28766
    53
  output as well.  Note that these commands are also useful in
wenzelm@28766
    54
  inspecting the current environment of term abbreviations.
wenzelm@28762
    55
wenzelm@28762
    56
  \item @{command "thm"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} retrieves
wenzelm@28762
    57
  theorems from the current theory or proof context.  Note that any
wenzelm@28762
    58
  attributes included in the theorem specifications are applied to a
wenzelm@28762
    59
  temporary context derived from the current theory or proof; the
wenzelm@28762
    60
  result is discarded, i.e.\ attributes involved in @{text "a\<^sub>1,
wenzelm@28762
    61
  \<dots>, a\<^sub>n"} do not have any permanent effect.
wenzelm@28762
    62
wenzelm@28762
    63
  \item @{command "prf"} displays the (compact) proof term of the
wenzelm@28762
    64
  current proof state (if present), or of the given theorems. Note
wenzelm@28762
    65
  that this requires proof terms to be switched on for the current
wenzelm@28762
    66
  object logic (see the ``Proof terms'' section of the Isabelle
wenzelm@28762
    67
  reference manual for information on how to do this).
wenzelm@28762
    68
wenzelm@28762
    69
  \item @{command "full_prf"} is like @{command "prf"}, but displays
wenzelm@28762
    70
  the full proof term, i.e.\ also displays information omitted in the
wenzelm@28762
    71
  compact proof term, which is denoted by ``@{text _}'' placeholders
wenzelm@28762
    72
  there.
wenzelm@28762
    73
wenzelm@28766
    74
  \item @{command "pr"}~@{text "goals, prems"} prints the current
wenzelm@28766
    75
  proof state (if present), including the proof context, current facts
wenzelm@28766
    76
  and goals.  The optional limit arguments affect the number of goals
wenzelm@28766
    77
  and premises to be displayed, which is initially 10 for both.
wenzelm@28766
    78
  Omitting limit values leaves the current setting unchanged.
wenzelm@28766
    79
wenzelm@28762
    80
  \end{description}
wenzelm@28762
    81
wenzelm@28762
    82
  All of the diagnostic commands above admit a list of @{text modes}
wenzelm@28762
    83
  to be specified, which is appended to the current print mode (see
wenzelm@28762
    84
  also \cite{isabelle-ref}).  Thus the output behavior may be modified
wenzelm@28762
    85
  according particular print mode features.  For example, @{command
wenzelm@28762
    86
  "pr"}~@{text "(latex xsymbols)"} would print the current proof state
wenzelm@28762
    87
  with mathematical symbols and special characters represented in
wenzelm@28762
    88
  {\LaTeX} source, according to the Isabelle style
wenzelm@28762
    89
  \cite{isabelle-sys}.
wenzelm@28762
    90
wenzelm@28762
    91
  Note that antiquotations (cf.\ \secref{sec:antiq}) provide a more
wenzelm@28762
    92
  systematic way to include formal items into the printed text
wenzelm@28762
    93
  document.
wenzelm@28762
    94
*}
wenzelm@28762
    95
wenzelm@28762
    96
wenzelm@28763
    97
subsection {* Details of printed content *}
wenzelm@28763
    98
wenzelm@28763
    99
text {*
wenzelm@28763
   100
  \begin{mldecls} 
wenzelm@28763
   101
    @{index_ML show_types: "bool ref"} & default @{ML false} \\
wenzelm@28763
   102
    @{index_ML show_sorts: "bool ref"} & default @{ML false} \\
wenzelm@28763
   103
    @{index_ML show_consts: "bool ref"} & default @{ML false} \\
wenzelm@28763
   104
    @{index_ML long_names: "bool ref"} & default @{ML false} \\
wenzelm@28763
   105
    @{index_ML short_names: "bool ref"} & default @{ML false} \\
wenzelm@28763
   106
    @{index_ML unique_names: "bool ref"} & default @{ML true} \\
wenzelm@28763
   107
    @{index_ML show_brackets: "bool ref"} & default @{ML false} \\
wenzelm@28765
   108
    @{index_ML eta_contract: "bool ref"} & default @{ML true} \\
wenzelm@28763
   109
    @{index_ML goals_limit: "int ref"} & default @{ML 10} \\
wenzelm@28763
   110
    @{index_ML Proof.show_main_goal: "bool ref"} & default @{ML false} \\
wenzelm@28763
   111
    @{index_ML show_hyps: "bool ref"} & default @{ML false} \\
wenzelm@28763
   112
    @{index_ML show_tags: "bool ref"} & default @{ML false} \\
wenzelm@28765
   113
    @{index_ML show_question_marks: "bool ref"} & default @{ML true} \\
wenzelm@28763
   114
  \end{mldecls}
wenzelm@28763
   115
wenzelm@28763
   116
  These global ML variables control the detail of information that is
wenzelm@28763
   117
  displayed for types, terms, theorems, goals etc.
wenzelm@28763
   118
wenzelm@28765
   119
  In interactive sessions, the user interface usually manages these
wenzelm@28765
   120
  global parameters of the Isabelle process, even with some concept of
wenzelm@28765
   121
  persistence.  Nonetheless it is occasionally useful to manipulate ML
wenzelm@28765
   122
  variables directly, e.g.\ using @{command "ML_val"} or @{command
wenzelm@28765
   123
  "ML_command"}.
wenzelm@28765
   124
wenzelm@28765
   125
  Batch-mode logic sessions may be configured by putting appropriate
wenzelm@28765
   126
  ML text directly into the @{verbatim ROOT.ML} file.
wenzelm@28765
   127
wenzelm@28763
   128
  \begin{description}
wenzelm@28763
   129
wenzelm@28763
   130
  \item @{ML show_types} and @{ML show_sorts} control printing of type
wenzelm@28763
   131
  constraints for term variables, and sort constraints for type
wenzelm@28763
   132
  variables.  By default, neither of these are shown in output.  If
wenzelm@28763
   133
  @{ML show_sorts} is set to @{ML true}, types are always shown as
wenzelm@28763
   134
  well.
wenzelm@28763
   135
wenzelm@28763
   136
  Note that displaying types and sorts may explain why a polymorphic
wenzelm@28763
   137
  inference rule fails to resolve with some goal, or why a rewrite
wenzelm@28763
   138
  rule does not apply as expected.
wenzelm@28763
   139
wenzelm@28763
   140
  \item @{ML show_consts} controls printing of types of constants when
wenzelm@28765
   141
  displaying a goal state.
wenzelm@28765
   142
wenzelm@28765
   143
  Note that the output can be enormous, because polymorphic constants
wenzelm@28765
   144
  often occur at several different type instances.
wenzelm@28763
   145
wenzelm@28763
   146
  \item @{ML long_names}, @{ML short_names}, and @{ML unique_names}
wenzelm@28765
   147
  control the way of printing fully qualified internal names in
wenzelm@28765
   148
  external form.  See also \secref{sec:antiq} for the document
wenzelm@28765
   149
  antiquotation options of the same names.
wenzelm@28763
   150
wenzelm@28765
   151
  \item @{ML show_brackets} controls bracketing in pretty printed
wenzelm@28765
   152
  output.  If set to @{ML true}, all sub-expressions of the pretty
wenzelm@28765
   153
  printing tree will be parenthesized, even if this produces malformed
wenzelm@28765
   154
  term syntax!  This crude way of showing the internal structure of
wenzelm@28765
   155
  pretty printed entities may occasionally help to diagnose problems
wenzelm@28765
   156
  with operator priorities, for example.
wenzelm@28763
   157
wenzelm@28763
   158
  \item @{ML eta_contract} controls @{text "\<eta>"}-contracted printing of
wenzelm@28763
   159
  terms.
wenzelm@28763
   160
wenzelm@28763
   161
  The @{text \<eta>}-contraction law asserts @{prop "(\<lambda>x. f x) \<equiv> f"},
wenzelm@28763
   162
  provided @{text x} is not free in @{text f}.  It asserts
wenzelm@28763
   163
  \emph{extensionality} of functions: @{prop "f \<equiv> g"} if @{prop "f x \<equiv>
wenzelm@28763
   164
  g x"} for all @{text x}.  Higher-order unification frequently puts
wenzelm@28763
   165
  terms into a fully @{text \<eta>}-expanded form.  For example, if @{text
wenzelm@28763
   166
  F} has type @{text "(\<tau> \<Rightarrow> \<tau>) \<Rightarrow> \<tau>"} then its expanded form is @{term
wenzelm@28763
   167
  "\<lambda>h. F (\<lambda>x. h x)"}.
wenzelm@28763
   168
wenzelm@28763
   169
  Setting @{ML eta_contract} makes Isabelle perform @{text
wenzelm@28763
   170
  \<eta>}-contractions before printing, so that @{term "\<lambda>h. F (\<lambda>x. h x)"}
wenzelm@28763
   171
  appears simply as @{text F}.
wenzelm@28763
   172
wenzelm@28763
   173
  Note that the distinction between a term and its @{text \<eta>}-expanded
wenzelm@28765
   174
  form occasionally matters.  While higher-order resolution and
wenzelm@28765
   175
  rewriting operate modulo @{text "\<alpha>\<beta>\<eta>"}-conversion, some other tools
wenzelm@28765
   176
  might look at terms more discretely.
wenzelm@28763
   177
wenzelm@28763
   178
  \item @{ML goals_limit} controls the maximum number of subgoals to
wenzelm@28765
   179
  be shown in goal output.
wenzelm@28763
   180
wenzelm@28763
   181
  \item @{ML Proof.show_main_goal} controls whether the main result to
wenzelm@28763
   182
  be proven should be displayed.  This information might be relevant
wenzelm@28765
   183
  for schematic goals, to inspect the current claim that has been
wenzelm@28765
   184
  synthesized so far.
wenzelm@28763
   185
wenzelm@28763
   186
  \item @{ML show_hyps} controls printing of implicit hypotheses of
wenzelm@28763
   187
  local facts.  Normally, only those hypotheses are displayed that are
wenzelm@28763
   188
  \emph{not} covered by the assumptions of the current context: this
wenzelm@28763
   189
  situation indicates a fault in some tool being used.
wenzelm@28763
   190
wenzelm@28765
   191
  By setting @{ML show_hyps} to @{ML true}, output of \emph{all}
wenzelm@28765
   192
  hypotheses can be enforced, which is occasionally useful for
wenzelm@28765
   193
  diagnostic purposes.
wenzelm@28763
   194
wenzelm@28763
   195
  \item @{ML show_tags} controls printing of extra annotations within
wenzelm@28765
   196
  theorems, such as internal position information, or the case names
wenzelm@28765
   197
  being attached by the attribute @{attribute case_names}.
wenzelm@28765
   198
wenzelm@28765
   199
  Note that the @{attribute tagged} and @{attribute untagged}
wenzelm@28765
   200
  attributes provide low-level access to the collection of tags
wenzelm@28765
   201
  associated with a theorem.
wenzelm@28765
   202
wenzelm@28765
   203
  \item @{ML show_question_marks} controls printing of question marks
wenzelm@28765
   204
  for schematic variables, such as @{text ?x}.  Only the leading
wenzelm@28765
   205
  question mark is affected, the remaining text is unchanged
wenzelm@28765
   206
  (including proper markup for schematic variables that might be
wenzelm@28765
   207
  relevant for user interfaces).
wenzelm@28765
   208
wenzelm@28765
   209
  \end{description}
wenzelm@28765
   210
*}
wenzelm@28765
   211
wenzelm@28765
   212
wenzelm@28765
   213
subsection {* Printing limits *}
wenzelm@28765
   214
wenzelm@28765
   215
text {*
wenzelm@28765
   216
  \begin{mldecls}
wenzelm@28765
   217
    @{index_ML Pretty.setdepth: "int -> unit"} \\
wenzelm@28765
   218
    @{index_ML Pretty.setmargin: "int -> unit"} \\
wenzelm@28765
   219
    @{index_ML print_depth: "int -> unit"} \\
wenzelm@28765
   220
  \end{mldecls}
wenzelm@28765
   221
wenzelm@28765
   222
  These ML functions set limits for pretty printed text.
wenzelm@28765
   223
wenzelm@28765
   224
  \begin{description}
wenzelm@28765
   225
wenzelm@28765
   226
  \item @{ML Pretty.setdepth}~@{text d} tells the pretty printer to
wenzelm@28765
   227
  limit the printing depth to @{text d}.  This affects the display of
wenzelm@28765
   228
  types, terms, theorems etc.  The default value is 0, which permits
wenzelm@28765
   229
  printing to an arbitrary depth.  Other useful values for @{text d}
wenzelm@28765
   230
  are 10 and 20.
wenzelm@28765
   231
wenzelm@28765
   232
  \item @{ML Pretty.setmargin}~@{text m} tells the pretty printer to
wenzelm@28765
   233
  assume a right margin (page width) of @{text m}.  The initial margin
wenzelm@28765
   234
  is 76, but user interfaces might adapt the margin automatically when
wenzelm@28765
   235
  resizing windows.
wenzelm@28765
   236
wenzelm@28765
   237
  \item @{ML print_depth}~@{text n} limits the printing depth of the
wenzelm@28765
   238
  ML toplevel pretty printer; the precise effect depends on the ML
wenzelm@28765
   239
  compiler and run-time system.  Typically @{text n} should be less
wenzelm@28765
   240
  than 10.  Bigger values such as 100--1000 are useful for debugging.
wenzelm@28763
   241
wenzelm@28763
   242
  \end{description}
wenzelm@28763
   243
*}
wenzelm@28763
   244
wenzelm@28763
   245
wenzelm@28762
   246
section {* Mixfix annotations *}
wenzelm@28762
   247
wenzelm@28762
   248
text {* Mixfix annotations specify concrete \emph{inner syntax} of
wenzelm@28767
   249
  Isabelle types and terms.  Some commands such as @{command
wenzelm@28767
   250
  "typedecl"} admit infixes only, while @{command "definition"} etc.\
wenzelm@28767
   251
  support the full range of general mixfixes and binders.  Fixed
wenzelm@28767
   252
  parameters in toplevel theorem statements, locale specifications
wenzelm@28767
   253
  also admit mixfix annotations.
wenzelm@28762
   254
wenzelm@28762
   255
  \indexouternonterm{infix}\indexouternonterm{mixfix}\indexouternonterm{structmixfix}
wenzelm@28762
   256
  \begin{rail}
wenzelm@28762
   257
    infix: '(' ('infix' | 'infixl' | 'infixr') string nat ')'
wenzelm@28762
   258
    ;
wenzelm@28762
   259
    mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')'
wenzelm@28762
   260
    ;
wenzelm@28762
   261
    structmixfix: mixfix | '(' 'structure' ')'
wenzelm@28762
   262
    ;
wenzelm@28762
   263
wenzelm@28762
   264
    prios: '[' (nat + ',') ']'
wenzelm@28762
   265
    ;
wenzelm@28762
   266
  \end{rail}
wenzelm@28762
   267
wenzelm@28762
   268
  Here the \railtok{string} specifications refer to the actual mixfix
wenzelm@28762
   269
  template, which may include literal text, spacing, blocks, and
wenzelm@28762
   270
  arguments (denoted by ``@{text _}''); the special symbol
wenzelm@28762
   271
  ``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') represents an index
wenzelm@28762
   272
  argument that specifies an implicit structure reference (see also
wenzelm@28762
   273
  \secref{sec:locale}).  Infix and binder declarations provide common
wenzelm@28762
   274
  abbreviations for particular mixfix declarations.  So in practice,
wenzelm@28762
   275
  mixfix templates mostly degenerate to literal text for concrete
wenzelm@28762
   276
  syntax, such as ``@{verbatim "++"}'' for an infix symbol.
wenzelm@28762
   277
wenzelm@28762
   278
  \medskip In full generality, mixfix declarations work as follows.
wenzelm@28762
   279
  Suppose a constant @{text "c :: \<tau>\<^sub>1 \<Rightarrow> \<dots> \<tau>\<^sub>n \<Rightarrow> \<tau>"} is
wenzelm@28762
   280
  annotated by @{text "(mixfix [p\<^sub>1, \<dots>, p\<^sub>n] p)"}, where @{text
wenzelm@28762
   281
  "mixfix"} is a string @{text "d\<^sub>0 _ d\<^sub>1 _ \<dots> _ d\<^sub>n"} consisting of
wenzelm@28762
   282
  delimiters that surround argument positions as indicated by
wenzelm@28762
   283
  underscores.
wenzelm@28762
   284
wenzelm@28762
   285
  Altogether this determines a production for a context-free priority
wenzelm@28762
   286
  grammar, where for each argument @{text "i"} the syntactic category
wenzelm@28762
   287
  is determined by @{text "\<tau>\<^sub>i"} (with priority @{text "p\<^sub>i"}), and
wenzelm@28762
   288
  the result category is determined from @{text "\<tau>"} (with
wenzelm@28762
   289
  priority @{text "p"}).  Priority specifications are optional, with
wenzelm@28762
   290
  default 0 for arguments and 1000 for the result.
wenzelm@28762
   291
wenzelm@28762
   292
  Since @{text "\<tau>"} may be again a function type, the constant
wenzelm@28762
   293
  type scheme may have more argument positions than the mixfix
wenzelm@28762
   294
  pattern.  Printing a nested application @{text "c t\<^sub>1 \<dots> t\<^sub>m"} for
wenzelm@28762
   295
  @{text "m > n"} works by attaching concrete notation only to the
wenzelm@28762
   296
  innermost part, essentially by printing @{text "(c t\<^sub>1 \<dots> t\<^sub>n) \<dots> t\<^sub>m"}
wenzelm@28762
   297
  instead.  If a term has fewer arguments than specified in the mixfix
wenzelm@28762
   298
  template, the concrete syntax is ignored.
wenzelm@28762
   299
wenzelm@28762
   300
  \medskip A mixfix template may also contain additional directives
wenzelm@28762
   301
  for pretty printing, notably spaces, blocks, and breaks.  The
wenzelm@28762
   302
  general template format is a sequence over any of the following
wenzelm@28762
   303
  entities.
wenzelm@28762
   304
wenzelm@28762
   305
  \begin{itemize}
wenzelm@28762
   306
wenzelm@28771
   307
  \item @{text "d"} is a delimiter, namely a non-empty sequence of
wenzelm@28771
   308
  characters other than the following special characters:
wenzelm@28762
   309
wenzelm@28771
   310
  \smallskip
wenzelm@28771
   311
  \begin{tabular}{ll}
wenzelm@28771
   312
    @{verbatim "'"} & single quote \\
wenzelm@28771
   313
    @{verbatim "_"} & underscore \\
wenzelm@28771
   314
    @{text "\<index>"} & index symbol \\
wenzelm@28771
   315
    @{verbatim "("} & open parenthesis \\
wenzelm@28771
   316
    @{verbatim ")"} & close parenthesis \\
wenzelm@28771
   317
    @{verbatim "/"} & slash \\
wenzelm@28771
   318
  \end{tabular}
wenzelm@28771
   319
  \medskip
wenzelm@28762
   320
wenzelm@28771
   321
  \item @{verbatim "'"} escapes the special meaning of these
wenzelm@28771
   322
  meta-characters, producing a literal version of the following
wenzelm@28771
   323
  character, unless that is a blank.
wenzelm@28771
   324
wenzelm@28771
   325
  A single quote followed by a blank separates delimiters, without
wenzelm@28771
   326
  affecting printing, but input tokens may have additional white space
wenzelm@28771
   327
  here.
wenzelm@28771
   328
wenzelm@28771
   329
  \item @{verbatim "_"} is an argument position, which stands for a
wenzelm@28762
   330
  certain syntactic category in the underlying grammar.
wenzelm@28762
   331
wenzelm@28771
   332
  \item @{text "\<index>"} is an indexed argument position; this is the place
wenzelm@28771
   333
  where implicit structure arguments can be attached.
wenzelm@28762
   334
wenzelm@28771
   335
  \item @{text "s"} is a non-empty sequence of spaces for printing.
wenzelm@28771
   336
  This and the following specifications do not affect parsing at all.
wenzelm@28762
   337
wenzelm@28771
   338
  \item @{verbatim "("}@{text n} opens a pretty printing block.  The
wenzelm@28762
   339
  optional number specifies how much indentation to add when a line
wenzelm@28762
   340
  break occurs within the block.  If the parenthesis is not followed
wenzelm@28762
   341
  by digits, the indentation defaults to 0.  A block specified via
wenzelm@28771
   342
  @{verbatim "(00"} is unbreakable.
wenzelm@28762
   343
wenzelm@28771
   344
  \item @{verbatim ")"} closes a pretty printing block.
wenzelm@28762
   345
wenzelm@28771
   346
  \item @{verbatim "//"} forces a line break.
wenzelm@28762
   347
wenzelm@28771
   348
  \item @{verbatim "/"}@{text s} allows a line break.  Here @{text s}
wenzelm@28771
   349
  stands for the string of spaces (zero or more) right after the
wenzelm@28771
   350
  slash.  These spaces are printed if the break is \emph{not} taken.
wenzelm@28762
   351
wenzelm@28762
   352
  \end{itemize}
wenzelm@28762
   353
wenzelm@28771
   354
  For example, the template @{verbatim "(_ +/ _)"} specifies an infix
wenzelm@28771
   355
  operator.  There are two argument positions; the delimiter
wenzelm@28771
   356
  @{verbatim "+"} is preceded by a space and followed by a space or
wenzelm@28771
   357
  line break; the entire phrase is a pretty printing block.
wenzelm@28762
   358
wenzelm@28762
   359
  The general idea of pretty printing with blocks and breaks is also
wenzelm@28762
   360
  described in \cite{paulson-ml2}.
wenzelm@28762
   361
*}
wenzelm@28762
   362
wenzelm@28762
   363
wenzelm@28766
   364
section {* Explicit term notation *}
wenzelm@28762
   365
wenzelm@28762
   366
text {*
wenzelm@28762
   367
  \begin{matharray}{rcll}
wenzelm@28762
   368
    @{command_def "notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
wenzelm@28762
   369
    @{command_def "no_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
wenzelm@28762
   370
  \end{matharray}
wenzelm@28762
   371
wenzelm@28762
   372
  \begin{rail}
wenzelm@28762
   373
    ('notation' | 'no\_notation') target? mode? (nameref structmixfix + 'and')
wenzelm@28762
   374
    ;
wenzelm@28762
   375
  \end{rail}
wenzelm@28762
   376
wenzelm@28762
   377
  \begin{description}
wenzelm@28762
   378
wenzelm@28762
   379
  \item @{command "notation"}~@{text "c (mx)"} associates mixfix
wenzelm@28762
   380
  syntax with an existing constant or fixed variable.  This is a
wenzelm@28762
   381
  robust interface to the underlying @{command "syntax"} primitive
wenzelm@28762
   382
  (\secref{sec:syn-trans}).  Type declaration and internal syntactic
wenzelm@28762
   383
  representation of the given entity is retrieved from the context.
wenzelm@28762
   384
  
wenzelm@28762
   385
  \item @{command "no_notation"} is similar to @{command "notation"},
wenzelm@28762
   386
  but removes the specified syntax annotation from the present
wenzelm@28762
   387
  context.
wenzelm@28762
   388
wenzelm@28762
   389
  \end{description}
wenzelm@28762
   390
*}
wenzelm@28762
   391
wenzelm@28769
   392
section {* The Pure syntax *}
wenzelm@28769
   393
wenzelm@28769
   394
subsection {* Priority grammars *}
wenzelm@28769
   395
wenzelm@28769
   396
text {* A context-free grammar consists of a set of \emph{terminal
wenzelm@28769
   397
  symbols}, a set of \emph{nonterminal symbols} and a set of
wenzelm@28769
   398
  \emph{productions}.  Productions have the form @{text "A = \<gamma>"},
wenzelm@28769
   399
  where @{text A} is a nonterminal and @{text \<gamma>} is a string of
wenzelm@28769
   400
  terminals and nonterminals.  One designated nonterminal is called
wenzelm@28769
   401
  the \emph{root symbol}.  The language defined by the grammar
wenzelm@28769
   402
  consists of all strings of terminals that can be derived from the
wenzelm@28769
   403
  root symbol by applying productions as rewrite rules.
wenzelm@28769
   404
wenzelm@28769
   405
  The standard Isabelle parser for inner syntax uses a \emph{priority
wenzelm@28769
   406
  grammar}.  Each nonterminal is decorated by an integer priority:
wenzelm@28769
   407
  @{text "A\<^sup>(\<^sup>p\<^sup>)"}.  In a derivation, @{text "A\<^sup>(\<^sup>p\<^sup>)"} may be rewritten
wenzelm@28769
   408
  using a production @{text "A\<^sup>(\<^sup>q\<^sup>) = \<gamma>"} only if @{text "p \<le> q"}.  Any
wenzelm@28769
   409
  priority grammar can be translated into a normal context-free
wenzelm@28769
   410
  grammar by introducing new nonterminals and productions.
wenzelm@28769
   411
wenzelm@28769
   412
  \medskip Formally, a set of context free productions @{text G}
wenzelm@28769
   413
  induces a derivation relation @{text "\<longrightarrow>\<^sub>G"} as follows.  Let @{text
wenzelm@28769
   414
  \<alpha>} and @{text \<beta>} denote strings of terminal or nonterminal symbols.
wenzelm@28769
   415
  Then
wenzelm@28769
   416
  \[
wenzelm@28769
   417
    @{text "\<alpha> A\<^sup>(\<^sup>p\<^sup>) \<beta> \<longrightarrow>\<^sub>G \<alpha> \<gamma> \<beta>"}
wenzelm@28769
   418
  \]
wenzelm@28769
   419
  if and only if @{text G} contains some production @{text "A\<^sup>(\<^sup>q\<^sup>) = \<gamma>"}
wenzelm@28769
   420
  for @{text "p \<le> q"}.
wenzelm@28769
   421
wenzelm@28769
   422
  \medskip The following grammar for arithmetic expressions
wenzelm@28769
   423
  demonstrates how binding power and associativity of operators can be
wenzelm@28769
   424
  enforced by priorities.
wenzelm@28769
   425
wenzelm@28769
   426
  \begin{center}
wenzelm@28769
   427
  \begin{tabular}{rclr}
wenzelm@28769
   428
  @{text "A\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} & @{text "="} & @{verbatim 0} \\
wenzelm@28769
   429
  @{text "A\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} & @{text "="} & @{verbatim "("} @{text "A\<^sup>(\<^sup>0\<^sup>)"} @{verbatim ")"} \\
wenzelm@28769
   430
  @{text "A\<^sup>(\<^sup>0\<^sup>)"} & @{text "="} & @{text "A\<^sup>(\<^sup>0\<^sup>)"} @{verbatim "+"} @{text "A\<^sup>(\<^sup>1\<^sup>)"} \\
wenzelm@28769
   431
  @{text "A\<^sup>(\<^sup>2\<^sup>)"} & @{text "="} & @{text "A\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "*"} @{text "A\<^sup>(\<^sup>2\<^sup>)"} \\
wenzelm@28769
   432
  @{text "A\<^sup>(\<^sup>3\<^sup>)"} & @{text "="} & @{verbatim "-"} @{text "A\<^sup>(\<^sup>3\<^sup>)"} \\
wenzelm@28769
   433
  \end{tabular}
wenzelm@28769
   434
  \end{center}
wenzelm@28769
   435
  The choice of priorities determines that @{verbatim "-"} binds
wenzelm@28769
   436
  tighter than @{verbatim "*"}, which binds tighter than @{verbatim
wenzelm@28769
   437
  "+"}.  Furthermore @{verbatim "+"} associates to the left and
wenzelm@28769
   438
  @{verbatim "*"} to the right.
wenzelm@28769
   439
wenzelm@28769
   440
  \medskip For clarity, grammars obey these conventions:
wenzelm@28769
   441
  \begin{itemize}
wenzelm@28769
   442
wenzelm@28769
   443
  \item All priorities must lie between 0 and 1000.
wenzelm@28769
   444
wenzelm@28769
   445
  \item Priority 0 on the right-hand side and priority 1000 on the
wenzelm@28769
   446
  left-hand side may be omitted.
wenzelm@28769
   447
wenzelm@28769
   448
  \item The production @{text "A\<^sup>(\<^sup>p\<^sup>) = \<alpha>"} is written as @{text "A = \<alpha>
wenzelm@28769
   449
  (p)"}, i.e.\ the priority of the left-hand side actually appears in
wenzelm@28769
   450
  a column on the far right.
wenzelm@28769
   451
wenzelm@28769
   452
  \item Alternatives are separated by @{text "|"}.
wenzelm@28769
   453
wenzelm@28769
   454
  \item Repetition is indicated by dots @{text "(\<dots>)"} in an informal
wenzelm@28769
   455
  but obvious way.
wenzelm@28769
   456
wenzelm@28769
   457
  \end{itemize}
wenzelm@28769
   458
wenzelm@28769
   459
  Using these conventions, the example grammar specification above
wenzelm@28769
   460
  takes the form:
wenzelm@28769
   461
  \begin{center}
wenzelm@28769
   462
  \begin{tabular}{rclc}
wenzelm@28769
   463
    @{text A} & @{text "="} & @{verbatim 0} & \qquad\qquad \\
wenzelm@28769
   464
              & @{text "|"} & @{verbatim "("} @{text A} @{verbatim ")"} \\
wenzelm@28769
   465
              & @{text "|"} & @{text A} @{verbatim "+"} @{text "A\<^sup>(\<^sup>1\<^sup>)"} & @{text "(0)"} \\
wenzelm@28769
   466
              & @{text "|"} & @{text "A\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "*"} @{text "A\<^sup>(\<^sup>2\<^sup>)"} & @{text "(2)"} \\
wenzelm@28769
   467
              & @{text "|"} & @{verbatim "-"} @{text "A\<^sup>(\<^sup>3\<^sup>)"} & @{text "(3)"} \\
wenzelm@28769
   468
  \end{tabular}
wenzelm@28769
   469
  \end{center}
wenzelm@28769
   470
*}
wenzelm@28769
   471
wenzelm@28769
   472
wenzelm@28770
   473
subsection {* The Pure grammar *}
wenzelm@28770
   474
wenzelm@28770
   475
text {*
wenzelm@28770
   476
  \begin{figure}[htb]\small
wenzelm@28770
   477
  \begin{center}
wenzelm@28770
   478
  \begin{tabular}{rclc}
wenzelm@28770
   479
wenzelm@28772
   480
  @{text any} & = & @{text "prop  |  logic"} \\\\
wenzelm@28770
   481
wenzelm@28772
   482
  @{text prop} & = & @{verbatim "("} @{text prop} @{verbatim ")"} \\
wenzelm@28772
   483
    & @{text "|"} & @{text "prop\<^sup>(\<^sup>4\<^sup>)"} @{verbatim "::"} @{text type} & @{text "(3)"} \\
wenzelm@28772
   484
    & @{text "|"} & @{verbatim PROP} @{text aprop} \\
wenzelm@28772
   485
    & @{text "|"} & @{text "any\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "=="} @{text "any\<^sup>(\<^sup>2\<^sup>)"} & @{text "(2)"} \\
wenzelm@28772
   486
    & @{text "|"} & @{text "any\<^sup>(\<^sup>3\<^sup>)"} @{verbatim "=?="} @{text "any\<^sup>(\<^sup>2\<^sup>)"} & @{text "(2)"} \\
wenzelm@28772
   487
    & @{text "|"} & @{text "prop\<^sup>(\<^sup>2\<^sup>)"} @{verbatim "==>"} @{text "prop\<^sup>(\<^sup>1\<^sup>)"} & @{text "(1)"} \\
wenzelm@28772
   488
    & @{text "|"} & @{verbatim "[|"} @{text prop} @{verbatim ";"} @{text "\<dots>"} @{verbatim ";"} @{text prop} @{verbatim "|]"} @{verbatim "==>"} @{text "prop\<^sup>(\<^sup>1\<^sup>)"} & @{text "(1)"} \\
wenzelm@28772
   489
    & @{text "|"} & @{verbatim "!!"} @{text idts} @{verbatim "."} @{text prop} & @{text "(0)"} \\
wenzelm@28772
   490
    & @{text "|"} & @{verbatim OFCLASS} @{verbatim "("} @{text type} @{verbatim ","} @{text logic} @{verbatim ")"} \\\\
wenzelm@28772
   491
wenzelm@28772
   492
  @{text aprop} & = & @{text "id  |  longid  |  var  |  logic\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)  "}@{verbatim "("} @{text any} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text any} @{verbatim ")"} \\\\
wenzelm@28772
   493
wenzelm@28772
   494
  @{text logic} & = & @{verbatim "("} @{text logic} @{verbatim ")"} \\
wenzelm@28772
   495
    & @{text "|"} & @{text "logic\<^sup>(\<^sup>4\<^sup>)"} @{verbatim "::"} @{text type} & @{text "(3)"} \\
wenzelm@28772
   496
    & @{text "|"} & @{text "id  |  longid  |  var  |  logic\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>)"} @{verbatim "("} @{text any} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text any} @{verbatim ")"} \\
wenzelm@28772
   497
    & @{text "|"} & @{verbatim "%"} @{text pttrns} @{verbatim "."} @{text "any\<^sup>(\<^sup>3\<^sup>)"} & @{text "(3)"} \\
wenzelm@28772
   498
    & @{text "|"} & @{verbatim TYPE} @{verbatim "("} @{text type} @{verbatim ")"} \\\\
wenzelm@28772
   499
wenzelm@28772
   500
  @{text idts} & = & @{text "idt  |  idt\<^sup>(\<^sup>1\<^sup>) idts"} \\\\
wenzelm@28772
   501
wenzelm@28772
   502
  @{text idt} & = & @{text "id  |  "}@{verbatim "("} @{text idt} @{verbatim ")"} \\
wenzelm@28772
   503
    & @{text "|"} & @{text id} @{verbatim "::"} @{text type} & @{text "(0)"} \\\\
wenzelm@28772
   504
wenzelm@28772
   505
  @{text pttrns} & = & @{text "pttrn  |  pttrn\<^sup>(\<^sup>1\<^sup>) pttrns"} \\\\
wenzelm@28772
   506
wenzelm@28772
   507
  @{text pttrn} & = & @{text idt} \\\\
wenzelm@28772
   508
wenzelm@28772
   509
  @{text type} & = & @{verbatim "("} @{text type} @{verbatim ")"} \\
wenzelm@28772
   510
    & @{text "|"} & @{text "tid  |  tvar  |  tid"} @{verbatim "::"} @{text "sort  |  tvar  "}@{verbatim "::"} @{text sort} \\
wenzelm@28772
   511
    & @{text "|"} & @{text "id  |  type\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>) id  |  "}@{verbatim "("} @{text type} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text type} @{verbatim ")"} @{text id} \\
wenzelm@28772
   512
    & @{text "|"} & @{text "longid  |  type\<^sup>(\<^sup>1\<^sup>0\<^sup>0\<^sup>0\<^sup>) longid  |  "}@{verbatim "("} @{text type} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text type} @{verbatim ")"} @{text longid} \\
wenzelm@28772
   513
    & @{text "|"} & @{text "type\<^sup>(\<^sup>1\<^sup>)"} @{verbatim "=>"} @{text type} & @{text "(0)"} \\
wenzelm@28772
   514
    & @{text "|"} & @{verbatim "["} @{text type} @{verbatim ","} @{text "\<dots>"} @{verbatim ","} @{text type} @{verbatim "]"} @{verbatim "=>"} @{text type} & @{text "(0)"} \\\\
wenzelm@28772
   515
wenzelm@28772
   516
  @{text sort} & = & @{text "id  |  longid  |  "}@{verbatim "{}"}@{text "  |  "}@{verbatim "{"} @{text "id | longid"}@{verbatim ","}@{text "\<dots>"}@{verbatim ","}@{text "id | longid"} @{verbatim "}"} \\
wenzelm@28770
   517
  \end{tabular}
wenzelm@28770
   518
  \end{center}
wenzelm@28770
   519
  \caption{The Pure grammar}\label{fig:pure-grammar}
wenzelm@28770
   520
  \end{figure}
wenzelm@28770
   521
wenzelm@28770
   522
  The priority grammar of the @{text "Pure"} theory is defined in
wenzelm@28770
   523
  \figref{fig:pure-grammar}.  The following nonterminals are
wenzelm@28770
   524
  introduced:
wenzelm@28770
   525
wenzelm@28770
   526
  \begin{description}
wenzelm@28770
   527
wenzelm@28770
   528
  \item @{text "any"} denotes any term.
wenzelm@28770
   529
wenzelm@28770
   530
  \item @{text "prop"} denotes meta-level propositions, which are
wenzelm@28770
   531
  terms of type @{typ prop}.  The syntax of such formulae of the
wenzelm@28770
   532
  meta-logic is carefully distinguished from usual conventions for
wenzelm@28770
   533
  object-logics.  In particular, plain @{text "\<lambda>"}-term
wenzelm@28770
   534
  notation is \emph{not} recognized as @{text "prop"}.
wenzelm@28770
   535
wenzelm@28770
   536
  \item @{text aprop} denotes atomic propositions, which are embedded
wenzelm@28770
   537
  into regular @{typ prop} by means of an explicit @{text "PROP"}
wenzelm@28770
   538
  token.
wenzelm@28770
   539
wenzelm@28770
   540
  Terms of type @{typ prop} with non-constant head, e.g.\ a plain
wenzelm@28770
   541
  variable, are printed in this form.  Constants that yield type @{typ
wenzelm@28770
   542
  prop} are expected to provide their own concrete syntax; otherwise
wenzelm@28770
   543
  the printed version will appear like @{typ logic} and cannot be
wenzelm@28770
   544
  parsed again as @{typ prop}.
wenzelm@28770
   545
wenzelm@28770
   546
  \item @{text logic} denotes arbitrary terms of a logical type,
wenzelm@28770
   547
  excluding type @{typ prop}.  This is the main syntactic category of
wenzelm@28770
   548
  object-logic entities, covering plain @{text \<lambda>}-term notation
wenzelm@28770
   549
  (variables, abstraction, application), plus anything defined by the
wenzelm@28770
   550
  user.
wenzelm@28770
   551
wenzelm@28770
   552
  When specifying notation for logical entities, all logical types
wenzelm@28770
   553
  (excluding @{typ prop}) are \emph{collapsed} to this single category
wenzelm@28770
   554
  of @{typ logic}.
wenzelm@28770
   555
wenzelm@28770
   556
  \item @{text idt} denotes identifiers, possibly constrained by
wenzelm@28770
   557
  types.
wenzelm@28770
   558
wenzelm@28770
   559
  \item @{text idts} denotes a sequence of @{text idt}.  This is the
wenzelm@28770
   560
  most basic category for variables in iterated binders, such as
wenzelm@28770
   561
  @{text "\<lambda>"} or @{text "\<And>"}.
wenzelm@28770
   562
wenzelm@28770
   563
  \item @{text pttrn} and @{text pttrns} denote patterns for
wenzelm@28770
   564
  abstraction, cases bindings etc.  In Pure, these categories start as
wenzelm@28770
   565
  a merely copy of @{text idt} and @{text idts}, respectively.
wenzelm@28770
   566
  Object-logics may add additional productions for binding forms.
wenzelm@28770
   567
wenzelm@28770
   568
  \item @{text type} denotes types of the meta-logic.
wenzelm@28770
   569
wenzelm@28770
   570
  \item @{text sort} denotes meta-level sorts.
wenzelm@28770
   571
wenzelm@28770
   572
  \end{description}
wenzelm@28770
   573
wenzelm@28770
   574
  \begin{warn}
wenzelm@28770
   575
  In @{text idts}, note that @{text "x :: nat y"} is parsed as @{text
wenzelm@28770
   576
  "x :: (nat y)"}, treating @{text y} like a type constructor applied
wenzelm@28770
   577
  to @{text nat}.  To avoid this interpretation, write @{text "(x ::
wenzelm@28770
   578
  nat) y"} with explicit parentheses.
wenzelm@28770
   579
wenzelm@28770
   580
  Similarly, @{text "x :: nat y :: nat"} is parsed as @{text "x ::
wenzelm@28770
   581
  (nat y :: nat)"}.  The correct form is @{text "(x :: nat) (y ::
wenzelm@28770
   582
  nat)"}, or @{text "(x :: nat) y :: nat"} if @{text y} is last in the
wenzelm@28770
   583
  sequence of identifiers.
wenzelm@28770
   584
  \end{warn}
wenzelm@28770
   585
wenzelm@28770
   586
  \begin{warn}
wenzelm@28770
   587
  Type constraints for terms bind very weakly.  For example, @{text "x
wenzelm@28770
   588
  < y :: nat"} is normally parsed as @{text "(x < y) :: nat"}, unless
wenzelm@28770
   589
  @{text "<"} has a very low priority, in which case the input is
wenzelm@28770
   590
  likely to be ambiguous.  The correct form is @{text "x < (y :: nat)"}.
wenzelm@28770
   591
  \end{warn}
wenzelm@28770
   592
*}
wenzelm@28770
   593
wenzelm@28770
   594
wenzelm@28762
   595
section {* Syntax and translations \label{sec:syn-trans} *}
wenzelm@28762
   596
wenzelm@28762
   597
text {*
wenzelm@28762
   598
  \begin{matharray}{rcl}
wenzelm@28762
   599
    @{command_def "nonterminals"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   600
    @{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   601
    @{command_def "no_syntax"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   602
    @{command_def "translations"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   603
    @{command_def "no_translations"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   604
  \end{matharray}
wenzelm@28762
   605
wenzelm@28762
   606
  \begin{rail}
wenzelm@28762
   607
    'nonterminals' (name +)
wenzelm@28762
   608
    ;
wenzelm@28762
   609
    ('syntax' | 'no\_syntax') mode? (constdecl +)
wenzelm@28762
   610
    ;
wenzelm@28762
   611
    ('translations' | 'no\_translations') (transpat ('==' | '=>' | '<=' | rightleftharpoons | rightharpoonup | leftharpoondown) transpat +)
wenzelm@28762
   612
    ;
wenzelm@28762
   613
wenzelm@28762
   614
    mode: ('(' ( name | 'output' | name 'output' ) ')')
wenzelm@28762
   615
    ;
wenzelm@28762
   616
    transpat: ('(' nameref ')')? string
wenzelm@28762
   617
    ;
wenzelm@28762
   618
  \end{rail}
wenzelm@28762
   619
wenzelm@28762
   620
  \begin{description}
wenzelm@28762
   621
  
wenzelm@28762
   622
  \item @{command "nonterminals"}~@{text c} declares a type
wenzelm@28762
   623
  constructor @{text c} (without arguments) to act as purely syntactic
wenzelm@28762
   624
  type: a nonterminal symbol of the inner syntax.
wenzelm@28762
   625
wenzelm@28762
   626
  \item @{command "syntax"}~@{text "(mode) decls"} is similar to
wenzelm@28762
   627
  @{command "consts"}~@{text decls}, except that the actual logical
wenzelm@28762
   628
  signature extension is omitted.  Thus the context free grammar of
wenzelm@28762
   629
  Isabelle's inner syntax may be augmented in arbitrary ways,
wenzelm@28762
   630
  independently of the logic.  The @{text mode} argument refers to the
wenzelm@28762
   631
  print mode that the grammar rules belong; unless the @{keyword_ref
wenzelm@28762
   632
  "output"} indicator is given, all productions are added both to the
wenzelm@28762
   633
  input and output grammar.
wenzelm@28762
   634
  
wenzelm@28762
   635
  \item @{command "no_syntax"}~@{text "(mode) decls"} removes grammar
wenzelm@28762
   636
  declarations (and translations) resulting from @{text decls}, which
wenzelm@28762
   637
  are interpreted in the same manner as for @{command "syntax"} above.
wenzelm@28762
   638
  
wenzelm@28762
   639
  \item @{command "translations"}~@{text rules} specifies syntactic
wenzelm@28762
   640
  translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}),
wenzelm@28762
   641
  parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}).
wenzelm@28762
   642
  Translation patterns may be prefixed by the syntactic category to be
wenzelm@28762
   643
  used for parsing; the default is @{text logic}.
wenzelm@28762
   644
  
wenzelm@28762
   645
  \item @{command "no_translations"}~@{text rules} removes syntactic
wenzelm@28762
   646
  translation rules, which are interpreted in the same manner as for
wenzelm@28762
   647
  @{command "translations"} above.
wenzelm@28762
   648
wenzelm@28762
   649
  \end{description}
wenzelm@28762
   650
*}
wenzelm@28762
   651
wenzelm@28762
   652
wenzelm@28762
   653
section {* Syntax translation functions *}
wenzelm@28762
   654
wenzelm@28762
   655
text {*
wenzelm@28762
   656
  \begin{matharray}{rcl}
wenzelm@28762
   657
    @{command_def "parse_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   658
    @{command_def "parse_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   659
    @{command_def "print_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   660
    @{command_def "typed_print_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   661
    @{command_def "print_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   662
  \end{matharray}
wenzelm@28762
   663
wenzelm@28762
   664
  \begin{rail}
wenzelm@28762
   665
  ( 'parse\_ast\_translation' | 'parse\_translation' | 'print\_translation' |
wenzelm@28762
   666
    'typed\_print\_translation' | 'print\_ast\_translation' ) ('(advanced)')? text
wenzelm@28762
   667
  ;
wenzelm@28762
   668
  \end{rail}
wenzelm@28762
   669
wenzelm@28762
   670
  Syntax translation functions written in ML admit almost arbitrary
wenzelm@28762
   671
  manipulations of Isabelle's inner syntax.  Any of the above commands
wenzelm@28762
   672
  have a single \railqtok{text} argument that refers to an ML
wenzelm@28762
   673
  expression of appropriate type, which are as follows by default:
wenzelm@28762
   674
wenzelm@28762
   675
%FIXME proper antiquotations
wenzelm@28762
   676
\begin{ttbox}
wenzelm@28762
   677
val parse_ast_translation   : (string * (ast list -> ast)) list
wenzelm@28762
   678
val parse_translation       : (string * (term list -> term)) list
wenzelm@28762
   679
val print_translation       : (string * (term list -> term)) list
wenzelm@28762
   680
val typed_print_translation :
wenzelm@28762
   681
  (string * (bool -> typ -> term list -> term)) list
wenzelm@28762
   682
val print_ast_translation   : (string * (ast list -> ast)) list
wenzelm@28762
   683
\end{ttbox}
wenzelm@28762
   684
wenzelm@28762
   685
  If the @{text "(advanced)"} option is given, the corresponding
wenzelm@28762
   686
  translation functions may depend on the current theory or proof
wenzelm@28762
   687
  context.  This allows to implement advanced syntax mechanisms, as
wenzelm@28762
   688
  translations functions may refer to specific theory declarations or
wenzelm@28762
   689
  auxiliary proof data.
wenzelm@28762
   690
wenzelm@28762
   691
  See also \cite[\S8]{isabelle-ref} for more information on the
wenzelm@28762
   692
  general concept of syntax transformations in Isabelle.
wenzelm@28762
   693
wenzelm@28762
   694
%FIXME proper antiquotations
wenzelm@28762
   695
\begin{ttbox}
wenzelm@28762
   696
val parse_ast_translation:
wenzelm@28762
   697
  (string * (Proof.context -> ast list -> ast)) list
wenzelm@28762
   698
val parse_translation:
wenzelm@28762
   699
  (string * (Proof.context -> term list -> term)) list
wenzelm@28762
   700
val print_translation:
wenzelm@28762
   701
  (string * (Proof.context -> term list -> term)) list
wenzelm@28762
   702
val typed_print_translation:
wenzelm@28762
   703
  (string * (Proof.context -> bool -> typ -> term list -> term)) list
wenzelm@28762
   704
val print_ast_translation:
wenzelm@28762
   705
  (string * (Proof.context -> ast list -> ast)) list
wenzelm@28762
   706
\end{ttbox}
wenzelm@28762
   707
*}
wenzelm@28762
   708
wenzelm@28762
   709
end