Skip to content

Commit

Permalink
Start working on formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Oct 7, 2024
1 parent 16708f3 commit f1e17fc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/haz3lformatter/Formatter.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open Haz3lcore;
let format = (~inline: bool, s: string): string => {
let seg =
ExpToSegment.exp_to_segment(
~settings=ExpToSegment.Settings.of_core(~inline, CoreSettings.on),
MakeTerm.from_zip_for_sem(Option.get(Printer.zipper_of_string(s))).
term,
);
let zipper = Zipper.unzip(seg);
Printer.zipper_to_string(~holes=Some("?"), zipper);
};
3 changes: 3 additions & 0 deletions src/haz3lformatter/FormatterMain.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
open Haz3lformatter;

print_endline(Formatter.format(~inline=false, In_channel.input_all(stdin)));
27 changes: 27 additions & 0 deletions test/Test_Formatter.re
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

open Alcotest;
open Haz3lcore;
open Haz3lformatter;

let parse_exp = (s: string) =>
MakeTerm.from_zip_for_sem(Option.get(Printer.zipper_of_string(s))).term;
let serialize = (exp: Exp.t): string => {
let seg =
ExpToSegment.exp_to_segment(
~settings=ExpToSegment.Settings.of_core(~inline=true, CoreSettings.on),
exp,
);
let zipper = Zipper.unzip(seg);
Printer.zipper_to_string(~holes=Some("?"), zipper);
};

let tests = [
test_case("Incomplete Function Definition", `Quick, () => {
check(
string,
"let = fun x -> in ",
"let ? = (fun x -> ?) in ?",
Formatter.format(~inline=true, "let = fun x -> in "),
)
}),
];
1 change: 1 addition & 0 deletions test/haz3ltest.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let (suite, _) =
("Evaluator", Test_Evaluator.tests),
("MakeTerm", Test_MakeTerm.tests),
("ExpToSegment", Test_ExpToSegment.tests),
("Formatter", Test_Formatter.tests),
],
);
Junit.to_file(Junit.make([suite]), "junit_tests.xml");

0 comments on commit f1e17fc

Please sign in to comment.