From 0f917ddf7289d7da49b49bb817fc53295b8db2bb Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Fri, 6 Jun 2025 22:25:48 -0400 Subject: [PATCH] format --- .ocamlformat | 2 +- src/core/route.ml | 34 +++++++++++++++++++++++----------- src/core/route.mli | 30 +++++++++++++++--------------- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/.ocamlformat b/.ocamlformat index 7db51435..6a377a91 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,4 +1,4 @@ -version = 0.26.2 +version = 0.27.0 profile=conventional margin=80 if-then-else=k-r diff --git a/src/core/route.ml b/src/core/route.ml index f989dc86..bfca5267 100644 --- a/src/core/route.ml +++ b/src/core/route.ml @@ -73,9 +73,9 @@ let rec pp_ : type a b. Buffer.t -> (a, b) t -> unit = | Rest { url_encoded } -> bpf out "" (if url_encoded then - "_urlencoded" - else - "") + "_urlencoded" + else + "") | Compose (Exact s, tl) -> bpf out "%s/%a" s pp_ tl | Compose (Int, tl) -> bpf out "/%a" pp_ tl | Compose (String, tl) -> bpf out "/%a" pp_ tl @@ -96,17 +96,29 @@ let rec to_url_rec : type b. Buffer.t -> (b, string) t -> b = fun buf route -> match route with | Fire -> Buffer.contents buf - | Rest {url_encoded=_} -> - (fun str -> Buffer.add_string buf str; Buffer.contents buf) + | Rest { url_encoded = _ } -> + fun str -> + Buffer.add_string buf str; + Buffer.contents buf | Compose (comp, rest) -> (match comp with - | Exact s -> Buffer.add_string buf s; Buffer.add_char buf '/'; to_url_rec buf rest - | Int -> (fun i -> Printf.bprintf buf "%d/" i; to_url_rec buf rest) + | Exact s -> + Buffer.add_string buf s; + Buffer.add_char buf '/'; + to_url_rec buf rest + | Int -> + fun i -> + Printf.bprintf buf "%d/" i; + to_url_rec buf rest | String -> - (fun s -> Printf.bprintf buf "%s/" s; to_url_rec buf rest) - | String_urlencoded -> - (fun s -> Printf.bprintf buf "%s/" (Util.percent_encode s); to_url_rec buf rest)) + fun s -> + Printf.bprintf buf "%s/" s; + to_url_rec buf rest + | String_urlencoded -> + fun s -> + Printf.bprintf buf "%s/" (Util.percent_encode s); + to_url_rec buf rest) -let to_url (h: ('a, string) t) : 'a = +let to_url (h : ('a, string) t) : 'a = let buf = Buffer.create 16 in to_url_rec buf h diff --git a/src/core/route.mli b/src/core/route.mli index 9d70c47e..7d0c3980 100644 --- a/src/core/route.mli +++ b/src/core/route.mli @@ -1,8 +1,8 @@ (** Routing - Basic type-safe routing of handlers based on URL paths. This is optional, - it is possible to only define the root handler with something like - {{: https://github.com/anuragsoni/routes/} Routes}. + Basic type-safe routing of handlers based on URL paths. This is optional, it + is possible to only define the root handler with something like + {{:https://github.com/anuragsoni/routes/} Routes}. @since 0.6 *) type ('a, 'b) comp @@ -27,31 +27,31 @@ val return : ('a, 'a) t (** Matches the empty path. *) val rest_of_path : (string -> 'a, 'a) t -(** Matches a string, even containing ['/']. This will match - the entirety of the remaining route. - @since 0.7 *) +(** Matches a string, even containing ['/']. This will match the entirety of the + remaining route. + @since 0.7 *) val rest_of_path_urlencoded : (string -> 'a, 'a) t -(** Matches a string, even containing ['/'], and URL-decode it (piecewise). - This will match the entirety of the remaining route. - @since 0.7 *) +(** Matches a string, even containing ['/'], and URL-decode it (piecewise). This + will match the entirety of the remaining route. + @since 0.7 *) val ( @/ ) : ('a, 'b) comp -> ('b, 'c) t -> ('a, 'c) t -(** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"], - and [route] matches ["bar/…"]. *) +(** [comp / route] matches ["foo/bar/…"] iff [comp] matches ["foo"], and [route] + matches ["bar/…"]. *) val exact_path : string -> ('a, 'b) t -> ('a, 'b) t (** [exact_path "foo/bar/..." r] is equivalent to - [exact "foo" @/ exact "bar" @/ ... @/ r] - @since 0.11 **) + [exact "foo" @/ exact "bar" @/ ... @/ r] + @since 0.11 **) val pp : Format.formatter -> _ t -> unit (** Print the route. - @since 0.7 *) + @since 0.7 *) val to_string : _ t -> string (** Print the route. - @since 0.7 *) + @since 0.7 *) val to_url : ('a, string) t -> 'a