Skip to content

Commit

Permalink
Merge pull request #24 from TypesLogicsCats/dune-migration
Browse files Browse the repository at this point in the history
Migrate from Jbuilder to Dune
  • Loading branch information
mjambon authored Jun 26, 2019
2 parents 81410c7 + dcc6501 commit 4c34787
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 68 deletions.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 1.0)
(name easy-format)
6 changes: 3 additions & 3 deletions easy-format.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
10 changes: 10 additions & 0 deletions examples/dune
Original file line number Diff line number Diff line change
@@ -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))
11 changes: 0 additions & 11 deletions examples/jbuild

This file was deleted.

2 changes: 1 addition & 1 deletion examples/simple_example.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down
4 changes: 4 additions & 0 deletions src/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name easy_format)
(public_name easy-format)
(synopsis "Indentation made easy(ier)"))
53 changes: 21 additions & 32 deletions src/easy_format.ml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) ->
Expand All @@ -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 _
Expand All @@ -161,32 +150,32 @@ 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
List ((op, sep, cl, p), children), true
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
Expand Down Expand Up @@ -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
Expand All @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/jbuild

This file was deleted.

10 changes: 10 additions & 0 deletions test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(executable
(name test_easy_format)
(libraries easy-format))

(alias
(name runtest)
(deps
(:< test_easy_format.exe))
(action
(run %{<})))
10 changes: 0 additions & 10 deletions test/jbuild

This file was deleted.

0 comments on commit 4c34787

Please sign in to comment.