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