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