src/Pure/Syntax/syntax.ML
author wenzelm
Thu May 19 16:15:38 1994 +0200 (1994-05-19)
changeset 383 fcea89074e4c
parent 330 2fda15dd1e0f
child 556 3f5f42467717
permissions -rw-r--r--
added incremental extension functions: extend_log_types, extend_type_gram,
extend_const_gram, extend_consts, extend_trfuns, extend_trrules;
replaced merge by merge_syntaxes;
various minor internal changes;
wenzelm@18
     1
(*  Title:      Pure/Syntax/syntax.ML
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
wenzelm@18
     4
wenzelm@18
     5
Root of Isabelle's syntax module.
clasohm@0
     6
*)
clasohm@0
     7
wenzelm@260
     8
signature BASIC_SYNTAX =
wenzelm@260
     9
sig
wenzelm@260
    10
  include AST0
wenzelm@260
    11
  include SEXTENSION0
wenzelm@383
    12
(*  include MIXFIX0   *)   (* FIXME *)
wenzelm@260
    13
  include PRINTER0
wenzelm@260
    14
end;
wenzelm@260
    15
clasohm@0
    16
signature SYNTAX =
clasohm@0
    17
sig
wenzelm@260
    18
  include AST1
clasohm@0
    19
  include LEXICON0
wenzelm@237
    20
  include SYN_EXT0
clasohm@0
    21
  include TYPE_EXT0
clasohm@0
    22
  include SEXTENSION1
clasohm@0
    23
  include PRINTER0
wenzelm@383
    24
  sharing type ast = Parser.SynExt.Ast.ast
wenzelm@383
    25
  structure Mixfix: MIXFIX
wenzelm@383
    26
  local open Mixfix in    (* FIXME *)
wenzelm@383
    27
    type syntax
wenzelm@383
    28
    val extend_log_types: syntax -> string list -> syntax
wenzelm@383
    29
    val extend_type_gram: syntax -> (string * int * mixfix) list -> syntax
wenzelm@383
    30
    val extend_const_gram: syntax -> (string * typ * mixfix) list -> syntax
wenzelm@383
    31
    val extend_consts: syntax -> string list -> syntax
wenzelm@383
    32
    val extend_trfuns: syntax ->
wenzelm@383
    33
      (string * (ast list -> ast)) list *
wenzelm@383
    34
      (string * (term list -> term)) list *
wenzelm@383
    35
      (string * (term list -> term)) list *
wenzelm@383
    36
      (string * (ast list -> ast)) list -> syntax
wenzelm@383
    37
    val extend_trrules: syntax -> xrule list -> syntax
wenzelm@383
    38
  end  (* FIXME *)
wenzelm@383
    39
    val extend: syntax -> (string -> typ) -> string list * string list * sext
wenzelm@383
    40
      -> syntax     (* FIXME *)
wenzelm@383
    41
    val merge_syntaxes: syntax -> syntax -> syntax
wenzelm@383
    42
    val type_syn: syntax
wenzelm@383
    43
    val print_gram: syntax -> unit
wenzelm@383
    44
    val print_trans: syntax -> unit
wenzelm@383
    45
    val print_syntax: syntax -> unit
wenzelm@383
    46
    val test_read: syntax -> string -> string -> unit
wenzelm@383
    47
    val read: syntax -> typ -> string -> term
wenzelm@383
    48
    val read_typ: syntax -> (indexname -> sort) -> string -> typ
wenzelm@383
    49
    val simple_read_typ: string -> typ
wenzelm@383
    50
    val pretty_term: syntax -> term -> Pretty.T
wenzelm@383
    51
    val pretty_typ: syntax -> typ -> Pretty.T
wenzelm@383
    52
    val string_of_term: syntax -> term -> string
wenzelm@383
    53
    val string_of_typ: syntax -> typ -> string
wenzelm@383
    54
    val simple_string_of_typ: typ -> string
wenzelm@383
    55
    val simple_pprint_typ: typ -> pprint_args -> unit
wenzelm@383
    56
clasohm@0
    57
end;
clasohm@0
    58
clasohm@0
    59
functor SyntaxFun(structure Symtab: SYMTAB and TypeExt: TYPE_EXT
wenzelm@383
    60
  and SExtension: SEXTENSION and Mixfix: MIXFIX and Printer: PRINTER
wenzelm@383
    61
  sharing Mixfix.SynExt = SExtension.Parser.SynExt = TypeExt.SynExt = Printer.SynExt)
wenzelm@383
    62
  : SYNTAX =
clasohm@0
    63
struct
clasohm@0
    64
wenzelm@237
    65
structure SynExt = TypeExt.SynExt;
wenzelm@237
    66
structure Parser = SExtension.Parser;
wenzelm@237
    67
structure Lexicon = Parser.Lexicon;
wenzelm@383
    68
structure Mixfix = Mixfix;
wenzelm@237
    69
open Lexicon SynExt SynExt.Ast Parser TypeExt SExtension Printer;
wenzelm@237
    70
wenzelm@237
    71
wenzelm@237
    72
(** tables of translation functions **)
wenzelm@237
    73
wenzelm@237
    74
(*the ref serves as unique id*)
wenzelm@237
    75
type 'a trtab = (('a list -> 'a) * unit ref) Symtab.table;
wenzelm@237
    76
wenzelm@383
    77
val dest_trtab = Symtab.dest;
wenzelm@237
    78
wenzelm@237
    79
fun lookup_trtab tab c =
wenzelm@237
    80
  apsome fst (Symtab.lookup (tab, c));
clasohm@0
    81
clasohm@0
    82
wenzelm@237
    83
(* empty, extend, merge trtabs *)
wenzelm@237
    84
wenzelm@383
    85
fun err_dup_trfuns name cs =
wenzelm@383
    86
  error ("More than one " ^ name ^ " for " ^ commas_quote cs);
wenzelm@237
    87
wenzelm@237
    88
val empty_trtab = Symtab.null;
wenzelm@237
    89
wenzelm@237
    90
fun extend_trtab tab trfuns name =
wenzelm@383
    91
  Symtab.extend_new (tab, map (fn (c, f) => (c, (f, ref ()))) trfuns)
wenzelm@383
    92
    handle Symtab.DUPS cs => err_dup_trfuns name cs;
wenzelm@237
    93
wenzelm@237
    94
fun merge_trtabs tab1 tab2 name =
wenzelm@237
    95
  Symtab.merge eq_snd (tab1, tab2)
wenzelm@383
    96
    handle Symtab.DUPS cs => err_dup_trfuns name cs;
wenzelm@237
    97
wenzelm@237
    98
wenzelm@237
    99
wenzelm@237
   100
(** tables of translation rules **)
wenzelm@237
   101
wenzelm@237
   102
type ruletab = (ast * ast) list Symtab.table;
wenzelm@237
   103
wenzelm@383
   104
fun dest_ruletab tab = flat (map snd (Symtab.dest tab));
wenzelm@237
   105
wenzelm@237
   106
wenzelm@237
   107
(* lookup_ruletab *)
wenzelm@237
   108
wenzelm@237
   109
fun lookup_ruletab tab =
wenzelm@237
   110
  if Symtab.is_null tab then None
wenzelm@237
   111
  else Some (fn a => Symtab.lookup_multi (tab, a));
wenzelm@237
   112
wenzelm@237
   113
wenzelm@237
   114
(* empty, extend, merge ruletabs *)
wenzelm@237
   115
wenzelm@237
   116
val empty_ruletab = Symtab.null;
wenzelm@237
   117
wenzelm@237
   118
fun extend_ruletab tab rules =
wenzelm@237
   119
  generic_extend (op =) Symtab.dest_multi Symtab.make_multi tab
wenzelm@237
   120
    (map (fn r => (head_of_rule r, r)) (distinct rules));
wenzelm@237
   121
wenzelm@237
   122
fun merge_ruletabs tab1 tab2 =
wenzelm@237
   123
  generic_merge (op =) Symtab.dest_multi Symtab.make_multi tab1 tab2;
clasohm@0
   124
clasohm@0
   125
clasohm@0
   126
clasohm@0
   127
(** datatype syntax **)
clasohm@0
   128
wenzelm@237
   129
datatype syntax =
wenzelm@237
   130
  Syntax of {
wenzelm@18
   131
    lexicon: lexicon,
wenzelm@18
   132
    roots: string list,
wenzelm@18
   133
    gram: gram,
wenzelm@18
   134
    consts: string list,
wenzelm@237
   135
    parse_ast_trtab: ast trtab,
wenzelm@237
   136
    parse_ruletab: ruletab,
wenzelm@237
   137
    parse_trtab: term trtab,
wenzelm@237
   138
    print_trtab: term trtab,
wenzelm@237
   139
    print_ruletab: ruletab,
wenzelm@237
   140
    print_ast_trtab: ast trtab,
wenzelm@18
   141
    prtab: prtab};
clasohm@0
   142
wenzelm@18
   143
wenzelm@237
   144
(* empty_syntax *)
wenzelm@18
   145
wenzelm@237
   146
val empty_syntax =
wenzelm@237
   147
  Syntax {
wenzelm@167
   148
    lexicon = empty_lexicon,
wenzelm@167
   149
    roots = [],
wenzelm@171
   150
    gram = empty_gram,
wenzelm@167
   151
    consts = [],
wenzelm@237
   152
    parse_ast_trtab = empty_trtab,
wenzelm@237
   153
    parse_ruletab = empty_ruletab,
wenzelm@237
   154
    parse_trtab = empty_trtab,
wenzelm@237
   155
    print_trtab = empty_trtab,
wenzelm@237
   156
    print_ruletab = empty_ruletab,
wenzelm@237
   157
    print_ast_trtab = empty_trtab,
wenzelm@167
   158
    prtab = empty_prtab};
wenzelm@167
   159
wenzelm@167
   160
wenzelm@237
   161
(* extend_syntax *)
wenzelm@167
   162
wenzelm@237
   163
fun extend_syntax (Syntax tabs) syn_ext =
wenzelm@167
   164
  let
wenzelm@167
   165
    val {lexicon, roots = roots1, gram, consts = consts1, parse_ast_trtab,
wenzelm@237
   166
      parse_ruletab, parse_trtab, print_trtab, print_ruletab, print_ast_trtab,
wenzelm@237
   167
      prtab} = tabs;
wenzelm@237
   168
    val SynExt {roots = roots2, xprods, consts = consts2, parse_ast_translation,
wenzelm@167
   169
      parse_rules, parse_translation, print_translation, print_rules,
wenzelm@237
   170
      print_ast_translation} = syn_ext;
wenzelm@167
   171
  in
wenzelm@237
   172
    Syntax {
wenzelm@237
   173
      lexicon = extend_lexicon lexicon (delims_of xprods),
wenzelm@237
   174
      roots = extend_list roots1 roots2,
wenzelm@237
   175
      gram = extend_gram gram roots2 xprods,
wenzelm@167
   176
      consts = consts2 union consts1,
wenzelm@167
   177
      parse_ast_trtab =
wenzelm@167
   178
        extend_trtab parse_ast_trtab parse_ast_translation "parse ast translation",
wenzelm@167
   179
      parse_ruletab = extend_ruletab parse_ruletab parse_rules,
wenzelm@167
   180
      parse_trtab = extend_trtab parse_trtab parse_translation "parse translation",
wenzelm@167
   181
      print_trtab = extend_trtab print_trtab print_translation "print translation",
wenzelm@167
   182
      print_ruletab = extend_ruletab print_ruletab print_rules,
wenzelm@237
   183
      print_ast_trtab =
wenzelm@237
   184
        extend_trtab print_ast_trtab print_ast_translation "print ast translation",
wenzelm@237
   185
      prtab = extend_prtab prtab xprods}
wenzelm@18
   186
  end;
wenzelm@18
   187
wenzelm@18
   188
wenzelm@237
   189
(* merge_syntaxes *)
clasohm@0
   190
wenzelm@237
   191
fun merge_syntaxes (Syntax tabs1) (Syntax tabs2) =
clasohm@0
   192
  let
wenzelm@237
   193
    val {lexicon = lexicon1, roots = roots1, gram = gram1, consts = consts1,
wenzelm@237
   194
      parse_ast_trtab = parse_ast_trtab1, parse_ruletab = parse_ruletab1,
wenzelm@237
   195
      parse_trtab = parse_trtab1, print_trtab = print_trtab1,
wenzelm@237
   196
      print_ruletab = print_ruletab1, print_ast_trtab = print_ast_trtab1,
wenzelm@237
   197
      prtab = prtab1} = tabs1;
wenzelm@237
   198
wenzelm@237
   199
    val {lexicon = lexicon2, roots = roots2, gram = gram2, consts = consts2,
wenzelm@237
   200
      parse_ast_trtab = parse_ast_trtab2, parse_ruletab = parse_ruletab2,
wenzelm@237
   201
      parse_trtab = parse_trtab2, print_trtab = print_trtab2,
wenzelm@237
   202
      print_ruletab = print_ruletab2, print_ast_trtab = print_ast_trtab2,
wenzelm@237
   203
      prtab = prtab2} = tabs2;
clasohm@0
   204
  in
wenzelm@237
   205
    Syntax {
wenzelm@237
   206
      lexicon = merge_lexicons lexicon1 lexicon2,
wenzelm@237
   207
      roots = merge_lists roots1 roots2,
wenzelm@237
   208
      gram = merge_grams gram1 gram2,
wenzelm@237
   209
      consts = merge_lists consts1 consts2,
wenzelm@237
   210
      parse_ast_trtab =
wenzelm@237
   211
        merge_trtabs parse_ast_trtab1 parse_ast_trtab2 "parse ast translation",
wenzelm@237
   212
      parse_ruletab = merge_ruletabs parse_ruletab1 parse_ruletab2,
wenzelm@237
   213
      parse_trtab = merge_trtabs parse_trtab1 parse_trtab2 "parse translation",
wenzelm@237
   214
      print_trtab = merge_trtabs print_trtab1 print_trtab2 "print translation",
wenzelm@237
   215
      print_ruletab = merge_ruletabs print_ruletab1 print_ruletab2,
wenzelm@237
   216
      print_ast_trtab =
wenzelm@237
   217
        merge_trtabs print_ast_trtab1 print_ast_trtab2 "print ast translation",
wenzelm@237
   218
      prtab = merge_prtabs prtab1 prtab2}
clasohm@0
   219
  end;
clasohm@0
   220
clasohm@0
   221
wenzelm@260
   222
(* type_syn *)
wenzelm@260
   223
wenzelm@260
   224
val type_syn = extend_syntax empty_syntax type_ext;
wenzelm@260
   225
wenzelm@260
   226
clasohm@0
   227
wenzelm@237
   228
(** inspect syntax **)
clasohm@0
   229
wenzelm@260
   230
fun pretty_strs_qs name strs =
wenzelm@260
   231
  Pretty.strs (name :: map quote (sort_strings strs));
clasohm@0
   232
wenzelm@18
   233
wenzelm@18
   234
(* print_gram *)
clasohm@0
   235
wenzelm@237
   236
fun print_gram (Syntax tabs) =
clasohm@0
   237
  let
wenzelm@237
   238
    val {lexicon, roots, gram, ...} = tabs;
clasohm@0
   239
  in
wenzelm@260
   240
    Pretty.writeln (pretty_strs_qs "lexicon:" (dest_lexicon lexicon));
wenzelm@260
   241
    Pretty.writeln (Pretty.strs ("roots:" :: roots));
wenzelm@260
   242
    Pretty.writeln (Pretty.big_list "prods:" (pretty_gram gram))
clasohm@0
   243
  end;
clasohm@0
   244
clasohm@0
   245
wenzelm@18
   246
(* print_trans *)
clasohm@0
   247
wenzelm@237
   248
fun print_trans (Syntax tabs) =
clasohm@0
   249
  let
wenzelm@260
   250
    fun pretty_trtab name tab =
wenzelm@260
   251
      pretty_strs_qs name (map fst (dest_trtab tab));
clasohm@0
   252
wenzelm@260
   253
    fun pretty_ruletab name tab =
wenzelm@260
   254
      Pretty.big_list name (map pretty_rule (dest_ruletab tab));
clasohm@0
   255
wenzelm@237
   256
    val {consts, parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab,
wenzelm@237
   257
      print_ruletab, print_ast_trtab, ...} = tabs;
clasohm@0
   258
  in
wenzelm@260
   259
    Pretty.writeln (pretty_strs_qs "consts:" consts);
wenzelm@260
   260
    Pretty.writeln (pretty_trtab "parse_ast_translation:" parse_ast_trtab);
wenzelm@260
   261
    Pretty.writeln (pretty_ruletab "parse_rules:" parse_ruletab);
wenzelm@260
   262
    Pretty.writeln (pretty_trtab "parse_translation:" parse_trtab);
wenzelm@260
   263
    Pretty.writeln (pretty_trtab "print_translation:" print_trtab);
wenzelm@260
   264
    Pretty.writeln (pretty_ruletab "print_rules:" print_ruletab);
wenzelm@260
   265
    Pretty.writeln (pretty_trtab "print_ast_translation:" print_ast_trtab)
clasohm@0
   266
  end;
clasohm@0
   267
clasohm@0
   268
clasohm@0
   269
(* print_syntax *)
clasohm@0
   270
wenzelm@237
   271
fun print_syntax syn = (print_gram syn; print_trans syn);
clasohm@0
   272
clasohm@0
   273
clasohm@0
   274
wenzelm@237
   275
(** read **)
wenzelm@18
   276
wenzelm@237
   277
(* test_read *)
wenzelm@18
   278
wenzelm@237
   279
fun test_read (Syntax tabs) root str =
wenzelm@18
   280
  let
wenzelm@237
   281
    val {lexicon, gram, parse_ast_trtab, parse_ruletab, ...} = tabs;
wenzelm@18
   282
wenzelm@18
   283
    val toks = tokenize lexicon false str;
clasohm@330
   284
    val _ = writeln ("tokens: " ^ space_implode " " (map display_token toks))
wenzelm@18
   285
wenzelm@383
   286
    fun show_pt pt =
wenzelm@383
   287
      let
wenzelm@383
   288
        val raw_ast = pt_to_ast (K None) pt;
wenzelm@383
   289
        val _ = writeln ("raw: " ^ str_of_ast raw_ast);
wenzelm@383
   290
        val pre_ast = pt_to_ast (lookup_trtab parse_ast_trtab) pt;
wenzelm@383
   291
        val _ = normalize true true (lookup_ruletab parse_ruletab) pre_ast;
wenzelm@383
   292
      in () end;
wenzelm@383
   293
  in
wenzelm@383
   294
    seq show_pt (parse gram root toks)
wenzelm@383
   295
  end;
wenzelm@18
   296
wenzelm@18
   297
wenzelm@260
   298
(* read_ast *)
wenzelm@260
   299
wenzelm@260
   300
fun read_ast (Syntax tabs) xids root str =
wenzelm@260
   301
  let
wenzelm@260
   302
    val {lexicon, gram, parse_ast_trtab, ...} = tabs;
clasohm@330
   303
    val pts = parse gram root (tokenize lexicon xids str);
clasohm@330
   304
wenzelm@383
   305
    fun show_pt pt =
wenzelm@383
   306
      writeln (str_of_ast (pt_to_ast (K None) pt));
wenzelm@260
   307
  in
wenzelm@383
   308
    (case pts of
wenzelm@383
   309
      [pt] => pt_to_ast (lookup_trtab parse_ast_trtab) pt
wenzelm@383
   310
    | _ =>
clasohm@330
   311
      (writeln ("Ambiguous input " ^ quote str);
wenzelm@383
   312
       writeln "produces the following parse trees:"; seq show_pt pts;
wenzelm@383
   313
       error "Please disambiguate the grammar or your input."))
wenzelm@260
   314
  end;
wenzelm@260
   315
wenzelm@260
   316
wenzelm@237
   317
(* read *)
clasohm@0
   318
wenzelm@237
   319
fun read (syn as Syntax tabs) ty str =
clasohm@0
   320
  let
wenzelm@237
   321
    val {parse_ruletab, parse_trtab, ...} = tabs;
wenzelm@18
   322
    val ast = read_ast syn false (typ_to_nonterm ty) str;
clasohm@0
   323
  in
wenzelm@237
   324
    ast_to_term (lookup_trtab parse_trtab)
wenzelm@237
   325
      (normalize_ast (lookup_ruletab parse_ruletab) ast)
clasohm@0
   326
  end;
clasohm@0
   327
clasohm@0
   328
wenzelm@237
   329
(* read types *)
clasohm@0
   330
wenzelm@237
   331
fun read_typ syn def_sort str =
wenzelm@237
   332
  typ_of_term def_sort (read syn typeT str);
wenzelm@144
   333
wenzelm@237
   334
fun simple_read_typ str = read_typ type_syn (K []) str;
wenzelm@144
   335
wenzelm@144
   336
wenzelm@237
   337
(* read rules *)
wenzelm@18
   338
wenzelm@18
   339
fun read_rule syn (xrule as ((_, lhs_src), (_, rhs_src))) =
wenzelm@18
   340
  let
wenzelm@237
   341
    val Syntax {consts, ...} = syn;
wenzelm@18
   342
wenzelm@18
   343
    fun constantify (ast as Constant _) = ast
wenzelm@18
   344
      | constantify (ast as Variable x) =
wenzelm@18
   345
          if x mem consts then Constant x else ast
wenzelm@18
   346
      | constantify (Appl asts) = Appl (map constantify asts);
clasohm@0
   347
wenzelm@18
   348
    fun read_pat (root, str) =
wenzelm@18
   349
      constantify (read_ast syn true root str)
wenzelm@18
   350
        handle ERROR => error ("The error above occurred in " ^ quote str);
wenzelm@18
   351
wenzelm@18
   352
    val rule as (lhs, rhs) = (pairself read_pat) xrule;
wenzelm@18
   353
  in
wenzelm@18
   354
    (case rule_error rule of
wenzelm@18
   355
      Some msg =>
wenzelm@18
   356
        error ("Error in syntax translation rule: " ^ msg ^
wenzelm@18
   357
          "\nexternal: " ^ quote lhs_src ^ "  ->  " ^ quote rhs_src ^
wenzelm@18
   358
          "\ninternal: " ^ str_of_ast lhs ^ "  ->  " ^ str_of_ast rhs)
wenzelm@18
   359
    | None => rule)
wenzelm@18
   360
  end;
clasohm@0
   361
wenzelm@18
   362
fun read_xrules syn xrules =
wenzelm@18
   363
  let
wenzelm@18
   364
    fun right_rule (xpat1 |-> xpat2) = Some (xpat1, xpat2)
wenzelm@18
   365
      | right_rule (xpat1 <-| xpat2) = None
wenzelm@18
   366
      | right_rule (xpat1 <-> xpat2) = Some (xpat1, xpat2);
clasohm@0
   367
wenzelm@18
   368
    fun left_rule (xpat1 |-> xpat2) = None
wenzelm@18
   369
      | left_rule (xpat1 <-| xpat2) = Some (xpat2, xpat1)
wenzelm@18
   370
      | left_rule (xpat1 <-> xpat2) = Some (xpat2, xpat1);
wenzelm@18
   371
  in
wenzelm@18
   372
    (map (read_rule syn) (mapfilter right_rule xrules),
wenzelm@18
   373
     map (read_rule syn) (mapfilter left_rule xrules))
wenzelm@18
   374
  end;
wenzelm@18
   375
wenzelm@18
   376
wenzelm@18
   377
wenzelm@18
   378
(** pretty terms or typs **)
wenzelm@18
   379
wenzelm@237
   380
fun pretty_t t_to_ast pretty_t (syn as Syntax tabs) t =
clasohm@0
   381
  let
wenzelm@237
   382
    val {print_trtab, print_ruletab, print_ast_trtab, prtab, ...} = tabs;
wenzelm@237
   383
    val ast = t_to_ast (lookup_trtab print_trtab) t;
clasohm@0
   384
  in
wenzelm@237
   385
    pretty_t prtab (lookup_trtab print_ast_trtab)
wenzelm@237
   386
      (normalize_ast (lookup_ruletab print_ruletab) ast)
clasohm@0
   387
  end;
clasohm@0
   388
clasohm@0
   389
val pretty_term = pretty_t term_to_ast pretty_term_ast;
clasohm@0
   390
val pretty_typ = pretty_t typ_to_ast pretty_typ_ast;
clasohm@0
   391
clasohm@0
   392
fun string_of_term syn t = Pretty.string_of (pretty_term syn t);
wenzelm@260
   393
fun string_of_typ syn ty = Pretty.string_of (pretty_typ syn ty);
clasohm@0
   394
wenzelm@260
   395
val simple_string_of_typ = string_of_typ type_syn;
wenzelm@260
   396
val simple_pprint_typ = Pretty.pprint o Pretty.quote o (pretty_typ type_syn);
clasohm@0
   397
clasohm@0
   398
clasohm@0
   399
wenzelm@383
   400
(** extend syntax (external interfaces) **)
wenzelm@383
   401
wenzelm@383
   402
(* FIXME -> syn_ext.ML *)
wenzelm@383
   403
fun syn_ext_const_names roots cs =
wenzelm@383
   404
  syn_ext roots [] [] cs ([], [], [], []) ([], []);
wenzelm@383
   405
wenzelm@383
   406
(* FIXME -> syn_ext.ML *)
wenzelm@383
   407
fun syn_ext_trfuns roots trfuns =
wenzelm@383
   408
  syn_ext roots [] [] [] trfuns ([], []);
wenzelm@383
   409
wenzelm@383
   410
wenzelm@383
   411
fun ext_syntax mk_syn_ext (syn as Syntax {roots, ...}) decls =
wenzelm@383
   412
  extend_syntax syn (mk_syn_ext roots decls);
wenzelm@383
   413
wenzelm@167
   414
wenzelm@383
   415
fun extend_log_types (syn as Syntax {roots, ...}) all_roots =
wenzelm@383
   416
  extend_syntax syn (syn_ext_roots all_roots (all_roots \\ roots));
wenzelm@383
   417
wenzelm@383
   418
val extend_type_gram = ext_syntax Mixfix.syn_ext_types;
wenzelm@383
   419
wenzelm@383
   420
val extend_const_gram = ext_syntax Mixfix.syn_ext_consts;
wenzelm@383
   421
wenzelm@383
   422
val extend_consts = ext_syntax syn_ext_const_names;
wenzelm@383
   423
wenzelm@383
   424
val extend_trfuns = ext_syntax syn_ext_trfuns;
wenzelm@383
   425
wenzelm@383
   426
fun extend_trrules syn xrules =
wenzelm@383
   427
  ext_syntax syn_ext_rules syn (read_xrules syn xrules);
wenzelm@383
   428
wenzelm@383
   429
wenzelm@383
   430
(* extend *)    (* FIXME remove *)
wenzelm@167
   431
wenzelm@237
   432
fun extend syn0 read_ty (all_roots, xconsts, sext) =
wenzelm@237
   433
  let
wenzelm@237
   434
    val Syntax {roots, ...} = syn0;
wenzelm@174
   435
wenzelm@237
   436
    val syn1 = extend_syntax syn0
clasohm@330
   437
      (syn_ext_of_sext all_roots (all_roots \\ roots) xconsts read_ty sext);
wenzelm@167
   438
wenzelm@237
   439
    val syn2 = extend_syntax syn1
clasohm@330
   440
      (syn_ext_rules all_roots (read_xrules syn1 (xrules_of sext)));
wenzelm@237
   441
  in syn2 end;
clasohm@0
   442
clasohm@0
   443
clasohm@0
   444
end;
clasohm@0
   445