103 |
103 |
104 fun eqn_error (SOME thm) s = error (s ^ ",\nin equation " ^ Display.string_of_thm_without_context thm) |
104 fun eqn_error (SOME thm) s = error (s ^ ",\nin equation " ^ Display.string_of_thm_without_context thm) |
105 | eqn_error NONE s = error s; |
105 | eqn_error NONE s = error s; |
106 |
106 |
107 val code_presentationN = "code_presentation"; |
107 val code_presentationN = "code_presentation"; |
108 val _ = Output.add_mode code_presentationN; |
108 val stmt_nameN = "stmt_name"; |
109 val _ = Markup.add_mode code_presentationN YXML.output_markup; |
109 val _ = Markup.add_mode code_presentationN YXML.output_markup; |
110 |
110 |
111 |
111 |
112 (** assembling and printing text pieces **) |
112 (** assembling and printing text pieces **) |
113 |
113 |
125 | enum_default default sep l r xs = enum sep l r xs; |
125 | enum_default default sep l r xs = enum sep l r xs; |
126 fun semicolon ps = Pretty.block [concat ps, str ";"]; |
126 fun semicolon ps = Pretty.block [concat ps, str ";"]; |
127 fun doublesemicolon ps = Pretty.block [concat ps, str ";;"]; |
127 fun doublesemicolon ps = Pretty.block [concat ps, str ";;"]; |
128 fun indent i = Print_Mode.setmp [] (Pretty.indent i); |
128 fun indent i = Print_Mode.setmp [] (Pretty.indent i); |
129 |
129 |
130 val stmt_nameN = "stmt_name"; |
|
131 fun markup_stmt name = Pretty.mark (code_presentationN, [(stmt_nameN, name)]); |
130 fun markup_stmt name = Pretty.mark (code_presentationN, [(stmt_nameN, name)]); |
132 fun filter_presentation presentation_names selected (XML.Elem ((name, attrs), xs)) = |
131 fun filter_presentation presentation_names selected (XML.Elem ((name, attrs), xs)) = |
133 implode (map (filter_presentation presentation_names |
132 implode (map (filter_presentation presentation_names |
134 (selected orelse (name = code_presentationN |
133 (selected orelse (name = code_presentationN |
135 andalso member (op =) presentation_names (the (Properties.get attrs stmt_nameN))))) xs) |
134 andalso member (op =) presentation_names (the (Properties.get attrs stmt_nameN))))) xs) |
136 | filter_presentation presentation_names selected (XML.Text s) = |
135 | filter_presentation presentation_names selected (XML.Text s) = |
137 if selected then s else ""; |
136 if selected then s else ""; |
138 |
137 |
|
138 fun maps_string s f [] = "" |
|
139 | maps_string s f (x :: xs) = |
|
140 let |
|
141 val s1 = f x; |
|
142 val s2 = maps_string s f xs; |
|
143 in if s1 = "" then s2 |
|
144 else if s2 = "" then s1 |
|
145 else s1 ^ s ^ s2 |
|
146 end; |
|
147 |
139 fun format presentation_names width p = |
148 fun format presentation_names width p = |
140 if null presentation_names then Print_Mode.setmp [] (Pretty.string_of_margin width) p ^ "\n" |
149 if null presentation_names then Print_Mode.setmp [] (Pretty.string_of_margin width) p ^ "\n" |
141 else Print_Mode.setmp [code_presentationN] (Pretty.string_of_margin width) p |
150 else Print_Mode.setmp [code_presentationN] (Pretty.string_of_margin width) p |
142 |> YXML.parse_body |
151 |> YXML.parse_body |
143 |> map (filter_presentation presentation_names false) |
152 |> tap (fn ts => tracing (cat_lines (map XML.string_of ts))) |
144 |> implode |
153 |> maps_string "\n\n" (filter_presentation presentation_names false) |
145 |> suffix "\n" |
154 |> suffix "\n" |
146 |
155 |
147 |
156 |
148 (** names and variable name contexts **) |
157 (** names and variable name contexts **) |
149 |
158 |