diff --git a/Makefile b/Makefile index df2f2f5..68df4f4 100644 --- a/Makefile +++ b/Makefile @@ -1,18 +1,18 @@ all: - @jbuilder build @install @DEFAULT + dune build @install @DEFAULT test: - @jbuilder runtest + dune runtest install: - @jbuilder install + dune install uninstall: - @jbuilder uninstall + dune uninstall check: test .PHONY: clean all check test install uninstall clean: - jbuilder clean + dune clean diff --git a/dune-project b/dune-project new file mode 100644 index 0000000..03aca7a --- /dev/null +++ b/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.0) +(name easy-format) diff --git a/easy-format.opam b/easy-format.opam index 51f2e87..f3f9990 100644 --- a/easy-format.opam +++ b/easy-format.opam @@ -5,11 +5,11 @@ homepage: "http://mjambon.com/easy-format.html" bug-reports: "https://github.com/mjambon/easy-format/issues" dev-repo: "https://github.com/mjambon/easy-format.git" build: [ - ["jbuilder" "build" "-p" name "-j" jobs] + ["dune" "build" "-p" name "-j" jobs] ] build-test: [ - ["jbuilder" "runtest" "-p" name] + ["dune" "runtest" "-p" name "-j" jobs] ] -depends: ["jbuilder" {build}] +depends: ["dune" {build & >= "1.0"}] available: [ ocaml-version >= "4.02.3"] \ No newline at end of file diff --git a/examples/dune b/examples/dune new file mode 100644 index 0000000..b5cca58 --- /dev/null +++ b/examples/dune @@ -0,0 +1,10 @@ +;; we don't include jsonpp here b/c it requires json-wheel + +(executables + (names simple_example lambda_example) + (modules :standard \ jsonpp) + (libraries easy-format)) + +(alias + (name DEFAULT) + (deps simple_example.exe lambda_example.exe)) diff --git a/examples/jbuild b/examples/jbuild deleted file mode 100644 index 9308eb4..0000000 --- a/examples/jbuild +++ /dev/null @@ -1,11 +0,0 @@ -(jbuild_version 1) - -;; we don't include jsonpp here b/c it requires json-wheel -(executables - ((names (simple_example lambda_example)) - (modules (:standard \ jsonpp)) - (libraries (easy-format)))) - -(alias - ((name DEFAULT) - (deps (simple_example.exe lambda_example.exe)))) \ No newline at end of file diff --git a/examples/simple_example.ml b/examples/simple_example.ml index 56abc67..409e28c 100644 --- a/examples/simple_example.ml +++ b/examples/simple_example.ml @@ -176,7 +176,7 @@ let make_heterogenous_list (container_wrap, wrap) = let print_margin fmt () = let margin = Format.pp_get_margin fmt () in - for i = 1 to margin do + for _ = 1 to margin do print_char '+' done; print_newline () diff --git a/src/dune b/src/dune new file mode 100644 index 0000000..28e8d16 --- /dev/null +++ b/src/dune @@ -0,0 +1,4 @@ +(library + (name easy_format) + (public_name easy-format) + (synopsis "Indentation made easy(ier)")) diff --git a/src/easy_format.ml b/src/easy_format.ml index 881f18e..a074de3 100644 --- a/src/easy_format.ml +++ b/src/easy_format.ml @@ -1,23 +1,12 @@ open Format -(** Shadow map and split with tailrecursive variants. *) -module List = struct - include List - (** Tail recursive of map *) - let map f l = List.rev_map f l |> List.rev - - (** Tail recursive version of split *) - let rev_split l = - let rec inner xs ys = function - | (x, y) :: xys -> - inner (x::xs) (y::ys) xys - | [] -> (xs, ys) - in - inner [] [] l - - let split l = rev_split (List.rev l) - -end +let rev_split l = + let rec inner xs ys = function + | (x, y) :: xys -> + inner (x::xs) (y::ys) xys + | [] -> (xs, ys) + in + inner [] [] l type wrap = [ | `Wrap_atoms @@ -127,7 +116,7 @@ let propagate_from_leaf_to_root let acc = init_acc x in map_node x acc | List (param, children) -> - let new_children, accs = List.rev_split (List.rev_map aux children) in + let new_children, accs = rev_split (List.rev_map aux children) in let acc = List.fold_left merge_acc (init_acc x) accs in map_node (List (param, new_children)) acc | Label ((x1, param), x2) -> @@ -149,8 +138,8 @@ let propagate_from_leaf_to_root let propagate_forced_breaks x = (* acc = whether to force breaks in wrappable lists or labels *) let init_acc = function - | List ((_, _, _, { wrap_body = `Force_breaks_rec }), _) - | Label ((_, { label_break = `Always_rec }), _) -> true + | List ((_, _, _, { wrap_body = `Force_breaks_rec; _ }), _) + | Label ((_, { label_break = `Always_rec; _ }), _) -> true | Atom _ | Label _ | Custom _ @@ -161,12 +150,12 @@ let propagate_forced_breaks x = in let map_node x force_breaks = match x with - | List ((_, _, _, { wrap_body = `Force_breaks_rec }), _) -> x, true - | List ((_, _, _, { wrap_body = `Force_breaks }), _) -> x, force_breaks + | List ((_, _, _, { wrap_body = `Force_breaks_rec; _ }), _) -> x, true + | List ((_, _, _, { wrap_body = `Force_breaks; _ }), _) -> x, force_breaks | List ((op, sep, cl, ({ wrap_body = (`Wrap_atoms | `Never_wrap - | `Always_wrap) } as p)), + | `Always_wrap); _ } as p)), children) -> if force_breaks then let p = { p with wrap_body = `Force_breaks } in @@ -174,19 +163,19 @@ let propagate_forced_breaks x = else x, false - | Label ((a, ({ label_break = `Auto } as lp)), b) -> + | Label ((a, ({ label_break = `Auto; _ } as lp)), b) -> if force_breaks then let lp = { lp with label_break = `Always } in Label ((a, lp), b), true else x, false - | List ((_, _, _, { wrap_body = `No_breaks }), _) - | Label ((_, { label_break = (`Always | `Always_rec | `Never) }), _) + | List ((_, _, _, { wrap_body = `No_breaks; _ }), _) + | Label ((_, { label_break = (`Always | `Always_rec | `Never); _ }), _) | Atom _ | Custom _ -> x, force_breaks in - let new_x, forced_breaks = + let new_x, _forced_breaks = propagate_from_leaf_to_root ~init_acc ~merge_acc @@ -288,7 +277,7 @@ struct let pp_open_xbox fmt p indent = match p.wrap_body with - `Always_wrap + `Always_wrap | `Never_wrap | `Wrap_atoms -> pp_open_hvbox fmt indent | `Force_breaks @@ -310,8 +299,8 @@ struct ((fun fmt -> pp_open_hovbox fmt 0), (fun fmt -> pp_close_box fmt ())) else - ((fun fmt -> ()), - (fun fmt -> ())) + ((fun _ -> ()), + (fun _ -> ())) let pp_open_nonaligned_box fmt p indent l = @@ -401,7 +390,7 @@ struct pp_print_string fmt " " (* Either horizontal or vertical list *) - and fprint_list fmt label ((op, sep, cl, p) as param) = function + and fprint_list fmt label ((op, _sep, cl, p) as param) = function [] -> fprint_opt_label fmt label; tag_string fmt p.opening_style op; diff --git a/src/jbuild b/src/jbuild deleted file mode 100644 index d0d51a3..0000000 --- a/src/jbuild +++ /dev/null @@ -1,6 +0,0 @@ -(jbuild_version 1) - -(library - ((name easy_format) - (public_name easy-format) - (synopsis "Indentation made easy(ier)"))) \ No newline at end of file diff --git a/test/dune b/test/dune new file mode 100644 index 0000000..976ff22 --- /dev/null +++ b/test/dune @@ -0,0 +1,10 @@ +(executable + (name test_easy_format) + (libraries easy-format)) + +(alias + (name runtest) + (deps + (:< test_easy_format.exe)) + (action + (run %{<}))) diff --git a/test/jbuild b/test/jbuild deleted file mode 100644 index f1631bb..0000000 --- a/test/jbuild +++ /dev/null @@ -1,10 +0,0 @@ -(jbuild_version 1) - -(executable - ((name test_easy_format) - (libraries (easy-format)))) - -(alias - ((name runtest) - (deps (test_easy_format.exe)) - (action (run ${<})))) \ No newline at end of file