123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125(*
RE - A regular expression library
Copyright (C) 2001 Jerome Vouillon
email: Jerome.Vouillon@pps.jussieu.fr
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, with
linking exception; either version 2.1 of the License, or (at
your option) any later version.
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*)moduleRe=CoreexceptionParse_errorexceptionNot_supportedletparses=letbuf=Parse_buffer.createsinletaccept=Parse_buffer.acceptbufinletaccept2=Parse_buffer.accept2bufinleteos()=Parse_buffer.eosbufinlettest2=Parse_buffer.test2bufinletget()=Parse_buffer.getbufinletrecregexp()=regexp'(branch())andregexp'left=ifaccept2'\\''|'thenregexp'(Re.alt[left;branch()])elseleftandbranch()=branch'[]andbranch'left=ifeos()||test2'\\''|'||test2'\\'')'thenRe.seq(List.revleft)elsebranch'(piece()::left)andpiece()=letr=atom()inifaccept'*'thenRe.reprelseifaccept'+'thenRe.rep1relseifaccept'?'thenRe.optrelserandatom()=ifaccept'.'thenRe.notnlelseifaccept'^'thenRe.bolelseifaccept'$'thenRe.eolelseifaccept'['thenifaccept'^'thenRe.compl(bracket[])elseRe.alt(bracket[])elseifaccept'\\'thenifaccept'('then(letr=regexp()inifnot(accept2'\\'')')thenraiseParse_error;Re.groupr)elseifaccept'`'thenRe.boselseifaccept'\''thenRe.eoselseifaccept'='thenRe.startelseifaccept'b'thenRe.alt[Re.bow;Re.eow]elseifaccept'B'thenRe.not_boundaryelseifaccept'<'thenRe.bowelseifaccept'>'thenRe.eowelseifaccept'w'thenRe.alt[Re.alnum;Re.char'_']elseifaccept'W'thenRe.compl[Re.alnum;Re.char'_']else(ifeos()thenraiseParse_error;matchget()with|('*'|'+'|'?'|'['|']'|'.'|'^'|'$'|'\\')asc->Re.charc|'0'..'9'->raiseNot_supported|_->raiseParse_error)else(ifeos()thenraiseParse_error;matchget()with|'*'|'+'|'?'->raiseParse_error|c->Re.charc)andbrackets=ifs<>[]&&accept']'thenselse(letc=char()inifaccept'-'thenifaccept']'thenRe.charc::Re.char'-'::selse(letc'=char()inbracket(Re.rgcc'::s))elsebracket(Re.charc::s))andchar()=ifeos()thenraiseParse_error;get()inletres=regexp()inifnot(eos())thenraiseParse_error;res;;letre?(case=true)s=letr=parsesinifcasethenrelseRe.no_caser;;letcompile=Re.compileletcompile_pat?(case=true)s=compile(re~cases)