| author | wenzelm | 
| Wed, 08 Jun 2011 22:16:21 +0200 | |
| changeset 43328 | 10d731b06ed7 | 
| parent 42382 | dcd983ee2c29 | 
| child 47850 | c638127b4653 | 
| permissions | -rw-r--r-- | 
| 18 | 1 | (* Title: Pure/Syntax/printer.ML | 
| 0 | 2 | Author: Tobias Nipkow and Markus Wenzel, TU Muenchen | 
| 18 | 3 | |
| 4 | Pretty printing of asts, terms, types and print (ast) translation. | |
| 0 | 5 | *) | 
| 6 | ||
| 42289 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 7 | signature BASIC_PRINTER = | 
| 2384 | 8 | sig | 
| 39137 
ccb53edd59f0
turned show_brackets into proper configuration option;
 wenzelm parents: 
39134diff
changeset | 9 | val show_brackets: bool Config.T | 
| 
ccb53edd59f0
turned show_brackets into proper configuration option;
 wenzelm parents: 
39134diff
changeset | 10 | val show_types: bool Config.T | 
| 39134 
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
 wenzelm parents: 
39128diff
changeset | 11 | val show_sorts: bool Config.T | 
| 39115 
a00da1674c1c
turned show_no_free_types into proper configuration option show_free_types, with flipped polarity;
 wenzelm parents: 
38980diff
changeset | 12 | val show_free_types: bool Config.T | 
| 39118 
12f3788be67b
turned show_all_types into proper configuration option;
 wenzelm parents: 
39117diff
changeset | 13 | val show_all_types: bool Config.T | 
| 39127 
e7ecbe86d22e
turned show_structs into proper configuration option;
 wenzelm parents: 
39118diff
changeset | 14 | val show_structs: bool Config.T | 
| 38980 
af73cf0dc31f
turned show_question_marks into proper configuration option;
 wenzelm parents: 
37852diff
changeset | 15 | val show_question_marks: bool Config.T | 
| 40956 | 16 | val pretty_priority: int Config.T | 
| 2384 | 17 | end; | 
| 0 | 18 | |
| 19 | signature PRINTER = | |
| 2384 | 20 | sig | 
| 42289 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 21 | include BASIC_PRINTER | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 22 | val show_brackets_default: bool Unsynchronized.ref | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 23 | val show_brackets_raw: Config.raw | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 24 | val show_types_default: bool Unsynchronized.ref | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 25 | val show_types_raw: Config.raw | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 26 | val show_sorts_default: bool Unsynchronized.ref | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 27 | val show_sorts_raw: Config.raw | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 28 | val show_structs_raw: Config.raw | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 29 | val show_question_marks_default: bool Unsynchronized.ref | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 30 | val show_question_marks_raw: Config.raw | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 31 | type prtabs | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 32 | val empty_prtabs: prtabs | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 33 | val update_prtabs: string -> Syntax_Ext.xprod list -> prtabs -> prtabs | 
| 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 34 | val remove_prtabs: string -> Syntax_Ext.xprod list -> prtabs -> prtabs | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 35 | val merge_prtabs: prtabs -> prtabs -> prtabs | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 36 | val pretty_term_ast: bool -> Proof.context -> prtabs -> | 
| 42254 | 37 | (string -> Proof.context -> Ast.ast list -> Ast.ast) -> | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 38 | (string -> string -> Pretty.T option) -> | 
| 42382 
dcd983ee2c29
provide structure Syntax early (before structure Type), back-patch check/uncheck later;
 wenzelm parents: 
42297diff
changeset | 39 | (string -> Markup.T list * string) -> | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 40 | Ast.ast -> Pretty.T list | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 41 | val pretty_typ_ast: Proof.context -> prtabs -> | 
| 42254 | 42 | (string -> Proof.context -> Ast.ast list -> Ast.ast) -> | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 43 | (string -> string -> Pretty.T option) -> | 
| 42382 
dcd983ee2c29
provide structure Syntax early (before structure Type), back-patch check/uncheck later;
 wenzelm parents: 
42297diff
changeset | 44 | (string -> Markup.T list * string) -> Ast.ast -> Pretty.T list | 
| 2384 | 45 | end; | 
| 0 | 46 | |
| 2365 | 47 | structure Printer: PRINTER = | 
| 0 | 48 | struct | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 49 | |
| 0 | 50 | (** options for printing **) | 
| 51 | ||
| 39137 
ccb53edd59f0
turned show_brackets into proper configuration option;
 wenzelm parents: 
39134diff
changeset | 52 | val show_brackets_default = Unsynchronized.ref false; | 
| 39163 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 53 | val show_brackets_raw = | 
| 39137 
ccb53edd59f0
turned show_brackets into proper configuration option;
 wenzelm parents: 
39134diff
changeset | 54 | Config.declare "show_brackets" (fn _ => Config.Bool (! show_brackets_default)); | 
| 39163 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 55 | val show_brackets = Config.bool show_brackets_raw; | 
| 39137 
ccb53edd59f0
turned show_brackets into proper configuration option;
 wenzelm parents: 
39134diff
changeset | 56 | |
| 39134 
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
 wenzelm parents: 
39128diff
changeset | 57 | val show_types_default = Unsynchronized.ref false; | 
| 39163 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 58 | val show_types_raw = Config.declare "show_types" (fn _ => Config.Bool (! show_types_default)); | 
| 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 59 | val show_types = Config.bool show_types_raw; | 
| 39134 
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
 wenzelm parents: 
39128diff
changeset | 60 | |
| 
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
 wenzelm parents: 
39128diff
changeset | 61 | val show_sorts_default = Unsynchronized.ref false; | 
| 39163 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 62 | val show_sorts_raw = Config.declare "show_sorts" (fn _ => Config.Bool (! show_sorts_default)); | 
| 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 63 | val show_sorts = Config.bool show_sorts_raw; | 
| 39134 
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
 wenzelm parents: 
39128diff
changeset | 64 | |
| 39118 
12f3788be67b
turned show_all_types into proper configuration option;
 wenzelm parents: 
39117diff
changeset | 65 | val show_free_types = Config.bool (Config.declare "show_free_types" (fn _ => Config.Bool true)); | 
| 
12f3788be67b
turned show_all_types into proper configuration option;
 wenzelm parents: 
39117diff
changeset | 66 | val show_all_types = Config.bool (Config.declare "show_all_types" (fn _ => Config.Bool false)); | 
| 39127 
e7ecbe86d22e
turned show_structs into proper configuration option;
 wenzelm parents: 
39118diff
changeset | 67 | |
| 39163 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 68 | val show_structs_raw = Config.declare "show_structs" (fn _ => Config.Bool false); | 
| 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 69 | val show_structs = Config.bool show_structs_raw; | 
| 0 | 70 | |
| 38980 
af73cf0dc31f
turned show_question_marks into proper configuration option;
 wenzelm parents: 
37852diff
changeset | 71 | val show_question_marks_default = Unsynchronized.ref true; | 
| 39163 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 72 | val show_question_marks_raw = | 
| 39116 
f14735a88886
more explicit Config.declare vs. Config.declare_global;
 wenzelm parents: 
39115diff
changeset | 73 | Config.declare "show_question_marks" (fn _ => Config.Bool (! show_question_marks_default)); | 
| 39163 
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
 wenzelm parents: 
39137diff
changeset | 74 | val show_question_marks = Config.bool show_question_marks_raw; | 
| 38980 
af73cf0dc31f
turned show_question_marks into proper configuration option;
 wenzelm parents: 
37852diff
changeset | 75 | |
| 14837 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 76 | |
| 0 | 77 | |
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 78 | (** type prtabs **) | 
| 0 | 79 | |
| 80 | datatype symb = | |
| 81 | Arg of int | | |
| 82 | TypArg of int | | |
| 83 | String of string | | |
| 23630 
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
 wenzelm parents: 
23615diff
changeset | 84 | Space of string | | 
| 0 | 85 | Break of int | | 
| 86 | Block of int * symb list; | |
| 87 | ||
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 88 | type prtabs = (string * ((symb list * int * int) list) Symtab.table) list; | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 89 | |
| 18957 | 90 | fun mode_tab prtabs mode = the_default Symtab.empty (AList.lookup (op =) prtabs mode); | 
| 19482 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 wenzelm parents: 
19374diff
changeset | 91 | fun mode_tabs prtabs modes = map_filter (AList.lookup (op =) prtabs) (modes @ [""]); | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 92 | |
| 18 | 93 | |
| 3816 | 94 | (* xprod_to_fmt *) | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 95 | |
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 96 | fun xprod_to_fmt (Syntax_Ext.XProd (_, _, "", _)) = NONE | 
| 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 97 | | xprod_to_fmt (Syntax_Ext.XProd (_, xsymbs, const, pri)) = | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 98 | let | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 99 | fun arg (s, p) = | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 100 | (if s = "type" then TypArg else Arg) | 
| 42297 
140f283266b7
discontinued Syntax.max_pri, which is not really a symbolic parameter;
 wenzelm parents: 
42289diff
changeset | 101 | (if Lexicon.is_terminal s then 1000 else p); | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 102 | |
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 103 | fun xsyms_to_syms (Syntax_Ext.Delim s :: xsyms) = | 
| 23630 
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
 wenzelm parents: 
23615diff
changeset | 104 | apfst (cons (String s)) (xsyms_to_syms xsyms) | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 105 | | xsyms_to_syms (Syntax_Ext.Argument s_p :: xsyms) = | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 106 | apfst (cons (arg s_p)) (xsyms_to_syms xsyms) | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 107 | | xsyms_to_syms (Syntax_Ext.Space s :: xsyms) = | 
| 23630 
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
 wenzelm parents: 
23615diff
changeset | 108 | apfst (cons (Space s)) (xsyms_to_syms xsyms) | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 109 | | xsyms_to_syms (Syntax_Ext.Bg i :: xsyms) = | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 110 | let | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 111 | val (bsyms, xsyms') = xsyms_to_syms xsyms; | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 112 | val (syms, xsyms'') = xsyms_to_syms xsyms'; | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 113 | in | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 114 | (Block (i, bsyms) :: syms, xsyms'') | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 115 | end | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 116 | | xsyms_to_syms (Syntax_Ext.Brk i :: xsyms) = | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 117 | apfst (cons (Break i)) (xsyms_to_syms xsyms) | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 118 | | xsyms_to_syms (Syntax_Ext.En :: xsyms) = ([], xsyms) | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 119 | | xsyms_to_syms [] = ([], []); | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 120 | |
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 121 | fun nargs (Arg _ :: syms) = nargs syms + 1 | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 122 | | nargs (TypArg _ :: syms) = nargs syms + 1 | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 123 | | nargs (String _ :: syms) = nargs syms | 
| 23630 
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
 wenzelm parents: 
23615diff
changeset | 124 | | nargs (Space _ :: syms) = nargs syms | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 125 | | nargs (Break _ :: syms) = nargs syms | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 126 | | nargs (Block (_, bsyms) :: syms) = nargs syms + nargs bsyms | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 127 | | nargs [] = 0; | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 128 | in | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 129 | (case xsyms_to_syms xsymbs of | 
| 15531 | 130 | (symbs, []) => SOME (const, (symbs, nargs symbs, pri)) | 
| 37852 
a902f158b4fc
eliminated old-style sys_error/SYS_ERROR in favour of exception Fail -- after careful checking that there is no overlap with existing handling of that;
 wenzelm parents: 
37216diff
changeset | 131 | | _ => raise Fail "Unbalanced pretty-printing blocks") | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 132 | end; | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 133 | |
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 134 | |
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 135 | (* empty, extend, merge prtabs *) | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 136 | |
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 137 | val empty_prtabs = []; | 
| 18 | 138 | |
| 25393 
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
 wenzelm parents: 
25386diff
changeset | 139 | fun update_prtabs mode xprods prtabs = | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 140 | let | 
| 19482 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 wenzelm parents: 
19374diff
changeset | 141 | val fmts = map_filter xprod_to_fmt xprods; | 
| 25393 
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
 wenzelm parents: 
25386diff
changeset | 142 | val tab' = fold (Symtab.update_list (op =)) fmts (mode_tab prtabs mode); | 
| 25386 | 143 | in AList.update (op =) (mode, tab') prtabs end; | 
| 15753 | 144 | |
| 25386 | 145 | fun remove_prtabs mode xprods prtabs = | 
| 146 | let | |
| 147 | val tab = mode_tab prtabs mode; | |
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 148 | val fmts = map_filter (fn xprod as Syntax_Ext.XProd (_, _, c, _) => | 
| 25386 | 149 | if null (Symtab.lookup_list tab c) then NONE | 
| 150 | else xprod_to_fmt xprod) xprods; | |
| 25393 
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
 wenzelm parents: 
25386diff
changeset | 151 | val tab' = fold (Symtab.remove_list (op =)) fmts tab; | 
| 
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
 wenzelm parents: 
25386diff
changeset | 152 | in AList.update (op =) (mode, tab') prtabs end; | 
| 0 | 153 | |
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 154 | fun merge_prtabs prtabs1 prtabs2 = | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 155 | let | 
| 19046 
bc5c6c9b114e
removed distinct, renamed gen_distinct to distinct;
 wenzelm parents: 
18977diff
changeset | 156 | val modes = distinct (op =) (map fst (prtabs1 @ prtabs2)); | 
| 18957 | 157 | fun merge m = (m, Symtab.merge_list (op =) (mode_tab prtabs1 m, mode_tab prtabs2 m)); | 
| 12292 | 158 | in map merge modes end; | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 159 | |
| 0 | 160 | |
| 161 | ||
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 162 | (** pretty term or typ asts **) | 
| 0 | 163 | |
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 164 | fun is_chain [Block (_, pr)] = is_chain pr | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 165 | | is_chain [Arg _] = true | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 166 | | is_chain _ = false; | 
| 506 
e0ca460d6e51
improved show_brackets again - Trueprop does not create () any more.
 nipkow parents: 
505diff
changeset | 167 | |
| 40956 | 168 | val pretty_priority = Config.int (Config.declare "Syntax.pretty_priority" (K (Config.Int 0))); | 
| 169 | ||
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 170 | fun pretty type_mode curried ctxt tabs trf token_trans markup_extern ast0 = | 
| 0 | 171 | let | 
| 39137 
ccb53edd59f0
turned show_brackets into proper configuration option;
 wenzelm parents: 
39134diff
changeset | 172 | val show_brackets = Config.get ctxt show_brackets; | 
| 35429 
afa8cf9e63d8
authentic syntax for classes and type constructors;
 wenzelm parents: 
35262diff
changeset | 173 | |
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 174 | (*default applications: prefix / postfix*) | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 175 | val appT = | 
| 42284 | 176 | if type_mode then Syntax_Trans.tappl_ast_tr' | 
| 177 | else if curried then Syntax_Trans.applC_ast_tr' | |
| 178 | else Syntax_Trans.appl_ast_tr'; | |
| 18 | 179 | |
| 23630 
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
 wenzelm parents: 
23615diff
changeset | 180 | fun synT _ ([], args) = ([], args) | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 181 | | synT m (Arg p :: symbs, t :: args) = | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 182 | let val (Ts, args') = synT m (symbs, args); | 
| 0 | 183 | in (astT (t, p) @ Ts, args') end | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 184 | | synT m (TypArg p :: symbs, t :: args) = | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 185 | let | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 186 | val (Ts, args') = synT m (symbs, args); | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 187 | in | 
| 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 188 | if type_mode then (astT (t, p) @ Ts, args') | 
| 40956 | 189 | else | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 190 | (pretty true curried (Config.put pretty_priority p ctxt) | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 191 | tabs trf token_trans markup_extern t @ Ts, args') | 
| 237 
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
 wenzelm parents: 
62diff
changeset | 192 | end | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 193 | | synT m (String s :: symbs, args) = | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 194 | let val (Ts, args') = synT m (symbs, args); | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 195 | in (Pretty.marks_str (m, s) :: Ts, args') end | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 196 | | synT m (Space s :: symbs, args) = | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 197 | let val (Ts, args') = synT m (symbs, args); | 
| 8457 | 198 | in (Pretty.str s :: Ts, args') end | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 199 | | synT m (Block (i, bsymbs) :: symbs, args) = | 
| 0 | 200 | let | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 201 | val (bTs, args') = synT m (bsymbs, args); | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 202 | val (Ts, args'') = synT m (symbs, args'); | 
| 14837 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 203 | val T = | 
| 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 204 | if i < 0 then Pretty.unbreakable (Pretty.block bTs) | 
| 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 205 | else Pretty.blk (i, bTs); | 
| 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 206 | in (T :: Ts, args'') end | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 207 | | synT m (Break i :: symbs, args) = | 
| 14837 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 208 | let | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 209 | val (Ts, args') = synT m (symbs, args); | 
| 14837 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 210 | val T = if i < 0 then Pretty.fbrk else Pretty.brk i; | 
| 
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
 wenzelm parents: 
14783diff
changeset | 211 | in (T :: Ts, args') end | 
| 0 | 212 | |
| 42297 
140f283266b7
discontinued Syntax.max_pri, which is not really a symbolic parameter;
 wenzelm parents: 
42289diff
changeset | 213 | and parT m (pr, args, p, p': int) = #1 (synT m | 
| 
140f283266b7
discontinued Syntax.max_pri, which is not really a symbolic parameter;
 wenzelm parents: 
42289diff
changeset | 214 | (if p > p' orelse (show_brackets andalso p' <> 1000 andalso not (is_chain pr)) | 
| 42288 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 215 |            then [Block (1, Space "(" :: pr @ [Space ")"])]
 | 
| 
2074b31650e6
discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
 wenzelm parents: 
42284diff
changeset | 216 | else pr, args)) | 
| 0 | 217 | |
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 218 | and atomT a = Pretty.marks_str (markup_extern a) | 
| 19374 
ae4a225e0c1f
pretty: late externing of consts (support authentic syntax);
 wenzelm parents: 
19046diff
changeset | 219 | |
| 
ae4a225e0c1f
pretty: late externing of consts (support authentic syntax);
 wenzelm parents: 
19046diff
changeset | 220 | and prefixT (_, a, [], _) = [atomT a] | 
| 16611 
edb368e2878f
proper treatment of advanced trfuns: pass thy argument;
 wenzelm parents: 
15973diff
changeset | 221 | | prefixT (c, _, args, p) = astT (appT (c, args), p) | 
| 0 | 222 | |
| 18 | 223 | and splitT 0 ([x], ys) = (x, ys) | 
| 5691 | 224 | | splitT 0 (rev_xs, ys) = (Ast.Appl (rev rev_xs), ys) | 
| 18 | 225 | | splitT n (rev_xs, y :: ys) = splitT (n - 1) (y :: rev_xs, ys) | 
| 226 | ||
| 0 | 227 | and combT (tup as (c, a, args, p)) = | 
| 228 | let | |
| 229 | val nargs = length args; | |
| 18 | 230 | |
| 2701 | 231 | (*find matching table entry, or print as prefix / postfix*) | 
| 6280 | 232 | fun prnt ([], []) = prefixT tup | 
| 18957 | 233 | | prnt ([], tb :: tbs) = prnt (Symtab.lookup_list tb a, tbs) | 
| 6280 | 234 | | prnt ((pr, n, p') :: prnps, tbs) = | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 235 | if nargs = n then parT (#1 (markup_extern a)) (pr, args, p, p') | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 236 | else if nargs > n andalso not type_mode then | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 237 | astT (appT (splitT n ([c], args)), p) | 
| 6280 | 238 | else prnt (prnps, tbs); | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 239 | in | 
| 26707 
ddf6bab64b96
token translations: context dependent, result Pretty.T;
 wenzelm parents: 
25393diff
changeset | 240 | (case tokentrT a args of | 
| 
ddf6bab64b96
token translations: context dependent, result Pretty.T;
 wenzelm parents: 
25393diff
changeset | 241 | SOME prt => [prt] | 
| 42254 | 242 | | NONE => astT (trf a ctxt args, p) handle Match => prnt ([], tabs)) | 
| 2200 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 243 | end | 
| 
2538977e94fa
added print_mode: string list ref (order of printer tables);
 wenzelm parents: 
1509diff
changeset | 244 | |
| 26707 
ddf6bab64b96
token translations: context dependent, result Pretty.T;
 wenzelm parents: 
25393diff
changeset | 245 | and tokentrT a [Ast.Variable x] = token_trans a x | 
| 
ddf6bab64b96
token translations: context dependent, result Pretty.T;
 wenzelm parents: 
25393diff
changeset | 246 | | tokentrT _ _ = NONE | 
| 
ddf6bab64b96
token translations: context dependent, result Pretty.T;
 wenzelm parents: 
25393diff
changeset | 247 | |
| 5691 | 248 | and astT (c as Ast.Constant a, p) = combT (c, a, [], p) | 
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 249 | | astT (ast as Ast.Variable _, _) = [Ast.pretty_ast ast] | 
| 6280 | 250 | | astT (Ast.Appl ((c as Ast.Constant a) :: (args as _ :: _)), p) = combT (c, a, args, p) | 
| 5691 | 251 | | astT (Ast.Appl (f :: (args as _ :: _)), p) = astT (appT (f, args), p) | 
| 252 |       | astT (ast as Ast.Appl _, _) = raise Ast.AST ("pretty: malformed ast", [ast]);
 | |
| 40956 | 253 | in astT (ast0, Config.get ctxt pretty_priority) end; | 
| 0 | 254 | |
| 255 | ||
| 256 | (* pretty_term_ast *) | |
| 257 | ||
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 258 | fun pretty_term_ast curried ctxt prtabs trf tokentrf extern ast = | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 259 | pretty false curried ctxt (mode_tabs prtabs (print_mode_value ())) trf tokentrf extern ast; | 
| 0 | 260 | |
| 261 | ||
| 262 | (* pretty_typ_ast *) | |
| 263 | ||
| 42267 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 264 | fun pretty_typ_ast ctxt prtabs trf tokentrf extern ast = | 
| 
9566078ad905
simplified printer context: uniform externing and static token translations;
 wenzelm parents: 
42262diff
changeset | 265 | pretty true false ctxt (mode_tabs prtabs (print_mode_value ())) trf tokentrf extern ast; | 
| 0 | 266 | |
| 267 | end; | |
| 42289 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 268 | |
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 269 | structure Basic_Printer: BASIC_PRINTER = Printer; | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 270 | open Basic_Printer; | 
| 
dafae095d733
discontinued special status of structure Printer;
 wenzelm parents: 
42288diff
changeset | 271 |