1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162(* Copyright (C) 2015--2018 Petter A. Urkedal <paurkedal@gmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your
* option) any later version, with the OCaml static compilation exception.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*)moduletypeMONAD=sigtype'atval(>>=):'at->('a->'bt)->'btvalreturn:'a->'atendmoduletypeS=sigtype'afuturevalread_sql_statement:('a->charoptionfuture)->'a->stringoptionfutureendmoduleMake(Io:MONAD)=structopenIoletread_sql_statementread_charic=letbuf=Buffer.create256inletfinish()=matchString.trim(Buffer.contentsbuf)with|""->returnNone|s->return(Somes)inletrecscanlevel=function|Some';'whenlevel=0->finish()|Some'\''->Buffer.add_charbuf'\'';read_charic>>=scan_quotelevel|Some'-'->read_charic>>=beginfunction|Some'-'->read_charic>>=scan_commentlevel|c_opt->Buffer.add_charbuf'-';scanlevelc_optend|Some'('->Buffer.add_charbuf'(';read_charic>>=scan(succlevel)|Some')'->Buffer.add_charbuf')';read_charic>>=scan(predlevel)|Somec->Buffer.add_charbufc;read_charic>>=scanlevel|None->finish()andscan_quotelevel=function|Some'\''->Buffer.add_charbuf'\'';read_charic>>=scanlevel|Somec->Buffer.add_charbufc;read_charic>>=scan_quotelevel|None->finish()andscan_commentlevel=function|Some'\n'->read_charic>>=scanlevel|Some_->read_charic>>=scan_commentlevel|None->finish()inread_charic>>=scan0end