1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759(* 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. *)openCommonopenToken_tagtypetoken=[`Doctypeofdoctype|`StartofToken_tag.t|`EndofToken_tag.t|`Charofint|`Commentofstring|`EOF]typestate=[`Data|`RCDATA|`RAWTEXT|`Script_data|`PLAINTEXT]letreplace_windows_1252_entity=function|0x80->0x20AC|0x82->0x201A|0x83->0x0192|0x84->0x201E|0x85->0x2026|0x86->0x2020|0x87->0x2021|0x88->0x02C6|0x89->0x2030|0x8A->0x0160|0x8B->0x2039|0x8C->0x0152|0x8E->0x017D|0x91->0x2018|0x92->0x2019|0x93->0x201C|0x94->0x201D|0x95->0x2022|0x96->0x2013|0x97->0x2014|0x98->0x02DC|0x99->0x2122|0x9A->0x0161|0x9B->0x203A|0x9C->0x0153|0x9E->0x017E|0x9F->0x0178|c->cletnamed_entity_trie=lazybeginlettrie=Trie.create()inArray.fold_left(funtrie(name,characters)->Trie.addnamecharacterstrie)trieEntities.entitiesendtypedoctype_buffers={mutabledoctype_name:Buffer.toption;mutablepublic_identifier:Buffer.toption;mutablesystem_identifier:Buffer.toption;mutableforce_quirks:bool}moduleDoctype_buffers=structtypet=doctype_buffers={mutabledoctype_name:Buffer.toption;mutablepublic_identifier:Buffer.toption;mutablesystem_identifier:Buffer.toption;mutableforce_quirks:bool}endletadd_doctype_charbufferc=letbuffer=matchbufferwith|None->Buffer.create32|Somebuffer->bufferinadd_utf_8bufferc;Somebuffertypetag_buffers={mutablestart:bool;tag_name:Buffer.t;mutableself_closing:bool;mutableattributes:(string*string)list}moduleTag_buffers=structtypet=tag_buffers={mutablestart:bool;tag_name:Buffer.t;mutableself_closing:bool;mutableattributes:(string*string)list}endletsequence_to_lowercase=List.map(fun(l,c)->l,to_lowercasec)openKstreamlettokenizereport(input,get_location)=letforeign=ref(fun()->false)inletlast_start_tag_name:stringoptionref=refNoneinletis_appropriate_end_tagname_buffer=match!last_start_tag_namewith|None->false|Somename->Buffer.contentsname_buffer=nameinletthrow=ref(fun_->())inletended=ref(fun_->())inletoutput=ref(fun_->())inletreccurrent_state=refdata_stateandemitts=current_state:=s;!outputtandemit_characterlcs=emit(l,`Charc)sandemit_characterscss=matchcswith|[]->s()|(l,c)::cs->emit_characterlc(fun()->emit_characterscss)andemit_eof()=emit(get_location(),`EOF)(fun()->!ended())andemit_tagltag'=letrecrev_deduplicateaccumulatorseenattributesk=matchattributeswith|[]->kaccumulator|(n,v)::more->iflist_mem_stringnseenthenreportl(`Bad_token(n,"tag","duplicate attribute"))!throw(fun()->rev_deduplicateaccumulatorseenmorek)elserev_deduplicate((n,v)::accumulator)(n::seen)morekinrev_deduplicate[][](List.revtag'.Tag_buffers.attributes)(funattributes->lettag={Token_tag.name=Buffer.contentstag'.tag_name;self_closing=tag'.self_closing;attributes=List.revattributes}in(funk->iftag'.startthenbeginlast_start_tag_name:=Sometag.name;k(`Starttag)endelse(funk->matchattributeswith|(n,_)::_->reportl(`Bad_token(n,"tag","end tag with attributes"))!throwk|_->k())@@(funk()->iftag.Token_tag.self_closingthenreportl(`Bad_token("/>","tag","end tag cannot be self-closing"))!throwkelsek())@@(fun()->k(`Endtag)))(funtoken->emit(l,token)data_state))andemit_commentlbuffer=emit(l,`Comment(Buffer.contentsbuffer))data_stateandemit_doctype?(quirks=false)ldoctype=ifquirksthendoctype.Doctype_buffers.force_quirks<-true;letif_not_missing=function|None->None|Somebuffer->Some(Buffer.contentsbuffer)inletdoctype={Common.doctype_name=if_not_missingdoctype.doctype_name;public_identifier=if_not_missingdoctype.public_identifier;system_identifier=if_not_missingdoctype.system_identifier;raw_text=None;force_quirks=doctype.force_quirks}inemit(l,`Doctypedoctype)data_state(* Implementation of 8.2.4.69 Tokenizing character references. *)andconsume_character_referencein_attributeadditionallocationk=peek_optioninput!throw(function|Some(_,(0x0009|0x000A|0x000C|0x0020|0x003C|0x0026))|None->kNone|Some(_,c)whenSomec=additional->kNone|Some(_,0x0023aspound)->letconsume_digitsfilterk=letbuffer=Buffer.create8inletreciterate()=next_optioninput!throw(function|Some(_,c)whenfilterc->Buffer.add_charbuffer(Char.chrc);iterate()|v->push_optioninputv;ifBuffer.lengthbuffer=0thenkNoneelsek(Some(Buffer.contentsbuffer)))initerate()inletfinish_digitsprefixtexts=letconsume_semicolonk=next_optioninput!throwbeginfunction|Some(_,0x003B)->k";"|v->push_optioninputv;reportlocation(`Bad_token(prefix^text,"character reference","missing ';' at end"))!throw(fun()->k"")endinletconvertssemicolonk'=letmaybe_n=trySome(int_of_strings)withFailure_->Noneinmatchmaybe_nwith|Somen->k'n|None->reportlocation(`Bad_token(prefix^text^semicolon,"character reference","out of range"))!throw(fun()->k(Some(`Oneu_rep)))inconsume_semicolonbeginfunsemicolon->convertssemicolonbeginfunn'->letn=replace_windows_1252_entityn'inifn<>n'thenreportlocation(`Bad_token(prefix^text^semicolon,"character reference","Windows-1252 character"))!throw(fun()->k(Some(`Onen)))elsematchnwith|nwhennot@@is_scalarn||n=0->reportlocation(`Bad_token(prefix^text^semicolon,"character reference","out of range"))!throw(fun()->k(Some(`Oneu_rep)))|nwhenis_control_charactern||is_non_charactern->reportlocation(`Bad_token(prefix^text^semicolon,"character reference","invalid HTML character"))!throw(fun()->k(Some(`Onen)))|n->k(Some(`Onen))endendinnext_expectedinput!throw(fun_->peek_optioninput!throw(function|Some(_,(0x0078|0x0058asc)asx)->letprefix=Printf.sprintf"&#%c"(Char.chrc)innext_expectedinput!throw(fun_->consume_digitsis_hex_digit(function|None->push_listinput[pound;x];reportlocation(`Bad_token(prefix,"character reference","expected digits"))!throw(fun()->kNone)|Somes->finish_digitsprefixs("0x"^s)))|_->letprefix="&#"inconsume_digitsis_digit(function|None->pushinputpound;reportlocation(`Bad_token(prefix,"character reference","expected digits"))!throw(fun()->kNone)|Somes->finish_digitsprefixss)))|_->letis_entity_likek=letfinishreplacetext=push_listinput(List.revreplace);ktextinletbuffer=Buffer.create16inletreciteratereplace=next_optioninput!throw(function|None->finishreplaceNone|Some((_,c)asv)whenis_alphanumericc->Buffer.add_charbuffer(Char.chrc);iterate(v::replace)|Some((_,0x003B)asv)->finish(v::replace)(Some(Buffer.contentsbuffer))|Somev->finish(v::replace)None)initerate[]inletfinishbestmatchedreplace=push_listinput(List.revreplace);matchbestwith|None->is_entity_like(function|None->kNone|Somes->reportlocation(`Bad_token("&"^s^";","entity reference","no such entity"))!throw(fun()->kNone))|Some(text,code_points)->next_optioninput!throw(function|Some(_,0x003B)->k(Somecode_points)|maybe_v->letunterminated()=push_optioninputmaybe_v;reportlocation(`Bad_token("&"^text,"entity reference","missing ';' at end"))!throw(fun()->k(Somecode_points))inifnotin_attributethenunterminated()elsematchmaybe_vwith|Some((_,c)asv)whenis_alphanumericc->push_listinput(List.rev(v::matched));kNone|Some((_,0x003D)asv)->push_listinput(List.rev(v::matched));reportlocation(`Bad_token("&"^text^"=","attribute","unterminated entity reference followed by '='"))!throw(fun()->kNone)|_->unterminated())inletrecmatch_namedbestmatchedreplacetrietext=next_optioninput!throw(function|None->finishbestmatchedreplace|Some((_,c)asv)->lettrie=Trie.advancectrieinadd_utf_8textc;matchTrie.matchestriewith|Trie.No->finishbestmatched(v::replace)|Trie.Prefix->match_namedbestmatched(v::replace)trietext|Trie.Multiplem->letw=Buffer.contentstextinmatch_named(Some(w,m))(v::(replace@matched))[]trietext|Trie.Yesm->letw=Buffer.contentstextinfinish(Some(w,m))(v::(replace@matched))[])inmatch_namedNone[][](Lazy.forcenamed_entity_trie)(Buffer.create16))(* 8.2.4.1. *)anddata_state()=next_optioninput!throwbeginfunction|Some(l,0x0026)->character_reference_statedata_statel|Some(l,0x003C)->tag_open_statel|Some(l,0)->reportl(`Bad_token("U+0000","content","null"))!throw(fun()->emit(l,`Char0)data_state)|None->emit_eof()|Some(l,c)->emit(l,`Charc)data_stateend(* 8.2.4.2, 8.2.4.4. *)andcharacter_reference_statestatel=consume_character_referencefalseNonelbeginfunction|None->emit(l,`Char0x0026)state|Some(`Onec)->emit(l,`Charc)state|Some(`Two(c,c'))->emit(l,`Charc)(fun()->emit(l,`Charc')state)end(* 8.2.4.3. *)andrcdata_state()=next_optioninput!throwbeginfunction|Some(l,0x0026)->character_reference_statercdata_statel|Some(l,0x003Casv)->text_less_than_sign_statercdata_statel[v]|Some(l,0)->reportl(`Bad_token("U+0000","content","null"))!throw(fun()->emit(l,`Charu_rep)rcdata_state)|None->emit_eof()|Some(l,c)->emit(l,`Charc)rcdata_stateend(* 8.2.4.5. *)andrawtext_state()=next_optioninput!throwbeginfunction|Some(l,0x003Casv)->text_less_than_sign_staterawtext_statel[v]|Some(l,0)->reportl(`Bad_token("U+0000","content","null"))!throw(fun()->emit(l,`Charu_rep)rawtext_state)|None->emit_eof()|Some(l,c)->emit(l,`Charc)rawtext_stateend(* 8.2.4.6. *)andscript_data_state()=next_optioninput!throwbeginfunction|Some(l,0x003Casv)->script_data_less_than_sign_statel[v]|Some(l,0)->reportl(`Bad_token("U+0000","content","null"))!throw(fun()->emit_characterlu_repscript_data_state)|None->emit_eof()|Some(l,c)->emit_characterlcscript_data_stateend(* 8.2.4.7. *)andplaintext_state()=next_optioninput!throwbeginfunction|Some(l,0)->reportl(`Bad_token("U+0000","content","null"))!throw(fun()->emit(l,`Charu_rep)plaintext_state)|None->emit_eof()|Some(l,c)->emit(l,`Charc)plaintext_stateend(* 8.2.4.8. *)andtag_open_statel'=lettag={start=true;tag_name=Buffer.create16;self_closing=false;attributes=[]}innext_optioninput!throwbeginfunction|Some(_,0x0021)->markup_declaration_open_statel'|Some(_,0x002F)->end_tag_open_statel'tag|Some(_,c)whenis_alphabeticc->add_utf_8tag.tag_name(to_lowercasec);tag_name_statel'tag|Some(_,0x003F)->reportl'(`Bad_token("<?","content","HTML does not have processing instructions"))!throw(fun()->bogus_comment_statel')|Some((l,c)asv)->reportl(`Bad_token(charc,"tag","invalid start character"))!throw(fun()->pushinputv;emit_characterl'0x003Cdata_state)|None->report(get_location())(`Unexpected_eoi"tag")!throw(fun()->emit_characterl'0x003Cdata_state)end(* 8.2.4.9. *)andend_tag_open_statel'tag=tag.start<-false;next_optioninput!throwbeginfunction|Some(_,c)whenis_alphabeticc->add_utf_8tag.tag_name(to_lowercasec);tag_name_statel'tag|Some(_,0x003E)->reportl'(`Bad_token("</>","tag","no tag name"))!throwdata_state|None->report(get_location())(`Unexpected_eoi"tag")!throw(fun()->letline,column=l'inemit(l',`Char0x003C)(fun()->emit((line,column+1),`Char0x002F)data_state))|Some(l,c)->reportl(`Bad_token(charc,"tag","invalid start character"))!throw(fun()->bogus_comment_statel')end(* 8.2.4.10. *)andtag_name_statel'tag=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_attribute_name_statel'tag|Some(_,0x002F)->self_closing_start_tag_statel'tag|Some(_,0x003E)->emit_tagl'tag|Some(l,0)->reportl(`Bad_token("U+0000","tag name","null"))!throw(fun()->add_utf_8tag.tag_nameu_rep;tag_name_statel'tag)|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(_,c)->add_utf_8tag.tag_name(to_lowercasec);tag_name_statel'tagend(* 8.2.4.11, 8.2.4.14. *)andtext_less_than_sign_statestatel'cs=next_optioninput!throwbeginfunction|Some(_,0x002Fasv)->text_end_tag_open_statestatel'(v::cs)|maybe_v->push_optioninputmaybe_v;emit_characterscsstateend(* 8.2.4.12, 8.2.4.15, 8.2.4.18, 8.2.4.26. *)andtext_end_tag_open_statestatel'cs=next_optioninput!throwbeginfunction|Some(_,casv)whenis_alphabeticc->letname_buffer=Buffer.create32inadd_utf_8name_buffer(to_lowercasec);text_end_tag_name_statestatel'(v::cs)name_buffer|maybe_v->push_optioninputmaybe_v;emit_characters(List.revcs)stateend(* 8.2.4.13, 8.2.4.16, 8.2.4.19, 8.2.4.27. *)andtext_end_tag_name_statestatel'csname_buffer=letcreate_tag()={start=false;tag_name=name_buffer;self_closing=false;attributes=[]}innext_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))whenis_appropriate_end_tagname_buffer->before_attribute_name_statel'(create_tag())|Some(_,0x002F)whenis_appropriate_end_tagname_buffer->self_closing_start_tag_statel'(create_tag())|Some(_,0x003E)whenis_appropriate_end_tagname_buffer->emit_tagl'(create_tag())|Some((_,c)asv)whenis_alphabeticc->add_utf_8name_buffer(to_lowercasec);text_end_tag_name_statestatel'(v::cs)name_buffer|maybe_v->push_optioninputmaybe_v;emit_characters(List.revcs)stateend(* 8.2.4.17. *)andscript_data_less_than_sign_statel'cs=next_optioninput!throwbeginfunction|Some(_,0x002Fasv)->text_end_tag_open_statescript_data_statel'(v::cs)|Some(_,0x0021asv)->emit_characters(List.rev(v::cs))(fun()->script_data_escape_start_statel')|maybe_v->push_optioninputmaybe_v;emit_characterscsscript_data_stateend(* 8.2.4.20. *)andscript_data_escape_start_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_escape_start_dash_statel')|maybe_v->push_optioninputmaybe_v;script_data_state()end(* 8.2.4.21. *)andscript_data_escape_start_dash_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_escaped_dash_dash_statel')|maybe_v->push_optioninputmaybe_v;script_data_state()end(* 8.2.4.22. *)andscript_data_escaped_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_escaped_dash_statel')|Some((l,0x003C)asv)->script_data_escaped_less_than_sign_statel'l[v]|Some(l,0)->reportl(`Bad_token("U+0000","script","null"))!throw(fun()->emit_characterlu_rep(fun()->script_data_escaped_statel'))|None->report(get_location())(`Unexpected_eoi"script")!throwdata_state|Some(l,c)->emit_characterlc(fun()->script_data_escaped_statel')end(* 8.2.4.23. *)andscript_data_escaped_dash_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_escaped_dash_dash_statel')|Some(l,0x003Casv)->script_data_escaped_less_than_sign_statel'l[v]|Some(l,0)->reportl(`Bad_token("U+0000","script","null"))!throw(fun()->emit_characterlu_rep(fun()->script_data_escaped_statel'))|None->report(get_location())(`Unexpected_eoi"script")!throwdata_state|Some(l,c)->emit_characterlc(fun()->script_data_escaped_statel')end(* 8.2.4.24. *)andscript_data_escaped_dash_dash_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_escaped_dash_dash_statel')|Some(l,0x003Casv)->script_data_escaped_less_than_sign_statel'l[v]|Some(l,0x003E)->emit_characterl0x003Escript_data_state|Some(l,0)->reportl(`Bad_token("U+0000","script","null"))!throw(fun()->emit_characterlu_rep(fun()->script_data_escaped_statel'))|None->report(get_location())(`Unexpected_eoi"script")!throwdata_state|Some(l,c)->emit_characterlc(fun()->script_data_escaped_statel')end(* 8.2.4.25. *)andscript_data_escaped_less_than_sign_statel'l''cs=next_optioninput!throwbeginfunction|Some(_,0x002Fasv)->text_end_tag_open_state(fun()->script_data_escaped_statel')l''(v::cs)|Some(_,casv)whenis_alphabeticc->lettag_buffer=Buffer.create32inadd_utf_8tag_buffer(to_lowercasec);emit_characters(List.rev(v::cs))(fun()->script_data_double_escape_start_statel'tag_buffer)|maybe_v->push_optioninputmaybe_v;emit_characterscs(fun()->script_data_escaped_statel')end(* 8.2.4.28. *)andscript_data_double_escape_start_statel'tag_buffer=next_optioninput!throwbeginfunction|Some(l,(0x0009|0x000A|0x000C|0x0020|0x002F|0x003Easc))->emit_characterlc(fun()->ifBuffer.contentstag_buffer="script"thenscript_data_double_escaped_statel'elsescript_data_escaped_statel')|Some(l,c)whenis_alphabeticc->add_utf_8tag_buffer(to_lowercasec);emit_characterlc(fun()->script_data_double_escape_start_statel'tag_buffer)|maybe_v->push_optioninputmaybe_v;script_data_escaped_statel'end(* 8.2.4.29. *)andscript_data_double_escaped_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_double_escaped_dash_statel')|Some(l,0x003C)->emit_characterl0x003C(fun()->script_data_double_escaped_less_than_sign_statel')|Some(l,0)->reportl(`Bad_token("U+0000","script","null"))!throw(fun()->emit_characterlu_rep(fun()->script_data_double_escaped_statel'))|None->report(get_location())(`Unexpected_eoi"script")!throwdata_state|Some(l,c)->emit_characterlc(fun()->script_data_double_escaped_statel')end(* 8.2.4.30. *)andscript_data_double_escaped_dash_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_double_escaped_dash_dash_statel')|Some(l,0x003C)->emit_characterl0x003C(fun()->script_data_double_escaped_less_than_sign_statel')|Some(l,0)->reportl(`Bad_token("U+0000","script","null"))!throw(fun()->emit_characterlu_rep(fun()->script_data_double_escaped_statel'))|None->report(get_location())(`Unexpected_eoi"script")!throwdata_state|Some(l,c)->emit_characterlc(fun()->script_data_double_escaped_statel')end(* 8.2.4.31. *)andscript_data_double_escaped_dash_dash_statel'=next_optioninput!throwbeginfunction|Some(l,0x002D)->emit_characterl0x002D(fun()->script_data_double_escaped_dash_dash_statel')|Some(l,0x003C)->emit_characterl0x003C(fun()->script_data_double_escaped_less_than_sign_statel')|Some(l,0x003E)->emit_characterl0x003Escript_data_state|Some(l,0)->reportl(`Bad_token("U+0000","script","null"))!throw(fun()->emit_characterlu_rep(fun()->script_data_double_escaped_statel'))|None->report(get_location())(`Unexpected_eoi"script")!throwdata_state|Some(l,c)->emit_characterlc(fun()->script_data_double_escaped_statel')end(* 8.2.4.32. *)andscript_data_double_escaped_less_than_sign_statel'=next_optioninput!throwbeginfunction|Some(l,0x002F)->lettag_buffer=Buffer.create32inemit_characterl0x002F(fun()->script_data_double_escape_end_statel'tag_buffer)|maybe_v->push_optioninputmaybe_v;script_data_double_escaped_statel'end(* 8.2.4.33. *)andscript_data_double_escape_end_statel'tag_buffer=next_optioninput!throwbeginfunction|Some(l,(0x0009|0x000A|0x000C|0x0020|0x002F|0x003Easc))->emit_characterlc(fun()->ifBuffer.contentstag_buffer="script"thenscript_data_escaped_statel'elsescript_data_double_escaped_statel')|Some(l,c)whenis_alphabeticc->add_utf_8tag_buffer(to_lowercasec);emit_characterlc(fun()->script_data_double_escape_end_statel'tag_buffer)|maybe_v->push_optioninputmaybe_v;script_data_double_escaped_statel'end(* 8.2.4.34. *)andbefore_attribute_name_statel'tag=letstart_attributec=letname_buffer=Buffer.create32inadd_utf_8name_bufferc;attribute_name_statel'tagname_bufferinnext_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_attribute_name_statel'tag|Some(_,0x002F)->self_closing_start_tag_statel'tag|Some(_,0x003E)->emit_tagl'tag|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(l,0)->reportl(`Bad_token("U+0000","attribute name","null"))!throw(fun()->start_attributeu_rep)|Some(l,(0x0022|0x0027|0x003C|0x003Dasc))->reportl(`Bad_token(charc,"attribute name","invalid start character"))!throw(fun()->start_attributec)|Some(_,c)->start_attribute(to_lowercasec)end(* 8.2.4.35. *)andattribute_name_statel'tagname_buffer=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->after_attribute_name_statel'tag(Buffer.contentsname_buffer)|Some(_,0x002F)->tag.attributes<-(Buffer.contentsname_buffer,"")::tag.attributes;self_closing_start_tag_statel'tag|Some(_,0x003D)->before_attribute_value_statel'tag(Buffer.contentsname_buffer)|Some(_,0x003E)->tag.attributes<-(Buffer.contentsname_buffer,"")::tag.attributes;emit_tagl'tag|Some(l,0)->reportl(`Bad_token("U+0000","attribute name","null"))!throw(fun()->add_utf_8name_bufferu_rep;attribute_name_statel'tagname_buffer)|Some(l,(0x0022|0x0027|0x003Casc))->reportl(`Bad_token(charc,"attribute name","invalid name character"))!throw(fun()->add_utf_8name_bufferc;attribute_name_statel'tagname_buffer)|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(_,c)->add_utf_8name_buffer(to_lowercasec);attribute_name_statel'tagname_bufferend(* 8.2.4.36. *)andafter_attribute_name_statel'tagname=letstart_next_attributec=tag.attributes<-(name,"")::tag.attributes;letname_buffer=Buffer.create32inadd_utf_8name_bufferc;attribute_name_statel'tagname_bufferinnext_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->after_attribute_name_statel'tagname|Some(_,0x002F)->tag.attributes<-(name,"")::tag.attributes;self_closing_start_tag_statel'tag|Some(_,0x003D)->before_attribute_value_statel'tagname|Some(_,0x003E)->tag.attributes<-(name,"")::tag.attributes;emit_tagl'tag|Some(l,0)->reportl(`Bad_token("U+0000","attribute name","null"))!throw(fun()->start_next_attributeu_rep)|Some(l,(0x0022|0x0027|0x003Casc))->reportl(`Bad_token(charc,"attribute name","invalid start character"))!throw(fun()->start_next_attributec)|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(_,c)->start_next_attribute(to_lowercasec)end(* 8.2.4.37. *)andbefore_attribute_value_statel'tagname=letstart_valuestatemaybe_c=letvalue_buffer=Buffer.create32inbeginmatchmaybe_cwith|None->()|Somec->add_utf_8value_buffercend;statel'tagnamevalue_bufferinnext_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_attribute_value_statel'tagname|Some(_,(0x0022|0x0027asc))->start_value(attribute_value_quoted_statec)None|Some(_,0x0026asv)->pushinputv;start_valueattribute_value_unquoted_stateNone|Some(l,0)->reportl(`Bad_token("U+0000","attribute value","null"))!throw(fun()->start_valueattribute_value_unquoted_state(Someu_rep))|Some(l,0x003E)->reportl(`Bad_token(">","tag","expected attribute value after '='"))!throw(fun()->tag.attributes<-(name,"")::tag.attributes;emit_tagl'tag)|Some(l,(0x003C|0x003D|0x0060asc))->reportl(`Bad_token(charc,"attribute value","invalid start character"))!throw(fun()->start_valueattribute_value_unquoted_state(Somec))|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(_,c)->start_valueattribute_value_unquoted_state(Somec)end(* 8.2.4.38 and 8.2.4.39. *)andattribute_value_quoted_statequotel'tagnamevalue_buffer=next_optioninput!throwbeginfunction|Some(_,c)whenc=quote->tag.attributes<-(name,Buffer.contentsvalue_buffer)::tag.attributes;after_attribute_value_quoted_statel'tag|Some(l,0x0026)->character_reference_in_attributequotelvalue_buffer(fun()->attribute_value_quoted_statequotel'tagnamevalue_buffer)|Some(l,0)->reportl(`Bad_token("U+0000","attribute value","null"))!throw(fun()->add_utf_8value_bufferu_rep;attribute_value_quoted_statequotel'tagnamevalue_buffer)|None->report(get_location())(`Unexpected_eoi"attribute value")!throwdata_state|Some(_,c)->add_utf_8value_bufferc;attribute_value_quoted_statequotel'tagnamevalue_bufferend(* 8.2.4.40. *)andattribute_value_unquoted_statel'tagnamevalue_buffer=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->tag.attributes<-(name,Buffer.contentsvalue_buffer)::tag.attributes;before_attribute_name_statel'tag|Some(l,0x0026)->character_reference_in_attribute0x003Elvalue_buffer(fun()->attribute_value_unquoted_statel'tagnamevalue_buffer)|Some(_,0x003E)->tag.attributes<-(name,Buffer.contentsvalue_buffer)::tag.attributes;emit_tagl'tag|Some(l,0)->reportl(`Bad_token("U+0000","attribute value","null"))!throw(fun()->add_utf_8value_bufferu_rep;attribute_value_unquoted_statel'tagnamevalue_buffer)|Some(l,(0x0022|0x0027|0x003C|0x003D|0x0060asc))->reportl(`Bad_token(charc,"attribute value","invalid character"))!throw(fun()->add_utf_8value_bufferc;attribute_value_unquoted_statel'tagnamevalue_buffer)|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(_,c)->add_utf_8value_bufferc;attribute_value_unquoted_statel'tagnamevalue_bufferend(* 8.2.4.41. *)andcharacter_reference_in_attributeallowedlvalue_bufferk=consume_character_referencetrue(Someallowed)lbeginfunction|None->add_utf_8value_buffer0x0026;k()|Some(`Onec)->add_utf_8value_bufferc;k()|Some(`Two(c,c'))->add_utf_8value_bufferc;add_utf_8value_bufferc';k()end(* 8.2.4.42. *)andafter_attribute_value_quoted_statel'tag=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_attribute_name_statel'tag|Some(_,0x002F)->self_closing_start_tag_statel'tag|Some(_,0x003E)->emit_tagl'tag|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(l,casv)->pushinputv;reportl(`Bad_token(charc,"tag","expected whitespace before attribute"))!throw(fun()->before_attribute_name_statel'tag)end(* 8.2.4.43. *)andself_closing_start_tag_statel'tag=next_optioninput!throwbeginfunction|Some(_,0x003E)->tag.self_closing<-true;emit_tagl'tag|None->report(get_location())(`Unexpected_eoi"tag")!throwdata_state|Some(l,casv)->pushinputv;reportl(`Bad_token(charc,"tag","expected '/>'"))!throw(fun()->before_attribute_name_statel'tag)end(* 8.2.4.44. *)andbogus_comment_statel'=letbuffer=Buffer.create256inletrecconsume()=next_optioninput!throwbeginfunction|Some(_,0x003E)->emit_commentl'buffer|Some(_,0)->add_utf_8bufferu_rep;consume()|None->emit_commentl'buffer|Some(_,c)->add_utf_8bufferc;consume()endinconsume()(* 8.2.4.45. *)andmarkup_declaration_open_statel'=peek_n2input!throwbeginfunction|[_,0x002D;_,0x002D]->next_n2input!throw(fun_->comment_start_statel'(Buffer.create64))|_->peek_n7input!throwbeginfunl->matchsequence_to_lowercaselwith|[_,0x64;_,0x6F;_,0x63;_,0x74;_,0x79;_,0x70;_,0x65]->next_n7input!throw(fun_->doctype_statel')|_->peek_n7input!throw(function|[_,0x5B;_,0x43;_,0x44;_,0x41;_,0x54;_,0x41;_,0x5B]->if!foreign()thennext_n7input!throw(fun_->cdata_section_state())elsereportl'(`Bad_token("<![CDATA[","content","CDATA sections not allowed in HTML"))!throw(fun()->bogus_comment_statel')|_->reportl'(`Bad_token("<!","comment","should begin with '<!--'"))!throw(fun()->bogus_comment_statel'))endend(* 8.2.4.46. *)andcomment_start_statel'buffer=next_optioninput!throwbeginfunction|Some(_,0x002D)->comment_start_dash_statel'buffer|Some(l,0)->reportl(`Bad_token("U+0000","comment","null"))!throw(fun()->add_utf_8bufferu_rep;comment_statel'buffer)|Some(_,0x003E)->reportl'(`Bad_token("<!-->","comment","'-->' overlaps '<!--'"))!throw(fun()->emit_commentl'buffer)|None->report(get_location())(`Unexpected_eoi"comment")!throw(fun()->emit_commentl'buffer)|Some(_,c)->add_utf_8bufferc;comment_statel'bufferend(* 8.2.4.47. *)andcomment_start_dash_statel'buffer=next_optioninput!throwbeginfunction|Some(_,0x002D)->comment_end_statel'buffer|Some(l,0)->reportl(`Bad_token("U+0000","comment","null"))!throw(fun()->Buffer.add_charbuffer'-';add_utf_8bufferu_rep;comment_statel'buffer)|Some(_,0x003E)->reportl'(`Bad_token("<!--->","comment","'-->' overlaps '<!--'"))!throw(fun()->emit_commentl'buffer)|None->report(get_location())(`Unexpected_eoi"comment")!throw(fun()->emit_commentl'buffer)|Some(_,c)->Buffer.add_charbuffer'-';add_utf_8bufferc;comment_statel'bufferend(* 8.2.4.48. *)andcomment_statel'buffer=next_optioninput!throwbeginfunction|Some(_,0x002D)->comment_end_dash_statel'buffer|Some(l,0)->reportl(`Bad_token("U+0000","comment","null"))!throw(fun()->add_utf_8bufferu_rep;comment_statel'buffer)|None->report(get_location())(`Unexpected_eoi"comment")!throw(fun()->emit_commentl'buffer)|Some(_,c)->add_utf_8bufferc;comment_statel'bufferend(* 8.2.4.49. *)andcomment_end_dash_statel'buffer=next_optioninput!throwbeginfunction|Some(_,0x002D)->comment_end_statel'buffer|Some(l,0)->reportl(`Bad_token("U+0000","comment","null"))!throw(fun()->Buffer.add_charbuffer'-';add_utf_8bufferu_rep;comment_statel'buffer)|None->report(get_location())(`Unexpected_eoi"comment")!throw(fun()->emit_commentl'buffer)|Some(_,c)->Buffer.add_charbuffer'-';add_utf_8bufferc;comment_statel'bufferend(* 8.2.4.50. *)andcomment_end_statel'buffer=next_optioninput!throwbeginfunction|Some(_,0x003E)->emit_commentl'buffer|Some(l,0)->reportl(`Bad_token("U+0000","comment","null"))!throw(fun()->Buffer.add_stringbuffer"--";add_utf_8bufferu_rep;comment_statel'buffer)|Some(l,0x0021)->reportl(`Bad_token("--!","comment","'--' should be in '-->'"))!throw(fun()->comment_end_bang_statel'buffer)|Some(l,0x002D)->reportl(`Bad_token("---","comment","'--' should be in '-->'"))!throw(fun()->Buffer.add_charbuffer'-';comment_end_statel'buffer)|None->report(get_location())(`Unexpected_eoi"comment")!throw(fun()->emit_commentl'buffer)|Some(l,c)->reportl(`Bad_token("--"^(charc),"comment","'--' should be in '-->'"))!throw(fun()->Buffer.add_stringbuffer"--";add_utf_8bufferc;comment_statel'buffer)end(* 8.2.4.51. *)andcomment_end_bang_statel'buffer=next_optioninput!throwbeginfunction|Some(_,0x002D)->Buffer.add_stringbuffer"--!";comment_end_dash_statel'buffer|Some(_,0x003E)->emit_commentl'buffer|Some(l,0)->reportl(`Bad_token("U+0000","comment","null"))!throw(fun()->Buffer.add_stringbuffer"--!";add_utf_8bufferu_rep;comment_statel'buffer)|None->report(get_location())(`Unexpected_eoi"comment")!throw(fun()->emit_commentl'buffer)|Some(_,c)->Buffer.add_stringbuffer"--!";add_utf_8bufferc;comment_statel'bufferend(* 8.2.5.52. *)anddoctype_statel'=letdoctype={doctype_name=None;public_identifier=None;system_identifier=None;force_quirks=false}innext_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_doctype_name_statel'doctype|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,casv)->reportl(`Bad_token(charc,"doctype","expected whitespace"))!throw(fun()->pushinputv;before_doctype_name_statel'doctype)end(* 8.2.5.53. *)andbefore_doctype_name_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_doctype_name_statel'doctype|Some(l,0)->reportl(`Bad_token("U+0000","doctype","null"))!throw(fun()->doctype.doctype_name<-add_doctype_chardoctype.doctype_nameu_rep;doctype_name_statel'doctype)|Some(l,0x003E)->reportl(`Bad_token(">","doctype","expected name"))!throw(fun()->emit_doctype~quirks:truel'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(_,c)->doctype.doctype_name<-add_doctype_chardoctype.doctype_name(to_lowercasec);doctype_name_statel'doctypeend(* 8.2.5.54. *)anddoctype_name_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->after_doctype_name_statel'doctype|Some(_,0x003E)->emit_doctypel'doctype|Some(l,0)->reportl(`Bad_token("U+0000","doctype","null"))!throw(fun()->doctype.doctype_name<-add_doctype_chardoctype.doctype_nameu_rep;doctype_name_statel'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(_,c)->doctype.doctype_name<-add_doctype_chardoctype.doctype_name(to_lowercasec);doctype_name_statel'doctypeend(* 8.2.4.55. *)andafter_doctype_name_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->after_doctype_name_statel'doctype|Some(_,0x003E)->emit_doctypel'doctype|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l'',casv)->pushinputv;next_n6input!throwbeginfunl->matchsequence_to_lowercaselwith|[_,0x70;_,0x75;_,0x62;_,0x6C;_,0x69;_,0x63]->after_doctype_public_keyword_statel'doctype|[_,0x73;_,0x79;_,0x73;_,0x74;_,0x65;_,0x6D]->after_doctype_system_keyword_statel'doctype|vs->push_listinputvs;reportl''(`Bad_token(charc,"doctype","expected 'PUBLIC' or 'SYSTEM'"))!throw(fun()->doctype.force_quirks<-true;bogus_doctype_statel'doctype)endend(* Helper. *)andbegin_public_identifierquotel'doctype=doctype.Doctype_buffers.public_identifier<-Some(Buffer.create32);doctype_identifier_quoted_state(fundoctypec->doctype.Doctype_buffers.public_identifier<-add_doctype_chardoctype.Doctype_buffers.public_identifierc)quoteafter_doctype_public_identifier_statel'doctype(* Helper. *)andbegin_system_identifierquotel'doctype=doctype.Doctype_buffers.system_identifier<-Some(Buffer.create32);doctype_identifier_quoted_state(fundoctypec->doctype.system_identifier<-add_doctype_chardoctype.system_identifierc)quoteafter_doctype_system_identifier_statel'doctype(* 8.2.4.56. *)andafter_doctype_public_keyword_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_doctype_public_identifier_statel'doctype|Some(l,(0x0022|0x0027asc))->reportl(`Bad_token(charc,"doctype","expected whitespace"))!throw(fun()->begin_public_identifiercl'doctype)|Some(l,0x003E)->reportl(`Bad_token(">","doctype","expected public identifier"))!throw(fun()->emit_doctype~quirks:truel'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,c)->reportl(`Bad_token(charc,"doctype","expected whitespace"))!throw(fun()->doctype.force_quirks<-true;bogus_doctype_statel'doctype)end(* 8.2.4.57. *)andbefore_doctype_public_identifier_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_doctype_public_identifier_statel'doctype|Some(_,(0x0022|0x0027asc))->begin_public_identifiercl'doctype|Some(l,0x003E)->reportl(`Bad_token(">","doctype","expected public identifier"))!throw(fun()->emit_doctype~quirks:truel'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,c)->reportl(`Bad_token(charc,"doctype","public identifier must be quoted"))!throw(fun()->doctype.force_quirks<-true;bogus_doctype_statel'doctype)end(* 8.2.4.58, 8.2.4.59, 8.2.4.64, 8.2.4.65. *)anddoctype_identifier_quoted_stateaddquotenext_statel'doctype=next_optioninput!throwbeginfunction|Some(_,c)whenc=quote->next_statel'doctype|Some(l,0)->reportl(`Bad_token("U+0000","doctype","null"))!throw(fun()->adddoctypeu_rep;doctype_identifier_quoted_stateaddquotenext_statel'doctype)|Some(l,0x003E)->reportl(`Bad_token(">","doctype","'>' in identifier"))!throw(fun()->emit_doctype~quirks:truel'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(_,c)->adddoctypec;doctype_identifier_quoted_stateaddquotenext_statel'doctypeend(* 8.2.4.60. *)andafter_doctype_public_identifier_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->between_doctype_public_and_system_identifiersl'doctype|Some(_,0x003E)->emit_doctypel'doctype|Some(l,(0x0022|0x0027asc))->reportl(`Bad_token(charc,"doctype","expected whitespace"))!throw(fun()->begin_system_identifiercl'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,c)->reportl(`Bad_token(charc,"doctype","system identifier must be quoted"))!throw(fun()->doctype.force_quirks<-true;bogus_doctype_statel'doctype)end(* 8.2.4.61. *)andbetween_doctype_public_and_system_identifiersl'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->between_doctype_public_and_system_identifiersl'doctype|Some(_,0x003E)->emit_doctypel'doctype|Some(_,(0x0022|0x0027asc))->begin_system_identifiercl'doctype|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,c)->reportl(`Bad_token(charc,"doctype","system identifier must be quoted"))!throw(fun()->doctype.force_quirks<-true;bogus_doctype_statel'doctype)end(* 8.2.4.62. *)andafter_doctype_system_keyword_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_doctype_system_identifier_statel'doctype|Some(l,(0x0022|0x0027asc))->reportl(`Bad_token(charc,"doctype","expected whitespace"))!throw(fun()->begin_system_identifiercl'doctype)|Some(l,0x003E)->reportl(`Bad_token(">","doctype","expected system identifier"))!throw(fun()->emit_doctype~quirks:truel'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,c)->reportl(`Bad_token(charc,"doctype","expected whitespace"))!throw(fun()->doctype.force_quirks<-true;bogus_doctype_statel'doctype)end(* 8.2.4.63. *)andbefore_doctype_system_identifier_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->before_doctype_system_identifier_statel'doctype|Some(_,(0x0022|0x0027asc))->begin_system_identifiercl'doctype|Some(l,0x003E)->reportl(`Bad_token(">","doctype","expected system identifier"))!throw(fun()->emit_doctype~quirks:truel'doctype)|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,c)->reportl(`Bad_token(charc,"doctype","system identifier must be quoted"))!throw(fun()->doctype.force_quirks<-true;bogus_doctype_statel'doctype)end(* 8.2.4.66. *)andafter_doctype_system_identifier_statel'doctype=next_optioninput!throwbeginfunction|Some(_,(0x0009|0x000A|0x000C|0x0020))->after_doctype_system_identifier_statel'doctype|Some(_,0x003E)->emit_doctypel'doctype|None->report(get_location())(`Unexpected_eoi"doctype")!throw(fun()->emit_doctype~quirks:truel'doctype)|Some(l,c)->reportl(`Bad_token(charc,"doctype","junk after system identifier"))!throw(fun()->bogus_doctype_statel'doctype)end(* 8.2.4.67. *)andbogus_doctype_statel'doctype=next_optioninput!throwbeginfunction|Some(_,0x003E)->emit_doctypel'doctype|None->emit_doctypel'doctype|_->bogus_doctype_statel'doctypeend(* 8.2.4.68. *)andcdata_section_state()=next_optioninput!throwbeginfunction|None->data_state()|Some(l,0x005D)->peek_n2input!throwbeginfunction|[_,0x005D;_,0x003E]->next_n2input!throw(fun_->data_state())|_->emit(l,`Char0x005D)cdata_section_stateend|Some(l,c)->emit(l,`Charc)cdata_section_stateendinletstream=(funthrow_ek->throw:=throw_;ended:=e;output:=k;!current_state())|>makeinletset_state=function|`Data->current_state:=data_state|`RCDATA->current_state:=rcdata_state|`RAWTEXT->current_state:=rawtext_state|`Script_data->current_state:=script_data_state|`PLAINTEXT->current_state:=plaintext_stateinletset_foreign=(:=)foreigninstream,set_state,set_foreign