Skip to content

Commit

Permalink
Merge pull request #62 from sim642/remove-rresult
Browse files Browse the repository at this point in the history
Remove remaining references to Rresult
  • Loading branch information
avsm authored Nov 4, 2023
2 parents 76bfa98 + 9de5a36 commit dbc5d3b
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 24 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ locally by running `dune utop`.
- : string Yaml.res = Result.Ok "foo1: bar1\nfoo2: 1\n"
# #require "yaml.unix" ;;
# Yaml_unix.to_file Fpath.(v "my.yml") (`String "bar") ;;
- : (unit, Rresult.R.msg) result = Result.Ok ()
- : (unit, [ `Msg of string ]) result = Result.Ok ()
# Yaml_unix.of_file Fpath.(v "my.yml");;
- : (Yaml.value, Rresult.R.msg) result = Result.Ok (`String "bar")
- : (Yaml.value, [ `Msg of string ]) result = Result.Ok (`String "bar")
# Yaml_unix.of_file_exn Fpath.(v "my.yml");;
- : Yaml.value = `String "bar"
```
Expand Down Expand Up @@ -106,7 +106,6 @@ We use the following major OCaml tools and libraries:
- **build:** [dune](https://github.com/janestreet/dune) is the build tool used.
- **ffi:** [ctypes](https://github.com/ocamllabs/ocaml-ctypes) is the library to interface with the C FFI exposed by libYaml.
- **preprocessor:** [ppx_sexp_conv](https://github.com/janestreet/ppx_sexp_conv) generates s-expression serialises and deserialisers for the types exposed by the library, exposed in a `yaml-sexp` package.
- **error handling:** [rresult](https://github.com/dbuenzli/rresult) is a set of combinators for returning errors as values, instead of raising OCaml exceptions.
- **tests:** [alcotest](https://github.com/mirage/alcotest) specifies conventional unit tests, and [crowbar](https://github.com/stedolan/crowbar) is used to drive property-based fuzz-testing of the library.

#### Library Architecture
Expand Down Expand Up @@ -155,8 +154,8 @@ to compile with the C header files for the yaml library. The resulting OCaml fu
are exported in the `yaml.ffi` ocamlfind library.

**OCaml API:** Finally, we define the OCaml API that uses the low-level FFI to expose
a well-typed OCaml interface. We adopt a convention of using the [Rresult](https://github.com/dbuenzli/rresult)
library to return explicit errors instead of raising OCaml exceptions. We also
a well-typed OCaml interface. We adopt a convention of using the standard `result`
type to return explicit errors instead of raising OCaml exceptions. We also
define some polymorphic variant types to represent various configuration options
(such as the printing style of different Yaml values).

Expand Down
4 changes: 2 additions & 2 deletions fuzz/fuzz.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

open Crowbar
open Rresult
open R.Infix

let ( >>= ) = Result.bind

(* Consume all the events in a stream using the
low-level API and return a bool to indicate success *)
Expand Down
4 changes: 2 additions & 2 deletions lib/yaml.mli
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ type layout_style = [ `Any | `Block | `Flow ]
notation. *)

type 'a res = ('a, [ `Msg of string ]) result
(** This library uses the {!Rresult.R.msg} conventions for returning errors
rather than raising exceptions. *)
(** This library uses the standard {!result} type for returning errors rather
than raising exceptions. *)

(** {2 Serialisers and deserialisers}
Expand Down
2 changes: 1 addition & 1 deletion tests/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let quoted_scalars =
(* Given an input string, we want to test two things:
- if the input is parsed as an expected Yaml.value and;
- if encoding the parsed Yaml.yaml results in the original string. *)
let open Rresult.R.Infix in
let ( >>= ) = Result.bind in
let test name str expected =
let actual_yaml = Yaml.yaml_of_string str in
let actual_value = actual_yaml >>= Yaml.to_json in
Expand Down
4 changes: 2 additions & 2 deletions tests/test_emit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

open Rresult
open R.Infix
module S = Yaml.Stream

let ( >>= ) = Result.bind

let scalar ?anchor ?tag ?(plain_implicit = true) ?(quoted_implicit = false)
?(style = `Plain) value : Yaml.scalar =
{ anchor; tag; plain_implicit; quoted_implicit; style; value }
Expand Down
8 changes: 3 additions & 5 deletions tests/test_event_parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

module T = Yaml_types.M
open Rresult

let ( >>= ) = Result.bind

let v file =
let open R.Infix in
Bos.OS.File.read file >>= fun buf ->
Yaml.Stream.parser buf >>= fun t ->
let rec iter_until_done fn =
Yaml.Stream.do_parse t >>= fun (e, _pos) ->
match e with
| Yaml.Stream.Event.Nothing -> R.ok ()
| _ -> iter_until_done fn
match e with Yaml.Stream.Event.Nothing -> Ok () | _ -> iter_until_done fn
in
iter_until_done ()
3 changes: 1 addition & 2 deletions tests/test_parse.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
open Rresult
let ( >>= ) = Result.bind

let v file =
let open R.Infix in
Bos.OS.File.read file >>= fun buf ->
Yaml.yaml_of_string buf >>= fun v ->
Yaml.to_json v >>= fun json ->
Expand Down
3 changes: 1 addition & 2 deletions tests/test_parse_sexp.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
open Rresult
let ( >>= ) = Result.bind

type t = { v : Yaml_sexp.value } [@@deriving sexp]

let v file =
let open R.Infix in
Bos.OS.File.read file >>= fun buf ->
Yaml.yaml_of_string buf >>= fun v ->
Yaml_sexp.sexp_of_yaml v |> fun s ->
Expand Down
5 changes: 2 additions & 3 deletions tests/test_reflect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *)

module T = Yaml_types.M
open Rresult

let ( >>= ) = Result.bind
let reflect e ev pos = Yaml.Stream.emit e ev

let v file =
let open R.Infix in
Bos.OS.File.read file >>= fun buf ->
Yaml.Stream.parser buf >>= fun t ->
Yaml.Stream.emitter () >>= fun e ->
let rec iter_until_done fn =
Yaml.Stream.do_parse t >>= fun (e, pos) ->
match e with
| Yaml.Stream.Event.Nothing -> R.ok ()
| Yaml.Stream.Event.Nothing -> Ok ()
| event -> fn event pos >>= fun () -> iter_until_done fn
in
iter_until_done (reflect e) >>= fun () ->
Expand Down

0 comments on commit dbc5d3b

Please sign in to comment.