80 (* definitions *) |
80 (* definitions *) |
81 |
81 |
82 fun pretty_definitions verbose ctxt = |
82 fun pretty_definitions verbose ctxt = |
83 let |
83 let |
84 val thy = Proof_Context.theory_of ctxt; |
84 val thy = Proof_Context.theory_of ctxt; |
|
85 val context = Proof_Context.defs_context ctxt; |
85 |
86 |
86 val const_space = Proof_Context.const_space ctxt; |
87 val const_space = Proof_Context.const_space ctxt; |
87 val type_space = Proof_Context.type_space ctxt; |
88 val type_space = Proof_Context.type_space ctxt; |
88 val item_space = fn Defs.Const => const_space | Defs.Type => type_space; |
89 val item_space = fn Defs.Const => const_space | Defs.Type => type_space; |
89 fun prune_item (k, c) = not verbose andalso Name_Space.is_concealed (item_space k) c; |
90 fun prune_item (k, c) = not verbose andalso Name_Space.is_concealed (item_space k) c; |
90 |
91 |
91 fun markup_extern_item (kind, name) = |
92 fun extern_item (kind, name) = |
92 let val (markup, xname) = Name_Space.markup_extern ctxt (item_space kind) name |
93 let val xname = Name_Space.extern ctxt (item_space kind) name |
93 in (markup, (kind, xname)) end; |
94 in (xname, (kind, name)) end; |
94 |
95 |
95 fun pretty_entry ((markup, (kind, xname)), args) = |
96 fun extern_item_ord ((xname1, (kind1, _)), (xname2, (kind2, _))) = |
96 let |
97 (case Defs.item_kind_ord (kind1, kind2) of |
97 val prt_prefix = |
98 EQUAL => string_ord (xname1, xname2) |
98 if kind = Defs.Type then [Pretty.keyword1 "type", Pretty.brk 1] else []; |
99 | ord => ord); |
99 val prt_item = Pretty.mark_str (markup, xname); |
100 |
100 val prt_args = Defs.pretty_args ctxt args; |
101 fun sort_items f = sort (extern_item_ord o apply2 f); |
101 in Pretty.block (prt_prefix @ [prt_item] @ prt_args) end; |
102 |
102 |
103 fun pretty_entry ((_: string, item), args) = Defs.pretty_entry context (item, args); |
103 fun sort_items f = sort (Defs.item_ord o apply2 (snd o f)); |
|
104 |
104 |
105 fun pretty_reduct (lhs, rhs) = Pretty.block |
105 fun pretty_reduct (lhs, rhs) = Pretty.block |
106 ([pretty_entry lhs, Pretty.str " ->", Pretty.brk 2] @ |
106 ([pretty_entry lhs, Pretty.str " ->", Pretty.brk 2] @ |
107 Pretty.commas (map pretty_entry (sort_items fst rhs))); |
107 Pretty.commas (map pretty_entry (sort_items fst rhs))); |
108 |
108 |
113 val {restricts, reducts} = Defs.dest defs; |
113 val {restricts, reducts} = Defs.dest defs; |
114 |
114 |
115 val (reds1, reds2) = |
115 val (reds1, reds2) = |
116 filter_out (prune_item o #1 o #1) reducts |
116 filter_out (prune_item o #1 o #1) reducts |
117 |> map (fn (lhs, rhs) => |
117 |> map (fn (lhs, rhs) => |
118 (apfst markup_extern_item lhs, map (apfst markup_extern_item) (filter_out (prune_item o fst) rhs))) |
118 (apfst extern_item lhs, map (apfst extern_item) (filter_out (prune_item o fst) rhs))) |
119 |> sort_items (#1 o #1) |
119 |> sort_items (#1 o #1) |
120 |> filter_out (null o #2) |
120 |> filter_out (null o #2) |
121 |> List.partition (Defs.plain_args o #2 o #1); |
121 |> List.partition (Defs.plain_args o #2 o #1); |
122 |
122 |
123 val rests = restricts |> map (apfst (apfst markup_extern_item)) |> sort_items (#1 o #1); |
123 val rests = restricts |> map (apfst (apfst extern_item)) |> sort_items (#1 o #1); |
124 in |
124 in |
125 Pretty.big_list "definitions:" |
125 Pretty.big_list "definitions:" |
126 (map (Pretty.text_fold o single) |
126 (map (Pretty.text_fold o single) |
127 [Pretty.big_list "non-overloaded LHS:" (map pretty_reduct reds1), |
127 [Pretty.big_list "non-overloaded LHS:" (map pretty_reduct reds1), |
128 Pretty.big_list "overloaded LHS:" (map pretty_reduct reds2), |
128 Pretty.big_list "overloaded LHS:" (map pretty_reduct reds2), |