src/Pure/Syntax/syntax.ML
author wenzelm
Tue, 31 Jan 2006 00:39:40 +0100
changeset 18857 c4b4fbd74ffb
parent 18720 dd1ebba12151
child 18921 f47c46d7d654
permissions -rw-r--r--
advanced translations: Context.generic;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     1
(*  Title:      Pure/Syntax/syntax.ML
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     4
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
     5
Root of Isabelle's syntax module.
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
     8
signature BASIC_SYNTAX =
2383
4127499d9b52 added extend_trfunsT;
wenzelm
parents: 2366
diff changeset
     9
sig
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
    10
  include AST0
556
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    11
  include SYN_TRANS0
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    12
  include MIXFIX0
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
    13
  include PRINTER0
2383
4127499d9b52 added extend_trfunsT;
wenzelm
parents: 2366
diff changeset
    14
end;
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
    15
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
signature SYNTAX =
2383
4127499d9b52 added extend_trfunsT;
wenzelm
parents: 2366
diff changeset
    17
sig
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
    18
  include AST1
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
  include LEXICON0
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
    20
  include SYN_EXT0
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
  include TYPE_EXT0
556
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    22
  include SYN_TRANS1
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    23
  include MIXFIX1
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
  include PRINTER0
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    25
  val extend_trtab: string -> (string * ('a * stamp)) list ->
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    26
    ('a * stamp) Symtab.table -> ('a * stamp) Symtab.table
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    27
  val merge_trtabs: string -> ('a * stamp) Symtab.table -> ('a * stamp) Symtab.table ->
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    28
    ('a * stamp) Symtab.table
14648
0e67b385a6df tuned interfaces to accomodate advanced translation functions;
wenzelm
parents: 14598
diff changeset
    29
  val merge_tr'tabs: ('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table
0e67b385a6df tuned interfaces to accomodate advanced translation functions;
wenzelm
parents: 14598
diff changeset
    30
    -> ('a * stamp) list Symtab.table
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    31
  val extend_tr'tab: (string * ('a * stamp)) list ->
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    32
    ('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
    33
  datatype 'a trrule =
3526
df4d0dad2b4e tuned warning;
wenzelm
parents: 2913
diff changeset
    34
    ParseRule of 'a * 'a |
df4d0dad2b4e tuned warning;
wenzelm
parents: 2913
diff changeset
    35
    PrintRule of 'a * 'a |
df4d0dad2b4e tuned warning;
wenzelm
parents: 2913
diff changeset
    36
    ParsePrintRule of 'a * 'a
556
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    37
  type syntax
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
    38
  val eq_syntax: syntax * syntax -> bool
14687
e089757b952a added is_keyword;
wenzelm
parents: 14648
diff changeset
    39
  val is_keyword: syntax -> string -> bool
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    40
  val default_mode: string * bool
12073
b4401452928e extend_XXX: sane argument order ... -> syntax -> syntax;
wenzelm
parents: 11546
diff changeset
    41
  val extend_type_gram: (string * int * mixfix) list -> syntax -> syntax
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
    42
  val extend_const_gram: (string -> bool) ->
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
    43
    string * bool -> (string * typ * mixfix) list -> syntax -> syntax
12073
b4401452928e extend_XXX: sane argument order ... -> syntax -> syntax;
wenzelm
parents: 11546
diff changeset
    44
  val extend_consts: string list -> syntax -> syntax
b4401452928e extend_XXX: sane argument order ... -> syntax -> syntax;
wenzelm
parents: 11546
diff changeset
    45
  val extend_trfuns:
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    46
    (string * ((ast list -> ast) * stamp)) list *
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    47
    (string * ((term list -> term) * stamp)) list *
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    48
    (string * ((bool -> typ -> term list -> term) * stamp)) list *
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    49
    (string * ((ast list -> ast) * stamp)) list -> syntax -> syntax
16613
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
    50
  val extend_advanced_trfuns:
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    51
    (string * ((Context.generic -> ast list -> ast) * stamp)) list *
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    52
    (string * ((Context.generic -> term list -> term) * stamp)) list *
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    53
    (string * ((Context.generic -> bool -> typ -> term list -> term) * stamp)) list *
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    54
    (string * ((Context.generic -> ast list -> ast) * stamp)) list -> syntax -> syntax
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    55
  val extend_tokentrfuns: (string * string * (string -> string * real)) list -> syntax -> syntax
12073
b4401452928e extend_XXX: sane argument order ... -> syntax -> syntax;
wenzelm
parents: 11546
diff changeset
    56
  val extend_trrules_i: ast trrule list -> syntax -> syntax
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    57
  val extend_trrules: Context.generic -> (string -> bool) -> syntax ->
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
    58
    (string * string) trrule list -> syntax -> syntax
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    59
  val remove_const_gram: (string -> bool) ->
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    60
    string * bool -> (string * typ * mixfix) list -> syntax -> syntax
4618
731bed12f762 export map_trrule;
wenzelm
parents: 4496
diff changeset
    61
  val map_trrule: ('a -> 'b) -> 'a trrule -> 'b trrule
556
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    62
  val merge_syntaxes: syntax -> syntax -> syntax
18720
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
    63
  val basic_syn: syntax
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
    64
  val basic_nonterms: string list
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
    65
  val appl_syntax: (string * string * mixfix) list
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
    66
  val applC_syntax: (string * string * mixfix) list
556
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    67
  val print_gram: syntax -> unit
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    68
  val print_trans: syntax -> unit
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
    69
  val print_syntax: syntax -> unit
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    70
  val read: Context.generic -> (string -> bool) -> syntax -> typ -> string -> term list
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    71
  val read_typ: Context.generic -> syntax -> ((indexname * sort) list -> indexname -> sort) ->
16613
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
    72
    (sort -> sort) -> string -> typ
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    73
  val read_sort: Context.generic -> syntax -> string -> sort
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    74
  val pretty_term: Context.generic -> syntax -> bool -> term -> Pretty.T
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    75
  val pretty_typ: Context.generic -> syntax -> typ -> Pretty.T
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
    76
  val pretty_sort: Context.generic -> syntax -> sort -> Pretty.T
882
b118d1ea0dfd moved ambiguity_level from sign.ML to Syntax/syntax.ML
clasohm
parents: 865
diff changeset
    77
  val ambiguity_level: int ref
14177
06b19a7e675a Added 'ambiguity_is_error' flag, which, if set, makes the parser fail,
skalberg
parents: 12785
diff changeset
    78
  val ambiguity_is_error: bool ref
2383
4127499d9b52 added extend_trfunsT;
wenzelm
parents: 2366
diff changeset
    79
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    80
12094
wenzelm
parents: 12073
diff changeset
    81
structure Syntax: SYNTAX =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    82
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    83
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
    84
(** tables of translation functions **)
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
    85
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
    86
(* parse (ast) translations *)
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
    87
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
    88
fun lookup_tr tab c = Option.map fst (Symtab.lookup tab c);
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
    89
383
fcea89074e4c added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents: 330
diff changeset
    90
fun err_dup_trfuns name cs =
fcea89074e4c added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents: 330
diff changeset
    91
  error ("More than one " ^ name ^ " for " ^ commas_quote cs);
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
    92
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    93
fun extend_trtab name trfuns tab = Symtab.extend (tab, trfuns)
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    94
  handle Symtab.DUPS cs => err_dup_trfuns name cs;
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
    95
15759
wenzelm
parents: 15755
diff changeset
    96
fun remove_trtab trfuns = fold (Symtab.remove SynExt.eq_trfun) trfuns;
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    97
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    98
fun merge_trtabs name tab1 tab2 = Symtab.merge SynExt.eq_trfun (tab1, tab2)
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
    99
  handle Symtab.DUPS cs => err_dup_trfuns name cs;
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   100
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   101
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   102
(* print (ast) translations *)
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   103
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
   104
fun lookup_tr' tab c = map fst (Symtab.lookup_multi tab c);
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
   105
fun extend_tr'tab trfuns = fold_rev Symtab.update_multi trfuns;
15759
wenzelm
parents: 15755
diff changeset
   106
fun remove_tr'tab trfuns = fold (Symtab.remove_multi SynExt.eq_trfun) trfuns;
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   107
fun merge_tr'tabs tab1 tab2 = Symtab.merge_multi' SynExt.eq_trfun (tab1, tab2);
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   108
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   109
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   110
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   111
(** tables of token translation functions **)
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   112
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   113
fun lookup_tokentr tabs modes =
17496
26535df536ae slight adaptions to library changes
haftmann
parents: 17412
diff changeset
   114
  let val trs = gen_distinct (eq_fst (op =))
17192
0cfbf76ed313 introduced AList.*
haftmann
parents: 17168
diff changeset
   115
    (List.concat (map (these o AList.lookup (op =) tabs) (modes @ [""])))
17314
04e21a27c0ad introduces some modern-style AList operations
haftmann
parents: 17221
diff changeset
   116
  in fn c => Option.map fst (AList.lookup (op =) trs c) end;
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   117
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   118
fun merge_tokentrtabs tabs1 tabs2 =
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   119
  let
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   120
    fun eq_tr ((c1, (_, s1)), (c2, (_, s2))) = c1 = c2 andalso s1 = s2;
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   121
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4618
diff changeset
   122
    fun name (s, _) = implode (tl (Symbol.explode s));
2706
91a640a91c6e improved err msg;
wenzelm
parents: 2700
diff changeset
   123
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   124
    fun merge mode =
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   125
      let
17213
ba65f3e5653c fixed ins_tokentr: AList.default;
wenzelm
parents: 17192
diff changeset
   126
        val trs1 = these (AList.lookup (op =) tabs1 mode);
ba65f3e5653c fixed ins_tokentr: AList.default;
wenzelm
parents: 17192
diff changeset
   127
        val trs2 = these (AList.lookup (op =) tabs2 mode);
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   128
        val trs = gen_distinct eq_tr (trs1 @ trs2);
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   129
      in
17496
26535df536ae slight adaptions to library changes
haftmann
parents: 17412
diff changeset
   130
        (case gen_duplicates (eq_fst (op =)) trs of
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   131
          [] => (mode, trs)
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   132
        | dups => error ("More than one token translation function in mode " ^
2706
91a640a91c6e improved err msg;
wenzelm
parents: 2700
diff changeset
   133
            quote mode ^ " for " ^ commas_quote (map name dups)))
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   134
      end;
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   135
  in
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   136
    map merge (distinct (map fst (tabs1 @ tabs2)))
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   137
  end;
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   138
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   139
fun extend_tokentrtab tokentrs tabs =
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   140
  let
17213
ba65f3e5653c fixed ins_tokentr: AList.default;
wenzelm
parents: 17192
diff changeset
   141
    fun ins_tokentr (m, c, f) =
ba65f3e5653c fixed ins_tokentr: AList.default;
wenzelm
parents: 17192
diff changeset
   142
      AList.default (op =) (m, [])
ba65f3e5653c fixed ins_tokentr: AList.default;
wenzelm
parents: 17192
diff changeset
   143
      #> AList.map_entry (op =) m (cons ("_" ^ c, (f, stamp ())));
15759
wenzelm
parents: 15755
diff changeset
   144
  in merge_tokentrtabs tabs (fold ins_tokentr tokentrs []) end;
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   145
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   146
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   147
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   148
(** tables of translation rules **)
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   149
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   150
type ruletab = (Ast.ast * Ast.ast) list Symtab.table;
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   151
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   152
fun dest_ruletab tab = List.concat (map snd (Symtab.dest tab));
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   153
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   154
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   155
(* empty, extend, merge ruletabs *)
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   156
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
   157
val extend_ruletab = fold_rev (fn r => Symtab.update_multi (Ast.head_of_rule r, r));
15759
wenzelm
parents: 15755
diff changeset
   158
val remove_ruletab = fold (fn r => Symtab.remove_multi (op =) (Ast.head_of_rule r, r));
12292
c4090cc2aa15 Symtab.merge_multi';
wenzelm
parents: 12094
diff changeset
   159
fun merge_ruletabs tab1 tab2 = Symtab.merge_multi' (op =) (tab1, tab2);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   160
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   161
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   162
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   163
(** datatype syntax **)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   165
datatype syntax =
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   166
  Syntax of {
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   167
    input: SynExt.xprod list,
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4618
diff changeset
   168
    lexicon: Scan.lexicon,
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   169
    gram: Parser.gram,
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   170
    consts: string list,
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2706
diff changeset
   171
    prmodes: string list,
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   172
    parse_ast_trtab: ((Context.generic -> Ast.ast list -> Ast.ast) * stamp) Symtab.table,
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   173
    parse_ruletab: ruletab,
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   174
    parse_trtab: ((Context.generic -> term list -> term) * stamp) Symtab.table,
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   175
    print_trtab: ((Context.generic -> bool -> typ -> term list -> term) * stamp) list Symtab.table,
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   176
    print_ruletab: ruletab,
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   177
    print_ast_trtab: ((Context.generic -> Ast.ast list -> Ast.ast) * stamp) list Symtab.table,
6322
7047300264c9 token translation: real;
wenzelm
parents: 6167
diff changeset
   178
    tokentrtab: (string * (string * ((string -> string * real) * stamp)) list) list,
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   179
    prtabs: Printer.prtabs} * stamp;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   180
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   181
fun eq_syntax (Syntax (_, s1), Syntax (_, s2)) = s1 = s2;
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   182
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   183
fun is_keyword (Syntax ({lexicon, ...}, _)) = Scan.is_literal lexicon o Symbol.explode;
14687
e089757b952a added is_keyword;
wenzelm
parents: 14648
diff changeset
   184
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   185
val default_mode = ("", true);
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   186
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   187
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   188
(* empty_syntax *)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   189
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   190
val empty_syntax = Syntax
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   191
  ({input = [],
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4618
diff changeset
   192
    lexicon = Scan.empty_lexicon,
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   193
    gram = Parser.empty_gram,
167
128e122acc89 added (partial) extend_tables;
wenzelm
parents: 144
diff changeset
   194
    consts = [],
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2706
diff changeset
   195
    prmodes = [],
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   196
    parse_ast_trtab = Symtab.empty,
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   197
    parse_ruletab = Symtab.empty,
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   198
    parse_trtab = Symtab.empty,
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   199
    print_trtab = Symtab.empty,
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   200
    print_ruletab = Symtab.empty,
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   201
    print_ast_trtab = Symtab.empty,
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   202
    tokentrtab = [],
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   203
    prtabs = Printer.empty_prtabs}, stamp ());
167
128e122acc89 added (partial) extend_tables;
wenzelm
parents: 144
diff changeset
   204
128e122acc89 added (partial) extend_tables;
wenzelm
parents: 144
diff changeset
   205
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   206
(* extend_syntax *)
167
128e122acc89 added (partial) extend_tables;
wenzelm
parents: 144
diff changeset
   207
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   208
fun extend_syntax (mode, inout) syn_ext (Syntax (tabs, _)) =
167
128e122acc89 added (partial) extend_tables;
wenzelm
parents: 144
diff changeset
   209
  let
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   210
    val {input, lexicon, gram, consts = consts1, prmodes = prmodes1,
2366
a163d2be1bb5 added chartrans;
wenzelm
parents: 2287
diff changeset
   211
      parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab,
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   212
      print_ast_trtab, tokentrtab, prtabs} = tabs;
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   213
    val SynExt.SynExt {xprods, consts = consts2, prmodes = prmodes2,
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2706
diff changeset
   214
      parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules,
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   215
      print_ast_translation, token_translation} = syn_ext;
167
128e122acc89 added (partial) extend_tables;
wenzelm
parents: 144
diff changeset
   216
  in
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   217
    Syntax
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   218
    ({input = if inout then xprods @ input else input,
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   219
      lexicon = if inout then Scan.extend_lexicon lexicon (SynExt.delims_of xprods) else lexicon,
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   220
      gram = if inout then Parser.extend_gram gram xprods else gram,
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   221
      consts = merge_lists' consts1 consts2,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   222
      prmodes = mode ins_string (merge_lists' prmodes1 prmodes2),
167
128e122acc89 added (partial) extend_tables;
wenzelm
parents: 144
diff changeset
   223
      parse_ast_trtab =
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   224
        extend_trtab "parse ast translation" parse_ast_translation parse_ast_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   225
      parse_ruletab = extend_ruletab parse_rules parse_ruletab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   226
      parse_trtab = extend_trtab "parse translation" parse_translation parse_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   227
      print_trtab = extend_tr'tab print_translation print_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   228
      print_ruletab = extend_ruletab print_rules print_ruletab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   229
      print_ast_trtab = extend_tr'tab print_ast_translation print_ast_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   230
      tokentrtab = extend_tokentrtab token_translation tokentrtab,
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   231
      prtabs = Printer.extend_prtabs mode xprods prtabs}, stamp ())
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   232
  end;
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   233
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   234
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   235
(* remove_syntax *)
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   236
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   237
fun remove_syntax (mode, inout) syn_ext (Syntax (tabs, _)) =
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   238
  let
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   239
    val SynExt.SynExt {xprods, consts = _, prmodes = _,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   240
      parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   241
      print_ast_translation, token_translation = _} = syn_ext;
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   242
    val {input, lexicon, gram, consts, prmodes,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   243
      parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   244
      print_ast_trtab, tokentrtab, prtabs} = tabs;
15759
wenzelm
parents: 15755
diff changeset
   245
    val input' = if inout then fold (remove (op =)) xprods input else input;
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   246
  in
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   247
    Syntax
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   248
    ({input = input',
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   249
      lexicon = if inout then Scan.make_lexicon (SynExt.delims_of input') else lexicon,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   250
      gram = if inout then Parser.make_gram input' else gram,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   251
      consts = consts,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   252
      prmodes = prmodes,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   253
      parse_ast_trtab = remove_trtab parse_ast_translation parse_ast_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   254
      parse_ruletab = remove_ruletab parse_rules parse_ruletab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   255
      parse_trtab = remove_trtab parse_translation parse_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   256
      print_trtab = remove_tr'tab print_translation print_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   257
      print_ruletab = remove_ruletab print_rules print_ruletab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   258
      print_ast_trtab = remove_tr'tab print_ast_translation print_ast_trtab,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   259
      tokentrtab = tokentrtab,
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   260
      prtabs = Printer.remove_prtabs mode xprods prtabs}, stamp ())
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   261
  end;
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   262
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   263
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   264
(* merge_syntaxes *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   265
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   266
fun merge_syntaxes (Syntax (tabs1, _)) (Syntax (tabs2, _)) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   267
  let
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   268
    val {input = input1, lexicon = lexicon1, gram = gram1, consts = consts1,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   269
      prmodes = prmodes1, parse_ast_trtab = parse_ast_trtab1,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   270
      parse_ruletab = parse_ruletab1, parse_trtab = parse_trtab1,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   271
      print_trtab = print_trtab1, print_ruletab = print_ruletab1,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   272
      print_ast_trtab = print_ast_trtab1, tokentrtab = tokentrtab1, prtabs = prtabs1} = tabs1;
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   273
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   274
    val {input = input2, lexicon = lexicon2, gram = gram2, consts = consts2,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   275
      prmodes = prmodes2, parse_ast_trtab = parse_ast_trtab2,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   276
      parse_ruletab = parse_ruletab2, parse_trtab = parse_trtab2,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   277
      print_trtab = print_trtab2, print_ruletab = print_ruletab2,
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   278
      print_ast_trtab = print_ast_trtab2, tokentrtab = tokentrtab2, prtabs = prtabs2} = tabs2;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   279
  in
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   280
    Syntax
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   281
    ({input = merge_lists' input1 input2,
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4618
diff changeset
   282
      lexicon = Scan.merge_lexicons lexicon1 lexicon2,
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   283
      gram = Parser.merge_grams gram1 gram2,
18428
4059413acbc1 sort_distinct;
wenzelm
parents: 17496
diff changeset
   284
      consts = sort_distinct string_ord (consts1 @ consts2),
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2706
diff changeset
   285
      prmodes = merge_lists prmodes1 prmodes2,
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   286
      parse_ast_trtab =
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   287
        merge_trtabs "parse ast translation" parse_ast_trtab1 parse_ast_trtab2,
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   288
      parse_ruletab = merge_ruletabs parse_ruletab1 parse_ruletab2,
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   289
      parse_trtab = merge_trtabs "parse translation" parse_trtab1 parse_trtab2,
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   290
      print_trtab = merge_tr'tabs print_trtab1 print_trtab2,
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   291
      print_ruletab = merge_ruletabs print_ruletab1 print_ruletab2,
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   292
      print_ast_trtab = merge_tr'tabs print_ast_trtab1 print_ast_trtab2,
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   293
      tokentrtab = merge_tokentrtabs tokentrtab1 tokentrtab2,
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   294
      prtabs = Printer.merge_prtabs prtabs1 prtabs2}, stamp ())
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   295
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   296
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   297
18720
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   298
(* basic syntax *)
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   299
18720
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   300
val basic_syn =
17168
e7951b191048 removed obsolete type_syn;
wenzelm
parents: 17079
diff changeset
   301
  empty_syntax
e7951b191048 removed obsolete type_syn;
wenzelm
parents: 17079
diff changeset
   302
  |> extend_syntax default_mode TypeExt.type_ext
e7951b191048 removed obsolete type_syn;
wenzelm
parents: 17079
diff changeset
   303
  |> extend_syntax default_mode SynExt.pure_ext;
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   304
18720
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   305
val basic_nonterms =
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   306
  (Lexicon.terminals @ [SynExt.logic, "type", "types", "sort", "classes",
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   307
    SynExt.args, SynExt.cargs, "pttrn", "pttrns", "idt", "idts", "aprop",
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   308
    "asms", SynExt.any, SynExt.sprop, "num_const", "index", "struct"]);
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   309
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   310
val appl_syntax =
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   311
 [("_appl", "[('b => 'a), args] => logic", Mixfix.Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   312
  ("_appl", "[('b => 'a), args] => aprop", Mixfix.Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   313
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   314
val applC_syntax =
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   315
 [("",       "'a => cargs",                  Mixfix.Delimfix "_"),
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   316
  ("_cargs", "['a, cargs] => cargs",         Mixfix.Mixfix ("_/ _", [1000, 1000], 1000)),
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   317
  ("_applC", "[('b => 'a), cargs] => logic", Mixfix.Mixfix ("(1_/ _)", [1000, 1000], 999)),
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   318
  ("_applC", "[('b => 'a), cargs] => aprop", Mixfix.Mixfix ("(1_/ _)", [1000, 1000], 999))];
dd1ebba12151 added basic syntax;
wenzelm
parents: 18678
diff changeset
   319
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   320
4887
bbc13af86c16 added trfun_names;
wenzelm
parents: 4703
diff changeset
   321
15759
wenzelm
parents: 15755
diff changeset
   322
(** print syntax **)
wenzelm
parents: 15755
diff changeset
   323
wenzelm
parents: 15755
diff changeset
   324
local
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   325
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   326
fun pretty_strs_qs name strs =
14598
7009f59711e3 Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents: 14177
diff changeset
   327
  Pretty.strs (name :: map Library.quote (sort_strings strs));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   328
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   329
fun pretty_gram (Syntax (tabs, _)) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   330
  let
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   331
    val {lexicon, prmodes, gram, prtabs, ...} = tabs;
2913
ce271fa4d8e2 fixed diagnostic output of print modes;
wenzelm
parents: 2706
diff changeset
   332
    val prmodes' = sort_strings (filter_out (equal "") prmodes);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   333
  in
8720
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   334
    [pretty_strs_qs "lexicon:" (Scan.dest_lexicon lexicon),
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   335
      Pretty.big_list "prods:" (Parser.pretty_gram gram),
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   336
      pretty_strs_qs "print modes:" prmodes']
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   337
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   338
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   339
fun pretty_trans (Syntax (tabs, _)) =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   340
  let
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   341
    fun pretty_trtab name tab =
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   342
      pretty_strs_qs name (Symtab.keys tab);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   343
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   344
    fun pretty_ruletab name tab =
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   345
      Pretty.big_list name (map Ast.pretty_rule (dest_ruletab tab));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   346
14598
7009f59711e3 Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents: 14177
diff changeset
   347
    fun pretty_tokentr (mode, trs) = Pretty.strs (Library.quote mode ^ ":" :: map fst trs);
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4618
diff changeset
   348
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   349
    val {consts, parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab,
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4618
diff changeset
   350
      print_ruletab, print_ast_trtab, tokentrtab, ...} = tabs;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   351
  in
8720
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   352
    [pretty_strs_qs "consts:" consts,
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   353
      pretty_trtab "parse_ast_translation:" parse_ast_trtab,
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   354
      pretty_ruletab "parse_rules:" parse_ruletab,
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   355
      pretty_trtab "parse_translation:" parse_trtab,
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   356
      pretty_trtab "print_translation:" print_trtab,
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   357
      pretty_ruletab "print_rules:" print_ruletab,
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   358
      pretty_trtab "print_ast_translation:" print_ast_trtab,
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   359
      Pretty.big_list "token_translation:" (map pretty_tokentr tokentrtab)]
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   360
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   361
15759
wenzelm
parents: 15755
diff changeset
   362
in
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   363
15759
wenzelm
parents: 15755
diff changeset
   364
fun print_gram syn = Pretty.writeln (Pretty.chunks (pretty_gram syn));
wenzelm
parents: 15755
diff changeset
   365
fun print_trans syn = Pretty.writeln (Pretty.chunks (pretty_trans syn));
wenzelm
parents: 15755
diff changeset
   366
fun print_syntax syn = Pretty.writeln (Pretty.chunks (pretty_gram syn @ pretty_trans syn));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   367
15759
wenzelm
parents: 15755
diff changeset
   368
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   369
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   370
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   371
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   372
(** read **)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   373
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   374
(* read_ast *)
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   375
882
b118d1ea0dfd moved ambiguity_level from sign.ML to Syntax/syntax.ML
clasohm
parents: 865
diff changeset
   376
val ambiguity_level = ref 1;
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   377
val ambiguity_is_error = ref false
882
b118d1ea0dfd moved ambiguity_level from sign.ML to Syntax/syntax.ML
clasohm
parents: 865
diff changeset
   378
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   379
fun read_asts context is_logtype (Syntax (tabs, _)) xids root str =
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   380
  let
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   381
    val {lexicon, gram, parse_ast_trtab, ...} = tabs;
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   382
    val root' = if root <> "prop" andalso is_logtype root then SynExt.logic else root;
4703
a50ab39756db adapted to symbols, scan;
wenzelm
parents: 4618
diff changeset
   383
    val chars = Symbol.explode str;
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   384
    val pts = Parser.parse gram root' (Lexicon.tokenize lexicon xids chars);
330
2fda15dd1e0f changed the way a grammar is generated to allow the new parser to work;
clasohm
parents: 260
diff changeset
   385
12292
c4090cc2aa15 Symtab.merge_multi';
wenzelm
parents: 12094
diff changeset
   386
    fun show_pt pt =
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   387
      Pretty.string_of (Ast.pretty_ast (hd (SynTrans.pts_to_asts context (K NONE) [pt])));
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   388
  in
16613
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   389
    conditional (length pts > ! ambiguity_level) (fn () =>
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   390
      if ! ambiguity_is_error then error ("Ambiguous input " ^ quote str)
16661
507438b27f66 use tracing for potentially voluminous ambiguity output;
wenzelm
parents: 16613
diff changeset
   391
      else (warning ("Ambiguous input " ^ quote str ^ "\n" ^
16716
57fd954ee326 tuned msg;
wenzelm
parents: 16669
diff changeset
   392
          "produces " ^ string_of_int (length pts) ^ " parse trees.");
16669
4748b1adad9c ambig msg: warning again;
wenzelm
parents: 16661
diff changeset
   393
         List.app (warning o show_pt) pts));
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   394
    SynTrans.pts_to_asts context (lookup_tr parse_ast_trtab) pts
260
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   395
  end;
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   396
967813b8a7bf added simple_string_of_typ, simple_pprint_typ;
wenzelm
parents: 237
diff changeset
   397
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   398
(* read *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   399
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   400
fun read context is_logtype (syn as Syntax (tabs, _)) ty str =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   401
  let
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   402
    val {parse_ruletab, parse_trtab, ...} = tabs;
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   403
    val asts = read_asts context is_logtype syn false (SynExt.typ_to_nonterm ty) str;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   404
  in
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   405
    SynTrans.asts_to_terms context (lookup_tr parse_trtab)
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
   406
      (map (Ast.normalize_ast (Symtab.lookup_multi parse_ruletab)) asts)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   407
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   408
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   409
237
a7d3e712767a MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents: 175
diff changeset
   410
(* read types *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   411
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   412
fun read_typ context syn get_sort map_sort str =
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   413
  (case read context (K false) syn SynExt.typeT str of
12316
79138d75405f removed unused simple_read_typ;
wenzelm
parents: 12292
diff changeset
   414
    [t] => TypeExt.typ_of_term (get_sort (TypeExt.raw_term_sorts t)) map_sort t
8894
0281bde335ca added read_sort;
wenzelm
parents: 8720
diff changeset
   415
  | _ => error "read_typ: ambiguous syntax");
144
0a0da273a6c5 added Syntax.read_typ;
wenzelm
parents: 47
diff changeset
   416
0a0da273a6c5 added Syntax.read_typ;
wenzelm
parents: 47
diff changeset
   417
8894
0281bde335ca added read_sort;
wenzelm
parents: 8720
diff changeset
   418
(* read sorts *)
0281bde335ca added read_sort;
wenzelm
parents: 8720
diff changeset
   419
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   420
fun read_sort context syn str =
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   421
  (case read context (K false) syn TypeExt.sortT str of
8894
0281bde335ca added read_sort;
wenzelm
parents: 8720
diff changeset
   422
    [t] => TypeExt.sort_of_term t
0281bde335ca added read_sort;
wenzelm
parents: 8720
diff changeset
   423
  | _ => error "read_sort: ambiguous syntax");
0281bde335ca added read_sort;
wenzelm
parents: 8720
diff changeset
   424
0281bde335ca added read_sort;
wenzelm
parents: 8720
diff changeset
   425
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   426
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   427
(** prepare translation rules **)
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   428
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   429
datatype 'a trrule =
3526
df4d0dad2b4e tuned warning;
wenzelm
parents: 2913
diff changeset
   430
  ParseRule of 'a * 'a |
df4d0dad2b4e tuned warning;
wenzelm
parents: 2913
diff changeset
   431
  PrintRule of 'a * 'a |
df4d0dad2b4e tuned warning;
wenzelm
parents: 2913
diff changeset
   432
  ParsePrintRule of 'a * 'a;
888
3a1de9454d13 improved read_xrules: patterns no longer read twice;
wenzelm
parents: 882
diff changeset
   433
4618
731bed12f762 export map_trrule;
wenzelm
parents: 4496
diff changeset
   434
fun map_trrule f (ParseRule (x, y)) = ParseRule (f x, f y)
731bed12f762 export map_trrule;
wenzelm
parents: 4496
diff changeset
   435
  | map_trrule f (PrintRule (x, y)) = PrintRule (f x, f y)
731bed12f762 export map_trrule;
wenzelm
parents: 4496
diff changeset
   436
  | map_trrule f (ParsePrintRule (x, y)) = ParsePrintRule (f x, f y);
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   437
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   438
fun parse_rule (ParseRule pats) = SOME pats
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   439
  | parse_rule (PrintRule _) = NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   440
  | parse_rule (ParsePrintRule pats) = SOME pats;
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   441
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   442
fun print_rule (ParseRule _) = NONE
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   443
  | print_rule (PrintRule pats) = SOME (swap pats)
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   444
  | print_rule (ParsePrintRule pats) = SOME (swap pats);
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   445
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   446
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   447
fun check_rule (rule as (lhs, rhs)) =
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   448
  (case Ast.rule_error rule of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   449
    SOME msg =>
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   450
      error ("Error in syntax translation rule: " ^ msg ^ "\n" ^
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   451
        Ast.str_of_ast lhs ^ "  ->  " ^ Ast.str_of_ast rhs)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   452
  | NONE => rule);
888
3a1de9454d13 improved read_xrules: patterns no longer read twice;
wenzelm
parents: 882
diff changeset
   453
3a1de9454d13 improved read_xrules: patterns no longer read twice;
wenzelm
parents: 882
diff changeset
   454
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   455
fun read_pattern context is_logtype syn (root, str) =
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   456
  let
17079
ce9663987126 added eq_syntax;
wenzelm
parents: 16716
diff changeset
   457
    val Syntax ({consts, ...}, _) = syn;
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   458
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   459
    fun constify (ast as Ast.Constant _) = ast
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   460
      | constify (ast as Ast.Variable x) =
8720
840c75ab2a7f Pretty.chunks;
wenzelm
parents: 7944
diff changeset
   461
          if x mem consts orelse NameSpace.is_qualified x then Ast.Constant x
3830
7797327eca1d constify: qualified is const;
wenzelm
parents: 3782
diff changeset
   462
          else ast
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   463
      | constify (Ast.Appl asts) = Ast.Appl (map constify asts);
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   464
  in
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   465
    (case read_asts context is_logtype syn true root str of
888
3a1de9454d13 improved read_xrules: patterns no longer read twice;
wenzelm
parents: 882
diff changeset
   466
      [ast] => constify ast
3a1de9454d13 improved read_xrules: patterns no longer read twice;
wenzelm
parents: 882
diff changeset
   467
    | _ => error ("Syntactically ambiguous input: " ^ quote str))
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18428
diff changeset
   468
  end handle ERROR msg =>
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18428
diff changeset
   469
    cat_error msg ("The error(s) above occurred in translation pattern " ^
888
3a1de9454d13 improved read_xrules: patterns no longer read twice;
wenzelm
parents: 882
diff changeset
   470
      quote str);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   471
556
3f5f42467717 added type xrule (from sextension.ML);
wenzelm
parents: 383
diff changeset
   472
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   473
fun prep_rules rd_pat raw_rules =
4618
731bed12f762 export map_trrule;
wenzelm
parents: 4496
diff changeset
   474
  let val rules = map (map_trrule rd_pat) raw_rules in
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   475
    (map check_rule (List.mapPartial parse_rule rules),
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   476
      map check_rule (List.mapPartial print_rule rules))
1158
96804ce95516 added extend_trrules_i;
wenzelm
parents: 1147
diff changeset
   477
  end
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   478
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   479
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   480
3779
ce8594f7e0c6 added pretty_sort;
wenzelm
parents: 3739
diff changeset
   481
(** pretty terms, typs, sorts **)
18
c9ec452ff08f lots of internal cleaning and tuning;
wenzelm
parents: 0
diff changeset
   482
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   483
fun pretty_t t_to_ast prt_t context (syn as Syntax (tabs, _)) curried t =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   484
  let
2700
80e6b48c5204 added token translation support;
wenzelm
parents: 2585
diff changeset
   485
    val {print_trtab, print_ruletab, print_ast_trtab, tokentrtab, prtabs, ...} = tabs;
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   486
    val ast = t_to_ast context (lookup_tr' print_trtab) t;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   487
  in
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   488
    prt_t context curried prtabs (lookup_tr' print_ast_trtab)
6167
2f354020efc3 corrected output of symbols for several (probably not all) relevant functions
oheimb
parents: 5702
diff changeset
   489
      (lookup_tokentr tokentrtab (! print_mode))
17412
e26cb20ef0cc TableFun/Symtab: curried lookup and update;
wenzelm
parents: 17314
diff changeset
   490
      (Ast.normalize_ast (Symtab.lookup_multi print_ruletab) ast)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   491
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   492
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   493
val pretty_term = pretty_t Printer.term_to_ast Printer.pretty_term_ast;
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   494
fun pretty_typ context syn = pretty_t Printer.typ_to_ast Printer.pretty_typ_ast context syn false;
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   495
fun pretty_sort context syn = pretty_t Printer.sort_to_ast Printer.pretty_typ_ast context syn false;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   496
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   497
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   498
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   499
(** extend syntax **)
383
fcea89074e4c added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents: 330
diff changeset
   500
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   501
fun ext_syntax' f is_logtype prmode decls = extend_syntax prmode (f is_logtype decls);
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   502
fun ext_syntax f = ext_syntax' (K f) (K false) default_mode;
383
fcea89074e4c added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents: 330
diff changeset
   503
16613
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   504
val extend_type_gram       = ext_syntax Mixfix.syn_ext_types;
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   505
val extend_const_gram      = ext_syntax' Mixfix.syn_ext_consts;
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   506
val extend_consts          = ext_syntax SynExt.syn_ext_const_names;
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   507
val extend_trfuns          = ext_syntax SynExt.syn_ext_trfuns;
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   508
val extend_advanced_trfuns = ext_syntax SynExt.syn_ext_advanced_trfuns;
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   509
val extend_tokentrfuns     = ext_syntax SynExt.syn_ext_tokentrfuns;
76e57e08dcb5 proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents: 15833
diff changeset
   510
val extend_trrules_i       = ext_syntax SynExt.syn_ext_rules o prep_rules I;
383
fcea89074e4c added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents: 330
diff changeset
   511
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   512
fun extend_trrules context is_logtype syn rules =
14904
7d8dc92fcb7f removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents: 14798
diff changeset
   513
  ext_syntax' (K SynExt.syn_ext_rules) (K false) default_mode
18857
c4b4fbd74ffb advanced translations: Context.generic;
wenzelm
parents: 18720
diff changeset
   514
    (prep_rules (read_pattern context is_logtype syn) rules);
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   515
15755
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   516
fun remove_const_gram is_logtype prmode decls =
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   517
  remove_syntax prmode (Mixfix.syn_ext_consts is_logtype decls);
50ac97ebe7d8 expect translations functions to be stamped already;
wenzelm
parents: 15574
diff changeset
   518
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   519
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   520
15833
78109c7012ed removed token_trans.ML (some content moved to syn_ext.ML);
wenzelm
parents: 15759
diff changeset
   521
(*export parts of internal Syntax structures*)
78109c7012ed removed token_trans.ML (some content moved to syn_ext.ML);
wenzelm
parents: 15759
diff changeset
   522
open Lexicon SynExt Ast Parser TypeExt SynTrans Mixfix Printer;
2366
a163d2be1bb5 added chartrans;
wenzelm
parents: 2287
diff changeset
   523
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   524
end;
5692
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   525
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   526
structure BasicSyntax: BASIC_SYNTAX = Syntax;
2e873c5f0e2c no open;
wenzelm
parents: 4887
diff changeset
   527
open BasicSyntax;