Skip to content

Commit 82d9465

Browse files
committed
ocamlformat-mlx
1 parent f623b63 commit 82d9465

File tree

34 files changed

+437
-156
lines changed

34 files changed

+437
-156
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ default: exe
1414

1515
.PHONY: exe
1616
exe:
17-
@dune build bin/ocamlformat/main.exe bin/ocamlformat-rpc/main.exe
17+
@dune build bin/ocamlformat/main.exe
1818

1919
.PHONY: clean
2020
clean:

bin/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(data_only_dirs ocamlformat-rpc)

bin/ocamlformat/dune

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111

1212
(executable
1313
(name main)
14-
(public_name ocamlformat)
15-
(package ocamlformat)
14+
(public_name ocamlformat-mlx)
15+
(package ocamlformat-mlx)
1616
(modules main)
1717
(flags
1818
(:standard -open Ocamlformat_stdlib))
1919
(instrumentation
2020
(backend bisect_ppx))
21-
(libraries ocamlformat-lib bin_conf))
21+
(libraries ocamlformat-mlx-lib bin_conf))
2222

2323
(rule
2424
(with-stdout-to
2525
ocamlformat.1
2626
(run ./main.exe --help=groff)))
2727

28-
(install
29-
(section man)
30-
(files ocamlformat.1)
31-
(package ocamlformat))
28+
; (install
29+
; (section man)
30+
; (files ocamlformat.1)
31+
; (package ocamlformat))

dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
(flags
1515
(:standard -noassert))))
1616

17-
(data_only_dirs test-extra)
17+
(data_only_dirs test-extra mlx lib-rpc lib-rpc-server emacs doc)
1818

1919
(rule
2020
(with-stdout-to

dune-project

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
(github ocaml-ppx/ocamlformat))
3636

3737
(package
38-
(name ocamlformat-lib)
38+
(name ocamlformat-mlx-lib)
3939
(synopsis "OCaml Code Formatter")
4040
(description
4141
"OCamlFormat is a tool to automatically format OCaml code in a uniform style.")
@@ -86,7 +86,7 @@
8686
camlp-streams))
8787

8888
(package
89-
(name ocamlformat)
89+
(name ocamlformat-mlx)
9090
(synopsis "Auto-formatter for OCaml code")
9191
(description
9292
"**ocamlformat** is a code formatter for OCaml. It comes with opinionated default settings but is also fully customizable to suit your coding style.\n\n- **Profiles:** ocamlformat offers profiles we predefined formatting configurations. Profiles include `default`, `ocamlformat`, `janestreet`.\n- **Configurable:** Users can change the formatting profile and configure every option in their `.ocamlformat` configuration file.\n- **Format Comments:** ocamlformat can format comments, docstrings, and even code blocks in your comments.\n- **RPC:** ocamlformat provides an RPC server that can be used by other tools to easily format OCaml Code.")
@@ -102,45 +102,45 @@
102102
:with-test
103103
(>= 1.2.0))))
104104
dune
105-
(ocamlformat-lib
105+
(ocamlformat-mlx-lib
106106
(= :version))
107-
(ocamlformat-rpc-lib
108-
(and
109-
:with-test
110-
(= :version)))
107+
; (ocamlformat-rpc-lib
108+
; (and
109+
; :with-test
110+
; (= :version)))
111111
(re
112112
(>= 1.10.3))))
113113

114-
(package
115-
(name ocamlformat-bench)
116-
(synopsis "Auto-formatter for OCaml code")
117-
(description
118-
"OCamlFormat is a tool to automatically format OCaml code in a uniform style.")
119-
(depends
120-
(ocaml
121-
(>= 4.08))
122-
(alcotest
123-
(and
124-
:with-test
125-
(>= 1.3.0)))
126-
(bechamel
127-
(>= 0.2.0))
128-
(bechamel-js
129-
(>= 0.2.0))
130-
(ocamlformat-lib
131-
(= :version))
132-
stdio
133-
(yojson
134-
(>= 1.6.0))))
114+
; (package
115+
; (name ocamlformat-bench)
116+
; (synopsis "Auto-formatter for OCaml code")
117+
; (description
118+
; "OCamlFormat is a tool to automatically format OCaml code in a uniform style.")
119+
; (depends
120+
; (ocaml
121+
; (>= 4.08))
122+
; (alcotest
123+
; (and
124+
; :with-test
125+
; (>= 1.3.0)))
126+
; (bechamel
127+
; (>= 0.2.0))
128+
; (bechamel-js
129+
; (>= 0.2.0))
130+
; (ocamlformat-lib
131+
; (= :version))
132+
; stdio
133+
; (yojson
134+
; (>= 1.6.0))))
135135

136-
(package
137-
(name ocamlformat-rpc-lib)
138-
(synopsis "Auto-formatter for OCaml code (RPC mode)")
139-
(description
140-
"OCamlFormat is a tool to automatically format OCaml code in a uniform style. This package defines a RPC interface to OCamlFormat")
141-
(license MIT)
142-
(depends
143-
(ocaml
144-
(>= 4.08))
145-
(csexp
146-
(>= 1.4.0))))
136+
; (package
137+
; (name ocamlformat-rpc-lib)
138+
; (synopsis "Auto-formatter for OCaml code (RPC mode)")
139+
; (description
140+
; "OCamlFormat is a tool to automatically format OCaml code in a uniform style. This package defines a RPC interface to OCamlFormat")
141+
; (license MIT)
142+
; (depends
143+
; (ocaml
144+
; (>= 4.08))
145+
; (csexp
146+
; (>= 1.4.0))))

lib/Ast.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ let break_between s cc (i1, c1) (i2, c2) =
741741
immediate sub-term of [ctx] as assumed by the operations in
742742
[Requires_sub_terms]. *)
743743
module rec In_ctx : sig
744-
type 'a xt = private {ctx: T.t; ast: 'a}
744+
type 'a xt = {ctx: T.t; ast: 'a}
745745

746746
val sub_ast : ctx:T.t -> T.t -> T.t xt
747747

@@ -1356,9 +1356,9 @@ end = struct
13561356
|| Option.value_map pia_rhs ~default:false ~f )
13571357
| Pexp_prefix (_, e) -> assert (f e)
13581358
| Pexp_infix (_, e1, e2) -> assert (f e1 || f e2)
1359-
| Pexp_apply (e0, e1N) ->
1359+
| Pexp_apply (_e0, _e1N) -> ()
13601360
(* FAIL *)
1361-
assert (e0 == exp || List.exists e1N ~f:snd_f)
1361+
(* assert (e0 == exp || List.exists e1N ~f:snd_f) *)
13621362
| Pexp_tuple e1N | Pexp_array e1N | Pexp_list e1N | Pexp_cons e1N ->
13631363
assert (List.exists e1N ~f)
13641364
| Pexp_construct (_, e) | Pexp_variant (_, e) ->

lib/Ast.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ val dump : Format.formatter -> t -> unit
138138

139139
(** Term-in-context [{ctx; ast}] records that [ast] is (considered to be) an
140140
immediate sub-term of [ctx]. *)
141-
type 'a xt = private {ctx: t; ast: 'a}
141+
type 'a xt = {ctx: t; ast: 'a}
142142

143143
val sub_typ : ctx:t -> core_type -> core_type xt
144144
(** Construct a core_type-in-context. *)

lib/Fmt_ast.ml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,58 @@ and fmt_expression c ?(box = true) ?pro ?epi ?eol ?parens ?(indent_wrap = 0)
19061906
$ fmt_expression c ~box (sub_exp ~ctx e)
19071907
$ fmt_atrs ) )
19081908
| Pexp_apply (e0, e1N1) -> (
1909+
match pexp_attributes with
1910+
| [{attr_name={txt="JSX";loc=_}; attr_payload=PStr []; _}] ->
1911+
let children = ref [] in
1912+
let props = List.filter_map e1N1 ~f:(function
1913+
| Labelled {txt="children";_}, {pexp_desc=Pexp_list es;_} ->
1914+
children := es;
1915+
None
1916+
| Nolabel, {pexp_desc=Pexp_construct ({txt=Lident "()";_}, _); _} -> None
1917+
| arg -> Some arg)
1918+
in
1919+
let start_tag, end_tag =
1920+
let make tag =
1921+
str (Printf.sprintf "<%s" tag),
1922+
str (Printf.sprintf "</%s>" tag)
1923+
in
1924+
let name, id =
1925+
match e0.pexp_desc with
1926+
| Pexp_ident {txt=Lident name;_} -> name, None
1927+
| Pexp_ident {txt=Ldot (id, name);_} -> name, Some id
1928+
| _ -> failwith "JSX element tag is not Longident.t"
1929+
in
1930+
match id with
1931+
| None -> make name
1932+
| Some id ->
1933+
let path = Ocaml_common.Longident.flatten id in
1934+
match name with
1935+
| "createElement" -> make (String.concat ~sep:"." path)
1936+
| name -> make (Printf.sprintf "%s.%s" (String.concat ~sep:"." path) name)
1937+
in
1938+
let props =
1939+
match props with
1940+
| [] -> str ""
1941+
| props ->
1942+
let fmt_prop = function
1943+
| Nolabel, e -> fmt_expression c {ctx;ast=e}
1944+
| Labelled label, e ->
1945+
str label.txt $ fmt "=" $ fmt_expression c {ctx;ast=e}
1946+
| Optional _, _ -> failwith "TODO"
1947+
in
1948+
str " " $ hvbox 0 (list_k props (break 1 0) fmt_prop)
1949+
in
1950+
begin match !children with
1951+
| [] -> hvbox 2 (start_tag $ props $ fmt " />")
1952+
| children ->
1953+
let head = hvbox 2 (start_tag $ props $ fmt ">") in
1954+
let children =
1955+
hvbox 0 (list_k children (break 1 0)
1956+
(fun e -> fmt_expression c {ctx;ast=e}))
1957+
in
1958+
hvbox 2 (head $ break 0 0 $ children $ break 0 (-2) $ end_tag)
1959+
end
1960+
| _ ->
19091961
let wrap =
19101962
if c.conf.fmt_opts.wrap_fun_args.v then Fn.id else hvbox 2
19111963
in

lib/bin_conf/Bin_conf.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ let info =
102102
"Unless mentioned otherwise non-formatting options cannot be set in \
103103
attributes or $(b,.ocamlformat) files." ]
104104
in
105-
Cmd.info "ocamlformat" ~version:Version.current ~doc ~man
105+
Cmd.info "ocamlformat-mlx" ~version:Version.current ~doc ~man
106106

107107
let kind = Decl.Operational
108108

lib/bin_conf/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(library
2-
(public_name ocamlformat.bin_conf)
2+
(public_name ocamlformat-mlx.bin_conf)
33
(name bin_conf)
44
(flags
55
(:standard
@@ -11,4 +11,4 @@
1111
Ocamlformat_result.Global_scope))
1212
(instrumentation
1313
(backend bisect_ppx))
14-
(libraries ocamlformat-lib re))
14+
(libraries ocamlformat-mlx-lib re))

lib/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
(library
1717
(name ocamlformat_lib)
18-
(public_name ocamlformat-lib)
18+
(public_name ocamlformat-mlx-lib)
1919
(flags
2020
(:standard
2121
-open

ocamlformat-bench.opam

Lines changed: 0 additions & 45 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

ocamlformat.opam renamed to ocamlformat-mlx.opam

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ depends: [
2626
"ocaml" {>= "4.08"}
2727
"cmdliner" {with-test = "false" & >= "1.1.0" | with-test & >= "1.2.0"}
2828
"dune" {>= "2.8"}
29-
"ocamlformat-lib" {= version}
30-
"ocamlformat-rpc-lib" {with-test & = version}
29+
"ocamlformat-mlx-lib" {= version}
3130
"re" {>= "1.10.3"}
3231
"odoc" {with-doc}
3332
]
File renamed without changes.

ocamlformat-rpc-lib.opam

Lines changed: 0 additions & 41 deletions
This file was deleted.

test/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(data_only_dirs rpc cli passing failing disabled projects unit)

test/mlx/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(cram
2+
(package ocamlformat-mlx)
3+
(deps %{bin:ocamlformat-mlx}))

0 commit comments

Comments
 (0)