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