diff --git a/test/example/dune b/test/example/dune new file mode 100644 index 0000000..2e305b1 --- /dev/null +++ b/test/example/dune @@ -0,0 +1,4 @@ +(executable + (name main)) + +(cram (deps ./main.exe)) diff --git a/test/example/dune-project b/test/example/dune-project new file mode 100644 index 0000000..025d490 --- /dev/null +++ b/test/example/dune-project @@ -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})))) + diff --git a/test/example/main.mlx b/test/example/main.mlx new file mode 100644 index 0000000..fda8058 --- /dev/null +++ b/test/example/main.mlx @@ -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 ( +