diff --git a/dune-project b/dune-project index 2b637a8..19fde5d 100644 --- a/dune-project +++ b/dune-project @@ -50,8 +50,6 @@ (cmdliner (>= 1.2.0)) dune-build-info - (iri - (>= 1.0.0)) (uucp (>= 15.1.0)) (eio_main diff --git a/forester.opam b/forester.opam index 6eb5fee..8533786 100644 --- a/forester.opam +++ b/forester.opam @@ -17,7 +17,6 @@ depends: [ "ppx_deriving" "cmdliner" {>= "1.2.0"} "dune-build-info" - "iri" {>= "1.0.0"} "uucp" {>= "15.1.0"} "eio_main" {>= "1.1"} "ptime" {>= "1.1.0"} diff --git a/lib/compiler/Eval.ml b/lib/compiler/Eval.ml index 55be58f..f0b2c5a 100644 --- a/lib/compiler/Eval.ml +++ b/lib/compiler/Eval.ml @@ -239,7 +239,7 @@ and eval_node node : V.t = | Ref -> begin match eval_pop_arg ~loc |> extract_iri with - | Ok href when URI.scheme href = URI_scheme.scheme -> + | Ok href when URI.scheme href = Some URI_scheme.scheme -> let content = T.Content [ @@ -356,7 +356,7 @@ and eval_node node : V.t = let href_arg = eval_pop_arg ~loc in let href = match extract_iri href_arg with - | Ok iri when URI.scheme iri = URI_scheme.scheme -> iri + | Ok iri when URI.scheme iri = Some URI_scheme.scheme -> iri | Ok iri -> Reporter.fatalf ?loc Type_error "Cannot transclude content with non-forester IRI %a" URI.pp iri | Error _ -> diff --git a/lib/core/URI_scheme.ml b/lib/core/URI_scheme.ml index 7202bea..311d30c 100644 --- a/lib/core/URI_scheme.ml +++ b/lib/core/URI_scheme.ml @@ -27,7 +27,7 @@ let hash_iri ~host hash_str = let is_named_iri iri = match URI.scheme iri, URI.path_components iri with - | sch, "hash" :: _ when sch = scheme -> false + | sch, "hash" :: _ when sch = Some scheme -> false | _ -> true let last_segment str = diff --git a/lib/core/Uri.ml b/lib/core/Uri.ml index 4b73947..fade071 100644 --- a/lib/core/Uri.ml +++ b/lib/core/Uri.ml @@ -1,53 +1,70 @@ module Basics = struct - type t = Iri.t + type t = { + scheme: string option; + userinfo: string option; + host: string option; + port: int option; + path: string; + fragment: string option; + } - let host = Iri.host - let scheme = Iri.scheme - let port = Iri.port - let path_string iri = Iri.path_string iri + let hydrate {scheme; userinfo; host; port; path; fragment} = + Uri.make ?scheme ?userinfo ?host ?port ~path ?fragment () - let equal x y = Iri.equal ~normalize: true x y - let compare x y = Iri.compare ~normalize: true x y - let resolve = Iri.resolve ~normalize: true - - let clean iri = Iri.with_query iri (Iri.query iri) - let hash (iri : t) = Hashtbl.hash (clean iri) + let dehydrate x = { + scheme = Uri.scheme x; + userinfo = Uri.userinfo x; + host = Uri.host x; + port = Uri.port x; + path = Uri.path x; + fragment = Uri.fragment x + } + let host x = x.host + let scheme x = x.scheme + let port x = x.port let path_components x = - match Iri.path x with - | Absolute xs -> xs - | Relative xs -> xs + List.filter (function "" -> false | _ -> true) @@ + String.split_on_char '/' @@ x.path + + let path_string x = + String.concat "/" @@ path_components x + + let equal = (=) + let compare = compare + + let resolve ~base x = + dehydrate @@ Uri.resolve "" (hydrate base) (hydrate x) + + let canonicalise iri = dehydrate @@ Uri.canonicalize @@ hydrate iri + let hash (iri : t) = Hashtbl.hash iri let with_path_components xs iri = - Iri.normalize @@ - match Iri.path iri with - | Absolute _ -> Iri.with_path iri (Absolute xs) - | Relative _ -> Iri.with_path iri (Relative xs) + dehydrate @@ + Uri.canonicalize @@ + Uri.with_path (hydrate iri) @@ String.concat "/" xs - let t = Repr.map Repr.string Iri.of_string Iri.to_string + let t = Repr.map Repr.string (Fun.compose dehydrate Uri.of_string) (Fun.compose Uri.to_string hydrate) let pp (fmt : Format.formatter) (iri : t) = Format.fprintf fmt "%s" @@ - Iri.to_string ~pctencode: false iri + Uri.to_string @@ hydrate iri (* wanted it not pct-encoded, but we'll see*) - let to_string = Iri.to_uri + let to_string x = Uri.to_string @@ hydrate x - let of_string_exn : string -> t = - Iri.of_string ~normalize: true + let of_string_exn str = + dehydrate @@ Uri.canonicalize @@ Uri.of_string str let make ?scheme ?user ?host ?port ?path () = - let path = Option.map (fun xs -> Iri.Absolute xs) path in - Iri.normalize @@ Iri.iri ?scheme ?user ?host ?port ?path () + let path = Option.map (String.concat "/") path in + dehydrate @@ Uri.canonicalize @@ Uri.make ?scheme ?userinfo: user ?host ?port ?path () let relativise ~(host : string) iri = - if scheme iri = "forest" && Iri.host iri = Some host then - let (Iri.Absolute components | Iri.Relative components) = Iri.path iri in - Iri.iri ~path: (Iri.Relative components) () + if scheme iri = Some "forest" && iri.host = Some host then + dehydrate @@ Uri.make ?scheme: (scheme iri) ~path: iri.path () else iri - - let canonicalise iri = Iri.normalize iri end module Set = Set.Make(Basics) diff --git a/lib/core/Uri.mli b/lib/core/Uri.mli index 15f23da..ab7b279 100644 --- a/lib/core/Uri.mli +++ b/lib/core/Uri.mli @@ -1,7 +1,7 @@ type t val host : t -> string option -val scheme : t -> string +val scheme : t -> string option val path_string : t -> string val path_components : t -> string list val with_path_components : string list -> t -> t @@ -12,9 +12,6 @@ val resolve : base: t -> t -> t val equal : t -> t -> bool val compare : t -> t -> int -(* TODO: get rid of *) -val clean : t -> t - val make : ?scheme: string -> ?user: string -> @@ -31,4 +28,4 @@ val of_string_exn : string -> t module Set : Set.S with type elt = t module Map : Map.S with type key = t -module Tbl : Hashtbl.S with type key = t \ No newline at end of file +module Tbl : Hashtbl.S with type key = t diff --git a/lib/core/Vertex.ml b/lib/core/Vertex.ml index f2bc7a3..b4b3499 100644 --- a/lib/core/Vertex.ml +++ b/lib/core/Vertex.ml @@ -11,7 +11,7 @@ type t = content vertex let clean = function | Content_vertex x -> Content_vertex x - | Iri_vertex iri -> Iri_vertex (URI.clean iri) + | Iri_vertex iri -> Iri_vertex iri let hash x = Hashtbl.hash (clean x) diff --git a/lib/core/dune b/lib/core/dune index d527262..84ed846 100644 --- a/lib/core/dune +++ b/lib/core/dune @@ -18,7 +18,7 @@ ocamlgraph bwd unix - iri + uri logs str lsp) diff --git a/lib/frontend/Legacy_xml_client.ml b/lib/frontend/Legacy_xml_client.ml index a449334..077b070 100644 --- a/lib/frontend/Legacy_xml_client.ml +++ b/lib/frontend/Legacy_xml_client.ml @@ -36,7 +36,7 @@ let transclusion_cache = Hashtbl.create 1000 let iri_to_string ~(config : Config.t) iri = match URI.host iri with - | Some host when URI.scheme iri = URI_scheme.scheme -> + | Some host when URI.scheme iri = Some URI_scheme.scheme -> if host = config.host then URI.path_string @@ URI.relativise ~host iri else @@ -62,7 +62,8 @@ let iri_is_home ~config iri = let route_resource_iri ~suffix (forest : State.t) iri = let config = forest.config in let host = Option.value ~default: "" @@ URI.host iri in - let bare_route = String.concat "-" @@ URI.path_components iri in + let components = URI.path_components iri in + let bare_route = String.concat "-" components in begin if host = config.host then if iri_is_home ~config iri then "index.xml" @@ -81,7 +82,7 @@ let route (forest : State.t) iri = | T.Asset _ -> "" in route_resource_iri ~suffix forest iri - | None when URI.scheme iri = URI_scheme.scheme -> + | None when URI.scheme iri = Some URI_scheme.scheme -> Reporter.emitf Broken_link "Could not route link to resource %a" URI.pp iri; URI.to_string iri | None ->