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