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