123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116(*
* Copyright (c) 2012 Anil Madhavapeddy <anil@recoil.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*)[@@@ocaml.warning"-32"]openRemoduleRaw=structlet(+)ab=seq[a;b]let(/)ab=alt[a;b]letgen_delims=Posix.re"[:/?#\\[\\]@]"letsub_delims=Posix.re"[!$&'()*+,;=]"letc_at=char'@'letc_colon=char':'letc_slash=char'/'letc_slash2=Posix.re"//"letc_dot=char'.'letc_question=char'?'letc_hash=char'#'letreserved=gen_delims/sub_delimsletunreserved=Posix.re"[A-Za-z0-9-._~]"lethexdig=Posix.re"[0-9A-Fa-f]"letpct_encoded=(char'%')+hexdig+hexdigletdec_octet=Posix.re"25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?"letipv4_address=(repn(dec_octet+c_dot)3(Some3))+dec_octet(* following RFC2234, RFC3986, RFC6874 and
http://people.spodhuis.org/phil.pennock/software/emit_ipv6_regexp-0.304
*)letzone_id=unreserved/pct_encodedletipv6_address=let(=|)na=repnan(Somen)inlet(<|)na=repna0(Somen)inleth16=repnhexdig1(Some4)inleth16c=h16+c_coloninletcc=c_colon+c_coloninletls32=(h16c+h16)/ipv4_addressin(char'['+(((6=|h16c)+ls32)/(cc+(5=|h16c)+ls32)/((1<|h16)+cc+(4=|h16c)+ls32)/((1<|((1<|h16c)+h16))+cc+(3=|h16c)+ls32)/((1<|((2<|h16c)+h16))+cc+(2=|h16c)+ls32)/((1<|((3<|h16c)+h16))+cc+h16c+ls32)/((1<|((4<|h16c)+h16))+cc+ls32)/((1<|((5<|h16c)+h16))+cc+h16)/((1<|((6<|h16c)+h16))+cc))+(opt(Posix.re"%25"+rep1zone_id))+char']')letreg_name=rep(unreserved/pct_encoded/sub_delims)lethost=ipv6_address/ipv4_address/reg_name(* | ipv4_literal TODO *)letuserinfo=rep(unreserved/pct_encoded/sub_delims/c_colon)letport=Posix.re"[0-9]*"letauthority=(opt((groupuserinfo)+c_at))+(grouphost)+(opt(c_colon+(groupport)))letnull_authority=(groupempty)+(groupempty)+(groupempty)letpchar=unreserved/pct_encoded/sub_delims/c_colon/c_atletsegment=reppcharletsegment_nz=rep1pcharletsegment_nz_nc=repn(unreserved/pct_encoded/sub_delims/c_at)1Noneletpath_abempty=rep(c_slash+segment)letpath_absolute=c_slash+(opt(segment_nz+(rep(c_slash+segment))))letpath_noscheme=segment_nz_nc+(rep(c_slash+segment))letpath_rootless=segment_nz+(rep(c_slash+segment))letpath_empty=emptyletpath=path_abempty(* begins with "/" or is empty *)/path_absolute(* begins with "/" but not "//" *)/path_noscheme(* begins with a non-colon segment *)/path_rootless(* begins with a segment *)/path_empty(* zero characters *)lethier_part=(c_slash2+authority+path_abempty)/(path_absolute/path_rootless/path_empty)letscheme=Posix.re"[A-Za-z][A-Za-z0-9+\\\\-\\.]*"letquery=group(rep(pchar/c_slash/c_question))letfragment=group(rep(pchar/c_slash/c_question))letabsolute_uri=scheme+c_colon+hier_part+(opt(c_question+query))leturi=scheme+c_colon+hier_part+(opt(c_question+query))+(opt(c_hash+fragment))letrelative_part=(c_slash2+authority+path_abempty)/(path_absolute/path_noscheme/path_empty)letrelative_ref=relative_part+(opt(c_question+query))+(opt(c_hash+fragment))leturi_reference=Posix.re"^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"endletipv4_address=Posix.compileRaw.ipv4_addressletipv6_address=Posix.compileRaw.ipv6_addressleturi_reference=Posix.compileRaw.uri_referenceletauthority=Posix.compileRaw.authoritylethost=Posix.compileRaw.host