1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950(*
* Copyright (c) 2018 Thomas Gazagnaire <thomas@gazagnaire.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)typesection=int*stringtypeline=Sectionofsection|Textofstring|BlockofBlock.ttypet=linelistlet pp_sectionppf(level,text)=Fmt.pfppf"%s %s"(String.makelevel'#')textletdump_lineppf=function|Blockblock->Fmt.pfppf"Block %a"Block.dumpblock|Sectionsection->Fmt.pfppf"Section %a"pp_sectionsection|Texttext->Fmt.pfppf"Text %S"textletpp_line?syntaxppf=function|Block block->Block.pp?syntaxppfblock|Sectionsection->Fmt.pfppf"%a\n"pp_sectionsection|Texts->Fmt.string ppfsletdumpppft=Fmt.Dump.(listdump_line)ppftletpp?syntaxppft=Fmt.pfppf"%a\n"Fmt.(list~sep:(any"\n")(pp_line?syntax))tletto_string=Fmt.to_to_stringppletenvst=List.fold_left(funaccline->matchlinewith|Blockb->(matchb.valuewith|OCaml{env;_}|Toplevel{env;_}->Ocaml_env.Set.addenvacc|Raw _|Cram _|Include_->acc)|Section_|Text_->acc)Ocaml_env.Set.empty t