Skip to content

Commit cb8043c

Browse files
committed
README
1 parent 936df0b commit cb8043c

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
_opam
22
_build
3+
_bin
34
*.install

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,63 @@
11
# mlx
22

3-
An OCaml syntax dialect which adds to JSX expressions to the language.
3+
An OCaml syntax dialect which adds JSX expressions to the language.
44

55
```
6-
let header title =
6+
let header ~children () =
77
<header>
88
<h1>title</h1>
99
</header>
1010
1111
let page =
1212
<html>
1313
<body>
14-
(header "Hello, world!")
14+
<header>"Hello, world!"</header>
1515
<div>
16-
"Some content gere"
16+
"Some content goes here"
1717
</div>
1818
</body>
1919
</html>
2020
```
2121

22+
This code is transformed into the following OCaml code:
23+
```
24+
let header ~children () =
25+
header () ~children:[ h1 () ~children:[ title ] [@JSX]; ] [@JSX]
26+
27+
let page =
28+
html () ~children:[
29+
body () ~children:[
30+
header () ~children:[ "Hello, world!" ] [@JSX];
31+
div () ~children:[ "Some content goes here" ] [@JSX];
32+
] [@JSX];
33+
] [@JSX]
34+
```
35+
36+
It is expected to use `mlx-pp` preprocessor with either a runtime lib which
37+
provides the implementation of such functions or a ppx which which further
38+
transforms `[@JSX]` attributes into the desired output.
39+
2240
## Installation & Usage
2341

24-
While mlx is not yet available on opam, you can use a custom opam repository to install it:
42+
Currently for editor integration an unreleased version of `ocaml-lsp-server` is
43+
needed (along with its depenedencies, `jsonrpc` and `lsp`).
44+
45+
Use the following commands to install the necessary packages:
2546
```sh
26-
opam repo add andreypopp https://github.com/andreypopp/opam-repository.git
27-
opam update
28-
opam pin add dune.dev --dev
47+
opam pin add jsonrpc.dev --dev
48+
opam pin add lsp.dev --dev
2949
opam pin add ocaml-lsp-server.dev --dev
30-
opam install mlx ocamlmerlin-mlx ocamlformat-mlx
50+
opam install mlx ocamlmerlin-mlx
3151
```
3252

33-
Then add the following config to your `dune-project` file:
53+
To make dune consider `.mlx` files as OCaml files you need to configure an mlx
54+
dialect, put this in your `dune-project` file:
3455
```
3556
(dialect
3657
(name mlx)
3758
(implementation
3859
(extension mlx)
3960
(merlin_reader mlx)
40-
(format
41-
(run ocamlformat-mlx %{input-file}))
4261
(preprocess
4362
(run mlx-pp %{input-file}))))
4463
```
45-
46-
Now dune will treat `.mlx` files as `.ml` files. If you use `ocaml-lsp-server`
47-
then autocompletion and other editor integrations should work out of the box.
48-
49-
To format `.mlx` files you'd need to run `dune fmt` or configure
50-
`ocamlformat-mlx` in your editor manually.

0 commit comments

Comments
 (0)