src/Pure/Syntax/syntax.ML
author wenzelm
Fri Feb 03 23:12:28 2006 +0100 (2006-02-03 ago)
changeset 18921 f47c46d7d654
parent 18857 c4b4fbd74ffb
child 18931 427df66052a1
permissions -rw-r--r--
canonical member/insert/merge;
     1 (*  Title:      Pure/Syntax/syntax.ML
     2     ID:         $Id$
     3     Author:     Tobias Nipkow and Markus Wenzel, TU Muenchen
     4 
     5 Root of Isabelle's syntax module.
     6 *)
     7 
     8 signature BASIC_SYNTAX =
     9 sig
    10   include AST0
    11   include SYN_TRANS0
    12   include MIXFIX0
    13   include PRINTER0
    14 end;
    15 
    16 signature SYNTAX =
    17 sig
    18   include AST1
    19   include LEXICON0
    20   include SYN_EXT0
    21   include TYPE_EXT0
    22   include SYN_TRANS1
    23   include MIXFIX1
    24   include PRINTER0
    25   val extend_trtab: string -> (string * ('a * stamp)) list ->
    26     ('a * stamp) Symtab.table -> ('a * stamp) Symtab.table
    27   val merge_trtabs: string -> ('a * stamp) Symtab.table -> ('a * stamp) Symtab.table ->
    28     ('a * stamp) Symtab.table
    29   val merge_tr'tabs: ('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table
    30     -> ('a * stamp) list Symtab.table
    31   val extend_tr'tab: (string * ('a * stamp)) list ->
    32     ('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table
    33   datatype 'a trrule =
    34     ParseRule of 'a * 'a |
    35     PrintRule of 'a * 'a |
    36     ParsePrintRule of 'a * 'a
    37   type syntax
    38   val eq_syntax: syntax * syntax -> bool
    39   val is_keyword: syntax -> string -> bool
    40   val default_mode: string * bool
    41   val extend_type_gram: (string * int * mixfix) list -> syntax -> syntax
    42   val extend_const_gram: (string -> bool) ->
    43     string * bool -> (string * typ * mixfix) list -> syntax -> syntax
    44   val extend_consts: string list -> syntax -> syntax
    45   val extend_trfuns:
    46     (string * ((ast list -> ast) * stamp)) list *
    47     (string * ((term list -> term) * stamp)) list *
    48     (string * ((bool -> typ -> term list -> term) * stamp)) list *
    49     (string * ((ast list -> ast) * stamp)) list -> syntax -> syntax
    50   val extend_advanced_trfuns:
    51     (string * ((Context.generic -> ast list -> ast) * stamp)) list *
    52     (string * ((Context.generic -> term list -> term) * stamp)) list *
    53     (string * ((Context.generic -> bool -> typ -> term list -> term) * stamp)) list *
    54     (string * ((Context.generic -> ast list -> ast) * stamp)) list -> syntax -> syntax
    55   val extend_tokentrfuns: (string * string * (string -> string * real)) list -> syntax -> syntax
    56   val extend_trrules_i: ast trrule list -> syntax -> syntax
    57   val extend_trrules: Context.generic -> (string -> bool) -> syntax ->
    58     (string * string) trrule list -> syntax -> syntax
    59   val remove_const_gram: (string -> bool) ->
    60     string * bool -> (string * typ * mixfix) list -> syntax -> syntax
    61   val map_trrule: ('a -> 'b) -> 'a trrule -> 'b trrule
    62   val merge_syntaxes: syntax -> syntax -> syntax
    63   val basic_syn: syntax
    64   val basic_nonterms: string list
    65   val appl_syntax: (string * string * mixfix) list
    66   val applC_syntax: (string * string * mixfix) list
    67   val print_gram: syntax -> unit
    68   val print_trans: syntax -> unit
    69   val print_syntax: syntax -> unit
    70   val read: Context.generic -> (string -> bool) -> syntax -> typ -> string -> term list
    71   val read_typ: Context.generic -> syntax -> ((indexname * sort) list -> indexname -> sort) ->
    72     (sort -> sort) -> string -> typ
    73   val read_sort: Context.generic -> syntax -> string -> sort
    74   val pretty_term: Context.generic -> syntax -> bool -> term -> Pretty.T
    75   val pretty_typ: Context.generic -> syntax -> typ -> Pretty.T
    76   val pretty_sort: Context.generic -> syntax -> sort -> Pretty.T
    77   val ambiguity_level: int ref
    78   val ambiguity_is_error: bool ref
    79 end;
    80 
    81 structure Syntax: SYNTAX =
    82 struct
    83 
    84 (** tables of translation functions **)
    85 
    86 (* parse (ast) translations *)
    87 
    88 fun lookup_tr tab c = Option.map fst (Symtab.lookup tab c);
    89 
    90 fun err_dup_trfuns name cs =
    91   error ("More than one " ^ name ^ " for " ^ commas_quote cs);
    92 
    93 fun extend_trtab name trfuns tab = Symtab.extend (tab, trfuns)
    94   handle Symtab.DUPS cs => err_dup_trfuns name cs;
    95 
    96 fun remove_trtab trfuns = fold (Symtab.remove SynExt.eq_trfun) trfuns;
    97 
    98 fun merge_trtabs name tab1 tab2 = Symtab.merge SynExt.eq_trfun (tab1, tab2)
    99   handle Symtab.DUPS cs => err_dup_trfuns name cs;
   100 
   101 
   102 (* print (ast) translations *)
   103 
   104 fun lookup_tr' tab c = map fst (Symtab.lookup_multi tab c);
   105 fun extend_tr'tab trfuns = fold_rev Symtab.update_multi trfuns;
   106 fun remove_tr'tab trfuns = fold (Symtab.remove_multi SynExt.eq_trfun) trfuns;
   107 fun merge_tr'tabs tab1 tab2 = Symtab.merge_multi' SynExt.eq_trfun (tab1, tab2);
   108 
   109 
   110 
   111 (** tables of token translation functions **)
   112 
   113 fun lookup_tokentr tabs modes =
   114   let val trs = gen_distinct (eq_fst (op =))
   115     (List.concat (map (these o AList.lookup (op =) tabs) (modes @ [""])))
   116   in fn c => Option.map fst (AList.lookup (op =) trs c) end;
   117 
   118 fun merge_tokentrtabs tabs1 tabs2 =
   119   let
   120     fun eq_tr ((c1, (_, s1)), (c2, (_, s2))) = c1 = c2 andalso s1 = s2;
   121 
   122     fun name (s, _) = implode (tl (Symbol.explode s));
   123 
   124     fun merge mode =
   125       let
   126         val trs1 = these (AList.lookup (op =) tabs1 mode);
   127         val trs2 = these (AList.lookup (op =) tabs2 mode);
   128         val trs = gen_distinct eq_tr (trs1 @ trs2);
   129       in
   130         (case gen_duplicates (eq_fst (op =)) trs of
   131           [] => (mode, trs)
   132         | dups => error ("More than one token translation function in mode " ^
   133             quote mode ^ " for " ^ commas_quote (map name dups)))
   134       end;
   135   in
   136     map merge (distinct (map fst (tabs1 @ tabs2)))
   137   end;
   138 
   139 fun extend_tokentrtab tokentrs tabs =
   140   let
   141     fun ins_tokentr (m, c, f) =
   142       AList.default (op =) (m, [])
   143       #> AList.map_entry (op =) m (cons ("_" ^ c, (f, stamp ())));
   144   in merge_tokentrtabs tabs (fold ins_tokentr tokentrs []) end;
   145 
   146 
   147 
   148 (** tables of translation rules **)
   149 
   150 type ruletab = (Ast.ast * Ast.ast) list Symtab.table;
   151 
   152 fun dest_ruletab tab = List.concat (map snd (Symtab.dest tab));
   153 
   154 
   155 (* empty, extend, merge ruletabs *)
   156 
   157 val extend_ruletab = fold_rev (fn r => Symtab.update_multi (Ast.head_of_rule r, r));
   158 val remove_ruletab = fold (fn r => Symtab.remove_multi (op =) (Ast.head_of_rule r, r));
   159 fun merge_ruletabs tab1 tab2 = Symtab.merge_multi' (op =) (tab1, tab2);
   160 
   161 
   162 
   163 (** datatype syntax **)
   164 
   165 datatype syntax =
   166   Syntax of {
   167     input: SynExt.xprod list,
   168     lexicon: Scan.lexicon,
   169     gram: Parser.gram,
   170     consts: string list,
   171     prmodes: string list,
   172     parse_ast_trtab: ((Context.generic -> Ast.ast list -> Ast.ast) * stamp) Symtab.table,
   173     parse_ruletab: ruletab,
   174     parse_trtab: ((Context.generic -> term list -> term) * stamp) Symtab.table,
   175     print_trtab: ((Context.generic -> bool -> typ -> term list -> term) * stamp) list Symtab.table,
   176     print_ruletab: ruletab,
   177     print_ast_trtab: ((Context.generic -> Ast.ast list -> Ast.ast) * stamp) list Symtab.table,
   178     tokentrtab: (string * (string * ((string -> string * real) * stamp)) list) list,
   179     prtabs: Printer.prtabs} * stamp;
   180 
   181 fun eq_syntax (Syntax (_, s1), Syntax (_, s2)) = s1 = s2;
   182 
   183 fun is_keyword (Syntax ({lexicon, ...}, _)) = Scan.is_literal lexicon o Symbol.explode;
   184 
   185 val default_mode = ("", true);
   186 
   187 
   188 (* empty_syntax *)
   189 
   190 val empty_syntax = Syntax
   191   ({input = [],
   192     lexicon = Scan.empty_lexicon,
   193     gram = Parser.empty_gram,
   194     consts = [],
   195     prmodes = [],
   196     parse_ast_trtab = Symtab.empty,
   197     parse_ruletab = Symtab.empty,
   198     parse_trtab = Symtab.empty,
   199     print_trtab = Symtab.empty,
   200     print_ruletab = Symtab.empty,
   201     print_ast_trtab = Symtab.empty,
   202     tokentrtab = [],
   203     prtabs = Printer.empty_prtabs}, stamp ());
   204 
   205 
   206 (* extend_syntax *)
   207 
   208 fun extend_syntax (mode, inout) syn_ext (Syntax (tabs, _)) =
   209   let
   210     val {input, lexicon, gram, consts = consts1, prmodes = prmodes1,
   211       parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab,
   212       print_ast_trtab, tokentrtab, prtabs} = tabs;
   213     val SynExt.SynExt {xprods, consts = consts2, prmodes = prmodes2,
   214       parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules,
   215       print_ast_translation, token_translation} = syn_ext;
   216   in
   217     Syntax
   218     ({input = if inout then xprods @ input else input,
   219       lexicon = if inout then Scan.extend_lexicon lexicon (SynExt.delims_of xprods) else lexicon,
   220       gram = if inout then Parser.extend_gram gram xprods else gram,
   221       consts = Library.merge (op =) (consts1, consts2),
   222       prmodes = insert (op =) mode (Library.merge (op =) (prmodes1, prmodes2)),
   223       parse_ast_trtab =
   224         extend_trtab "parse ast translation" parse_ast_translation parse_ast_trtab,
   225       parse_ruletab = extend_ruletab parse_rules parse_ruletab,
   226       parse_trtab = extend_trtab "parse translation" parse_translation parse_trtab,
   227       print_trtab = extend_tr'tab print_translation print_trtab,
   228       print_ruletab = extend_ruletab print_rules print_ruletab,
   229       print_ast_trtab = extend_tr'tab print_ast_translation print_ast_trtab,
   230       tokentrtab = extend_tokentrtab token_translation tokentrtab,
   231       prtabs = Printer.extend_prtabs mode xprods prtabs}, stamp ())
   232   end;
   233 
   234 
   235 (* remove_syntax *)
   236 
   237 fun remove_syntax (mode, inout) syn_ext (Syntax (tabs, _)) =
   238   let
   239     val SynExt.SynExt {xprods, consts = _, prmodes = _,
   240       parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules,
   241       print_ast_translation, token_translation = _} = syn_ext;
   242     val {input, lexicon, gram, consts, prmodes,
   243       parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab,
   244       print_ast_trtab, tokentrtab, prtabs} = tabs;
   245     val input' = if inout then fold (remove (op =)) xprods input else input;
   246   in
   247     Syntax
   248     ({input = input',
   249       lexicon = if inout then Scan.make_lexicon (SynExt.delims_of input') else lexicon,
   250       gram = if inout then Parser.make_gram input' else gram,
   251       consts = consts,
   252       prmodes = prmodes,
   253       parse_ast_trtab = remove_trtab parse_ast_translation parse_ast_trtab,
   254       parse_ruletab = remove_ruletab parse_rules parse_ruletab,
   255       parse_trtab = remove_trtab parse_translation parse_trtab,
   256       print_trtab = remove_tr'tab print_translation print_trtab,
   257       print_ruletab = remove_ruletab print_rules print_ruletab,
   258       print_ast_trtab = remove_tr'tab print_ast_translation print_ast_trtab,
   259       tokentrtab = tokentrtab,
   260       prtabs = Printer.remove_prtabs mode xprods prtabs}, stamp ())
   261   end;
   262 
   263 
   264 (* merge_syntaxes *)
   265 
   266 fun merge_syntaxes (Syntax (tabs1, _)) (Syntax (tabs2, _)) =
   267   let
   268     val {input = input1, lexicon = lexicon1, gram = gram1, consts = consts1,
   269       prmodes = prmodes1, parse_ast_trtab = parse_ast_trtab1,
   270       parse_ruletab = parse_ruletab1, parse_trtab = parse_trtab1,
   271       print_trtab = print_trtab1, print_ruletab = print_ruletab1,
   272       print_ast_trtab = print_ast_trtab1, tokentrtab = tokentrtab1, prtabs = prtabs1} = tabs1;
   273 
   274     val {input = input2, lexicon = lexicon2, gram = gram2, consts = consts2,
   275       prmodes = prmodes2, parse_ast_trtab = parse_ast_trtab2,
   276       parse_ruletab = parse_ruletab2, parse_trtab = parse_trtab2,
   277       print_trtab = print_trtab2, print_ruletab = print_ruletab2,
   278       print_ast_trtab = print_ast_trtab2, tokentrtab = tokentrtab2, prtabs = prtabs2} = tabs2;
   279   in
   280     Syntax
   281     ({input = Library.merge (op =) (input1, input2),
   282       lexicon = Scan.merge_lexicons lexicon1 lexicon2,
   283       gram = Parser.merge_grams gram1 gram2,
   284       consts = sort_distinct string_ord (consts1 @ consts2),
   285       prmodes = Library.merge (op =) (prmodes1, prmodes2),
   286       parse_ast_trtab =
   287         merge_trtabs "parse ast translation" parse_ast_trtab1 parse_ast_trtab2,
   288       parse_ruletab = merge_ruletabs parse_ruletab1 parse_ruletab2,
   289       parse_trtab = merge_trtabs "parse translation" parse_trtab1 parse_trtab2,
   290       print_trtab = merge_tr'tabs print_trtab1 print_trtab2,
   291       print_ruletab = merge_ruletabs print_ruletab1 print_ruletab2,
   292       print_ast_trtab = merge_tr'tabs print_ast_trtab1 print_ast_trtab2,
   293       tokentrtab = merge_tokentrtabs tokentrtab1 tokentrtab2,
   294       prtabs = Printer.merge_prtabs prtabs1 prtabs2}, stamp ())
   295   end;
   296 
   297 
   298 (* basic syntax *)
   299 
   300 val basic_syn =
   301   empty_syntax
   302   |> extend_syntax default_mode TypeExt.type_ext
   303   |> extend_syntax default_mode SynExt.pure_ext;
   304 
   305 val basic_nonterms =
   306   (Lexicon.terminals @ [SynExt.logic, "type", "types", "sort", "classes",
   307     SynExt.args, SynExt.cargs, "pttrn", "pttrns", "idt", "idts", "aprop",
   308     "asms", SynExt.any, SynExt.sprop, "num_const", "index", "struct"]);
   309 
   310 val appl_syntax =
   311  [("_appl", "[('b => 'a), args] => logic", Mixfix.Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)),
   312   ("_appl", "[('b => 'a), args] => aprop", Mixfix.Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))];
   313 
   314 val applC_syntax =
   315  [("",       "'a => cargs",                  Mixfix.Delimfix "_"),
   316   ("_cargs", "['a, cargs] => cargs",         Mixfix.Mixfix ("_/ _", [1000, 1000], 1000)),
   317   ("_applC", "[('b => 'a), cargs] => logic", Mixfix.Mixfix ("(1_/ _)", [1000, 1000], 999)),
   318   ("_applC", "[('b => 'a), cargs] => aprop", Mixfix.Mixfix ("(1_/ _)", [1000, 1000], 999))];
   319 
   320 
   321 
   322 (** print syntax **)
   323 
   324 local
   325 
   326 fun pretty_strs_qs name strs =
   327   Pretty.strs (name :: map Library.quote (sort_strings strs));
   328 
   329 fun pretty_gram (Syntax (tabs, _)) =
   330   let
   331     val {lexicon, prmodes, gram, prtabs, ...} = tabs;
   332     val prmodes' = sort_strings (filter_out (equal "") prmodes);
   333   in
   334     [pretty_strs_qs "lexicon:" (Scan.dest_lexicon lexicon),
   335       Pretty.big_list "prods:" (Parser.pretty_gram gram),
   336       pretty_strs_qs "print modes:" prmodes']
   337   end;
   338 
   339 fun pretty_trans (Syntax (tabs, _)) =
   340   let
   341     fun pretty_trtab name tab =
   342       pretty_strs_qs name (Symtab.keys tab);
   343 
   344     fun pretty_ruletab name tab =
   345       Pretty.big_list name (map Ast.pretty_rule (dest_ruletab tab));
   346 
   347     fun pretty_tokentr (mode, trs) = Pretty.strs (Library.quote mode ^ ":" :: map fst trs);
   348 
   349     val {consts, parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab,
   350       print_ruletab, print_ast_trtab, tokentrtab, ...} = tabs;
   351   in
   352     [pretty_strs_qs "consts:" consts,
   353       pretty_trtab "parse_ast_translation:" parse_ast_trtab,
   354       pretty_ruletab "parse_rules:" parse_ruletab,
   355       pretty_trtab "parse_translation:" parse_trtab,
   356       pretty_trtab "print_translation:" print_trtab,
   357       pretty_ruletab "print_rules:" print_ruletab,
   358       pretty_trtab "print_ast_translation:" print_ast_trtab,
   359       Pretty.big_list "token_translation:" (map pretty_tokentr tokentrtab)]
   360   end;
   361 
   362 in
   363 
   364 fun print_gram syn = Pretty.writeln (Pretty.chunks (pretty_gram syn));
   365 fun print_trans syn = Pretty.writeln (Pretty.chunks (pretty_trans syn));
   366 fun print_syntax syn = Pretty.writeln (Pretty.chunks (pretty_gram syn @ pretty_trans syn));
   367 
   368 end;
   369 
   370 
   371 
   372 (** read **)
   373 
   374 (* read_ast *)
   375 
   376 val ambiguity_level = ref 1;
   377 val ambiguity_is_error = ref false
   378 
   379 fun read_asts context is_logtype (Syntax (tabs, _)) xids root str =
   380   let
   381     val {lexicon, gram, parse_ast_trtab, ...} = tabs;
   382     val root' = if root <> "prop" andalso is_logtype root then SynExt.logic else root;
   383     val chars = Symbol.explode str;
   384     val pts = Parser.parse gram root' (Lexicon.tokenize lexicon xids chars);
   385 
   386     fun show_pt pt =
   387       Pretty.string_of (Ast.pretty_ast (hd (SynTrans.pts_to_asts context (K NONE) [pt])));
   388   in
   389     conditional (length pts > ! ambiguity_level) (fn () =>
   390       if ! ambiguity_is_error then error ("Ambiguous input " ^ quote str)
   391       else (warning ("Ambiguous input " ^ quote str ^ "\n" ^
   392           "produces " ^ string_of_int (length pts) ^ " parse trees.");
   393          List.app (warning o show_pt) pts));
   394     SynTrans.pts_to_asts context (lookup_tr parse_ast_trtab) pts
   395   end;
   396 
   397 
   398 (* read *)
   399 
   400 fun read context is_logtype (syn as Syntax (tabs, _)) ty str =
   401   let
   402     val {parse_ruletab, parse_trtab, ...} = tabs;
   403     val asts = read_asts context is_logtype syn false (SynExt.typ_to_nonterm ty) str;
   404   in
   405     SynTrans.asts_to_terms context (lookup_tr parse_trtab)
   406       (map (Ast.normalize_ast (Symtab.lookup_multi parse_ruletab)) asts)
   407   end;
   408 
   409 
   410 (* read types *)
   411 
   412 fun read_typ context syn get_sort map_sort str =
   413   (case read context (K false) syn SynExt.typeT str of
   414     [t] => TypeExt.typ_of_term (get_sort (TypeExt.raw_term_sorts t)) map_sort t
   415   | _ => error "read_typ: ambiguous syntax");
   416 
   417 
   418 (* read sorts *)
   419 
   420 fun read_sort context syn str =
   421   (case read context (K false) syn TypeExt.sortT str of
   422     [t] => TypeExt.sort_of_term t
   423   | _ => error "read_sort: ambiguous syntax");
   424 
   425 
   426 
   427 (** prepare translation rules **)
   428 
   429 datatype 'a trrule =
   430   ParseRule of 'a * 'a |
   431   PrintRule of 'a * 'a |
   432   ParsePrintRule of 'a * 'a;
   433 
   434 fun map_trrule f (ParseRule (x, y)) = ParseRule (f x, f y)
   435   | map_trrule f (PrintRule (x, y)) = PrintRule (f x, f y)
   436   | map_trrule f (ParsePrintRule (x, y)) = ParsePrintRule (f x, f y);
   437 
   438 fun parse_rule (ParseRule pats) = SOME pats
   439   | parse_rule (PrintRule _) = NONE
   440   | parse_rule (ParsePrintRule pats) = SOME pats;
   441 
   442 fun print_rule (ParseRule _) = NONE
   443   | print_rule (PrintRule pats) = SOME (swap pats)
   444   | print_rule (ParsePrintRule pats) = SOME (swap pats);
   445 
   446 
   447 fun check_rule (rule as (lhs, rhs)) =
   448   (case Ast.rule_error rule of
   449     SOME msg =>
   450       error ("Error in syntax translation rule: " ^ msg ^ "\n" ^
   451         Ast.str_of_ast lhs ^ "  ->  " ^ Ast.str_of_ast rhs)
   452   | NONE => rule);
   453 
   454 
   455 fun read_pattern context is_logtype syn (root, str) =
   456   let
   457     val Syntax ({consts, ...}, _) = syn;
   458 
   459     fun constify (ast as Ast.Constant _) = ast
   460       | constify (ast as Ast.Variable x) =
   461           if x mem consts orelse NameSpace.is_qualified x then Ast.Constant x
   462           else ast
   463       | constify (Ast.Appl asts) = Ast.Appl (map constify asts);
   464   in
   465     (case read_asts context is_logtype syn true root str of
   466       [ast] => constify ast
   467     | _ => error ("Syntactically ambiguous input: " ^ quote str))
   468   end handle ERROR msg =>
   469     cat_error msg ("The error(s) above occurred in translation pattern " ^
   470       quote str);
   471 
   472 
   473 fun prep_rules rd_pat raw_rules =
   474   let val rules = map (map_trrule rd_pat) raw_rules in
   475     (map check_rule (List.mapPartial parse_rule rules),
   476       map check_rule (List.mapPartial print_rule rules))
   477   end
   478 
   479 
   480 
   481 (** pretty terms, typs, sorts **)
   482 
   483 fun pretty_t t_to_ast prt_t context (syn as Syntax (tabs, _)) curried t =
   484   let
   485     val {print_trtab, print_ruletab, print_ast_trtab, tokentrtab, prtabs, ...} = tabs;
   486     val ast = t_to_ast context (lookup_tr' print_trtab) t;
   487   in
   488     prt_t context curried prtabs (lookup_tr' print_ast_trtab)
   489       (lookup_tokentr tokentrtab (! print_mode))
   490       (Ast.normalize_ast (Symtab.lookup_multi print_ruletab) ast)
   491   end;
   492 
   493 val pretty_term = pretty_t Printer.term_to_ast Printer.pretty_term_ast;
   494 fun pretty_typ context syn = pretty_t Printer.typ_to_ast Printer.pretty_typ_ast context syn false;
   495 fun pretty_sort context syn = pretty_t Printer.sort_to_ast Printer.pretty_typ_ast context syn false;
   496 
   497 
   498 
   499 (** extend syntax **)
   500 
   501 fun ext_syntax' f is_logtype prmode decls = extend_syntax prmode (f is_logtype decls);
   502 fun ext_syntax f = ext_syntax' (K f) (K false) default_mode;
   503 
   504 val extend_type_gram       = ext_syntax Mixfix.syn_ext_types;
   505 val extend_const_gram      = ext_syntax' Mixfix.syn_ext_consts;
   506 val extend_consts          = ext_syntax SynExt.syn_ext_const_names;
   507 val extend_trfuns          = ext_syntax SynExt.syn_ext_trfuns;
   508 val extend_advanced_trfuns = ext_syntax SynExt.syn_ext_advanced_trfuns;
   509 val extend_tokentrfuns     = ext_syntax SynExt.syn_ext_tokentrfuns;
   510 val extend_trrules_i       = ext_syntax SynExt.syn_ext_rules o prep_rules I;
   511 
   512 fun extend_trrules context is_logtype syn rules =
   513   ext_syntax' (K SynExt.syn_ext_rules) (K false) default_mode
   514     (prep_rules (read_pattern context is_logtype syn) rules);
   515 
   516 fun remove_const_gram is_logtype prmode decls =
   517   remove_syntax prmode (Mixfix.syn_ext_consts is_logtype decls);
   518 
   519 
   520 
   521 (*export parts of internal Syntax structures*)
   522 open Lexicon SynExt Ast Parser TypeExt SynTrans Mixfix Printer;
   523 
   524 end;
   525 
   526 structure BasicSyntax: BASIC_SYNTAX = Syntax;
   527 open BasicSyntax;