-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a70bd4
commit c299afb
Showing
4 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(executable | ||
(name main)) | ||
|
||
(cram (deps ./main.exe)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(lang dune 3.10) | ||
|
||
(generate_opam_files false) | ||
|
||
(package | ||
(name mlx-example) | ||
(depends dune mlx)) | ||
|
||
(dialect | ||
(name mlx) | ||
(implementation | ||
(extension mlx) | ||
(preprocess | ||
(run mlx-pp %{input-file})))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
open Printf | ||
|
||
type doc = Element of string * doc list | Text of string | ||
|
||
let render d = | ||
let rec render indent = | ||
let indents = List.init indent (fun _ -> " ") |> String.concat "" in | ||
function | ||
| Element(name, children) -> | ||
let children = List.map (render (indent + 1)) children in | ||
sprintf "%s<%s>\n%s\n%s</%s>" indents name (String.concat "\n" children) indents name | ||
| Text s -> sprintf "%s%s" indents s | ||
in | ||
render 0 d | ||
|
||
let div ~children () = Element ("div", children) | ||
let text s = Text s | ||
|
||
let () = | ||
print_endline (render ( | ||
<div> | ||
<div>(text "title")</div> | ||
<div>(text "content")</div> | ||
</div> | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
$ ./main.exe | ||
<div> | ||
<div> | ||
title | ||
</div> | ||
<div> | ||
content | ||
</div> | ||
</div> |