Skip to content

Commit

Permalink
Merge pull request #138 from avsm/uri-3
Browse files Browse the repository at this point in the history
prepare uri 3
  • Loading branch information
avsm committed Jul 10, 2019
2 parents 1f37ecc + eeb919e commit a2d304a
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 169 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ script: bash ./.travis-docker.sh
env:
global:
- PACKAGE="uri"
- PRE_INSTALL_HOOK="cd /home/opam/opam-repository && git pull origin master && opam update -uy"
- POST_INSTALL_HOOK="opam --yes depext -yui react ssl lwt"
- PINS="uri-sexp:."
- PINS="uri.dev:. uri-sexp.dev:."
- REVDEPS="cohttp git github irmin syndic"
matrix:
- DISTRO=centos OCAML_VERSION=4.04
Expand Down
8 changes: 5 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ v3.0.0 2019-07-06
Code that was formerly using `uri.sexp` in its build will now need to
move to `uri-sexp` instead (#134 @Julow @dinosaure).

* Create a `Uri.Re` module instead of the toplevel `Uri_re`, and
deprecate the latter. The `Uri_re` toplevel module will be removed
in the next major release of this library (#134 @Julow @dinosaure).
* Remove the deprecated `Uri_re` module. All code should be using the
`Uri.Re` module instead (@avsm @Julow).

* Remove the `uri.top` library, since we install the toplevel printer
automatically since 2.2.0 via an attribute.

v2.2.1 2019-06-02
-----------------
Expand Down
8 changes: 0 additions & 8 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
(library
(name uri)
(public_name uri)
(wrapped (transition "Please switch to using Uri.Re instead of Uri_re, which will be removed in Uri.4.0.0 and higher."))
(modules uri uri_re)
(libraries re.posix stringext))

(library
(name uri_top)
(public_name uri.top)
(modules uri_top)
(libraries uri compiler-libs))
104 changes: 104 additions & 0 deletions lib/uri.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,107 @@

[@@@ocaml.warning "-32"]

module Uri_re = struct
open Re

module Raw = struct
let (+) a b = seq [a;b]
let (/) a b = alt [a;b]

let gen_delims = Posix.re "[:/?#\\[\\]@]"
let sub_delims = Posix.re "[!$&'()*+,;=]"
let c_at = char '@'
let c_colon = char ':'
let c_slash = char '/'
let c_slash2 = Posix.re "//"
let c_dot = char '.'
let c_question = char '?'
let c_hash = char '#'

let reserved = gen_delims / sub_delims
let unreserved = Posix.re "[A-Za-z0-9-._~]"
let hexdig = Posix.re "[0-9A-Fa-f]"
let pct_encoded = (char '%') + hexdig + hexdig

let dec_octet = Posix.re "25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?"
let ipv4_address = (repn (dec_octet + c_dot) 3 (Some 3)) + dec_octet

(* following RFC2234, RFC3986, RFC6874 and
http://people.spodhuis.org/phil.pennock/software/emit_ipv6_regexp-0.304
*)
let zone_id = unreserved / pct_encoded
let ipv6_address =
let (=|) n a = repn a n (Some n) in
let (<|) n a = repn a 0 (Some n) in
let h16 = repn hexdig 1 (Some 4) in
let h16c = h16 + c_colon in
let cc = c_colon + c_colon in
let ls32 = (h16c + h16) / ipv4_address in
( 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" + rep1 zone_id))
+ char ']'
)

let reg_name = rep ( unreserved / pct_encoded / sub_delims )

let host = ipv6_address / ipv4_address / reg_name (* | ipv4_literal TODO *)
let userinfo = rep (unreserved / pct_encoded / sub_delims / c_colon)
let port = Posix.re "[0-9]*"
let authority = (opt ((group userinfo) + c_at)) + (group host) + (opt (c_colon + (group port)))
let null_authority = (group empty) + (group empty) + (group empty)

let pchar = unreserved / pct_encoded / sub_delims / c_colon / c_at
let segment = rep pchar
let segment_nz = rep1 pchar
let segment_nz_nc = repn (unreserved / pct_encoded / sub_delims / c_at) 1 None
let path_abempty = rep (c_slash + segment)
let path_absolute = c_slash + (opt (segment_nz + (rep (c_slash + segment))))
let path_noscheme = segment_nz_nc + (rep (c_slash + segment ))
let path_rootless = segment_nz + (rep (c_slash + segment ))
let path_empty = empty

let path = 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 *)

let hier_part = (c_slash2 + authority + path_abempty)
/ (path_absolute / path_rootless / path_empty)

let scheme = Posix.re "[A-Za-z][A-Za-z0-9+\\\\-\\.]*"
let query = group (rep ( pchar / c_slash / c_question))
let fragment = group (rep (pchar / c_slash / c_question))

let absolute_uri = scheme + c_colon + hier_part + (opt (c_question + query))

let uri = scheme + c_colon + hier_part + (opt (c_question + query)) + (opt (c_hash + fragment))

let relative_part = (c_slash2 + authority + path_abempty) / (path_absolute / path_noscheme / path_empty)

let relative_ref = relative_part + (opt (c_question + query)) + (opt (c_hash + fragment))

let uri_reference = Posix.re "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"
end

let ipv4_address = Posix.compile Raw.ipv4_address
let ipv6_address = Posix.compile Raw.ipv6_address
let uri_reference = Posix.compile Raw.uri_reference
let authority = Posix.compile Raw.authority

let host = Posix.compile Raw.host
end

type component = [
| `Scheme
| `Authority
Expand Down Expand Up @@ -894,3 +995,6 @@ let canonicalize uri =

let pp ppf uri = Format.pp_print_string ppf (to_string uri)
let pp_hum ppf uri = Format.pp_print_string ppf (to_string uri)

module Re = Uri_re

9 changes: 9 additions & 0 deletions lib/uri.mli
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,12 @@ val pp : Format.formatter -> t -> unit [@@ocaml.toplevel_printer]

(** [pp_hum] is now an alias for the {!pp} function. *)
val pp_hum : Format.formatter -> t -> unit

(** Regular expressions for URI parsing. *)
module Re : sig
val ipv4_address : Re.re
val ipv6_address : Re.re
val uri_reference : Re.re
val authority : Re.re
val host : Re.re
end
116 changes: 0 additions & 116 deletions lib/uri_re.ml

This file was deleted.

24 changes: 0 additions & 24 deletions lib/uri_re.mli

This file was deleted.

17 changes: 0 additions & 17 deletions lib/uri_top.ml

This file was deleted.

0 comments on commit a2d304a

Please sign in to comment.