doc-src/MacroHints
author lcp
Tue, 09 Nov 1993 16:47:38 +0100
changeset 103 30bd42401ab2
child 106 7a5d207e6151
permissions -rw-r--r--
Initial revision
lcp@103
     1
lcp@103
     2
Hints
lcp@103
     3
=====
lcp@103
     4
lcp@103
     5
This is an incomprehensive list of facts about the new version of the syntax
lcp@103
     6
module (the macro system).
lcp@103
     7
lcp@103
     8
lcp@103
     9
- Syntax of "translations" section is list of <xrule> where: (metachars: [ | ])
lcp@103
    10
lcp@103
    11
    <xrule> ::= [(<id>)] <string> [ => | <= | == ] [(<id>)] <string>
lcp@103
    12
lcp@103
    13
  One such line specifies a parse rule (=>) or a print rule (<=) or both (==).
lcp@103
    14
  The optional <id> before each <string> specifies the name of the syntactic
lcp@103
    15
  category to be used for parsing the string; the default is logic. Note that
lcp@103
    16
  this has no influence on the applicability of rules.
lcp@103
    17
lcp@103
    18
  Example:
lcp@103
    19
lcp@103
    20
    translations
lcp@103
    21
      (prop) "x:X"  == (prop) "|- x:X"
lcp@103
    22
      "Lam x:A.B"   == "Abs(A, %x.B)"
lcp@103
    23
      "Pi x:A.B"    => "Prod(A, %x.B)"
lcp@103
    24
lcp@103
    25
  All rules of a theory will be shown in their internal (ast * ast) form by
lcp@103
    26
  Syntax.print_trans.
lcp@103
    27
lcp@103
    28
- Caveat: rewrite rules know no "context" nor "semantics", e.g. something
lcp@103
    29
  like "('a, Nil)Cons", "% Nil Cons. Cons(a, Nil)" or "Cons(a, [])" will be
lcp@103
    30
  rewritten by the rules "[x]" <= "Cons(x, [])", "[]" <= "Nil"; (this is a
lcp@103
    31
  general problem with macro systems);
lcp@103
    32
lcp@103
    33
- syn_of: theory -> Syntax.syntax
lcp@103
    34
lcp@103
    35
- Syntax.print_gram shows grammer of syntax
lcp@103
    36
lcp@103
    37
- Syntax.print_trans shows translations of syntax
lcp@103
    38
lcp@103
    39
- Syntax.print_syntax shows grammer and translations of syntax
lcp@103
    40
lcp@103
    41
- Ast.stat_normalize := true enables output of statistics after normalizing;
lcp@103
    42
lcp@103
    43
- Ast.trace_normalize := true enables verbose output while normalizing and
lcp@103
    44
  statistics;
lcp@103
    45
lcp@103
    46
- eta_contract := false disables eta contraction when printing terms;
lcp@103
    47
lcp@103
    48
- asts: (see also Pure/Syntax/ast.ML *)
lcp@103
    49
lcp@103
    50
    (*Asts come in two flavours:
lcp@103
    51
       - proper asts representing terms and types: Variables are treated like
lcp@103
    52
         Constants;
lcp@103
    53
       - patterns used as lhs and rhs in rules: Variables are placeholders for
lcp@103
    54
         proper asts.*)
lcp@103
    55
lcp@103
    56
    datatype ast =
lcp@103
    57
      Constant of string |    (* "not", "_%", "fun" *)
lcp@103
    58
      Variable of string |    (* x, ?x, 'a, ?'a *)
lcp@103
    59
      Appl of ast list;       (* (f x y z), ("fun" 'a 'b) *)
lcp@103
    60
lcp@103
    61
    (*the list of subasts of an Appl node has to contain at least 2 elements, i.e.
lcp@103
    62
      there are no empty asts or nullary applications; use mk_appl for convenience*)
lcp@103
    63
lcp@103
    64
- ast output style:
lcp@103
    65
    Constant a              ->  "a"
lcp@103
    66
    Variable a              ->  a
lcp@103
    67
    Appl [ast1, ..., astn]  ->  (ast1 ... astn)
lcp@103
    68
lcp@103
    69
- sext: (see also Pure/Syntax/sextension.ML)
lcp@103
    70
lcp@103
    71
    (** datatype sext **)
lcp@103
    72
lcp@103
    73
    datatype xrule =
lcp@103
    74
      op |-> of (string * string) * (string * string) |
lcp@103
    75
      op <-| of (string * string) * (string * string) |
lcp@103
    76
      op <-> of (string * string) * (string * string);
lcp@103
    77
lcp@103
    78
    datatype sext =
lcp@103
    79
      Sext of {
lcp@103
    80
        mixfix: mixfix list,
lcp@103
    81
        parse_translation: (string * (term list -> term)) list,
lcp@103
    82
        print_translation: (string * (term list -> term)) list} |
lcp@103
    83
      NewSext of {
lcp@103
    84
        mixfix: mixfix list,
lcp@103
    85
        xrules: xrule list,
lcp@103
    86
        parse_ast_translation: (string * (ast list -> ast)) list,
lcp@103
    87
        parse_preproc: (ast -> ast) option,
lcp@103
    88
        parse_postproc: (ast -> ast) option,
lcp@103
    89
        parse_translation: (string * (term list -> term)) list,
lcp@103
    90
        print_translation: (string * (term list -> term)) list,
lcp@103
    91
        print_preproc: (ast -> ast) option,
lcp@103
    92
        print_postproc: (ast -> ast) option,
lcp@103
    93
        print_ast_translation: (string * (ast list -> ast)) list};
lcp@103
    94
lcp@103
    95
- local (thy, ext) order of rules is preserved, global (merge) order is
lcp@103
    96
  unspecified;
lcp@103
    97
lcp@103
    98
- read asts contain a mixture of Constant and Variable atoms (some
lcp@103
    99
  Variables become Const later);
lcp@103
   100
lcp@103
   101
- *.thy-file/ML-section: all declarations will be exported, therefore
lcp@103
   102
  one should use local-in-end constructs where appropriate; especially
lcp@103
   103
  the examples in Logics/Defining could be better behaved;
lcp@103
   104
lcp@103
   105
- [document the asts generated by the standard syntactic categories
lcp@103
   106
  (idt, idts, args, ...)];
lcp@103
   107
lcp@103
   108
- print(_ast)_translation: the constant has to disappear or execption
lcp@103
   109
  Match raised, otherwise the printer will not terminate;
lcp@103
   110
lcp@103
   111
- binders are implemented traditionally, i.e. as parse/print_translations
lcp@103
   112
  (compatibility, alpha, eta, HOL hack easy);
lcp@103
   113
lcp@103
   114
- changes to the term/ast "parsetree" structure: renamed most constants
lcp@103
   115
  (_args, _idts, ...), unified typ applications, _tapp/_tappl, type atoms
lcp@103
   116
  no Const rather than Free;
lcp@103
   117
lcp@103
   118
- misfeature: eta-contraction before rewriting therefore bounded quantifiers,
lcp@103
   119
  Collect etc. may fall back to internal form;
lcp@103
   120
lcp@103
   121
- changes and fixes to printing of types:
lcp@103
   122
lcp@103
   123
    "'a => 'b => 'c" now printed as "['a,'b] => 'c";
lcp@103
   124
lcp@103
   125
    constraints now printed iff not dummyT and show_types enabled, changed
lcp@103
   126
    internal print_translations accordingly; old translations that intruduce
lcp@103
   127
    frees may cause printing of constraints at all occurences;
lcp@103
   128
lcp@103
   129
    constraints of bound vars now printed where bound (i.e. "%x::'a. x" rather
lcp@103
   130
    than "%x. x::'a") and put in braces if necessary ("%(x::'a) y::'b. f(x,y)");
lcp@103
   131
lcp@103
   132
    constraints of bound var printed even if a free var in another scope happens
lcp@103
   133
    to have the same name and type;
lcp@103
   134
lcp@103
   135
- [man: toplevel pretty printers for NJ];
lcp@103
   136
lcp@103
   137
- (syntactic constants "_..." (e.g. "_idts") are reserved, you may use "@..."
lcp@103
   138
  or "*..." instead);
lcp@103
   139
lcp@103
   140
- Printer: clash of fun/type constants with concrete syntax type/fun
lcp@103
   141
  constants causes incorrect printing of of applications;
lcp@103
   142