Skip to content

Commit

Permalink
⚗️ Experimental HTML printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeta611 committed Sep 23, 2024
1 parent 3de7382 commit 9bb8d66
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
11 changes: 10 additions & 1 deletion bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ let () =
let opt_parse_js = ref false in
let opt_fuel = ref None in
let opt_report = ref false in
let opt_report_html = ref false in
let opt_verbosity = ref Logs.Info in

let usage_msg =
Expand All @@ -53,6 +54,9 @@ let () =
( "-report",
Arg.Unit (fun _ -> opt_report := true),
"Report the view trees" );
( "-report-html",
Arg.Unit (fun _ -> opt_report_html := true),
"Report the view trees in HTML" );
("-fuel", Arg.Int (fun n -> opt_fuel := Some n), "[fuel] Run with fuel");
]
in
Expand All @@ -72,7 +76,12 @@ let () =
Sexp.pp_hum Stdlib.Format.std_formatter (Syntax.Prog.sexp_of_t prog)
else
let { Interp.steps; _ } =
Interp.run ?fuel:!opt_fuel ~report:!opt_report prog
Interp.run ?fuel:!opt_fuel
~report:
(if !opt_report_html then `Html
else if !opt_report then `Text
else `Mute)
prog
in
printf "\nSteps: %d\n" steps;
Stdlib.exit (if Logs.err_count () > 0 then 1 else 0))
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
menhir
ppx_jane
printbox
printbox-html
printbox-text
stdio
(alcotest :with-test))
Expand Down
9 changes: 8 additions & 1 deletion lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
(name react_trace)
(preprocess
(pps ppx_jane))
(libraries core logs flow_parser ppx_jane printbox printbox-text))
(libraries
core
logs
flow_parser
ppx_jane
printbox
printbox-text
printbox-html))

(ocamllex lexer)

Expand Down
26 changes: 16 additions & 10 deletions lib/interp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,22 +229,28 @@ module Report_box = struct
in
B.(vlist [ part_view_box; children ] |> frame)

let log ?(msg : string option) (pt : Path.t) : unit =
let log ?(msg : string option) ?(html : bool = false) (pt : Path.t) : unit =
(match msg with Some msg -> Logs.info (fun m -> m "%s" msg) | None -> ());
PrintBox_text.output stdout (path pt);
Out_channel.(
newline stdout;
flush stdout)

let log_h (report : bool) =
if not html then (
PrintBox_text.output stdout (path pt);
Out_channel.(
newline stdout;
flush stdout))
else PrintBox_html.to_string (path pt) |> print_endline

let log_h (report : [ `Mute | `Text | `Html ]) =
{
effc =
(fun (type a) (eff : a t) ->
match eff with
| Log { msg; path } ->
Some
(fun (k : (a, _) continuation) ->
continue k (if report then log ~msg path else ()))
continue k
(match report with
| `Mute -> ()
| `Text -> log ~msg path
| `Html -> log ~msg ~html:true path))
| _ -> None);
}
end
Expand Down Expand Up @@ -550,8 +556,8 @@ let step_path (path : Path.t) : bool =

type run_info = { steps : int; mem : Tree_mem.t }

let run ?(fuel : int option) ?(report : bool = false) (prog : Prog.t) : run_info
=
let run ?(fuel : int option) ?(report : [ `Mute | `Text | `Html ] = `Mute)
(prog : Prog.t) : run_info =
Logger.run prog;

let driver () =
Expand Down
1 change: 1 addition & 0 deletions react_trace.opam
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ depends: [
"menhir"
"ppx_jane"
"printbox"
"printbox-html"
"printbox-text"
"stdio"
"alcotest" {with-test}
Expand Down

0 comments on commit 9bb8d66

Please sign in to comment.