doc-src/IsarRef/Thy/Inner_Syntax.thy
author wenzelm
Thu, 13 Nov 2008 21:49:46 +0100
changeset 28763 b5e6122ff575
parent 28762 f5d79aeffd81
child 28765 da8f6f4a74be
permissions -rw-r--r--
added pretty printing options (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@28762
    15
    @{command_def "pr"}@{text "\<^sup>*"} & : & @{text "any \<rightarrow>"} \\
wenzelm@28762
    16
    @{command_def "thm"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    17
    @{command_def "term"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    18
    @{command_def "prop"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    19
    @{command_def "typ"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    20
    @{command_def "prf"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\
wenzelm@28762
    21
    @{command_def "full_prf"}@{text "\<^sup>*"} & : & @{text "context \<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@28762
    28
    'pr' modes? nat? (',' nat)?
wenzelm@28762
    29
    ;
wenzelm@28762
    30
    'thm' modes? thmrefs
wenzelm@28762
    31
    ;
wenzelm@28762
    32
    'term' modes? term
wenzelm@28762
    33
    ;
wenzelm@28762
    34
    'prop' modes? prop
wenzelm@28762
    35
    ;
wenzelm@28762
    36
    'typ' modes? type
wenzelm@28762
    37
    ;
wenzelm@28762
    38
    'prf' modes? thmrefs?
wenzelm@28762
    39
    ;
wenzelm@28762
    40
    'full\_prf' modes? thmrefs?
wenzelm@28762
    41
    ;
wenzelm@28762
    42
wenzelm@28762
    43
    modes: '(' (name + ) ')'
wenzelm@28762
    44
    ;
wenzelm@28762
    45
  \end{rail}
wenzelm@28762
    46
wenzelm@28762
    47
  \begin{description}
wenzelm@28762
    48
wenzelm@28762
    49
  \item @{command "pr"}~@{text "goals, prems"} prints the current
wenzelm@28762
    50
  proof state (if present), including the proof context, current facts
wenzelm@28762
    51
  and goals.  The optional limit arguments affect the number of goals
wenzelm@28762
    52
  and premises to be displayed, which is initially 10 for both.
wenzelm@28762
    53
  Omitting limit values leaves the current setting unchanged.
wenzelm@28762
    54
wenzelm@28762
    55
  \item @{command "thm"}~@{text "a\<^sub>1 \<dots> a\<^sub>n"} retrieves
wenzelm@28762
    56
  theorems from the current theory or proof context.  Note that any
wenzelm@28762
    57
  attributes included in the theorem specifications are applied to a
wenzelm@28762
    58
  temporary context derived from the current theory or proof; the
wenzelm@28762
    59
  result is discarded, i.e.\ attributes involved in @{text "a\<^sub>1,
wenzelm@28762
    60
  \<dots>, a\<^sub>n"} do not have any permanent effect.
wenzelm@28762
    61
wenzelm@28762
    62
  \item @{command "term"}~@{text t} and @{command "prop"}~@{text \<phi>}
wenzelm@28762
    63
  read, type-check and print terms or propositions according to the
wenzelm@28762
    64
  current theory or proof context; the inferred type of @{text t} is
wenzelm@28762
    65
  output as well.  Note that these commands are also useful in
wenzelm@28762
    66
  inspecting the current environment of term abbreviations.
wenzelm@28762
    67
wenzelm@28762
    68
  \item @{command "typ"}~@{text \<tau>} reads and prints types of the
wenzelm@28762
    69
  meta-logic according to the current theory or proof context.
wenzelm@28762
    70
wenzelm@28762
    71
  \item @{command "prf"} displays the (compact) proof term of the
wenzelm@28762
    72
  current proof state (if present), or of the given theorems. Note
wenzelm@28762
    73
  that this requires proof terms to be switched on for the current
wenzelm@28762
    74
  object logic (see the ``Proof terms'' section of the Isabelle
wenzelm@28762
    75
  reference manual for information on how to do this).
wenzelm@28762
    76
wenzelm@28762
    77
  \item @{command "full_prf"} is like @{command "prf"}, but displays
wenzelm@28762
    78
  the full proof term, i.e.\ also displays information omitted in the
wenzelm@28762
    79
  compact proof term, which is denoted by ``@{text _}'' placeholders
wenzelm@28762
    80
  there.
wenzelm@28762
    81
wenzelm@28762
    82
  \end{description}
wenzelm@28762
    83
wenzelm@28762
    84
  All of the diagnostic commands above admit a list of @{text modes}
wenzelm@28762
    85
  to be specified, which is appended to the current print mode (see
wenzelm@28762
    86
  also \cite{isabelle-ref}).  Thus the output behavior may be modified
wenzelm@28762
    87
  according particular print mode features.  For example, @{command
wenzelm@28762
    88
  "pr"}~@{text "(latex xsymbols)"} would print the current proof state
wenzelm@28762
    89
  with mathematical symbols and special characters represented in
wenzelm@28762
    90
  {\LaTeX} source, according to the Isabelle style
wenzelm@28762
    91
  \cite{isabelle-sys}.
wenzelm@28762
    92
wenzelm@28762
    93
  Note that antiquotations (cf.\ \secref{sec:antiq}) provide a more
wenzelm@28762
    94
  systematic way to include formal items into the printed text
wenzelm@28762
    95
  document.
wenzelm@28762
    96
*}
wenzelm@28762
    97
wenzelm@28762
    98
wenzelm@28763
    99
subsection {* Printing limits *}
wenzelm@28763
   100
wenzelm@28763
   101
text {*
wenzelm@28763
   102
  \begin{mldecls}
wenzelm@28763
   103
    @{index_ML Pretty.setdepth: "int -> unit"} \\
wenzelm@28763
   104
    @{index_ML Pretty.setmargin: "int -> unit"} \\
wenzelm@28763
   105
    @{index_ML print_depth: "int -> unit"} \\
wenzelm@28763
   106
  \end{mldecls}
wenzelm@28763
   107
wenzelm@28763
   108
  These ML functions set limits for pretty printed text output.
wenzelm@28763
   109
wenzelm@28763
   110
  \begin{description}
wenzelm@28763
   111
wenzelm@28763
   112
  \item @{ML Pretty.setdepth}~@{text d} tells the pretty printer to
wenzelm@28763
   113
  limit the printing depth to @{text d}.  This affects the display of
wenzelm@28763
   114
  types, terms, theorems etc.  The default value is 0, which permits
wenzelm@28763
   115
  printing to an arbitrary depth.  Useful values for @{text d} are 10
wenzelm@28763
   116
  and 20.
wenzelm@28763
   117
wenzelm@28763
   118
  \item @{ML Pretty.setmargin}~@{text m} tells the pretty printer to
wenzelm@28763
   119
  assume a right margin (page width) of @{text m}.  The initial margin
wenzelm@28763
   120
  is 76.  User interfaces may adapt this default automatically, when
wenzelm@28763
   121
  resizing windows etc.
wenzelm@28763
   122
wenzelm@28763
   123
  \item @{ML print_depth}~@{text n} limits the printing depth of the
wenzelm@28763
   124
  ML toplevel pretty printer; the precise effect depends on the ML
wenzelm@28763
   125
  compiler and run-time system.  Typically @{text n} should be less
wenzelm@28763
   126
  than 10.  Bigger values such as 100--1000 are useful for debugging.
wenzelm@28763
   127
wenzelm@28763
   128
  \end{description}
wenzelm@28763
   129
*}
wenzelm@28763
   130
wenzelm@28763
   131
wenzelm@28763
   132
subsection {* Details of printed content *}
wenzelm@28763
   133
wenzelm@28763
   134
text {*
wenzelm@28763
   135
  \begin{mldecls} 
wenzelm@28763
   136
    @{index_ML show_types: "bool ref"} & default @{ML false} \\
wenzelm@28763
   137
    @{index_ML show_sorts: "bool ref"} & default @{ML false} \\
wenzelm@28763
   138
    @{index_ML show_consts: "bool ref"} & default @{ML false} \\
wenzelm@28763
   139
    @{index_ML long_names: "bool ref"} & default @{ML false} \\
wenzelm@28763
   140
    @{index_ML short_names: "bool ref"} & default @{ML false} \\
wenzelm@28763
   141
    @{index_ML unique_names: "bool ref"} & default @{ML true} \\
wenzelm@28763
   142
    @{index_ML show_brackets: "bool ref"} & default @{ML false} \\
wenzelm@28763
   143
    @{index_ML eta_contract: "bool ref"} \\
wenzelm@28763
   144
    @{index_ML goals_limit: "int ref"} & default @{ML 10} \\
wenzelm@28763
   145
    @{index_ML Proof.show_main_goal: "bool ref"} & default @{ML false} \\
wenzelm@28763
   146
    @{index_ML show_hyps: "bool ref"} & default @{ML false} \\
wenzelm@28763
   147
    @{index_ML show_tags: "bool ref"} & default @{ML false} \\
wenzelm@28763
   148
  \end{mldecls}
wenzelm@28763
   149
wenzelm@28763
   150
  These global ML variables control the detail of information that is
wenzelm@28763
   151
  displayed for types, terms, theorems, goals etc.
wenzelm@28763
   152
wenzelm@28763
   153
  \begin{description}
wenzelm@28763
   154
wenzelm@28763
   155
  \item @{ML show_types} and @{ML show_sorts} control printing of type
wenzelm@28763
   156
  constraints for term variables, and sort constraints for type
wenzelm@28763
   157
  variables.  By default, neither of these are shown in output.  If
wenzelm@28763
   158
  @{ML show_sorts} is set to @{ML true}, types are always shown as
wenzelm@28763
   159
  well.
wenzelm@28763
   160
wenzelm@28763
   161
  Note that displaying types and sorts may explain why a polymorphic
wenzelm@28763
   162
  inference rule fails to resolve with some goal, or why a rewrite
wenzelm@28763
   163
  rule does not apply as expected.
wenzelm@28763
   164
wenzelm@28763
   165
  \item @{ML show_consts} controls printing of types of constants when
wenzelm@28763
   166
  printing proof states.  Note that the output can be enormous as
wenzelm@28763
   167
  polymorphic constants often occur at several different type
wenzelm@28763
   168
  instances.
wenzelm@28763
   169
wenzelm@28763
   170
  \item @{ML long_names}, @{ML short_names}, and @{ML unique_names}
wenzelm@28763
   171
  modify the way of printing qualified names in external form.  See
wenzelm@28763
   172
  also the description of document antiquotation options in
wenzelm@28763
   173
  \secref{sec:antiq}.
wenzelm@28763
   174
wenzelm@28763
   175
  \item @{ML show_brackets} controls insertion of bracketing in pretty
wenzelm@28763
   176
  printed output.  If set to @{ML true}, all sub-expressions of the
wenzelm@28763
   177
  pretty printing tree will be parenthesized, even if this produces
wenzelm@28763
   178
  malformed term syntax!  This crude way of showing the full structure
wenzelm@28763
   179
  of pretty printed entities might help to diagnose problems with
wenzelm@28763
   180
  operator priorities, for example.
wenzelm@28763
   181
wenzelm@28763
   182
  \item @{ML eta_contract} controls @{text "\<eta>"}-contracted printing of
wenzelm@28763
   183
  terms.
wenzelm@28763
   184
wenzelm@28763
   185
  The @{text \<eta>}-contraction law asserts @{prop "(\<lambda>x. f x) \<equiv> f"},
wenzelm@28763
   186
  provided @{text x} is not free in @{text f}.  It asserts
wenzelm@28763
   187
  \emph{extensionality} of functions: @{prop "f \<equiv> g"} if @{prop "f x \<equiv>
wenzelm@28763
   188
  g x"} for all @{text x}.  Higher-order unification frequently puts
wenzelm@28763
   189
  terms into a fully @{text \<eta>}-expanded form.  For example, if @{text
wenzelm@28763
   190
  F} has type @{text "(\<tau> \<Rightarrow> \<tau>) \<Rightarrow> \<tau>"} then its expanded form is @{term
wenzelm@28763
   191
  "\<lambda>h. F (\<lambda>x. h x)"}.
wenzelm@28763
   192
wenzelm@28763
   193
  Setting @{ML eta_contract} makes Isabelle perform @{text
wenzelm@28763
   194
  \<eta>}-contractions before printing, so that @{term "\<lambda>h. F (\<lambda>x. h x)"}
wenzelm@28763
   195
  appears simply as @{text F}.
wenzelm@28763
   196
wenzelm@28763
   197
  Note that the distinction between a term and its @{text \<eta>}-expanded
wenzelm@28763
   198
  form occasionally matters.
wenzelm@28763
   199
wenzelm@28763
   200
wenzelm@28763
   201
  \item @{ML goals_limit} controls the maximum number of subgoals to
wenzelm@28763
   202
  be shown in proof state output.
wenzelm@28763
   203
wenzelm@28763
   204
  \item @{ML Proof.show_main_goal} controls whether the main result to
wenzelm@28763
   205
  be proven should be displayed.  This information might be relevant
wenzelm@28763
   206
  for schematic goals, to see the current claim being synthesized.
wenzelm@28763
   207
wenzelm@28763
   208
  \item @{ML show_hyps} controls printing of implicit hypotheses of
wenzelm@28763
   209
  local facts.  Normally, only those hypotheses are displayed that are
wenzelm@28763
   210
  \emph{not} covered by the assumptions of the current context: this
wenzelm@28763
   211
  situation indicates a fault in some tool being used.
wenzelm@28763
   212
wenzelm@28763
   213
  By setting @{ML show_hyps} to @{ML true}, output of all hypotheses
wenzelm@28763
   214
  can be enforced.  Which is occasionally usefule for diagnostic
wenzelm@28763
   215
  purposes.
wenzelm@28763
   216
wenzelm@28763
   217
  \item @{ML show_tags} controls printing of extra annotations within
wenzelm@28763
   218
  theorems, such as the case names being attached by the attribute
wenzelm@28763
   219
  @{attribute case_names}.
wenzelm@28763
   220
wenzelm@28763
   221
  \end{description}
wenzelm@28763
   222
*}
wenzelm@28763
   223
wenzelm@28763
   224
wenzelm@28762
   225
section {* Mixfix annotations *}
wenzelm@28762
   226
wenzelm@28762
   227
text {* Mixfix annotations specify concrete \emph{inner syntax} of
wenzelm@28762
   228
  Isabelle types and terms.  Some commands such as @{command "types"}
wenzelm@28762
   229
  (see \secref{sec:types-pure}) admit infixes only, while @{command
wenzelm@28762
   230
  "consts"} (see \secref{sec:consts}) and @{command "syntax"} (see
wenzelm@28762
   231
  \secref{sec:syn-trans}) support the full range of general mixfixes
wenzelm@28762
   232
  and binders.
wenzelm@28762
   233
wenzelm@28762
   234
  \indexouternonterm{infix}\indexouternonterm{mixfix}\indexouternonterm{structmixfix}
wenzelm@28762
   235
  \begin{rail}
wenzelm@28762
   236
    infix: '(' ('infix' | 'infixl' | 'infixr') string nat ')'
wenzelm@28762
   237
    ;
wenzelm@28762
   238
    mixfix: infix | '(' string prios? nat? ')' | '(' 'binder' string prios? nat ')'
wenzelm@28762
   239
    ;
wenzelm@28762
   240
    structmixfix: mixfix | '(' 'structure' ')'
wenzelm@28762
   241
    ;
wenzelm@28762
   242
wenzelm@28762
   243
    prios: '[' (nat + ',') ']'
wenzelm@28762
   244
    ;
wenzelm@28762
   245
  \end{rail}
wenzelm@28762
   246
wenzelm@28762
   247
  Here the \railtok{string} specifications refer to the actual mixfix
wenzelm@28762
   248
  template, which may include literal text, spacing, blocks, and
wenzelm@28762
   249
  arguments (denoted by ``@{text _}''); the special symbol
wenzelm@28762
   250
  ``@{verbatim "\<index>"}'' (printed as ``@{text "\<index>"}'') represents an index
wenzelm@28762
   251
  argument that specifies an implicit structure reference (see also
wenzelm@28762
   252
  \secref{sec:locale}).  Infix and binder declarations provide common
wenzelm@28762
   253
  abbreviations for particular mixfix declarations.  So in practice,
wenzelm@28762
   254
  mixfix templates mostly degenerate to literal text for concrete
wenzelm@28762
   255
  syntax, such as ``@{verbatim "++"}'' for an infix symbol.
wenzelm@28762
   256
wenzelm@28762
   257
  \medskip In full generality, mixfix declarations work as follows.
wenzelm@28762
   258
  Suppose a constant @{text "c :: \<tau>\<^sub>1 \<Rightarrow> \<dots> \<tau>\<^sub>n \<Rightarrow> \<tau>"} is
wenzelm@28762
   259
  annotated by @{text "(mixfix [p\<^sub>1, \<dots>, p\<^sub>n] p)"}, where @{text
wenzelm@28762
   260
  "mixfix"} is a string @{text "d\<^sub>0 _ d\<^sub>1 _ \<dots> _ d\<^sub>n"} consisting of
wenzelm@28762
   261
  delimiters that surround argument positions as indicated by
wenzelm@28762
   262
  underscores.
wenzelm@28762
   263
wenzelm@28762
   264
  Altogether this determines a production for a context-free priority
wenzelm@28762
   265
  grammar, where for each argument @{text "i"} the syntactic category
wenzelm@28762
   266
  is determined by @{text "\<tau>\<^sub>i"} (with priority @{text "p\<^sub>i"}), and
wenzelm@28762
   267
  the result category is determined from @{text "\<tau>"} (with
wenzelm@28762
   268
  priority @{text "p"}).  Priority specifications are optional, with
wenzelm@28762
   269
  default 0 for arguments and 1000 for the result.
wenzelm@28762
   270
wenzelm@28762
   271
  Since @{text "\<tau>"} may be again a function type, the constant
wenzelm@28762
   272
  type scheme may have more argument positions than the mixfix
wenzelm@28762
   273
  pattern.  Printing a nested application @{text "c t\<^sub>1 \<dots> t\<^sub>m"} for
wenzelm@28762
   274
  @{text "m > n"} works by attaching concrete notation only to the
wenzelm@28762
   275
  innermost part, essentially by printing @{text "(c t\<^sub>1 \<dots> t\<^sub>n) \<dots> t\<^sub>m"}
wenzelm@28762
   276
  instead.  If a term has fewer arguments than specified in the mixfix
wenzelm@28762
   277
  template, the concrete syntax is ignored.
wenzelm@28762
   278
wenzelm@28762
   279
  \medskip A mixfix template may also contain additional directives
wenzelm@28762
   280
  for pretty printing, notably spaces, blocks, and breaks.  The
wenzelm@28762
   281
  general template format is a sequence over any of the following
wenzelm@28762
   282
  entities.
wenzelm@28762
   283
wenzelm@28762
   284
  \begin{itemize}
wenzelm@28762
   285
wenzelm@28762
   286
  \item @{text "\<^bold>d"} is a delimiter, namely a non-empty
wenzelm@28762
   287
  sequence of characters other than the special characters @{text "'"}
wenzelm@28762
   288
  (single quote), @{text "_"} (underscore), @{text "\<index>"} (index
wenzelm@28762
   289
  symbol), @{text "/"} (slash), @{text "("} and @{text ")"}
wenzelm@28762
   290
  (parentheses).
wenzelm@28762
   291
wenzelm@28762
   292
  A single quote escapes the special meaning of these meta-characters,
wenzelm@28762
   293
  producing a literal version of the following character, unless that
wenzelm@28762
   294
  is a blank.  A single quote followed by a blank separates
wenzelm@28762
   295
  delimiters, without affecting printing, but input tokens may have
wenzelm@28762
   296
  additional white space here.
wenzelm@28762
   297
wenzelm@28762
   298
  \item @{text "_"} is an argument position, which stands for a
wenzelm@28762
   299
  certain syntactic category in the underlying grammar.
wenzelm@28762
   300
wenzelm@28762
   301
  \item @{text "\<index>"} is an indexed argument position; this is
wenzelm@28762
   302
  the place where implicit structure arguments can be attached.
wenzelm@28762
   303
wenzelm@28762
   304
  \item @{text "\<^bold>s"} is a non-empty sequence of spaces for
wenzelm@28762
   305
  printing.  This and the following specifications do not affect
wenzelm@28762
   306
  parsing at all.
wenzelm@28762
   307
wenzelm@28762
   308
  \item @{text "(\<^bold>n"} opens a pretty printing block.  The
wenzelm@28762
   309
  optional number specifies how much indentation to add when a line
wenzelm@28762
   310
  break occurs within the block.  If the parenthesis is not followed
wenzelm@28762
   311
  by digits, the indentation defaults to 0.  A block specified via
wenzelm@28762
   312
  @{text "(00"} is unbreakable.
wenzelm@28762
   313
wenzelm@28762
   314
  \item @{text ")"} closes a pretty printing block.
wenzelm@28762
   315
wenzelm@28762
   316
  \item @{text "//"} forces a line break.
wenzelm@28762
   317
wenzelm@28762
   318
  \item @{text "/\<^bold>s"} allows a line break.  Here @{text
wenzelm@28762
   319
  "\<^bold>s"} stands for the string of spaces (zero or more) right
wenzelm@28762
   320
  after the slash.  These spaces are printed if the break is
wenzelm@28762
   321
  \emph{not} taken.
wenzelm@28762
   322
wenzelm@28762
   323
  \end{itemize}
wenzelm@28762
   324
wenzelm@28762
   325
  For example, the template @{text "(_ +/ _)"} specifies an infix
wenzelm@28762
   326
  operator.  There are two argument positions; the delimiter @{text
wenzelm@28762
   327
  "+"} is preceded by a space and followed by a space or line break;
wenzelm@28762
   328
  the entire phrase is a pretty printing block.
wenzelm@28762
   329
wenzelm@28762
   330
  The general idea of pretty printing with blocks and breaks is also
wenzelm@28762
   331
  described in \cite{paulson-ml2}.
wenzelm@28762
   332
*}
wenzelm@28762
   333
wenzelm@28762
   334
wenzelm@28762
   335
section {* Additional term notation *}
wenzelm@28762
   336
wenzelm@28762
   337
text {*
wenzelm@28762
   338
  \begin{matharray}{rcll}
wenzelm@28762
   339
    @{command_def "notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
wenzelm@28762
   340
    @{command_def "no_notation"} & : & @{text "local_theory \<rightarrow> local_theory"} \\
wenzelm@28762
   341
  \end{matharray}
wenzelm@28762
   342
wenzelm@28762
   343
  \begin{rail}
wenzelm@28762
   344
    ('notation' | 'no\_notation') target? mode? (nameref structmixfix + 'and')
wenzelm@28762
   345
    ;
wenzelm@28762
   346
  \end{rail}
wenzelm@28762
   347
wenzelm@28762
   348
  \begin{description}
wenzelm@28762
   349
wenzelm@28762
   350
  \item @{command "notation"}~@{text "c (mx)"} associates mixfix
wenzelm@28762
   351
  syntax with an existing constant or fixed variable.  This is a
wenzelm@28762
   352
  robust interface to the underlying @{command "syntax"} primitive
wenzelm@28762
   353
  (\secref{sec:syn-trans}).  Type declaration and internal syntactic
wenzelm@28762
   354
  representation of the given entity is retrieved from the context.
wenzelm@28762
   355
  
wenzelm@28762
   356
  \item @{command "no_notation"} is similar to @{command "notation"},
wenzelm@28762
   357
  but removes the specified syntax annotation from the present
wenzelm@28762
   358
  context.
wenzelm@28762
   359
wenzelm@28762
   360
  \end{description}
wenzelm@28762
   361
*}
wenzelm@28762
   362
wenzelm@28762
   363
section {* Syntax and translations \label{sec:syn-trans} *}
wenzelm@28762
   364
wenzelm@28762
   365
text {*
wenzelm@28762
   366
  \begin{matharray}{rcl}
wenzelm@28762
   367
    @{command_def "nonterminals"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   368
    @{command_def "syntax"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   369
    @{command_def "no_syntax"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   370
    @{command_def "translations"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   371
    @{command_def "no_translations"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   372
  \end{matharray}
wenzelm@28762
   373
wenzelm@28762
   374
  \begin{rail}
wenzelm@28762
   375
    'nonterminals' (name +)
wenzelm@28762
   376
    ;
wenzelm@28762
   377
    ('syntax' | 'no\_syntax') mode? (constdecl +)
wenzelm@28762
   378
    ;
wenzelm@28762
   379
    ('translations' | 'no\_translations') (transpat ('==' | '=>' | '<=' | rightleftharpoons | rightharpoonup | leftharpoondown) transpat +)
wenzelm@28762
   380
    ;
wenzelm@28762
   381
wenzelm@28762
   382
    mode: ('(' ( name | 'output' | name 'output' ) ')')
wenzelm@28762
   383
    ;
wenzelm@28762
   384
    transpat: ('(' nameref ')')? string
wenzelm@28762
   385
    ;
wenzelm@28762
   386
  \end{rail}
wenzelm@28762
   387
wenzelm@28762
   388
  \begin{description}
wenzelm@28762
   389
  
wenzelm@28762
   390
  \item @{command "nonterminals"}~@{text c} declares a type
wenzelm@28762
   391
  constructor @{text c} (without arguments) to act as purely syntactic
wenzelm@28762
   392
  type: a nonterminal symbol of the inner syntax.
wenzelm@28762
   393
wenzelm@28762
   394
  \item @{command "syntax"}~@{text "(mode) decls"} is similar to
wenzelm@28762
   395
  @{command "consts"}~@{text decls}, except that the actual logical
wenzelm@28762
   396
  signature extension is omitted.  Thus the context free grammar of
wenzelm@28762
   397
  Isabelle's inner syntax may be augmented in arbitrary ways,
wenzelm@28762
   398
  independently of the logic.  The @{text mode} argument refers to the
wenzelm@28762
   399
  print mode that the grammar rules belong; unless the @{keyword_ref
wenzelm@28762
   400
  "output"} indicator is given, all productions are added both to the
wenzelm@28762
   401
  input and output grammar.
wenzelm@28762
   402
  
wenzelm@28762
   403
  \item @{command "no_syntax"}~@{text "(mode) decls"} removes grammar
wenzelm@28762
   404
  declarations (and translations) resulting from @{text decls}, which
wenzelm@28762
   405
  are interpreted in the same manner as for @{command "syntax"} above.
wenzelm@28762
   406
  
wenzelm@28762
   407
  \item @{command "translations"}~@{text rules} specifies syntactic
wenzelm@28762
   408
  translation rules (i.e.\ macros): parse~/ print rules (@{text "\<rightleftharpoons>"}),
wenzelm@28762
   409
  parse rules (@{text "\<rightharpoonup>"}), or print rules (@{text "\<leftharpoondown>"}).
wenzelm@28762
   410
  Translation patterns may be prefixed by the syntactic category to be
wenzelm@28762
   411
  used for parsing; the default is @{text logic}.
wenzelm@28762
   412
  
wenzelm@28762
   413
  \item @{command "no_translations"}~@{text rules} removes syntactic
wenzelm@28762
   414
  translation rules, which are interpreted in the same manner as for
wenzelm@28762
   415
  @{command "translations"} above.
wenzelm@28762
   416
wenzelm@28762
   417
  \end{description}
wenzelm@28762
   418
*}
wenzelm@28762
   419
wenzelm@28762
   420
wenzelm@28762
   421
section {* Syntax translation functions *}
wenzelm@28762
   422
wenzelm@28762
   423
text {*
wenzelm@28762
   424
  \begin{matharray}{rcl}
wenzelm@28762
   425
    @{command_def "parse_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   426
    @{command_def "parse_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   427
    @{command_def "print_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   428
    @{command_def "typed_print_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   429
    @{command_def "print_ast_translation"} & : & @{text "theory \<rightarrow> theory"} \\
wenzelm@28762
   430
  \end{matharray}
wenzelm@28762
   431
wenzelm@28762
   432
  \begin{rail}
wenzelm@28762
   433
  ( 'parse\_ast\_translation' | 'parse\_translation' | 'print\_translation' |
wenzelm@28762
   434
    'typed\_print\_translation' | 'print\_ast\_translation' ) ('(advanced)')? text
wenzelm@28762
   435
  ;
wenzelm@28762
   436
  \end{rail}
wenzelm@28762
   437
wenzelm@28762
   438
  Syntax translation functions written in ML admit almost arbitrary
wenzelm@28762
   439
  manipulations of Isabelle's inner syntax.  Any of the above commands
wenzelm@28762
   440
  have a single \railqtok{text} argument that refers to an ML
wenzelm@28762
   441
  expression of appropriate type, which are as follows by default:
wenzelm@28762
   442
wenzelm@28762
   443
%FIXME proper antiquotations
wenzelm@28762
   444
\begin{ttbox}
wenzelm@28762
   445
val parse_ast_translation   : (string * (ast list -> ast)) list
wenzelm@28762
   446
val parse_translation       : (string * (term list -> term)) list
wenzelm@28762
   447
val print_translation       : (string * (term list -> term)) list
wenzelm@28762
   448
val typed_print_translation :
wenzelm@28762
   449
  (string * (bool -> typ -> term list -> term)) list
wenzelm@28762
   450
val print_ast_translation   : (string * (ast list -> ast)) list
wenzelm@28762
   451
\end{ttbox}
wenzelm@28762
   452
wenzelm@28762
   453
  If the @{text "(advanced)"} option is given, the corresponding
wenzelm@28762
   454
  translation functions may depend on the current theory or proof
wenzelm@28762
   455
  context.  This allows to implement advanced syntax mechanisms, as
wenzelm@28762
   456
  translations functions may refer to specific theory declarations or
wenzelm@28762
   457
  auxiliary proof data.
wenzelm@28762
   458
wenzelm@28762
   459
  See also \cite[\S8]{isabelle-ref} for more information on the
wenzelm@28762
   460
  general concept of syntax transformations in Isabelle.
wenzelm@28762
   461
wenzelm@28762
   462
%FIXME proper antiquotations
wenzelm@28762
   463
\begin{ttbox}
wenzelm@28762
   464
val parse_ast_translation:
wenzelm@28762
   465
  (string * (Proof.context -> ast list -> ast)) list
wenzelm@28762
   466
val parse_translation:
wenzelm@28762
   467
  (string * (Proof.context -> term list -> term)) list
wenzelm@28762
   468
val print_translation:
wenzelm@28762
   469
  (string * (Proof.context -> term list -> term)) list
wenzelm@28762
   470
val typed_print_translation:
wenzelm@28762
   471
  (string * (Proof.context -> bool -> typ -> term list -> term)) list
wenzelm@28762
   472
val print_ast_translation:
wenzelm@28762
   473
  (string * (Proof.context -> ast list -> ast)) list
wenzelm@28762
   474
\end{ttbox}
wenzelm@28762
   475
*}
wenzelm@28762
   476
wenzelm@28762
   477
end