src/Pure/Syntax/syntax.ML
author wenzelm
Mon Aug 20 23:41:43 2007 +0200 (2007-08-20)
changeset 24372 743575ccfec8
parent 24341 7b8da2396c49
child 24488 646e782ba8ff
permissions -rw-r--r--
standard_parse_term: added pp/check argument, include disambig here (from sign.ML);
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@24263
     5
Standard Isabelle syntax, based on arbitrary context-free grammars
wenzelm@24263
     6
(specified by mixfix declarations).
clasohm@0
     7
*)
clasohm@0
     8
wenzelm@260
     9
signature BASIC_SYNTAX =
wenzelm@2383
    10
sig
wenzelm@260
    11
  include AST0
wenzelm@556
    12
  include SYN_TRANS0
wenzelm@556
    13
  include MIXFIX0
wenzelm@260
    14
  include PRINTER0
wenzelm@2383
    15
end;
wenzelm@260
    16
clasohm@0
    17
signature SYNTAX =
wenzelm@2383
    18
sig
wenzelm@260
    19
  include AST1
clasohm@0
    20
  include LEXICON0
wenzelm@237
    21
  include SYN_EXT0
clasohm@0
    22
  include TYPE_EXT0
wenzelm@556
    23
  include SYN_TRANS1
wenzelm@556
    24
  include MIXFIX1
clasohm@0
    25
  include PRINTER0
wenzelm@15755
    26
  val extend_trtab: string -> (string * ('a * stamp)) list ->
wenzelm@15755
    27
    ('a * stamp) Symtab.table -> ('a * stamp) Symtab.table
wenzelm@15755
    28
  val merge_trtabs: string -> ('a * stamp) Symtab.table -> ('a * stamp) Symtab.table ->
wenzelm@15755
    29
    ('a * stamp) Symtab.table
wenzelm@14648
    30
  val merge_tr'tabs: ('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table
wenzelm@14648
    31
    -> ('a * stamp) list Symtab.table
wenzelm@15755
    32
  val extend_tr'tab: (string * ('a * stamp)) list ->
wenzelm@15755
    33
    ('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table
wenzelm@1158
    34
  datatype 'a trrule =
wenzelm@3526
    35
    ParseRule of 'a * 'a |
wenzelm@3526
    36
    PrintRule of 'a * 'a |
wenzelm@3526
    37
    ParsePrintRule of 'a * 'a
wenzelm@556
    38
  type syntax
wenzelm@17079
    39
  val eq_syntax: syntax * syntax -> bool
wenzelm@14687
    40
  val is_keyword: syntax -> string -> bool
wenzelm@20784
    41
  type mode
wenzelm@20784
    42
  val default_mode: mode
wenzelm@21702
    43
  val input_mode: mode
wenzelm@21826
    44
  val internalM: string
wenzelm@12073
    45
  val extend_type_gram: (string * int * mixfix) list -> syntax -> syntax
wenzelm@14904
    46
  val extend_const_gram: (string -> bool) ->
wenzelm@20784
    47
    mode -> (string * typ * mixfix) list -> syntax -> syntax
wenzelm@12073
    48
  val extend_consts: string list -> syntax -> syntax
wenzelm@12073
    49
  val extend_trfuns:
wenzelm@15755
    50
    (string * ((ast list -> ast) * stamp)) list *
wenzelm@15755
    51
    (string * ((term list -> term) * stamp)) list *
wenzelm@15755
    52
    (string * ((bool -> typ -> term list -> term) * stamp)) list *
wenzelm@15755
    53
    (string * ((ast list -> ast) * stamp)) list -> syntax -> syntax
wenzelm@16613
    54
  val extend_advanced_trfuns:
wenzelm@21772
    55
    (string * ((Proof.context -> ast list -> ast) * stamp)) list *
wenzelm@21772
    56
    (string * ((Proof.context -> term list -> term) * stamp)) list *
wenzelm@21772
    57
    (string * ((Proof.context -> bool -> typ -> term list -> term) * stamp)) list *
wenzelm@21772
    58
    (string * ((Proof.context -> ast list -> ast) * stamp)) list -> syntax -> syntax
wenzelm@23660
    59
  val extend_tokentrfuns: (string * string * (string -> output * int)) list -> syntax -> syntax
wenzelm@19262
    60
  val remove_const_gram: (string -> bool) ->
wenzelm@20784
    61
    mode -> (string * typ * mixfix) list -> syntax -> syntax
wenzelm@21772
    62
  val extend_trrules: Proof.context -> (string -> bool) -> syntax ->
wenzelm@14904
    63
    (string * string) trrule list -> syntax -> syntax
wenzelm@21772
    64
  val remove_trrules: Proof.context -> (string -> bool) -> syntax ->
wenzelm@19262
    65
    (string * string) trrule list -> syntax -> syntax
wenzelm@19262
    66
  val extend_trrules_i: ast trrule list -> syntax -> syntax
wenzelm@19262
    67
  val remove_trrules_i: ast trrule list -> syntax -> syntax
wenzelm@4618
    68
  val map_trrule: ('a -> 'b) -> 'a trrule -> 'b trrule
wenzelm@556
    69
  val merge_syntaxes: syntax -> syntax -> syntax
wenzelm@18720
    70
  val basic_syn: syntax
wenzelm@18720
    71
  val basic_nonterms: string list
wenzelm@556
    72
  val print_gram: syntax -> unit
wenzelm@556
    73
  val print_trans: syntax -> unit
wenzelm@556
    74
  val print_syntax: syntax -> unit
wenzelm@21772
    75
  val read: Proof.context -> (string -> bool) -> syntax -> typ -> string -> term list
wenzelm@24372
    76
  val standard_parse_term: Pretty.pp -> (term -> term Exn.result) ->
wenzelm@22703
    77
    (((string * int) * sort) list -> string * int -> Term.sort) ->
wenzelm@22703
    78
    (string -> string option) -> (string -> string option) ->
wenzelm@22703
    79
    (typ -> typ) -> (sort -> sort) -> Proof.context ->
wenzelm@24372
    80
    (string -> bool) -> syntax -> typ -> string -> term
wenzelm@24278
    81
  val standard_parse_typ: Proof.context -> syntax -> ((indexname * sort) list -> indexname -> sort) ->
wenzelm@16613
    82
    (sort -> sort) -> string -> typ
wenzelm@24278
    83
  val standard_parse_sort: Proof.context -> syntax -> (sort -> sort) -> string -> sort
wenzelm@21772
    84
  val pretty_term: (string -> xstring) -> Proof.context -> syntax -> bool -> term -> Pretty.T
wenzelm@21772
    85
  val pretty_typ: Proof.context -> syntax -> typ -> Pretty.T
wenzelm@21772
    86
  val pretty_sort: Proof.context -> syntax -> sort -> Pretty.T
clasohm@882
    87
  val ambiguity_level: int ref
skalberg@14177
    88
  val ambiguity_is_error: bool ref
wenzelm@24263
    89
  val install_parsers:
wenzelm@24263
    90
   {sort: Proof.context -> string -> sort,
wenzelm@24263
    91
    typ: Proof.context -> string -> typ,
wenzelm@24263
    92
    term: Proof.context -> string -> term,
wenzelm@24263
    93
    prop: Proof.context -> string -> term} -> unit
wenzelm@24263
    94
  val parse_sort: Proof.context -> string -> sort
wenzelm@24263
    95
  val parse_typ: Proof.context -> string -> typ
wenzelm@24263
    96
  val parse_term: Proof.context -> string -> term
wenzelm@24263
    97
  val parse_prop: Proof.context -> string -> term
wenzelm@24278
    98
  val global_parse_sort: theory -> string -> sort
wenzelm@24278
    99
  val global_parse_typ: theory -> string -> typ
wenzelm@24278
   100
  val global_parse_term: theory -> string -> term
wenzelm@24278
   101
  val global_parse_prop: theory -> string -> term
wenzelm@24263
   102
  val add_type_check: (term list -> Proof.context -> Term.term list * Proof.context) ->
wenzelm@24263
   103
    Context.generic -> Context.generic
wenzelm@24263
   104
  val type_check: term list -> Proof.context -> term list * Proof.context
wenzelm@24263
   105
  val check_terms: Proof.context -> term list -> term list
wenzelm@24263
   106
  val check_props: Proof.context -> term list -> term list
wenzelm@24263
   107
  val check_typs: Proof.context -> typ list -> typ list
wenzelm@24263
   108
  val read_sort: Proof.context -> string -> sort
wenzelm@24263
   109
  val read_typ: Proof.context -> string -> typ
wenzelm@24263
   110
  val read_terms: Proof.context -> string list -> term list
wenzelm@24263
   111
  val read_props: Proof.context -> string list -> term list
wenzelm@24263
   112
  val read_term: Proof.context -> string -> term
wenzelm@24263
   113
  val read_prop: Proof.context -> string -> term
wenzelm@24278
   114
  val global_read_sort: theory -> string -> sort
wenzelm@24278
   115
  val global_read_typ: theory -> string -> typ
wenzelm@24278
   116
  val global_read_term: theory -> string -> term
wenzelm@24278
   117
  val global_read_prop: theory -> string -> term
wenzelm@2383
   118
end;
clasohm@0
   119
wenzelm@12094
   120
structure Syntax: SYNTAX =
clasohm@0
   121
struct
clasohm@0
   122
wenzelm@237
   123
(** tables of translation functions **)
wenzelm@237
   124
wenzelm@5692
   125
(* parse (ast) translations *)
wenzelm@5692
   126
wenzelm@17412
   127
fun lookup_tr tab c = Option.map fst (Symtab.lookup tab c);
wenzelm@237
   128
wenzelm@23655
   129
fun err_dup_trfun name c =
wenzelm@23655
   130
  error ("More than one " ^ name ^ " for " ^ quote c);
wenzelm@237
   131
wenzelm@21536
   132
fun remove_trtab trfuns = fold (Symtab.remove SynExt.eq_trfun) trfuns;
wenzelm@21536
   133
wenzelm@21536
   134
fun extend_trtab name trfuns tab = Symtab.extend (remove_trtab trfuns tab, trfuns)
wenzelm@23655
   135
  handle Symtab.DUP c => err_dup_trfun name c;
wenzelm@237
   136
wenzelm@15755
   137
fun merge_trtabs name tab1 tab2 = Symtab.merge SynExt.eq_trfun (tab1, tab2)
wenzelm@23655
   138
  handle Symtab.DUP c => err_dup_trfun name c;
wenzelm@237
   139
wenzelm@237
   140
wenzelm@5692
   141
(* print (ast) translations *)
wenzelm@5692
   142
wenzelm@18931
   143
fun lookup_tr' tab c = map fst (Symtab.lookup_list tab c);
wenzelm@18931
   144
fun extend_tr'tab trfuns = fold_rev Symtab.update_list trfuns;
wenzelm@18931
   145
fun remove_tr'tab trfuns = fold (Symtab.remove_list SynExt.eq_trfun) trfuns;
wenzelm@18931
   146
fun merge_tr'tabs tab1 tab2 = Symtab.merge_list SynExt.eq_trfun (tab1, tab2);
wenzelm@5692
   147
wenzelm@5692
   148
wenzelm@237
   149
wenzelm@2700
   150
(** tables of token translation functions **)
wenzelm@2700
   151
wenzelm@2700
   152
fun lookup_tokentr tabs modes =
wenzelm@19482
   153
  let val trs = distinct (eq_fst (op =)) (maps (these o AList.lookup (op =) tabs) (modes @ [""]))
haftmann@17314
   154
  in fn c => Option.map fst (AList.lookup (op =) trs c) end;
wenzelm@2700
   155
wenzelm@2700
   156
fun merge_tokentrtabs tabs1 tabs2 =
wenzelm@2700
   157
  let
wenzelm@2700
   158
    fun eq_tr ((c1, (_, s1)), (c2, (_, s2))) = c1 = c2 andalso s1 = s2;
wenzelm@2700
   159
wenzelm@4703
   160
    fun name (s, _) = implode (tl (Symbol.explode s));
wenzelm@2706
   161
wenzelm@2700
   162
    fun merge mode =
wenzelm@2700
   163
      let
wenzelm@17213
   164
        val trs1 = these (AList.lookup (op =) tabs1 mode);
wenzelm@17213
   165
        val trs2 = these (AList.lookup (op =) tabs2 mode);
wenzelm@19046
   166
        val trs = distinct eq_tr (trs1 @ trs2);
wenzelm@2700
   167
      in
wenzelm@18964
   168
        (case duplicates (eq_fst (op =)) trs of
wenzelm@2700
   169
          [] => (mode, trs)
wenzelm@2700
   170
        | dups => error ("More than one token translation function in mode " ^
wenzelm@2706
   171
            quote mode ^ " for " ^ commas_quote (map name dups)))
wenzelm@2700
   172
      end;
wenzelm@19046
   173
  in map merge (distinct (op =) (map fst (tabs1 @ tabs2))) end;
wenzelm@2700
   174
wenzelm@15755
   175
fun extend_tokentrtab tokentrs tabs =
wenzelm@2700
   176
  let
wenzelm@17213
   177
    fun ins_tokentr (m, c, f) =
wenzelm@17213
   178
      AList.default (op =) (m, [])
wenzelm@17213
   179
      #> AList.map_entry (op =) m (cons ("_" ^ c, (f, stamp ())));
wenzelm@15759
   180
  in merge_tokentrtabs tabs (fold ins_tokentr tokentrs []) end;
wenzelm@2700
   181
wenzelm@2700
   182
wenzelm@2700
   183
wenzelm@237
   184
(** tables of translation rules **)
wenzelm@237
   185
wenzelm@5692
   186
type ruletab = (Ast.ast * Ast.ast) list Symtab.table;
wenzelm@237
   187
wenzelm@19482
   188
fun dest_ruletab tab = maps snd (Symtab.dest tab);
wenzelm@237
   189
wenzelm@237
   190
wenzelm@237
   191
(* empty, extend, merge ruletabs *)
wenzelm@237
   192
wenzelm@18931
   193
val extend_ruletab = fold_rev (fn r => Symtab.update_list (Ast.head_of_rule r, r));
wenzelm@18931
   194
val remove_ruletab = fold (fn r => Symtab.remove_list (op =) (Ast.head_of_rule r, r));
wenzelm@18931
   195
fun merge_ruletabs tab1 tab2 = Symtab.merge_list (op =) (tab1, tab2);
clasohm@0
   196
clasohm@0
   197
clasohm@0
   198
clasohm@0
   199
(** datatype syntax **)
clasohm@0
   200
wenzelm@237
   201
datatype syntax =
wenzelm@237
   202
  Syntax of {
wenzelm@15755
   203
    input: SynExt.xprod list,
wenzelm@4703
   204
    lexicon: Scan.lexicon,
wenzelm@5692
   205
    gram: Parser.gram,
wenzelm@18
   206
    consts: string list,
wenzelm@2913
   207
    prmodes: string list,
wenzelm@21772
   208
    parse_ast_trtab: ((Proof.context -> Ast.ast list -> Ast.ast) * stamp) Symtab.table,
wenzelm@237
   209
    parse_ruletab: ruletab,
wenzelm@21772
   210
    parse_trtab: ((Proof.context -> term list -> term) * stamp) Symtab.table,
wenzelm@21772
   211
    print_trtab: ((Proof.context -> bool -> typ -> term list -> term) * stamp) list Symtab.table,
wenzelm@237
   212
    print_ruletab: ruletab,
wenzelm@21772
   213
    print_ast_trtab: ((Proof.context -> Ast.ast list -> Ast.ast) * stamp) list Symtab.table,
wenzelm@23660
   214
    tokentrtab: (string * (string * ((string -> output * int) * stamp)) list) list,
wenzelm@17079
   215
    prtabs: Printer.prtabs} * stamp;
clasohm@0
   216
wenzelm@17079
   217
fun eq_syntax (Syntax (_, s1), Syntax (_, s2)) = s1 = s2;
wenzelm@17079
   218
wenzelm@17079
   219
fun is_keyword (Syntax ({lexicon, ...}, _)) = Scan.is_literal lexicon o Symbol.explode;
wenzelm@14687
   220
wenzelm@20784
   221
type mode = string * bool;
wenzelm@15755
   222
val default_mode = ("", true);
wenzelm@21702
   223
val input_mode = ("input", true);
wenzelm@21826
   224
val internalM = "internal";
wenzelm@15755
   225
wenzelm@18
   226
wenzelm@237
   227
(* empty_syntax *)
wenzelm@18
   228
wenzelm@17079
   229
val empty_syntax = Syntax
wenzelm@17079
   230
  ({input = [],
wenzelm@4703
   231
    lexicon = Scan.empty_lexicon,
wenzelm@5692
   232
    gram = Parser.empty_gram,
wenzelm@167
   233
    consts = [],
wenzelm@2913
   234
    prmodes = [],
wenzelm@5692
   235
    parse_ast_trtab = Symtab.empty,
wenzelm@5692
   236
    parse_ruletab = Symtab.empty,
wenzelm@5692
   237
    parse_trtab = Symtab.empty,
wenzelm@5692
   238
    print_trtab = Symtab.empty,
wenzelm@5692
   239
    print_ruletab = Symtab.empty,
wenzelm@5692
   240
    print_ast_trtab = Symtab.empty,
wenzelm@2700
   241
    tokentrtab = [],
wenzelm@17079
   242
    prtabs = Printer.empty_prtabs}, stamp ());
wenzelm@167
   243
wenzelm@167
   244
wenzelm@237
   245
(* extend_syntax *)
wenzelm@167
   246
wenzelm@17079
   247
fun extend_syntax (mode, inout) syn_ext (Syntax (tabs, _)) =
wenzelm@167
   248
  let
wenzelm@15755
   249
    val {input, lexicon, gram, consts = consts1, prmodes = prmodes1,
wenzelm@2366
   250
      parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab,
wenzelm@2700
   251
      print_ast_trtab, tokentrtab, prtabs} = tabs;
wenzelm@14904
   252
    val SynExt.SynExt {xprods, consts = consts2, prmodes = prmodes2,
wenzelm@2913
   253
      parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules,
wenzelm@2700
   254
      print_ast_translation, token_translation} = syn_ext;
wenzelm@19546
   255
    fun if_inout xs = if inout then xs else [];
wenzelm@167
   256
  in
wenzelm@17079
   257
    Syntax
wenzelm@19546
   258
    ({input = if_inout xprods @ input,
wenzelm@22121
   259
      lexicon = Scan.extend_lexicon (if_inout (SynExt.delims_of xprods)) lexicon,
wenzelm@19546
   260
      gram = Parser.extend_gram gram (if_inout xprods),
wenzelm@19546
   261
      consts = Library.merge (op =) (consts1, filter_out NameSpace.is_qualified consts2),
wenzelm@18921
   262
      prmodes = insert (op =) mode (Library.merge (op =) (prmodes1, prmodes2)),
wenzelm@167
   263
      parse_ast_trtab =
wenzelm@19546
   264
        extend_trtab "parse ast translation" (if_inout parse_ast_translation) parse_ast_trtab,
wenzelm@19546
   265
      parse_ruletab = extend_ruletab (if_inout parse_rules) parse_ruletab,
wenzelm@19546
   266
      parse_trtab = extend_trtab "parse translation" (if_inout parse_translation) parse_trtab,
wenzelm@15755
   267
      print_trtab = extend_tr'tab print_translation print_trtab,
wenzelm@15755
   268
      print_ruletab = extend_ruletab print_rules print_ruletab,
wenzelm@15755
   269
      print_ast_trtab = extend_tr'tab print_ast_translation print_ast_trtab,
wenzelm@15755
   270
      tokentrtab = extend_tokentrtab token_translation tokentrtab,
wenzelm@17079
   271
      prtabs = Printer.extend_prtabs mode xprods prtabs}, stamp ())
wenzelm@18
   272
  end;
wenzelm@18
   273
wenzelm@15755
   274
wenzelm@15755
   275
(* remove_syntax *)
wenzelm@15755
   276
wenzelm@17079
   277
fun remove_syntax (mode, inout) syn_ext (Syntax (tabs, _)) =
wenzelm@15755
   278
  let
wenzelm@15755
   279
    val SynExt.SynExt {xprods, consts = _, prmodes = _,
wenzelm@15755
   280
      parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules,
wenzelm@15755
   281
      print_ast_translation, token_translation = _} = syn_ext;
wenzelm@15755
   282
    val {input, lexicon, gram, consts, prmodes,
wenzelm@15755
   283
      parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab,
wenzelm@15755
   284
      print_ast_trtab, tokentrtab, prtabs} = tabs;
wenzelm@19300
   285
    val input' = if inout then subtract (op =) xprods input else input;
wenzelm@19546
   286
    fun if_inout xs = if inout then xs else [];
wenzelm@15755
   287
  in
wenzelm@17079
   288
    Syntax
wenzelm@17079
   289
    ({input = input',
wenzelm@15755
   290
      lexicon = if inout then Scan.make_lexicon (SynExt.delims_of input') else lexicon,
wenzelm@15755
   291
      gram = if inout then Parser.make_gram input' else gram,
wenzelm@15755
   292
      consts = consts,
wenzelm@15755
   293
      prmodes = prmodes,
wenzelm@19546
   294
      parse_ast_trtab = remove_trtab (if_inout parse_ast_translation) parse_ast_trtab,
wenzelm@19546
   295
      parse_ruletab = remove_ruletab (if_inout parse_rules) parse_ruletab,
wenzelm@19546
   296
      parse_trtab = remove_trtab (if_inout parse_translation) parse_trtab,
wenzelm@15755
   297
      print_trtab = remove_tr'tab print_translation print_trtab,
wenzelm@15755
   298
      print_ruletab = remove_ruletab print_rules print_ruletab,
wenzelm@15755
   299
      print_ast_trtab = remove_tr'tab print_ast_translation print_ast_trtab,
wenzelm@15755
   300
      tokentrtab = tokentrtab,
wenzelm@17079
   301
      prtabs = Printer.remove_prtabs mode xprods prtabs}, stamp ())
wenzelm@15755
   302
  end;
wenzelm@14904
   303
wenzelm@18
   304
wenzelm@237
   305
(* merge_syntaxes *)
clasohm@0
   306
wenzelm@17079
   307
fun merge_syntaxes (Syntax (tabs1, _)) (Syntax (tabs2, _)) =
clasohm@0
   308
  let
wenzelm@15755
   309
    val {input = input1, lexicon = lexicon1, gram = gram1, consts = consts1,
wenzelm@15755
   310
      prmodes = prmodes1, parse_ast_trtab = parse_ast_trtab1,
wenzelm@15755
   311
      parse_ruletab = parse_ruletab1, parse_trtab = parse_trtab1,
wenzelm@15755
   312
      print_trtab = print_trtab1, print_ruletab = print_ruletab1,
wenzelm@15755
   313
      print_ast_trtab = print_ast_trtab1, tokentrtab = tokentrtab1, prtabs = prtabs1} = tabs1;
wenzelm@237
   314
wenzelm@15755
   315
    val {input = input2, lexicon = lexicon2, gram = gram2, consts = consts2,
wenzelm@15755
   316
      prmodes = prmodes2, parse_ast_trtab = parse_ast_trtab2,
wenzelm@15755
   317
      parse_ruletab = parse_ruletab2, parse_trtab = parse_trtab2,
wenzelm@15755
   318
      print_trtab = print_trtab2, print_ruletab = print_ruletab2,
wenzelm@15755
   319
      print_ast_trtab = print_ast_trtab2, tokentrtab = tokentrtab2, prtabs = prtabs2} = tabs2;
clasohm@0
   320
  in
wenzelm@17079
   321
    Syntax
wenzelm@18921
   322
    ({input = Library.merge (op =) (input1, input2),
wenzelm@4703
   323
      lexicon = Scan.merge_lexicons lexicon1 lexicon2,
wenzelm@5692
   324
      gram = Parser.merge_grams gram1 gram2,
wenzelm@18428
   325
      consts = sort_distinct string_ord (consts1 @ consts2),
wenzelm@18921
   326
      prmodes = Library.merge (op =) (prmodes1, prmodes2),
wenzelm@237
   327
      parse_ast_trtab =
wenzelm@15755
   328
        merge_trtabs "parse ast translation" parse_ast_trtab1 parse_ast_trtab2,
wenzelm@237
   329
      parse_ruletab = merge_ruletabs parse_ruletab1 parse_ruletab2,
wenzelm@15755
   330
      parse_trtab = merge_trtabs "parse translation" parse_trtab1 parse_trtab2,
wenzelm@5692
   331
      print_trtab = merge_tr'tabs print_trtab1 print_trtab2,
wenzelm@237
   332
      print_ruletab = merge_ruletabs print_ruletab1 print_ruletab2,
wenzelm@5692
   333
      print_ast_trtab = merge_tr'tabs print_ast_trtab1 print_ast_trtab2,
wenzelm@2700
   334
      tokentrtab = merge_tokentrtabs tokentrtab1 tokentrtab2,
wenzelm@17079
   335
      prtabs = Printer.merge_prtabs prtabs1 prtabs2}, stamp ())
clasohm@0
   336
  end;
clasohm@0
   337
clasohm@0
   338
wenzelm@18720
   339
(* basic syntax *)
wenzelm@260
   340
wenzelm@18720
   341
val basic_syn =
wenzelm@17168
   342
  empty_syntax
wenzelm@17168
   343
  |> extend_syntax default_mode TypeExt.type_ext
wenzelm@17168
   344
  |> extend_syntax default_mode SynExt.pure_ext;
wenzelm@260
   345
wenzelm@18720
   346
val basic_nonterms =
wenzelm@18720
   347
  (Lexicon.terminals @ [SynExt.logic, "type", "types", "sort", "classes",
wenzelm@18720
   348
    SynExt.args, SynExt.cargs, "pttrn", "pttrns", "idt", "idts", "aprop",
wenzelm@22573
   349
    "asms", SynExt.any_, SynExt.sprop, "num_const", "index", "struct"]);
wenzelm@18720
   350
clasohm@0
   351
wenzelm@4887
   352
wenzelm@15759
   353
(** print syntax **)
wenzelm@15759
   354
wenzelm@15759
   355
local
clasohm@0
   356
wenzelm@260
   357
fun pretty_strs_qs name strs =
berghofe@14598
   358
  Pretty.strs (name :: map Library.quote (sort_strings strs));
clasohm@0
   359
wenzelm@17079
   360
fun pretty_gram (Syntax (tabs, _)) =
clasohm@0
   361
  let
wenzelm@14904
   362
    val {lexicon, prmodes, gram, prtabs, ...} = tabs;
wenzelm@2913
   363
    val prmodes' = sort_strings (filter_out (equal "") prmodes);
clasohm@0
   364
  in
wenzelm@8720
   365
    [pretty_strs_qs "lexicon:" (Scan.dest_lexicon lexicon),
wenzelm@8720
   366
      Pretty.big_list "prods:" (Parser.pretty_gram gram),
wenzelm@8720
   367
      pretty_strs_qs "print modes:" prmodes']
clasohm@0
   368
  end;
clasohm@0
   369
wenzelm@17079
   370
fun pretty_trans (Syntax (tabs, _)) =
clasohm@0
   371
  let
wenzelm@260
   372
    fun pretty_trtab name tab =
wenzelm@5692
   373
      pretty_strs_qs name (Symtab.keys tab);
clasohm@0
   374
wenzelm@260
   375
    fun pretty_ruletab name tab =
wenzelm@5692
   376
      Pretty.big_list name (map Ast.pretty_rule (dest_ruletab tab));
clasohm@0
   377
berghofe@14598
   378
    fun pretty_tokentr (mode, trs) = Pretty.strs (Library.quote mode ^ ":" :: map fst trs);
wenzelm@4703
   379
wenzelm@237
   380
    val {consts, parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab,
wenzelm@4703
   381
      print_ruletab, print_ast_trtab, tokentrtab, ...} = tabs;
clasohm@0
   382
  in
wenzelm@8720
   383
    [pretty_strs_qs "consts:" consts,
wenzelm@8720
   384
      pretty_trtab "parse_ast_translation:" parse_ast_trtab,
wenzelm@8720
   385
      pretty_ruletab "parse_rules:" parse_ruletab,
wenzelm@8720
   386
      pretty_trtab "parse_translation:" parse_trtab,
wenzelm@8720
   387
      pretty_trtab "print_translation:" print_trtab,
wenzelm@8720
   388
      pretty_ruletab "print_rules:" print_ruletab,
wenzelm@8720
   389
      pretty_trtab "print_ast_translation:" print_ast_trtab,
wenzelm@8720
   390
      Pretty.big_list "token_translation:" (map pretty_tokentr tokentrtab)]
clasohm@0
   391
  end;
clasohm@0
   392
wenzelm@15759
   393
in
clasohm@0
   394
wenzelm@15759
   395
fun print_gram syn = Pretty.writeln (Pretty.chunks (pretty_gram syn));
wenzelm@15759
   396
fun print_trans syn = Pretty.writeln (Pretty.chunks (pretty_trans syn));
wenzelm@15759
   397
fun print_syntax syn = Pretty.writeln (Pretty.chunks (pretty_gram syn @ pretty_trans syn));
clasohm@0
   398
wenzelm@15759
   399
end;
clasohm@0
   400
clasohm@0
   401
clasohm@0
   402
wenzelm@237
   403
(** read **)
wenzelm@18
   404
wenzelm@260
   405
(* read_ast *)
wenzelm@260
   406
clasohm@882
   407
val ambiguity_level = ref 1;
wenzelm@24263
   408
val ambiguity_is_error = ref false;
clasohm@882
   409
wenzelm@21772
   410
fun read_asts ctxt is_logtype (Syntax (tabs, _)) xids root str =
wenzelm@260
   411
  let
wenzelm@14904
   412
    val {lexicon, gram, parse_ast_trtab, ...} = tabs;
wenzelm@14904
   413
    val root' = if root <> "prop" andalso is_logtype root then SynExt.logic else root;
wenzelm@4703
   414
    val chars = Symbol.explode str;
wenzelm@5692
   415
    val pts = Parser.parse gram root' (Lexicon.tokenize lexicon xids chars);
clasohm@330
   416
wenzelm@12292
   417
    fun show_pt pt =
wenzelm@21772
   418
      Pretty.string_of (Ast.pretty_ast (hd (SynTrans.pts_to_asts ctxt (K NONE) [pt])));
wenzelm@260
   419
  in
wenzelm@21962
   420
    if length pts > ! ambiguity_level then
wenzelm@16613
   421
      if ! ambiguity_is_error then error ("Ambiguous input " ^ quote str)
wenzelm@16661
   422
      else (warning ("Ambiguous input " ^ quote str ^ "\n" ^
wenzelm@16716
   423
          "produces " ^ string_of_int (length pts) ^ " parse trees.");
wenzelm@21962
   424
         List.app (warning o show_pt) pts)
wenzelm@21962
   425
    else ();
wenzelm@21772
   426
    SynTrans.pts_to_asts ctxt (lookup_tr parse_ast_trtab) pts
wenzelm@260
   427
  end;
wenzelm@260
   428
wenzelm@260
   429
wenzelm@237
   430
(* read *)
clasohm@0
   431
wenzelm@21772
   432
fun read ctxt is_logtype (syn as Syntax (tabs, _)) ty str =
clasohm@0
   433
  let
wenzelm@237
   434
    val {parse_ruletab, parse_trtab, ...} = tabs;
wenzelm@21772
   435
    val asts = read_asts ctxt is_logtype syn false (SynExt.typ_to_nonterm ty) str;
clasohm@0
   436
  in
wenzelm@21772
   437
    SynTrans.asts_to_terms ctxt (lookup_tr parse_trtab)
wenzelm@18931
   438
      (map (Ast.normalize_ast (Symtab.lookup_list parse_ruletab)) asts)
clasohm@0
   439
  end;
clasohm@0
   440
clasohm@0
   441
wenzelm@22703
   442
(* read terms *)
wenzelm@22703
   443
wenzelm@24372
   444
(*brute-force disambiguation via type-inference*)
wenzelm@24372
   445
fun disambig _ _ [t] = t
wenzelm@24372
   446
  | disambig pp check ts =
wenzelm@24372
   447
      let
wenzelm@24372
   448
        val err_results = map check ts;
wenzelm@24372
   449
        val errs = map_filter (fn Exn.Exn (ERROR msg) => SOME msg | _ => NONE) err_results;
wenzelm@24372
   450
        val results = map_filter Exn.get_result err_results;
wenzelm@24372
   451
wenzelm@24372
   452
        val ambiguity = length ts;
wenzelm@24372
   453
        fun ambig_msg () =
wenzelm@24372
   454
          if ambiguity > 1 andalso ambiguity <= ! ambiguity_level then
wenzelm@24372
   455
            "Got more than one parse tree.\n\
wenzelm@24372
   456
            \Retry with smaller ambiguity_level for more information."
wenzelm@24372
   457
          else "";
wenzelm@24372
   458
      in
wenzelm@24372
   459
        if null results then cat_error (ambig_msg ()) (cat_lines errs)
wenzelm@24372
   460
        else if length results = 1 then
wenzelm@24372
   461
          (if ambiguity > ! ambiguity_level then
wenzelm@24372
   462
            warning "Fortunately, only one parse tree is type correct.\n\
wenzelm@24372
   463
              \You may still want to disambiguate your grammar or your input."
wenzelm@24372
   464
          else (); hd results)
wenzelm@24372
   465
        else cat_error (ambig_msg ()) ("More than one term is type correct:\n" ^
wenzelm@24372
   466
          cat_lines (map (Pretty.string_of_term pp) ts))
wenzelm@24372
   467
      end;
wenzelm@24372
   468
wenzelm@24372
   469
fun standard_parse_term pp check get_sort map_const map_free map_type map_sort
wenzelm@24372
   470
    ctxt is_logtype syn ty str =
wenzelm@24372
   471
  read ctxt is_logtype syn ty str
wenzelm@24372
   472
  |> map (TypeExt.decode_term get_sort map_const map_free map_type map_sort)
wenzelm@24372
   473
  |> disambig (Printer.pp_show_brackets pp) check;
wenzelm@22703
   474
wenzelm@22703
   475
wenzelm@237
   476
(* read types *)
clasohm@0
   477
wenzelm@24278
   478
fun standard_parse_typ ctxt syn get_sort map_sort str =
wenzelm@21772
   479
  (case read ctxt (K false) syn SynExt.typeT str of
wenzelm@22703
   480
    [t] => TypeExt.typ_of_term (get_sort (TypeExt.term_sorts map_sort t)) map_sort t
wenzelm@8894
   481
  | _ => error "read_typ: ambiguous syntax");
wenzelm@144
   482
wenzelm@144
   483
wenzelm@8894
   484
(* read sorts *)
wenzelm@8894
   485
wenzelm@24278
   486
fun standard_parse_sort ctxt syn map_sort str =
wenzelm@21772
   487
  (case read ctxt (K false) syn TypeExt.sortT str of
wenzelm@22703
   488
    [t] => TypeExt.sort_of_term map_sort t
wenzelm@8894
   489
  | _ => error "read_sort: ambiguous syntax");
wenzelm@8894
   490
wenzelm@8894
   491
wenzelm@18
   492
wenzelm@1158
   493
(** prepare translation rules **)
wenzelm@1158
   494
wenzelm@1158
   495
datatype 'a trrule =
wenzelm@3526
   496
  ParseRule of 'a * 'a |
wenzelm@3526
   497
  PrintRule of 'a * 'a |
wenzelm@3526
   498
  ParsePrintRule of 'a * 'a;
wenzelm@888
   499
wenzelm@4618
   500
fun map_trrule f (ParseRule (x, y)) = ParseRule (f x, f y)
wenzelm@4618
   501
  | map_trrule f (PrintRule (x, y)) = PrintRule (f x, f y)
wenzelm@4618
   502
  | map_trrule f (ParsePrintRule (x, y)) = ParsePrintRule (f x, f y);
wenzelm@1158
   503
skalberg@15531
   504
fun parse_rule (ParseRule pats) = SOME pats
skalberg@15531
   505
  | parse_rule (PrintRule _) = NONE
skalberg@15531
   506
  | parse_rule (ParsePrintRule pats) = SOME pats;
wenzelm@1158
   507
skalberg@15531
   508
fun print_rule (ParseRule _) = NONE
skalberg@15531
   509
  | print_rule (PrintRule pats) = SOME (swap pats)
skalberg@15531
   510
  | print_rule (ParsePrintRule pats) = SOME (swap pats);
wenzelm@1158
   511
wenzelm@1158
   512
wenzelm@19262
   513
local
wenzelm@19262
   514
wenzelm@1158
   515
fun check_rule (rule as (lhs, rhs)) =
wenzelm@5692
   516
  (case Ast.rule_error rule of
skalberg@15531
   517
    SOME msg =>
wenzelm@1158
   518
      error ("Error in syntax translation rule: " ^ msg ^ "\n" ^
wenzelm@5692
   519
        Ast.str_of_ast lhs ^ "  ->  " ^ Ast.str_of_ast rhs)
skalberg@15531
   520
  | NONE => rule);
wenzelm@888
   521
wenzelm@888
   522
wenzelm@21772
   523
fun read_pattern ctxt is_logtype syn (root, str) =
wenzelm@18
   524
  let
wenzelm@17079
   525
    val Syntax ({consts, ...}, _) = syn;
wenzelm@18
   526
wenzelm@5692
   527
    fun constify (ast as Ast.Constant _) = ast
wenzelm@5692
   528
      | constify (ast as Ast.Variable x) =
wenzelm@20664
   529
          if member (op =) consts x orelse NameSpace.is_qualified x then Ast.Constant x
wenzelm@3830
   530
          else ast
wenzelm@5692
   531
      | constify (Ast.Appl asts) = Ast.Appl (map constify asts);
wenzelm@18
   532
  in
wenzelm@21772
   533
    (case read_asts ctxt is_logtype syn true root str of
wenzelm@888
   534
      [ast] => constify ast
wenzelm@888
   535
    | _ => error ("Syntactically ambiguous input: " ^ quote str))
wenzelm@18678
   536
  end handle ERROR msg =>
wenzelm@18678
   537
    cat_error msg ("The error(s) above occurred in translation pattern " ^
wenzelm@888
   538
      quote str);
clasohm@0
   539
wenzelm@1158
   540
fun prep_rules rd_pat raw_rules =
wenzelm@4618
   541
  let val rules = map (map_trrule rd_pat) raw_rules in
wenzelm@19482
   542
    (map check_rule (map_filter parse_rule rules),
wenzelm@19482
   543
      map check_rule (map_filter print_rule rules))
wenzelm@1158
   544
  end
wenzelm@18
   545
wenzelm@19262
   546
in
wenzelm@19262
   547
wenzelm@19262
   548
val cert_rules = prep_rules I;
wenzelm@19262
   549
wenzelm@21772
   550
fun read_rules ctxt is_logtype syn =
wenzelm@21772
   551
  prep_rules (read_pattern ctxt is_logtype syn);
wenzelm@19262
   552
wenzelm@19262
   553
end;
wenzelm@19262
   554
wenzelm@18
   555
wenzelm@18
   556
wenzelm@3779
   557
(** pretty terms, typs, sorts **)
wenzelm@18
   558
wenzelm@23631
   559
fun pretty_t t_to_ast prt_t markup ctxt (syn as Syntax (tabs, _)) curried t =
clasohm@0
   560
  let
wenzelm@2700
   561
    val {print_trtab, print_ruletab, print_ast_trtab, tokentrtab, prtabs, ...} = tabs;
wenzelm@21772
   562
    val ast = t_to_ast ctxt (lookup_tr' print_trtab) t;
clasohm@0
   563
  in
wenzelm@23631
   564
    Pretty.markup markup (prt_t ctxt curried prtabs (lookup_tr' print_ast_trtab)
oheimb@6167
   565
      (lookup_tokentr tokentrtab (! print_mode))
wenzelm@23631
   566
      (Ast.normalize_ast (Symtab.lookup_list print_ruletab) ast))
clasohm@0
   567
  end;
clasohm@0
   568
wenzelm@23631
   569
fun pretty_term extern =
wenzelm@23631
   570
  pretty_t Printer.term_to_ast (Printer.pretty_term_ast extern) Markup.term;
wenzelm@23631
   571
fun pretty_typ ctxt syn =
wenzelm@23631
   572
  pretty_t Printer.typ_to_ast Printer.pretty_typ_ast Markup.typ ctxt syn false;
wenzelm@23631
   573
fun pretty_sort ctxt syn =
wenzelm@23631
   574
  pretty_t Printer.sort_to_ast Printer.pretty_typ_ast Markup.sort ctxt syn false;
clasohm@0
   575
clasohm@0
   576
clasohm@0
   577
wenzelm@19262
   578
(** modify syntax **)
wenzelm@383
   579
wenzelm@14904
   580
fun ext_syntax' f is_logtype prmode decls = extend_syntax prmode (f is_logtype decls);
wenzelm@14904
   581
fun ext_syntax f = ext_syntax' (K f) (K false) default_mode;
wenzelm@383
   582
wenzelm@16613
   583
val extend_type_gram       = ext_syntax Mixfix.syn_ext_types;
wenzelm@16613
   584
val extend_const_gram      = ext_syntax' Mixfix.syn_ext_consts;
wenzelm@16613
   585
val extend_consts          = ext_syntax SynExt.syn_ext_const_names;
wenzelm@16613
   586
val extend_trfuns          = ext_syntax SynExt.syn_ext_trfuns;
wenzelm@16613
   587
val extend_advanced_trfuns = ext_syntax SynExt.syn_ext_advanced_trfuns;
wenzelm@16613
   588
val extend_tokentrfuns     = ext_syntax SynExt.syn_ext_tokentrfuns;
wenzelm@5692
   589
wenzelm@15755
   590
fun remove_const_gram is_logtype prmode decls =
wenzelm@15755
   591
  remove_syntax prmode (Mixfix.syn_ext_consts is_logtype decls);
wenzelm@15755
   592
wenzelm@21772
   593
fun extend_trrules ctxt is_logtype syn =
wenzelm@21772
   594
  ext_syntax SynExt.syn_ext_rules o read_rules ctxt is_logtype syn;
wenzelm@19262
   595
wenzelm@21772
   596
fun remove_trrules ctxt is_logtype syn =
wenzelm@21772
   597
  remove_syntax default_mode o SynExt.syn_ext_rules o read_rules ctxt is_logtype syn;
wenzelm@19262
   598
wenzelm@19262
   599
val extend_trrules_i = ext_syntax SynExt.syn_ext_rules o cert_rules;
wenzelm@19262
   600
val remove_trrules_i = remove_syntax default_mode o SynExt.syn_ext_rules o cert_rules;
wenzelm@5692
   601
wenzelm@5692
   602
wenzelm@24263
   603
wenzelm@24263
   604
(** generic parsing and type-checking **)
wenzelm@24263
   605
wenzelm@24263
   606
(* parsing *)
wenzelm@24263
   607
wenzelm@24263
   608
type parsers =
wenzelm@24263
   609
 {sort: Proof.context -> string -> sort,
wenzelm@24263
   610
  typ: Proof.context -> string -> typ,
wenzelm@24263
   611
  term: Proof.context -> string -> term,
wenzelm@24263
   612
  prop: Proof.context -> string -> term};
wenzelm@24263
   613
wenzelm@24263
   614
local
wenzelm@24263
   615
  val parsers = ref (NONE: parsers option);
wenzelm@24263
   616
in
wenzelm@24263
   617
  fun install_parsers ps = CRITICAL (fn () =>
wenzelm@24263
   618
    if is_some (! parsers) then error "Inner syntax parsers already installed"
wenzelm@24263
   619
    else parsers := SOME ps);
wenzelm@24263
   620
wenzelm@24263
   621
  fun parse which ctxt s =
wenzelm@24263
   622
    (case ! parsers of
wenzelm@24263
   623
      NONE => error "Inner syntax parsers not yet installed"
wenzelm@24263
   624
    | SOME ps => which ps ctxt s);
wenzelm@24263
   625
end;
wenzelm@24263
   626
wenzelm@24263
   627
val parse_sort = parse #sort;
wenzelm@24263
   628
val parse_typ = parse #typ;
wenzelm@24263
   629
val parse_term = parse #term;
wenzelm@24263
   630
val parse_prop = parse #prop;
wenzelm@24263
   631
wenzelm@24278
   632
val global_parse_sort = parse_sort o ProofContext.init;
wenzelm@24278
   633
val global_parse_typ = parse_typ o ProofContext.init;
wenzelm@24278
   634
val global_parse_term = parse_term o ProofContext.init;
wenzelm@24278
   635
val global_parse_prop = parse_prop o ProofContext.init;
wenzelm@24278
   636
wenzelm@24263
   637
wenzelm@24263
   638
(* type-checking *)
wenzelm@24263
   639
wenzelm@24263
   640
structure TypeCheck = GenericDataFun
wenzelm@24263
   641
(
wenzelm@24263
   642
  type T = ((term list -> Proof.context -> term list * Proof.context) * stamp) list;
wenzelm@24263
   643
  val empty = [];
wenzelm@24263
   644
  val extend = I;
wenzelm@24263
   645
  fun merge _ type_checks : T = Library.merge (eq_snd op =) type_checks;
wenzelm@24263
   646
);
wenzelm@24263
   647
wenzelm@24263
   648
fun add_type_check f = TypeCheck.map (cons (f, stamp ()));
wenzelm@24263
   649
wenzelm@24263
   650
fun type_check ts0 ctxt0 =
wenzelm@24263
   651
  let
wenzelm@24341
   652
    val funs = map #1 (rev (TypeCheck.get (Context.Proof ctxt0)));
wenzelm@24263
   653
    fun check [] ts ctxt = (ts, ctxt)
wenzelm@24341
   654
      | check (f :: fs) ts ctxt = f ts ctxt |-> check fs;
wenzelm@24263
   655
wenzelm@24263
   656
    fun check_fixpoint ts ctxt =
wenzelm@24263
   657
      let val (ts', ctxt') = check funs ts ctxt in
wenzelm@24263
   658
        if eq_list (op aconv) (ts, ts') then (ts, ctxt)
wenzelm@24263
   659
        else check_fixpoint ts' ctxt'
wenzelm@24263
   660
      end;
wenzelm@24341
   661
  in (case funs of [f] => f ts0 ctxt0 | _ => check_fixpoint ts0 ctxt0) end;
wenzelm@24263
   662
wenzelm@24263
   663
fun check_terms ctxt ts = #1 (type_check ts ctxt);
wenzelm@24263
   664
fun check_props ctxt = map (fn t => TypeInfer.constrain t propT) #> check_terms ctxt;
wenzelm@24263
   665
fun check_typs ctxt = map Logic.mk_type #> check_terms ctxt #> map Logic.dest_type;
wenzelm@24263
   666
wenzelm@24263
   667
fun check_sort ctxt S =
wenzelm@24263
   668
  (case singleton (check_typs ctxt) (TFree ("", S)) of   (* FIXME TypeInfer.invent_type (!?) *)
wenzelm@24263
   669
    TFree ("", S') => S'
wenzelm@24263
   670
  | T => raise TYPE ("check_sort", [T], []));
wenzelm@24263
   671
wenzelm@24263
   672
wenzelm@24263
   673
(* combined operations *)
wenzelm@24263
   674
wenzelm@24263
   675
fun read_sort ctxt = parse_sort ctxt #> check_sort ctxt;
wenzelm@24263
   676
fun read_typ ctxt = parse_typ ctxt #> singleton (check_typs ctxt);
wenzelm@24263
   677
wenzelm@24263
   678
fun read_terms ctxt = map (parse_term ctxt) #> check_terms ctxt;
wenzelm@24263
   679
fun read_props ctxt = map (parse_prop ctxt) #> check_props ctxt;
wenzelm@24263
   680
wenzelm@24263
   681
val read_term = singleton o read_terms;
wenzelm@24263
   682
val read_prop = singleton o read_props;
wenzelm@24263
   683
wenzelm@24278
   684
val global_read_sort = read_sort o ProofContext.init;
wenzelm@24278
   685
val global_read_typ = read_typ o ProofContext.init;
wenzelm@24278
   686
val global_read_term = read_term o ProofContext.init;
wenzelm@24278
   687
val global_read_prop = read_prop o ProofContext.init;
wenzelm@24278
   688
wenzelm@24263
   689
wenzelm@15833
   690
(*export parts of internal Syntax structures*)
wenzelm@15833
   691
open Lexicon SynExt Ast Parser TypeExt SynTrans Mixfix Printer;
wenzelm@2366
   692
clasohm@0
   693
end;
wenzelm@5692
   694
wenzelm@5692
   695
structure BasicSyntax: BASIC_SYNTAX = Syntax;
wenzelm@5692
   696
open BasicSyntax;
wenzelm@23923
   697
wenzelm@23923
   698
structure Hidden = struct end;
wenzelm@23923
   699
structure Ast = Hidden;
wenzelm@23923
   700
structure SynExt = Hidden;
wenzelm@23923
   701
structure Parser = Hidden;
wenzelm@23923
   702
structure TypeExt = Hidden;
wenzelm@23923
   703
structure SynTrans = Hidden;
wenzelm@23923
   704
structure Mixfix = Hidden;
wenzelm@23923
   705
structure Printer = Hidden;