Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file uReStr.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151# 1 "Camomile/public/uReStr.ml"(** Module for a Str-like regular expression syntax *)(* Copyright (C) 2003 Yamagata Yoriyuki. distributed with LGPL *)(* 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 2 of *)(* the License, or (at your option) any later version. *)(* As a special exception to the GNU Library General Public License, you *)(* may link, statically or dynamically, a "work that uses this library" *)(* with a publicly distributed version of this library to produce an *)(* executable file containing portions of this library, and distribute *)(* that executable file under terms of your choice, without any of the *)(* additional requirements listed in clause 6 of the GNU Library General *)(* Public License. By "a publicly distributed version of this library", *)(* we mean either the unmodified Library as distributed by the authors, *)(* or a modified version of this library that is distributed under the *)(* conditions defined in clause 3 of the GNU Library General Public *)(* License. This exception does not however invalidate any other reasons *)(* why the executable file might be covered by the GNU Library General *)(* Public License . *)(* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *)(* USA *)(* You can contact the authour by sending email to *)(* yoriyuki.y@gmail.com *)moduletypeInterface=sigtyperegexp=URe.regexp(** Theses functions are similar to Str. *)valregexp:string->regexpvalquote:string->stringvalregexp_string:string->regexpmoduletypeType=sigtypetexttypeindextypecompiled_regexpmoduleSubText:SubText.Typewithtypeur_text=textandtypeur_index=index(** Compile regular expressions. *)valcompile:regexp->compiled_regexp(** [regexp_match ?sem r t i] tries matching [r] and substrings
of [t] beginning from [i]. If match successes, [Some g] is
returned where [g] is the array containing the matched
string of [n]-th group in the [n]-element.
The matched string of the whole [r] is stored in the [0]-th element.
If matching fails, [None] is returned. *)valregexp_match:?sem:URe.match_semantics->compiled_regexp->text->index->SubText.toptionarrayoption(** [string_match r t i] tests whether [r] can match a substring
of [t] beginning from [i]. *)valstring_match:compiled_regexp->text->index->bool(** [search_forward ?sem r t i] searches a substring of [t]
matching [r] from [i]. The returned value is similar to
{!URe.Type.regexp_match}. *)valsearch_forward:?sem:URe.match_semantics->compiled_regexp->text->index->SubText.toptionarrayoptionendmoduleMake(Text:UnicodeString.Type):Typewithtypetext=Text.tandtypeindex=Text.indexendmoduleConfigure(Config:ConfigInt.Type)=structtyperegexp=URe.regexpmoduleUnidata=Unidata.Make(Config)moduleUCharInfo=UCharInfo.Make(Config)moduletypeType=URe.Typeletproperty_to_setname=ifname="Any"thenUSet.compl(USet.empty)elsetryletcat=Unidata.cat_of_namenameinletm=UCharInfo.load_general_category_map()inUMap.map_to_set((=)cat)mwithNot_found->tryletscript=Unidata.script_of_namenameinletm=UCharInfo.load_script_map()inUMap.map_to_set((=)script)mwithNot_found->UCharInfo.load_property_set_by_namenameletregexps=letlexbuf=Lexing.from_stringsinlettree=UReStrParser.startUReStrLexer.tokenlexbufinletrecg=function`Sets->s|`Propertyname->property_to_setname|`Intr(n1,n2)->USet.inter(gn1)(gn2)|`Union(n1,n2)->USet.union(gn1)(gn2)|`Diff(n1,n2)->USet.diff(gn1)(gn2)|`Compln->USet.compl(gn)inletrecf=function`Alt(r1,r2)->`Alt(fr1,fr2)|`Seq(r1,r2)->`Seq(fr1,fr2)|`Repr->`Rep(fr)|`Repn(r,n,m)->`Repn(fr,n,m)|`Afterr->`After(fr)|`Beforer->`Before(fr)|`Groupr->`Group(fr)|`SetNotationset_notation->`Set(gset_notation)|`Sets->`Sets|`Stringulist->`Stringulist|(`Epsilon|`OneChar|`BoS|`EoS)asr->rinftreeletquotes=letb=Buffer.create8inString.iter(func->matchcwith'.'->Buffer.add_stringb"\\."|'*'->Buffer.add_stringb"\\*"|'+'->Buffer.add_stringb"\\+"|'?'->Buffer.add_stringb"\\?"|'['->Buffer.add_stringb"\\["|']'->Buffer.add_stringb"\\]"|'^'->Buffer.add_stringb"\\^"|'$'->Buffer.add_stringb"\\$"|'\\'->Buffer.add_stringb"\\\\"|c->Buffer.add_charbc)s;Buffer.contentsbletregexp_strings=letb=ref[]inUTF8.iter(funu->b:=u::!b)s;`String(List.rev!b)moduleMake(Text:UnicodeString.Type)=URe.Make(Text)end