123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337(* This file is part of Markup.ml, released under the MIT license. See
LICENSE.md for details, or visit https://github.com/aantron/markup.ml. *)moduletypeIO=sigtype'atvalreturn:'a->'atvalof_cps:((exn->unit)->('a->unit)->unit)->'atvalto_cps:(unit->'at)->((exn->unit)->('a->unit)->unit)endmoduleSynchronous:IOwithtype'at='a=structtype'at='aexceptionNot_synchronousletreturnx=xletof_cpsf=letresult=refNoneinfraise(funv->result:=Somev);match!resultwith|None->raiseNot_synchronous|Somev->vletto_cpsf=funthrowk->matchf()with|v->kv|exceptionexn->throwexnendtypeasync=unittypesync=unittype('data,'sync)stream='dataKstream.tletkstreams=sletof_kstreams=sletof_list=Kstream.of_listtypelocation=Common.locationletcompare_locations=Common.compare_locationsmoduleError=Errortypename=Common.nametypexml_declaration=Common.xml_declaration={version:string;encoding:stringoption;standalone:booloption}typedoctype=Common.doctype={doctype_name:stringoption;public_identifier:stringoption;system_identifier:stringoption;raw_text:stringoption;force_quirks:bool}typesignal=Common.signalletsignal_to_string=Common.signal_to_stringtype'sparser={mutablelocation:location;mutablesignals:(signal,'s)stream}letsignalsparser=parser.signalsletlocationparser=parser.locationletstream_to_parsers=letparser={location=(1,1);signals=Kstream.empty()}inparser.signals<-s|>Kstream.map(fun(l,v)_k->parser.location<-l;kv);parsermoduleCps=structletparse_xmlreport?encodingnamespaceentitycontextsource=letwith_encoding(encoding:Encoding.t)k=source|>encoding~report|>Input.preprocessCommon.is_valid_xml_charreport|>Xml_tokenizer.tokenizereportentity|>Xml_parser.parsecontextnamespacereport|>kinletconstructorthrowk=matchencodingwith|Someencoding->with_encodingencodingk|None->Detect.select_xmlsourcethrow(funencoding->with_encodingencodingk)inKstream.constructconstructor|>stream_to_parserletwrite_xmlreportprefixsignals=signals|>Xml_writer.writereportprefix|>Utility.strings_to_bytesletparse_htmlreport?encodingcontextsource=letwith_encoding(encoding:Encoding.t)k=source|>encoding~report|>Input.preprocessCommon.is_valid_html_charreport|>Html_tokenizer.tokenizereport|>Html_parser.parsecontextreport|>kinletconstructorthrowk=matchencodingwith|Someencoding->with_encodingencodingk|None->Detect.select_htmlsourcethrow(funencoding->with_encodingencodingk)inKstream.constructconstructor|>stream_to_parserletwrite_html?escape_attribute?escape_textsignals=signals|>Html_writer.write?escape_attribute?escape_text|>Utility.strings_to_bytesendletstring=Stream_io.stringletbuffer=Stream_io.bufferletchannel=Stream_io.channelletfile=Stream_io.fileletto_channelcbytes=Stream_io.to_channelcbytes|>Synchronous.of_cpsletto_filefbytes=Stream_io.to_filefbytes|>Synchronous.of_cpsletpreprocess_input_streamsource=Input.preprocess(fun_->true)Error.ignore_errorssourceincludeUtilitymoduleNs=structlethtml=Common.html_nsletsvg=Common.svg_nsletmathml=Common.mathml_nsletxml=Common.xml_nsletxmlns=Common.xmlns_nsletxlink=Common.xlink_nsendmoduletypeASYNCHRONOUS=sigtype'aiomoduleEncoding:sigtypet=Encoding.tvaldecode:?report:(location->Error.t->unitio)->t->(char,_)stream->(int,async)streamendvalparse_xml:?report:(location->Error.t->unitio)->?encoding:Encoding.t->?namespace:(string->stringoption)->?entity:(string->stringoption)->?context:[<`Document|`Fragment]->(char,_)stream->asyncparservalwrite_xml:?report:((signal*int)->Error.t->unitio)->?prefix:(string->stringoption)->([<signal],_)stream->(char,async)streamvalparse_html:?report:(location->Error.t->unitio)->?encoding:Encoding.t->?context:[<`Document|`Fragmentofstring]->(char,_)stream->asyncparservalwrite_html:?escape_attribute:(string->string)->?escape_text:(string->string)->([<signal],_)stream->(char,async)streamvalfn:(unit->charoptionio)->(char,async)streamvalto_string:(char,_)stream->stringiovalto_buffer:(char,_)stream->Buffer.tiovalstream:(unit->'aoptionio)->('a,async)streamvalnext:('a,_)stream->'aoptioniovalpeek:('a,_)stream->'aoptioniovaltransform:('a->'b->('clist*'aoption)io)->'a->('b,_)stream->('c,async)streamvalfold:('a->'b->'aio)->'a->('b,_)stream->'aiovalmap:('a->'bio)->('a,_)stream->('b,async)streamvalfilter:('a->boolio)->('a,_)stream->('a,async)streamvalfilter_map:('a->'boptionio)->('a,_)stream->('b,async)streamvaliter:('a->unitio)->('a,_)stream->unitiovaldrain:('a,_)stream->unitiovalto_list:('a,_)stream->'alistiovalload:('a,_)stream->('a,sync)streamiovaltree:?text:(stringlist->'a)->?element:(name->(name*string)list->'alist->'a)->?comment:(string->'a)->?pi:(string->string->'a)->?xml:(xml_declaration->'a)->?doctype:(doctype->'a)->([<signal],_)stream->'aoptionioendmoduleAsynchronous(IO:IO)=structletwrap_reportreport=funle->IO.to_cps(fun()->reportle)moduleEncoding=structincludeEncodingletdecode?(report=fun__->IO.return())(f:Encoding.t)s=f~report:(wrap_reportreport)sendletparse_xml?(report=fun__->IO.return())?encoding?(namespace=fun_->None)?(entity=fun_->None)?contextsource=Cps.parse_xml(wrap_reportreport)?encodingnamespaceentitycontextsourceletwrite_xml?(report=fun__->IO.return())?(prefix=fun_->None)signals=Cps.write_xml(wrap_reportreport)prefixsignalsletparse_html?(report=fun__->IO.return())?encoding?contextsource=Cps.parse_html(wrap_reportreport)?encodingcontextsourceletwrite_html?escape_attribute?escape_textsignals=Cps.write_html?escape_attribute?escape_textsignalsletto_stringbytes=Stream_io.to_stringbytes|>IO.of_cpsletto_bufferbytes=Stream_io.to_bufferbytes|>IO.of_cpsletstreamf=letf=IO.to_cpsfin(funthrowek->fthrow(function|None->e()|Somev->kv))|>Kstream.makeletfn=streamletnexts=Kstream.next_options|>IO.of_cpsletpeeks=Kstream.peek_options|>IO.of_cps(* Without Flambda, thunks are repeatedly created and passed on IO.to_cps,
resulting in a performance penalty. Flambda seems to optimize this away,
however. *)lettransformfvs=Kstream.transform(funvs->IO.to_cps(fun()->fvs))vsletfoldfvs=Kstream.fold(funvv'->IO.to_cps(fun()->fvv'))vs|>IO.of_cpsletmapfs=Kstream.map(funv->IO.to_cps(fun()->fv))sletfilterfs=Kstream.filter(funv->IO.to_cps(fun()->fv))sletfilter_mapfs=Kstream.filter_map(funv->IO.to_cps(fun()->fv))sletiterfs=Kstream.iter(funv->IO.to_cps(fun()->fv))s|>IO.of_cpsletdrains=iter(fun_->IO.return())sletto_lists=Kstream.to_lists|>IO.of_cpsletloads=(funthrowk->Kstream.to_liststhrow(funl->k(Kstream.of_listl)))|>IO.of_cpslettree?text?element?comment?pi?xml?doctypes=Utility.tree?text?element?comment?pi?xml?doctypes|>IO.of_cpsendincludeAsynchronous(Synchronous)