Skip to content

Commit

Permalink
Fix tuple generator
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Dec 15, 2024
1 parent ee3b6bf commit f90e146
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/haz3lmenhir/AST.re
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,19 @@ let arb_exp_sized: QCheck.arbitrary(exp) =
),
),
// Need to make ExpToSegment add parens for tuples for menhir
// Gen.join(
// Gen.map(
// (sizes: array(int)) => {
// let exps = Array.map((size: int) => self(size), sizes);
// let flattened = Gen.flatten_a(exps);
// Gen.map(
// (exps: array(exp)) => TupleExp(Array.to_list(exps)),
// flattened,
// );
// },
// list_sizes,
// ),
// ),
Gen.join(
Gen.map(
(sizes: array(int)) => {
let exps = Array.map((size: int) => self(size), sizes);
let flattened = Gen.flatten_a(exps);
Gen.map(
(exps: array(exp)) => TupleExp(Array.to_list(exps)),
flattened,
);
},
list_sizes,
),
),
]);
}
}),
Expand Down
17 changes: 17 additions & 0 deletions test/Test_Menhir.re
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,22 @@ let qcheck_menhir_maketerm_equivalent_test =
exp => {
let core_exp = Conversion.Exp.of_menhir_ast(exp);

// TODO Maybe only do this when necessary.
// TODO Check with Matthew if I'm using this correctly
// Add parens around tuples
let core_exp =
Exp.map_term(
~f_exp=
(cont, e) =>
switch (e.term) {
| Tuple(es) =>
Parens(Tuple(es |> List.map(cont)) |> Exp.fresh)
|> Exp.fresh
| _ => cont(e)
},
core_exp,
);

let segment =
ExpToSegment.exp_to_segment(
~settings=
Expand All @@ -264,6 +280,7 @@ let qcheck_menhir_maketerm_equivalent_test =
);

let serialized = Printer.of_segment(~holes=Some("?"), segment);
print_endline("Serialized: " ++ serialized);
let make_term_parsed = make_term_parse(serialized);
let menhir_parsed =
Haz3lmenhir.Conversion.Exp.of_menhir_ast(
Expand Down

0 comments on commit f90e146

Please sign in to comment.