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