author | krauss |
Tue, 22 Feb 2011 16:47:18 +0100 | |
changeset 41817 | c7be23634728 |
parent 40956 | 95fe8598c0c9 |
child 42048 | afd11ca8e018 |
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 |
||
7 |
signature PRINTER0 = |
|
2384 | 8 |
sig |
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
9 |
val show_brackets_default: bool Unsynchronized.ref |
39163
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents:
39137
diff
changeset
|
10 |
val show_brackets_raw: Config.raw |
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
11 |
val show_brackets: bool Config.T |
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
12 |
val show_types_default: bool Unsynchronized.ref |
39163
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents:
39137
diff
changeset
|
13 |
val show_types_raw: Config.raw |
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
14 |
val show_types: bool Config.T |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
15 |
val show_sorts_default: bool Unsynchronized.ref |
39163
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents:
39137
diff
changeset
|
16 |
val show_sorts_raw: Config.raw |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
17 |
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:
38980
diff
changeset
|
18 |
val show_free_types: bool Config.T |
39118
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
39117
diff
changeset
|
19 |
val show_all_types: bool Config.T |
39163
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents:
39137
diff
changeset
|
20 |
val show_structs_raw: Config.raw |
39127
e7ecbe86d22e
turned show_structs into proper configuration option;
wenzelm
parents:
39118
diff
changeset
|
21 |
val show_structs: bool Config.T |
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
22 |
val show_question_marks_default: bool Unsynchronized.ref |
39163
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents:
39137
diff
changeset
|
23 |
val show_question_marks_raw: Config.raw |
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
24 |
val show_question_marks: bool Config.T |
40956 | 25 |
val pretty_priority: int Config.T |
2384 | 26 |
end; |
0 | 27 |
|
28 |
signature PRINTER = |
|
2384 | 29 |
sig |
0 | 30 |
include PRINTER0 |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
31 |
val sort_to_ast: Proof.context -> |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
32 |
(string -> (Proof.context -> bool -> typ -> term list -> term) list) -> sort -> Ast.ast |
21772 | 33 |
val typ_to_ast: Proof.context -> |
34 |
(string -> (Proof.context -> bool -> typ -> term list -> term) list) -> typ -> Ast.ast |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
35 |
val term_to_ast: {structs: string list, fixes: string list} -> string list -> Proof.context -> |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
36 |
(string -> (Proof.context -> bool -> typ -> term list -> term) list) -> term -> Ast.ast |
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
37 |
type prtabs |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
38 |
val empty_prtabs: prtabs |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
39 |
val update_prtabs: string -> Syn_Ext.xprod list -> prtabs -> prtabs |
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
40 |
val remove_prtabs: string -> Syn_Ext.xprod list -> prtabs -> prtabs |
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
41 |
val merge_prtabs: prtabs -> prtabs -> prtabs |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
42 |
val pretty_term_ast: {extern_class: string -> xstring, extern_type: string -> xstring, |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
43 |
extern_const: string -> xstring} -> Proof.context -> bool -> prtabs -> |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
44 |
(string -> (Proof.context -> Ast.ast list -> Ast.ast) list) -> |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
45 |
(string -> (Proof.context -> string -> Pretty.T) option) -> Ast.ast -> Pretty.T list |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
46 |
val pretty_typ_ast: {extern_class: string -> xstring, extern_type: string -> xstring} -> |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
47 |
Proof.context -> bool -> prtabs -> |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
48 |
(string -> (Proof.context -> Ast.ast list -> Ast.ast) list) -> |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
49 |
(string -> (Proof.context -> string -> Pretty.T) option) -> Ast.ast -> Pretty.T list |
2384 | 50 |
end; |
0 | 51 |
|
2365 | 52 |
structure Printer: PRINTER = |
0 | 53 |
struct |
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
54 |
|
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
55 |
|
0 | 56 |
(** options for printing **) |
57 |
||
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
58 |
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:
39137
diff
changeset
|
59 |
val show_brackets_raw = |
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
60 |
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:
39137
diff
changeset
|
61 |
val show_brackets = Config.bool show_brackets_raw; |
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
62 |
|
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
63 |
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:
39137
diff
changeset
|
64 |
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:
39137
diff
changeset
|
65 |
val show_types = Config.bool show_types_raw; |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
66 |
|
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
67 |
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:
39137
diff
changeset
|
68 |
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:
39137
diff
changeset
|
69 |
val show_sorts = Config.bool show_sorts_raw; |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
70 |
|
39118
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
39117
diff
changeset
|
71 |
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:
39117
diff
changeset
|
72 |
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:
39118
diff
changeset
|
73 |
|
39163
4d701c0388c3
more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents:
39137
diff
changeset
|
74 |
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:
39137
diff
changeset
|
75 |
val show_structs = Config.bool show_structs_raw; |
0 | 76 |
|
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
77 |
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:
39137
diff
changeset
|
78 |
val show_question_marks_raw = |
39116
f14735a88886
more explicit Config.declare vs. Config.declare_global;
wenzelm
parents:
39115
diff
changeset
|
79 |
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:
39137
diff
changeset
|
80 |
val show_question_marks = Config.bool show_question_marks_raw; |
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
81 |
|
14837
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
82 |
|
0 | 83 |
|
2701 | 84 |
(** misc utils **) |
85 |
||
86 |
(* apply print (ast) translation function *) |
|
0 | 87 |
|
23937
66e1f24d655d
eliminated transform_failure (to avoid critical section for main transactions);
wenzelm
parents:
23660
diff
changeset
|
88 |
fun apply_trans ctxt fns args = |
16611
edb368e2878f
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15973
diff
changeset
|
89 |
let |
edb368e2878f
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15973
diff
changeset
|
90 |
fun app_first [] = raise Match |
21772 | 91 |
| app_first (f :: fs) = f ctxt args handle Match => app_first fs; |
23937
66e1f24d655d
eliminated transform_failure (to avoid critical section for main transactions);
wenzelm
parents:
23660
diff
changeset
|
92 |
in app_first fns end; |
5691 | 93 |
|
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
94 |
fun apply_typed x fs = map (fn f => fn ctxt => f ctxt (Config.get ctxt show_sorts) x) fs; |
4147 | 95 |
|
0 | 96 |
|
2701 | 97 |
(* simple_ast_of *) |
98 |
||
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
99 |
fun simple_ast_of ctxt = |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
100 |
let |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
101 |
val tune_var = if Config.get ctxt show_question_marks then I else unprefix "?"; |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
102 |
fun ast_of (Const (c, _)) = Ast.Constant c |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
103 |
| ast_of (Free (x, _)) = Ast.Variable x |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
104 |
| ast_of (Var (xi, _)) = Ast.Variable (tune_var (Term.string_of_vname xi)) |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
105 |
| ast_of (t as _ $ _) = |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
106 |
let val (f, args) = strip_comb t |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
107 |
in Ast.mk_appl (ast_of f) (map ast_of args) end |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
108 |
| ast_of (Bound i) = Ast.Variable ("B." ^ string_of_int i) |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
109 |
| ast_of (Abs _) = raise Fail "simple_ast_of: Abs"; |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
110 |
in ast_of end; |
2701 | 111 |
|
112 |
||
113 |
||
3776 | 114 |
(** sort_to_ast, typ_to_ast **) |
2701 | 115 |
|
21772 | 116 |
fun ast_of_termT ctxt trf tm = |
0 | 117 |
let |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
118 |
val ctxt' = Config.put show_sorts false ctxt; |
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
119 |
fun ast_of (t as Const ("_tfree", _) $ Free _) = simple_ast_of ctxt t |
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
120 |
| ast_of (t as Const ("_tvar", _) $ Var _) = simple_ast_of ctxt t |
2701 | 121 |
| ast_of (Const (a, _)) = trans a [] |
122 |
| ast_of (t as _ $ _) = |
|
123 |
(case strip_comb t of |
|
124 |
(Const (a, _), args) => trans a args |
|
5691 | 125 |
| (f, args) => Ast.Appl (map ast_of (f :: args))) |
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
126 |
| ast_of t = simple_ast_of ctxt t |
2701 | 127 |
and trans a args = |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
128 |
ast_of (apply_trans ctxt' (apply_typed dummyT (trf a)) args) |
5691 | 129 |
handle Match => Ast.mk_appl (Ast.Constant a) (map ast_of args); |
130 |
in ast_of tm end; |
|
617 | 131 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
132 |
fun sort_to_ast ctxt trf S = ast_of_termT ctxt trf (Type_Ext.term_of_sort S); |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
133 |
fun typ_to_ast ctxt trf T = |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
134 |
ast_of_termT ctxt trf (Type_Ext.term_of_typ (Config.get ctxt show_sorts) T); |
2701 | 135 |
|
136 |
||
137 |
||
138 |
(** term_to_ast **) |
|
139 |
||
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
140 |
fun term_to_ast idents consts ctxt trf tm = |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
141 |
let |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
142 |
val show_types = |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
143 |
Config.get ctxt show_types orelse Config.get ctxt show_sorts orelse |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
144 |
Config.get ctxt show_all_types; |
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
145 |
val show_sorts = Config.get ctxt show_sorts; |
39127
e7ecbe86d22e
turned show_structs into proper configuration option;
wenzelm
parents:
39118
diff
changeset
|
146 |
val show_structs = Config.get ctxt show_structs; |
39115
a00da1674c1c
turned show_no_free_types into proper configuration option show_free_types, with flipped polarity;
wenzelm
parents:
38980
diff
changeset
|
147 |
val show_free_types = Config.get ctxt show_free_types; |
39118
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
39117
diff
changeset
|
148 |
val show_all_types = Config.get ctxt show_all_types; |
12f3788be67b
turned show_all_types into proper configuration option;
wenzelm
parents:
39117
diff
changeset
|
149 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
150 |
val {structs, fixes} = idents; |
2701 | 151 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
152 |
fun mark_atoms ((t as Const (c, T)) $ u) = |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
153 |
if member (op =) Syn_Ext.standard_token_markers c |
35435
e6c03f397eb8
mark_atoms: more precise treatment of SynExt.standard_token_markers vs. syntax consts;
wenzelm
parents:
35429
diff
changeset
|
154 |
then t $ u else mark_atoms t $ mark_atoms u |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
155 |
| mark_atoms (t $ u) = mark_atoms t $ mark_atoms u |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
156 |
| mark_atoms (Abs (x, T, t)) = Abs (x, T, mark_atoms t) |
35435
e6c03f397eb8
mark_atoms: more precise treatment of SynExt.standard_token_markers vs. syntax consts;
wenzelm
parents:
35429
diff
changeset
|
157 |
| mark_atoms (t as Const (c, T)) = |
e6c03f397eb8
mark_atoms: more precise treatment of SynExt.standard_token_markers vs. syntax consts;
wenzelm
parents:
35429
diff
changeset
|
158 |
if member (op =) consts c then t |
e6c03f397eb8
mark_atoms: more precise treatment of SynExt.standard_token_markers vs. syntax consts;
wenzelm
parents:
35429
diff
changeset
|
159 |
else Const (Lexicon.mark_const c, T) |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
160 |
| mark_atoms (t as Free (x, T)) = |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
161 |
let val i = find_index (fn s => s = x) structs + 1 in |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
162 |
if i = 0 andalso member (op =) fixes x then |
35435
e6c03f397eb8
mark_atoms: more precise treatment of SynExt.standard_token_markers vs. syntax consts;
wenzelm
parents:
35429
diff
changeset
|
163 |
Const (Lexicon.mark_fixed x, T) |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
164 |
else if i = 1 andalso not show_structs then |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
165 |
Lexicon.const "_struct" $ Lexicon.const "_indexdefault" |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
166 |
else Lexicon.const "_free" $ t |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
167 |
end |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
168 |
| mark_atoms (t as Var (xi, T)) = |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
169 |
if xi = Syn_Ext.dddot_indexname then Const ("_DDDOT", T) |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
170 |
else Lexicon.const "_var" $ t |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
171 |
| mark_atoms a = a; |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
172 |
|
0 | 173 |
fun prune_typs (t_seen as (Const _, _)) = t_seen |
174 |
| prune_typs (t as Free (x, ty), seen) = |
|
175 |
if ty = dummyT then (t, seen) |
|
39115
a00da1674c1c
turned show_no_free_types into proper configuration option show_free_types, with flipped polarity;
wenzelm
parents:
38980
diff
changeset
|
176 |
else if not show_free_types orelse member (op aconv) seen t then (Lexicon.free x, seen) |
0 | 177 |
else (t, t :: seen) |
178 |
| prune_typs (t as Var (xi, ty), seen) = |
|
179 |
if ty = dummyT then (t, seen) |
|
39115
a00da1674c1c
turned show_no_free_types into proper configuration option show_free_types, with flipped polarity;
wenzelm
parents:
38980
diff
changeset
|
180 |
else if not show_free_types orelse member (op aconv) seen t then (Lexicon.var xi, seen) |
0 | 181 |
else (t, t :: seen) |
182 |
| prune_typs (t_seen as (Bound _, _)) = t_seen |
|
183 |
| prune_typs (Abs (x, ty, t), seen) = |
|
184 |
let val (t', seen') = prune_typs (t, seen); |
|
185 |
in (Abs (x, ty, t'), seen') end |
|
186 |
| prune_typs (t1 $ t2, seen) = |
|
187 |
let |
|
188 |
val (t1', seen') = prune_typs (t1, seen); |
|
189 |
val (t2', seen'') = prune_typs (t2, seen'); |
|
6767 | 190 |
in (t1' $ t2', seen'') end; |
0 | 191 |
|
2701 | 192 |
fun ast_of tm = |
193 |
(case strip_comb tm of |
|
39128
93a7365fb4ee
turned eta_contract into proper configuration option;
wenzelm
parents:
39127
diff
changeset
|
194 |
(t as Abs _, ts) => Ast.mk_appl (ast_of (Syn_Trans.abs_tr' ctxt t)) (map ast_of ts) |
2701 | 195 |
| ((c as Const ("_free", _)), Free (x, T) :: ts) => |
5691 | 196 |
Ast.mk_appl (constrain (c $ Lexicon.free x) T) (map ast_of ts) |
21748 | 197 |
| ((c as Const ("_var", _)), Var (xi, T) :: ts) => |
198 |
Ast.mk_appl (constrain (c $ Lexicon.var xi) T) (map ast_of ts) |
|
2701 | 199 |
| ((c as Const ("_bound", _)), Free (x, T) :: ts) => |
5691 | 200 |
Ast.mk_appl (constrain (c $ Lexicon.free x) T) (map ast_of ts) |
21748 | 201 |
| (Const ("_idtdummy", T), ts) => |
202 |
Ast.mk_appl (constrain (Lexicon.const "_idtdummy") T) (map ast_of ts) |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
203 |
| (const as Const (c, T), ts) => |
14696 | 204 |
if show_all_types |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
205 |
then Ast.mk_appl (constrain const T) (map ast_of ts) |
14696 | 206 |
else trans c T ts |
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
207 |
| (t, ts) => Ast.mk_appl (simple_ast_of ctxt t) (map ast_of ts)) |
0 | 208 |
|
2384 | 209 |
and trans a T args = |
39134
917b4b6ba3d2
turned show_sorts/show_types into proper configuration options;
wenzelm
parents:
39128
diff
changeset
|
210 |
ast_of (apply_trans ctxt (apply_typed T (trf a)) args) |
5691 | 211 |
handle Match => Ast.mk_appl (Ast.Constant a) (map ast_of args) |
0 | 212 |
|
2701 | 213 |
and constrain t T = |
214 |
if show_types andalso T <> dummyT then |
|
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
215 |
Ast.Appl [Ast.Constant Syn_Ext.constrainC, simple_ast_of ctxt t, |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
216 |
ast_of_termT ctxt trf (Type_Ext.term_of_typ show_sorts T)] |
38980
af73cf0dc31f
turned show_question_marks into proper configuration option;
wenzelm
parents:
37852
diff
changeset
|
217 |
else simple_ast_of ctxt t; |
0 | 218 |
in |
2701 | 219 |
tm |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
220 |
|> Syn_Trans.prop_tr' |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
221 |
|> show_types ? (#1 o prune_typs o rpair []) |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
222 |
|> mark_atoms |
2701 | 223 |
|> ast_of |
0 | 224 |
end; |
225 |
||
226 |
||
227 |
||
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
228 |
(** type prtabs **) |
0 | 229 |
|
230 |
datatype symb = |
|
231 |
Arg of int | |
|
232 |
TypArg of int | |
|
233 |
String of string | |
|
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
234 |
Space of string | |
0 | 235 |
Break of int | |
236 |
Block of int * symb list; |
|
237 |
||
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
238 |
type prtabs = (string * ((symb list * int * int) list) Symtab.table) list; |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
239 |
|
18957 | 240 |
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:
19374
diff
changeset
|
241 |
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:
1509
diff
changeset
|
242 |
|
18 | 243 |
|
3816 | 244 |
(* xprod_to_fmt *) |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
245 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
246 |
fun xprod_to_fmt (Syn_Ext.XProd (_, _, "", _)) = NONE |
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
247 |
| xprod_to_fmt (Syn_Ext.XProd (_, xsymbs, const, pri)) = |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
248 |
let |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
249 |
fun arg (s, p) = |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
250 |
(if s = "type" then TypArg else Arg) |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
251 |
(if Lexicon.is_terminal s then Syn_Ext.max_pri else p); |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
252 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
253 |
fun xsyms_to_syms (Syn_Ext.Delim s :: xsyms) = |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
254 |
apfst (cons (String s)) (xsyms_to_syms xsyms) |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
255 |
| xsyms_to_syms (Syn_Ext.Argument s_p :: xsyms) = |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
256 |
apfst (cons (arg s_p)) (xsyms_to_syms xsyms) |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
257 |
| xsyms_to_syms (Syn_Ext.Space s :: xsyms) = |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
258 |
apfst (cons (Space s)) (xsyms_to_syms xsyms) |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
259 |
| xsyms_to_syms (Syn_Ext.Bg i :: xsyms) = |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
260 |
let |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
261 |
val (bsyms, xsyms') = xsyms_to_syms xsyms; |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
262 |
val (syms, xsyms'') = xsyms_to_syms xsyms'; |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
263 |
in |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
264 |
(Block (i, bsyms) :: syms, xsyms'') |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
265 |
end |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
266 |
| xsyms_to_syms (Syn_Ext.Brk i :: xsyms) = |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
267 |
apfst (cons (Break i)) (xsyms_to_syms xsyms) |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
268 |
| xsyms_to_syms (Syn_Ext.En :: xsyms) = ([], xsyms) |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
269 |
| xsyms_to_syms [] = ([], []); |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
270 |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
271 |
fun nargs (Arg _ :: syms) = nargs syms + 1 |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
272 |
| nargs (TypArg _ :: syms) = nargs syms + 1 |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
273 |
| nargs (String _ :: syms) = nargs syms |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
274 |
| nargs (Space _ :: syms) = nargs syms |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
275 |
| nargs (Break _ :: syms) = nargs syms |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
276 |
| nargs (Block (_, bsyms) :: syms) = nargs syms + nargs bsyms |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
277 |
| nargs [] = 0; |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
278 |
in |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
279 |
(case xsyms_to_syms xsymbs of |
15531 | 280 |
(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:
37216
diff
changeset
|
281 |
| _ => raise Fail "Unbalanced pretty-printing blocks") |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
282 |
end; |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
283 |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
284 |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
285 |
(* empty, extend, merge prtabs *) |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
286 |
|
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
287 |
val empty_prtabs = []; |
18 | 288 |
|
25393
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
wenzelm
parents:
25386
diff
changeset
|
289 |
fun update_prtabs mode xprods prtabs = |
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
290 |
let |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19374
diff
changeset
|
291 |
val fmts = map_filter xprod_to_fmt xprods; |
25393
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
wenzelm
parents:
25386
diff
changeset
|
292 |
val tab' = fold (Symtab.update_list (op =)) fmts (mode_tab prtabs mode); |
25386 | 293 |
in AList.update (op =) (mode, tab') prtabs end; |
15753 | 294 |
|
25386 | 295 |
fun remove_prtabs mode xprods prtabs = |
296 |
let |
|
297 |
val tab = mode_tab prtabs mode; |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
298 |
val fmts = map_filter (fn xprod as Syn_Ext.XProd (_, _, c, _) => |
25386 | 299 |
if null (Symtab.lookup_list tab c) then NONE |
300 |
else xprod_to_fmt xprod) xprods; |
|
25393
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
wenzelm
parents:
25386
diff
changeset
|
301 |
val tab' = fold (Symtab.remove_list (op =)) fmts tab; |
0856e0141062
replaced extend_prtabs by update_prtabs (absorb duplicates);
wenzelm
parents:
25386
diff
changeset
|
302 |
in AList.update (op =) (mode, tab') prtabs end; |
0 | 303 |
|
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
304 |
fun merge_prtabs prtabs1 prtabs2 = |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
305 |
let |
19046
bc5c6c9b114e
removed distinct, renamed gen_distinct to distinct;
wenzelm
parents:
18977
diff
changeset
|
306 |
val modes = distinct (op =) (map fst (prtabs1 @ prtabs2)); |
18957 | 307 |
fun merge m = (m, Symtab.merge_list (op =) (mode_tab prtabs1 m, mode_tab prtabs2 m)); |
12292 | 308 |
in map merge modes end; |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
309 |
|
0 | 310 |
|
311 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
312 |
(** pretty term or typ asts **) |
0 | 313 |
|
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
314 |
fun is_chain [Block (_, pr)] = is_chain pr |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
315 |
| is_chain [Arg _] = true |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
316 |
| is_chain _ = false; |
506
e0ca460d6e51
improved show_brackets again - Trueprop does not create () any more.
nipkow
parents:
505
diff
changeset
|
317 |
|
40956 | 318 |
val pretty_priority = Config.int (Config.declare "Syntax.pretty_priority" (K (Config.Int 0))); |
319 |
||
320 |
fun pretty extern ctxt tabs trf tokentrf type_mode curried ast0 = |
|
0 | 321 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
322 |
val {extern_class, extern_type, extern_const} = extern; |
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
323 |
val show_brackets = Config.get ctxt show_brackets; |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
324 |
|
26707
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
325 |
fun token_trans a x = |
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
326 |
(case tokentrf a of |
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
327 |
NONE => |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
328 |
if member (op =) Syn_Ext.standard_token_classes a |
26707
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
329 |
then SOME (Pretty.str x) else NONE |
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
330 |
| SOME f => SOME (f ctxt x)); |
2701 | 331 |
|
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
332 |
(*default applications: prefix / postfix*) |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
333 |
val appT = |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
334 |
if type_mode then Type_Ext.tappl_ast_tr' |
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
335 |
else if curried then Syn_Trans.applC_ast_tr' |
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
35435
diff
changeset
|
336 |
else Syn_Trans.appl_ast_tr'; |
18 | 337 |
|
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
338 |
fun synT _ ([], args) = ([], args) |
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
339 |
| synT markup (Arg p :: symbs, t :: args) = |
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
340 |
let val (Ts, args') = synT markup (symbs, args); |
0 | 341 |
in (astT (t, p) @ Ts, args') end |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
342 |
| synT markup (TypArg p :: symbs, t :: args) = |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
343 |
let |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
344 |
val (Ts, args') = synT markup (symbs, args); |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
345 |
in |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
346 |
if type_mode then (astT (t, p) @ Ts, args') |
40956 | 347 |
else |
348 |
(pretty extern (Config.put pretty_priority p ctxt) |
|
349 |
tabs trf tokentrf true curried t @ Ts, args') |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
62
diff
changeset
|
350 |
end |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
351 |
| synT markup (String s :: symbs, args) = |
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
352 |
let val (Ts, args') = synT markup (symbs, args); |
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
353 |
in (markup (Pretty.str s) :: Ts, args') end |
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
354 |
| synT markup (Space s :: symbs, args) = |
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
355 |
let val (Ts, args') = synT markup (symbs, args); |
8457 | 356 |
in (Pretty.str s :: Ts, args') end |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
357 |
| synT markup (Block (i, bsymbs) :: symbs, args) = |
0 | 358 |
let |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
359 |
val (bTs, args') = synT markup (bsymbs, args); |
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
360 |
val (Ts, args'') = synT markup (symbs, args'); |
14837
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
361 |
val T = |
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
362 |
if i < 0 then Pretty.unbreakable (Pretty.block bTs) |
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
363 |
else Pretty.blk (i, bTs); |
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
364 |
in (T :: Ts, args'') end |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
365 |
| synT markup (Break i :: symbs, args) = |
14837
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
366 |
let |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
367 |
val (Ts, args') = synT markup (symbs, args); |
14837
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
368 |
val T = if i < 0 then Pretty.fbrk else Pretty.brk i; |
827c68f8267c
added pp_show_brackets; support unbreakable blocks;
wenzelm
parents:
14783
diff
changeset
|
369 |
in (T :: Ts, args') end |
0 | 370 |
|
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
371 |
and parT markup (pr, args, p, p': int) = #1 (synT markup |
39137
ccb53edd59f0
turned show_brackets into proper configuration option;
wenzelm
parents:
39134
diff
changeset
|
372 |
(if p > p' orelse (show_brackets andalso p' <> Syn_Ext.max_pri andalso not (is_chain pr)) |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
373 |
then [Block (1, Space "(" :: pr @ [Space ")"])] |
554 | 374 |
else pr, args)) |
0 | 375 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
376 |
and atomT a = a |> Lexicon.unmark |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
377 |
{case_class = fn c => Pretty.mark (Markup.tclass c) (Pretty.str (extern_class c)), |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
378 |
case_type = fn c => Pretty.mark (Markup.tycon c) (Pretty.str (extern_type c)), |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
379 |
case_const = fn c => Pretty.mark (Markup.const c) (Pretty.str (extern_const c)), |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
380 |
case_fixed = fn x => the (token_trans "_free" x), |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
381 |
case_default = Pretty.str} |
19374
ae4a225e0c1f
pretty: late externing of consts (support authentic syntax);
wenzelm
parents:
19046
diff
changeset
|
382 |
|
ae4a225e0c1f
pretty: late externing of consts (support authentic syntax);
wenzelm
parents:
19046
diff
changeset
|
383 |
and prefixT (_, a, [], _) = [atomT a] |
16611
edb368e2878f
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15973
diff
changeset
|
384 |
| prefixT (c, _, args, p) = astT (appT (c, args), p) |
0 | 385 |
|
18 | 386 |
and splitT 0 ([x], ys) = (x, ys) |
5691 | 387 |
| splitT 0 (rev_xs, ys) = (Ast.Appl (rev rev_xs), ys) |
18 | 388 |
| splitT n (rev_xs, y :: ys) = splitT (n - 1) (y :: rev_xs, ys) |
389 |
||
0 | 390 |
and combT (tup as (c, a, args, p)) = |
391 |
let |
|
392 |
val nargs = length args; |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
393 |
val markup = a |> Lexicon.unmark |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
394 |
{case_class = Pretty.mark o Markup.tclass, |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
395 |
case_type = Pretty.mark o Markup.tycon, |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
396 |
case_const = Pretty.mark o Markup.const, |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
397 |
case_fixed = Pretty.mark o Markup.fixed, |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
398 |
case_default = K I}; |
18 | 399 |
|
2701 | 400 |
(*find matching table entry, or print as prefix / postfix*) |
6280 | 401 |
fun prnt ([], []) = prefixT tup |
18957 | 402 |
| prnt ([], tb :: tbs) = prnt (Symtab.lookup_list tb a, tbs) |
6280 | 403 |
| prnt ((pr, n, p') :: prnps, tbs) = |
23630
bc22daeed49e
pretty: markup for syntax/name of authentic consts;
wenzelm
parents:
23615
diff
changeset
|
404 |
if nargs = n then parT markup (pr, args, p, p') |
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
405 |
else if nargs > n andalso not type_mode then |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
406 |
astT (appT (splitT n ([c], args)), p) |
6280 | 407 |
else prnt (prnps, tbs); |
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
408 |
in |
26707
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
409 |
(case tokentrT a args of |
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
410 |
SOME prt => [prt] |
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
411 |
| NONE => astT (apply_trans ctxt (trf a) args, p) handle Match => prnt ([], tabs)) |
2200
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
412 |
end |
2538977e94fa
added print_mode: string list ref (order of printer tables);
wenzelm
parents:
1509
diff
changeset
|
413 |
|
26707
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
414 |
and tokentrT a [Ast.Variable x] = token_trans a x |
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
415 |
| tokentrT _ _ = NONE |
ddf6bab64b96
token translations: context dependent, result Pretty.T;
wenzelm
parents:
25393
diff
changeset
|
416 |
|
5691 | 417 |
and astT (c as Ast.Constant a, p) = combT (c, a, [], p) |
8457 | 418 |
| astT (Ast.Variable x, _) = [Pretty.str x] |
6280 | 419 |
| astT (Ast.Appl ((c as Ast.Constant a) :: (args as _ :: _)), p) = combT (c, a, args, p) |
5691 | 420 |
| astT (Ast.Appl (f :: (args as _ :: _)), p) = astT (appT (f, args), p) |
421 |
| astT (ast as Ast.Appl _, _) = raise Ast.AST ("pretty: malformed ast", [ast]); |
|
40956 | 422 |
in astT (ast0, Config.get ctxt pretty_priority) end; |
0 | 423 |
|
424 |
||
425 |
(* pretty_term_ast *) |
|
426 |
||
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
427 |
fun pretty_term_ast extern ctxt curried prtabs trf tokentrf ast = |
40956 | 428 |
pretty extern ctxt (mode_tabs prtabs (print_mode_value ())) trf tokentrf false curried ast; |
0 | 429 |
|
430 |
||
431 |
(* pretty_typ_ast *) |
|
432 |
||
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
433 |
fun pretty_typ_ast {extern_class, extern_type} ctxt _ prtabs trf tokentrf ast = |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
434 |
pretty {extern_class = extern_class, extern_type = extern_type, extern_const = I} |
40956 | 435 |
ctxt (mode_tabs prtabs (print_mode_value ())) trf tokentrf true false ast; |
0 | 436 |
|
437 |
end; |