src/Pure/Syntax/syn_ext.ML
author wenzelm
Mon Dec 11 21:39:26 2006 +0100 (2006-12-11)
changeset 21772 7c7ade4f537b
parent 20675 cb19d18aef01
child 21858 05f57309170c
permissions -rw-r--r--
advanced translation functions: Proof.context;
wenzelm@240
     1
(*  Title:      Pure/Syntax/syn_ext.ML
wenzelm@240
     2
    ID:         $Id$
wenzelm@911
     3
    Author:     Markus Wenzel and Carsten Clasohm, TU Muenchen
wenzelm@240
     4
wenzelm@240
     5
Syntax extension (internal interface).
wenzelm@240
     6
*)
wenzelm@240
     7
wenzelm@240
     8
signature SYN_EXT0 =
wenzelm@4050
     9
sig
wenzelm@6760
    10
  val dddot_indexname: indexname
wenzelm@6760
    11
  val constrainC: string
wenzelm@240
    12
  val typeT: typ
wenzelm@5690
    13
  val max_pri: int
wenzelm@15754
    14
  val stamp_trfun: stamp -> string * 'a -> string * ('a * stamp)
wenzelm@15754
    15
  val mk_trfun: string * 'a -> string * ('a * stamp)
wenzelm@15754
    16
  val eq_trfun: ('a * stamp) * ('a * stamp) -> bool
wenzelm@15835
    17
  val tokentrans_mode: string -> (string * (string -> string * real)) list ->
wenzelm@15835
    18
    (string * string * (string -> string * real)) list
wenzelm@15835
    19
  val standard_token_classes: string list
wenzelm@4050
    20
end;
wenzelm@240
    21
wenzelm@240
    22
signature SYN_EXT =
wenzelm@4050
    23
sig
wenzelm@240
    24
  include SYN_EXT0
paulson@1510
    25
  val logic: string
paulson@1510
    26
  val args: string
paulson@1510
    27
  val cargs: string
paulson@1510
    28
  val any: string
paulson@1510
    29
  val sprop: string
paulson@1510
    30
  val typ_to_nonterm: typ -> string
paulson@1510
    31
  datatype xsymb =
paulson@1510
    32
    Delim of string |
paulson@1510
    33
    Argument of string * int |
paulson@1510
    34
    Space of string |
paulson@1510
    35
    Bg of int | Brk of int | En
paulson@1510
    36
  datatype xprod = XProd of string * xsymb list * string * int
paulson@1510
    37
  val chain_pri: int
wenzelm@4701
    38
  val delims_of: xprod list -> string list list
paulson@1510
    39
  datatype mfix = Mfix of string * typ * string * int list * int
paulson@1510
    40
  datatype syn_ext =
paulson@1510
    41
    SynExt of {
paulson@1510
    42
      xprods: xprod list,
paulson@1510
    43
      consts: string list,
wenzelm@2913
    44
      prmodes: string list,
wenzelm@21772
    45
      parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
paulson@1510
    46
      parse_rules: (Ast.ast * Ast.ast) list,
wenzelm@21772
    47
      parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
wenzelm@18857
    48
      print_translation:
wenzelm@21772
    49
        (string * ((Proof.context -> bool -> typ -> term list -> term) * stamp)) list,
paulson@1510
    50
      print_rules: (Ast.ast * Ast.ast) list,
wenzelm@21772
    51
      print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
wenzelm@6322
    52
      token_translation: (string * string * (string -> string * real)) list}
wenzelm@19004
    53
  val mfix_delims: string -> string list
wenzelm@4054
    54
  val mfix_args: string -> int
wenzelm@12865
    55
  val escape_mfix: string -> string
wenzelm@18566
    56
  val unlocalize_mfix: string -> string
wenzelm@14903
    57
  val syn_ext': bool -> (string -> bool) -> mfix list ->
wenzelm@21772
    58
    string list -> (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
wenzelm@21772
    59
    (string * ((Proof.context -> term list -> term) * stamp)) list *
wenzelm@21772
    60
    (string * ((Proof.context -> bool -> typ -> term list -> term) * stamp)) list *
wenzelm@21772
    61
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list
wenzelm@6322
    62
    -> (string * string * (string -> string * real)) list
paulson@1510
    63
    -> (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
wenzelm@14903
    64
  val syn_ext: mfix list -> string list ->
wenzelm@21772
    65
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
wenzelm@21772
    66
    (string * ((Proof.context -> term list -> term) * stamp)) list *
wenzelm@21772
    67
    (string * ((Proof.context -> bool -> typ -> term list -> term) * stamp)) list *
wenzelm@21772
    68
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list
wenzelm@6322
    69
    -> (string * string * (string -> string * real)) list
paulson@1510
    70
    -> (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
wenzelm@14903
    71
  val syn_ext_const_names: string list -> syn_ext
wenzelm@14903
    72
  val syn_ext_rules: (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
wenzelm@14903
    73
  val syn_ext_trfuns:
wenzelm@15754
    74
    (string * ((Ast.ast list -> Ast.ast) * stamp)) list *
wenzelm@15754
    75
    (string * ((term list -> term) * stamp)) list *
wenzelm@15754
    76
    (string * ((bool -> typ -> term list -> term) * stamp)) list *
wenzelm@15754
    77
    (string * ((Ast.ast list -> Ast.ast) * stamp)) list -> syn_ext
wenzelm@16610
    78
  val syn_ext_advanced_trfuns:
wenzelm@21772
    79
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
wenzelm@21772
    80
    (string * ((Proof.context -> term list -> term) * stamp)) list *
wenzelm@21772
    81
    (string * ((Proof.context -> bool -> typ -> term list -> term) * stamp)) list *
wenzelm@21772
    82
    (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list -> syn_ext
wenzelm@14903
    83
  val syn_ext_tokentrfuns: (string * string * (string -> string * real)) list -> syn_ext
wenzelm@15835
    84
  val standard_token_markers: string list
paulson@1510
    85
  val pure_ext: syn_ext
wenzelm@4050
    86
end;
wenzelm@240
    87
wenzelm@15754
    88
structure SynExt: SYN_EXT =
wenzelm@240
    89
struct
wenzelm@240
    90
wenzelm@2694
    91
wenzelm@240
    92
(** misc definitions **)
wenzelm@240
    93
wenzelm@7472
    94
val dddot_indexname = ("dddot", 0);
wenzelm@6760
    95
val constrainC = "_constrain";
wenzelm@6760
    96
wenzelm@6760
    97
wenzelm@240
    98
(* syntactic categories *)
wenzelm@240
    99
wenzelm@240
   100
val logic = "logic";
wenzelm@240
   101
val logicT = Type (logic, []);
wenzelm@240
   102
wenzelm@240
   103
val args = "args";
clasohm@1178
   104
val cargs = "cargs";
wenzelm@240
   105
clasohm@330
   106
val typeT = Type ("type", []);
wenzelm@240
   107
clasohm@764
   108
val sprop = "#prop";
clasohm@764
   109
val spropT = Type (sprop, []);
wenzelm@240
   110
clasohm@764
   111
val any = "any";
clasohm@624
   112
val anyT = Type (any, []);
clasohm@624
   113
wenzelm@780
   114
wenzelm@240
   115
wenzelm@240
   116
(** datatype xprod **)
wenzelm@240
   117
wenzelm@240
   118
(*Delim s: delimiter s
wenzelm@240
   119
  Argument (s, p): nonterminal s requiring priority >= p, or valued token
wenzelm@240
   120
  Space s: some white space for printing
wenzelm@240
   121
  Bg, Brk, En: blocks and breaks for pretty printing*)
wenzelm@240
   122
wenzelm@240
   123
datatype xsymb =
wenzelm@240
   124
  Delim of string |
wenzelm@240
   125
  Argument of string * int |
wenzelm@240
   126
  Space of string |
wenzelm@240
   127
  Bg of int | Brk of int | En;
wenzelm@240
   128
wenzelm@12513
   129
fun is_delim (Delim _) = true
wenzelm@12513
   130
  | is_delim _ = false;
wenzelm@12513
   131
wenzelm@12513
   132
fun is_terminal (Delim _) = true
wenzelm@12513
   133
  | is_terminal (Argument (s, _)) = Lexicon.is_terminal s
wenzelm@12513
   134
  | is_terminal _ = false;
wenzelm@12513
   135
wenzelm@12513
   136
fun is_argument (Argument _) = true
wenzelm@12513
   137
  | is_argument _ = false;
wenzelm@12513
   138
wenzelm@12513
   139
fun is_index (Argument ("index", _)) = true
wenzelm@12513
   140
  | is_index _ = false;
wenzelm@12513
   141
wenzelm@12513
   142
val index = Argument ("index", 1000);
wenzelm@12513
   143
wenzelm@240
   144
wenzelm@240
   145
(*XProd (lhs, syms, c, p):
wenzelm@240
   146
    lhs: name of nonterminal on the lhs of the production
wenzelm@240
   147
    syms: list of symbols on the rhs of the production
wenzelm@240
   148
    c: head of parse tree
wenzelm@240
   149
    p: priority of this production*)
wenzelm@240
   150
wenzelm@240
   151
datatype xprod = XProd of string * xsymb list * string * int;
wenzelm@240
   152
wenzelm@240
   153
val max_pri = 1000;   (*maximum legal priority*)
wenzelm@240
   154
val chain_pri = ~1;   (*dummy for chain productions*)
wenzelm@240
   155
wenzelm@240
   156
fun delims_of xprods =
wenzelm@19004
   157
  fold (fn XProd (_, xsymbs, _, _) =>
wenzelm@19004
   158
    fold (fn Delim s => insert (op =) s | _ => I) xsymbs) xprods []
wenzelm@19004
   159
  |> map Symbol.explode;
wenzelm@240
   160
wenzelm@240
   161
wenzelm@240
   162
wenzelm@240
   163
(** datatype mfix **)
wenzelm@240
   164
wenzelm@240
   165
(*Mfix (sy, ty, c, ps, p):
wenzelm@240
   166
    sy: rhs of production as symbolic string
wenzelm@240
   167
    ty: type description of production
wenzelm@240
   168
    c: head of parse tree
wenzelm@240
   169
    ps: priorities of arguments in sy
wenzelm@240
   170
    p: priority of production*)
wenzelm@240
   171
wenzelm@240
   172
datatype mfix = Mfix of string * typ * string * int list * int;
wenzelm@240
   173
wenzelm@12513
   174
fun err_in_mfix msg (Mfix (sy, _, const, _, _)) =
wenzelm@18678
   175
  cat_error msg ("in mixfix annotation " ^ quote sy ^ " for " ^ quote const);
wenzelm@12513
   176
wenzelm@240
   177
wenzelm@240
   178
(* typ_to_nonterm *)
wenzelm@240
   179
clasohm@865
   180
fun typ_to_nt _ (Type (c, _)) = c
clasohm@865
   181
  | typ_to_nt default _ = default;
clasohm@865
   182
clasohm@764
   183
(*get nonterminal for rhs*)
clasohm@865
   184
val typ_to_nonterm = typ_to_nt any;
wenzelm@240
   185
clasohm@764
   186
(*get nonterminal for lhs*)
clasohm@865
   187
val typ_to_nonterm1 = typ_to_nt logic;
wenzelm@240
   188
wenzelm@240
   189
wenzelm@19004
   190
(* read mixfix annotations *)
wenzelm@4050
   191
wenzelm@4050
   192
local
wenzelm@19004
   193
wenzelm@20675
   194
val is_meta = member (op =) ["(", ")", "/", "_", "\\<index>"];
wenzelm@19004
   195
wenzelm@19004
   196
val scan_delim_char =
wenzelm@19004
   197
  $$ "'" |-- Scan.one ((not o Symbol.is_blank) andf Symbol.not_eof) ||
wenzelm@19004
   198
  Scan.one ((not o is_meta) andf (not o Symbol.is_blank) andf Symbol.not_eof);
wenzelm@19004
   199
wenzelm@19004
   200
fun read_int ["0", "0"] = ~1
wenzelm@19004
   201
  | read_int cs = #1 (Library.read_int cs);
wenzelm@4050
   202
wenzelm@19004
   203
val scan_sym =
wenzelm@19004
   204
  $$ "_" >> K (Argument ("", 0)) ||
wenzelm@19004
   205
  $$ "\\<index>" >> K index ||
wenzelm@19004
   206
  $$ "(" |-- Scan.any Symbol.is_digit >> (Bg o read_int) ||
wenzelm@19004
   207
  $$ ")" >> K En ||
wenzelm@19004
   208
  $$ "/" -- $$ "/" >> K (Brk ~1) ||
wenzelm@19004
   209
  $$ "/" |-- Scan.any Symbol.is_blank >> (Brk o length) ||
wenzelm@19004
   210
  Scan.any1 Symbol.is_blank >> (Space o implode) ||
wenzelm@19004
   211
  Scan.repeat1 scan_delim_char >> (Delim o implode);
wenzelm@14819
   212
wenzelm@19004
   213
val scan_symb =
wenzelm@19004
   214
  scan_sym >> SOME ||
wenzelm@19004
   215
  $$ "'" -- Scan.one Symbol.is_blank >> K NONE;
wenzelm@19004
   216
wenzelm@19305
   217
val scan_symbs = Scan.repeat scan_symb --| Scan.ahead (~$$ "'");
wenzelm@19482
   218
val read_symbs = map_filter I o the o Scan.read Symbol.stopper scan_symbs;
wenzelm@4050
   219
wenzelm@19004
   220
fun unique_index xsymbs =
wenzelm@19004
   221
  if length (List.filter is_index xsymbs) <= 1 then xsymbs
wenzelm@19004
   222
  else error "Duplicate index arguments (\\<index>)";
wenzelm@4050
   223
wenzelm@19004
   224
in
wenzelm@12513
   225
wenzelm@19004
   226
val read_mfix = unique_index o read_symbs o Symbol.explode;
wenzelm@19004
   227
wenzelm@19004
   228
fun mfix_delims sy = fold_rev (fn Delim s => cons s | _ => I) (read_mfix sy) [];
wenzelm@19004
   229
val mfix_args = length o List.filter is_argument o read_mfix;
wenzelm@19004
   230
wenzelm@19004
   231
val escape_mfix = implode o map (fn s => if is_meta s then "'" ^ s else s) o Symbol.explode;
wenzelm@19004
   232
wenzelm@4050
   233
end;
wenzelm@4050
   234
wenzelm@18566
   235
val unlocalize_mfix =
wenzelm@18566
   236
  let
wenzelm@18566
   237
    fun unloc ("'" :: "\\<^loc>" :: ss) = unloc ss
wenzelm@18566
   238
      | unloc ("\\<^loc>" :: ss) = unloc ss
wenzelm@18566
   239
      | unloc (s :: ss) = s :: unloc ss
wenzelm@18566
   240
      | unloc [] = [];
wenzelm@18566
   241
  in Symbol.explode #> unloc #> implode end;  
wenzelm@18566
   242
wenzelm@4050
   243
wenzelm@240
   244
(* mfix_to_xprod *)
wenzelm@240
   245
wenzelm@14903
   246
fun mfix_to_xprod convert is_logtype (mfix as Mfix (sy, typ, const, pris, pri)) =
wenzelm@240
   247
  let
wenzelm@240
   248
    fun check_pri p =
wenzelm@240
   249
      if p >= 0 andalso p <= max_pri then ()
wenzelm@12513
   250
      else err_in_mfix ("Precedence out of range: " ^ string_of_int p) mfix;
wenzelm@240
   251
wenzelm@240
   252
    fun blocks_ok [] 0 = true
wenzelm@240
   253
      | blocks_ok [] _ = false
wenzelm@240
   254
      | blocks_ok (Bg _ :: syms) n = blocks_ok syms (n + 1)
wenzelm@240
   255
      | blocks_ok (En :: _) 0 = false
wenzelm@240
   256
      | blocks_ok (En :: syms) n = blocks_ok syms (n - 1)
wenzelm@240
   257
      | blocks_ok (_ :: syms) n = blocks_ok syms n;
wenzelm@240
   258
wenzelm@240
   259
    fun check_blocks syms =
wenzelm@240
   260
      if blocks_ok syms 0 then ()
wenzelm@12513
   261
      else err_in_mfix "Unbalanced block parentheses" mfix;
wenzelm@240
   262
wenzelm@240
   263
wenzelm@240
   264
    val cons_fst = apfst o cons;
wenzelm@240
   265
wenzelm@240
   266
    fun add_args [] ty [] = ([], typ_to_nonterm1 ty)
wenzelm@12513
   267
      | add_args [] _ _ = err_in_mfix "Too many precedences" mfix
wenzelm@12513
   268
      | add_args ((arg as Argument ("index", _)) :: syms) ty ps =
wenzelm@12513
   269
          cons_fst arg (add_args syms ty ps)
wenzelm@240
   270
      | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) [] =
wenzelm@240
   271
          cons_fst (Argument (typ_to_nonterm ty, 0)) (add_args syms tys [])
wenzelm@240
   272
      | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) (p :: ps) =
wenzelm@240
   273
          cons_fst (Argument (typ_to_nonterm ty, p)) (add_args syms tys ps)
wenzelm@240
   274
      | add_args (Argument _ :: _) _ _ =
wenzelm@12513
   275
          err_in_mfix "More arguments than in corresponding type" mfix
wenzelm@240
   276
      | add_args (sym :: syms) ty ps = cons_fst sym (add_args syms ty ps);
wenzelm@240
   277
wenzelm@240
   278
    fun rem_pri (Argument (s, _)) = Argument (s, chain_pri)
wenzelm@240
   279
      | rem_pri sym = sym;
wenzelm@240
   280
wenzelm@4054
   281
    fun logify_types copy_prod (a as (Argument (s, p))) =
wenzelm@14903
   282
          if s <> "prop" andalso is_logtype s then Argument (logic, p) else a
wenzelm@4054
   283
      | logify_types _ a = a;
wenzelm@240
   284
wenzelm@2364
   285
wenzelm@19004
   286
    val raw_symbs = read_mfix sy handle ERROR msg => err_in_mfix msg mfix;
skalberg@15570
   287
    val args = List.filter (fn Argument _ => true | _ => false) raw_symbs;
wenzelm@12513
   288
    val (const', typ', parse_rules) =
wenzelm@12513
   289
      if not (exists is_index args) then (const, typ, [])
wenzelm@12513
   290
      else
wenzelm@12513
   291
        let
wenzelm@14697
   292
          val indexed_const = if const <> "" then "_indexed_" ^ const
wenzelm@12513
   293
            else err_in_mfix "Missing constant name for indexed syntax" mfix;
wenzelm@14697
   294
          val rangeT = Term.range_type typ handle Match =>
wenzelm@12513
   295
            err_in_mfix "Missing structure argument for indexed syntax" mfix;
wenzelm@12513
   296
wenzelm@20076
   297
          val xs = map Ast.Variable (Name.invent_list [] "xa" (length args - 1));
wenzelm@19012
   298
          val (xs1, xs2) = chop (find_index is_index args) xs;
wenzelm@12513
   299
          val i = Ast.Variable "i";
wenzelm@14697
   300
          val lhs = Ast.mk_appl (Ast.Constant indexed_const)
wenzelm@14697
   301
            (xs1 @ [Ast.mk_appl (Ast.Constant "_index") [i]] @ xs2);
wenzelm@14697
   302
          val rhs = Ast.mk_appl (Ast.Constant const) (i :: xs);
wenzelm@14697
   303
        in (indexed_const, rangeT, [(lhs, rhs)]) end;
wenzelm@12513
   304
wenzelm@12513
   305
    val (symbs, lhs) = add_args raw_symbs typ' pris;
wenzelm@12513
   306
wenzelm@2364
   307
    val copy_prod =
wenzelm@20675
   308
      (lhs = "prop" orelse lhs = "logic")
wenzelm@2364
   309
        andalso const <> ""
wenzelm@2364
   310
        andalso not (null symbs)
wenzelm@2364
   311
        andalso not (exists is_delim symbs);
wenzelm@2364
   312
    val lhs' =
wenzelm@2364
   313
      if convert andalso not copy_prod then
wenzelm@14903
   314
       (if lhs = "prop" then sprop else if is_logtype lhs then logic else lhs)
wenzelm@2364
   315
      else lhs;
wenzelm@4054
   316
    val symbs' = map (logify_types copy_prod) symbs;
wenzelm@12513
   317
    val xprod = XProd (lhs', symbs', const', pri);
wenzelm@240
   318
skalberg@15570
   319
    val _ = (List.app check_pri pris; check_pri pri; check_blocks symbs');
wenzelm@12513
   320
    val xprod' =
wenzelm@12513
   321
      if Lexicon.is_terminal lhs' then err_in_mfix ("Illegal lhs: " ^ lhs') mfix
wenzelm@12513
   322
      else if const <> "" then xprod
skalberg@15570
   323
      else if length (List.filter is_argument symbs') <> 1 then
wenzelm@12513
   324
        err_in_mfix "Copy production must have exactly one argument" mfix
wenzelm@12513
   325
      else if exists is_terminal symbs' then xprod
wenzelm@12513
   326
      else XProd (lhs', map rem_pri symbs', "", chain_pri);
wenzelm@12513
   327
wenzelm@12513
   328
  in (xprod', parse_rules) end;
wenzelm@12513
   329
wenzelm@240
   330
wenzelm@240
   331
wenzelm@240
   332
(** datatype syn_ext **)
wenzelm@240
   333
wenzelm@240
   334
datatype syn_ext =
wenzelm@240
   335
  SynExt of {
wenzelm@240
   336
    xprods: xprod list,
wenzelm@240
   337
    consts: string list,
wenzelm@2913
   338
    prmodes: string list,
wenzelm@21772
   339
    parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
paulson@1510
   340
    parse_rules: (Ast.ast * Ast.ast) list,
wenzelm@21772
   341
    parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
wenzelm@18857
   342
    print_translation:
wenzelm@21772
   343
      (string * ((Proof.context -> bool -> typ -> term list -> term) * stamp)) list,
paulson@1510
   344
    print_rules: (Ast.ast * Ast.ast) list,
wenzelm@21772
   345
    print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
wenzelm@15754
   346
    token_translation: (string * string * (string -> string * real)) list};
wenzelm@240
   347
wenzelm@240
   348
wenzelm@240
   349
(* syn_ext *)
wenzelm@240
   350
wenzelm@14903
   351
fun syn_ext' convert is_logtype mfixes consts trfuns tokentrfuns (parse_rules, print_rules) =
wenzelm@240
   352
  let
wenzelm@240
   353
    val (parse_ast_translation, parse_translation, print_translation,
wenzelm@240
   354
      print_ast_translation) = trfuns;
wenzelm@240
   355
wenzelm@14903
   356
    val (xprods, parse_rules') = map (mfix_to_xprod convert is_logtype) mfixes
wenzelm@19482
   357
      |> split_list |> apsnd (rev o flat);
wenzelm@19046
   358
    val mfix_consts =
wenzelm@19046
   359
      distinct (op =) (map (fn Mfix x => #3 x) mfixes @ map (fn XProd x => #3 x) xprods);
wenzelm@240
   360
  in
wenzelm@240
   361
    SynExt {
clasohm@624
   362
      xprods = xprods,
wenzelm@11546
   363
      consts = consts union_string mfix_consts,
wenzelm@19046
   364
      prmodes = distinct (op =) (map (fn (m, _, _) => m) tokentrfuns),
wenzelm@240
   365
      parse_ast_translation = parse_ast_translation,
wenzelm@12513
   366
      parse_rules = parse_rules' @ parse_rules,
wenzelm@240
   367
      parse_translation = parse_translation,
wenzelm@240
   368
      print_translation = print_translation,
wenzelm@12513
   369
      print_rules = map swap parse_rules' @ print_rules,
wenzelm@2694
   370
      print_ast_translation = print_ast_translation,
wenzelm@2694
   371
      token_translation = tokentrfuns}
wenzelm@240
   372
  end;
wenzelm@240
   373
wenzelm@2382
   374
wenzelm@14903
   375
val syn_ext = syn_ext' true (K false);
wenzelm@555
   376
wenzelm@14903
   377
fun syn_ext_const_names cs = syn_ext [] cs ([], [], [], []) [] ([], []);
wenzelm@14903
   378
fun syn_ext_rules rules = syn_ext [] [] ([], [], [], []) [] rules;
wenzelm@16610
   379
fun syn_ext_advanced_trfuns trfuns = syn_ext [] [] trfuns [] ([], []);
wenzelm@14903
   380
fun syn_ext_tokentrfuns trfuns = syn_ext [] [] ([], [], [], []) trfuns ([], []);
wenzelm@2382
   381
wenzelm@16610
   382
fun syn_ext_trfuns (atrs, trs, tr's, atr's) =
wenzelm@16610
   383
  let fun simple (name, (f, s)) = (name, (K f, s)) in
wenzelm@16610
   384
    syn_ext_advanced_trfuns (map simple atrs, map simple trs, map simple tr's, map simple atr's)
wenzelm@16610
   385
  end;
wenzelm@16610
   386
wenzelm@15754
   387
fun stamp_trfun s (c, f) = (c, (f, s));
wenzelm@15754
   388
fun mk_trfun tr = stamp_trfun (stamp ()) tr;
wenzelm@15754
   389
fun eq_trfun ((_, s1:stamp), (_, s2)) = s1 = s2;
wenzelm@15754
   390
wenzelm@240
   391
wenzelm@15835
   392
(* token translations *)
wenzelm@15835
   393
wenzelm@15835
   394
fun tokentrans_mode m trs = map (fn (s, f) => (m, s, f)) trs;
wenzelm@15835
   395
wenzelm@15835
   396
val standard_token_classes =
wenzelm@15835
   397
  ["class", "tfree", "tvar", "free", "bound", "var", "num", "xnum", "xstr"];
wenzelm@15835
   398
wenzelm@15835
   399
val standard_token_markers = map (fn s => "_" ^ s) standard_token_classes;
wenzelm@15835
   400
wenzelm@15835
   401
clasohm@764
   402
(* pure_ext *)
wenzelm@240
   403
wenzelm@14903
   404
val pure_ext = syn_ext' false (K false)
clasohm@764
   405
  [Mfix ("_", spropT --> propT, "", [0], 0),
clasohm@764
   406
   Mfix ("_", logicT --> anyT, "", [0], 0),
clasohm@764
   407
   Mfix ("_", spropT --> anyT, "", [0], 0),
clasohm@764
   408
   Mfix ("'(_')", logicT --> logicT, "", [0], max_pri),
clasohm@764
   409
   Mfix ("'(_')", spropT --> spropT, "", [0], max_pri),
clasohm@764
   410
   Mfix ("_::_",  [logicT, typeT] ---> logicT, "_constrain", [4, 0], 3),
clasohm@764
   411
   Mfix ("_::_",  [spropT, typeT] ---> spropT, "_constrain", [4, 0], 3)]
clasohm@764
   412
  []
clasohm@764
   413
  ([], [], [], [])
wenzelm@2694
   414
  []
clasohm@764
   415
  ([], []);
wenzelm@240
   416
wenzelm@240
   417
end;