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