src/Tools/Code/code_printer.ML
changeset 80848 df85df6315af
parent 80847 93c2058896a4
child 80851 b1ed84a5215b
equal deleted inserted replaced
80847:93c2058896a4 80848:df85df6315af
   136 val indent = Pretty.indent;
   136 val indent = Pretty.indent;
   137 
   137 
   138 fun markup_stmt sym =
   138 fun markup_stmt sym =
   139   Pretty.mark (code_presentationN, [(stmt_nameN, Code_Symbol.marker sym)]);
   139   Pretty.mark (code_presentationN, [(stmt_nameN, Code_Symbol.marker sym)]);
   140 
   140 
   141 val add_text = XML.traverse_text Buffer.add;
   141 val add_text = XML.traverse_text Bytes.add;
   142 
   142 
   143 fun filter_presentation [] xml =
   143 fun filter_presentation [] xml =
   144       Buffer.build (fold add_text xml)
   144       Bytes.build (fold add_text xml)
   145   | filter_presentation presentation_syms xml =
   145   | filter_presentation presentation_syms xml =
   146       let
   146       let
   147         val presentation_idents = map Code_Symbol.marker presentation_syms
   147         val presentation_idents = map Code_Symbol.marker presentation_syms
   148         fun is_selected (name, attrs) =
   148         fun is_selected (name, attrs) =
   149           name = code_presentationN
   149           name = code_presentationN
   150           andalso member (op =) presentation_idents (the (Properties.get attrs stmt_nameN));
   150           andalso member (op =) presentation_idents (the (Properties.get attrs stmt_nameN));
   151         fun add_content_with_space tree (is_first, buf) =
   151         fun add_content_with_space tree (is_first, buf) =
   152           buf
   152           buf
   153           |> not is_first ? Buffer.add "\n\n"
   153           |> not is_first ? Bytes.add "\n\n"
   154           |> add_text tree
   154           |> add_text tree
   155           |> pair false;
   155           |> pair false;
   156         fun filter (XML.Elem (name_attrs, xs)) =
   156         fun filter (XML.Elem (name_attrs, xs)) =
   157               fold (if is_selected name_attrs then add_content_with_space else filter) xs
   157               fold (if is_selected name_attrs then add_content_with_space else filter) xs
   158           | filter (XML.Text _) = I;
   158           | filter (XML.Text _) = I;
   159       in snd (fold filter xml (true, Buffer.empty)) end;
   159       in snd (fold filter xml (true, Bytes.empty)) end;
   160 
   160 
   161 fun format presentation_names width =
   161 fun format presentation_names width =
   162   Pretty.output_buffer (Pretty.markup_output_ops (SOME width))
   162   Pretty.output (Pretty.markup_output_ops (SOME width))
   163   #> Bytes.buffer
       
   164   #> YXML.parse_body_bytes
   163   #> YXML.parse_body_bytes
   165   #> filter_presentation presentation_names
   164   #> filter_presentation presentation_names
   166   #> Buffer.add "\n"
   165   #> Bytes.add "\n";
   167   #> Bytes.buffer;
       
   168 
   166 
   169 
   167 
   170 (** names and variable name contexts **)
   168 (** names and variable name contexts **)
   171 
   169 
   172 type var_ctxt = string Symtab.table * Name.context;
   170 type var_ctxt = string Symtab.table * Name.context;