12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152(* 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. *)openCommonopenKstreamletpreprocessis_valid_charreportsource=letfirst_char=reftrueinletline=ref1inletcolumn=ref1inletget_location()=!line,!columninletstream=(funthrowemptyk->letnewline()=letlocation=!line,!columninline:=!line+1;column:=1;k(location,0x0A)inletsymbolc=letlocation=!line,!columnincolumn:=!column+1;k(location,c)inletreciterate()=nextsourcethrowempty(function|0xFEFFwhen!first_char->first_char:=false;iterate()|0x0D->nextsourcethrownewline(function|0x0A->newline()|c->pushsourcec;newline())|0x0A->newline()|cwhennot(is_valid_charc)->report(!line,!column)(`Bad_token(format_charc,"input","out of range"))throw(fun()->symbolc)|c->symbolc)initerate())|>makeinstream,get_location