Skip to content

Commit

Permalink
debugging tokenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
gcrois committed Oct 10, 2024
1 parent ff45b9d commit b9d437b
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
31 changes: 24 additions & 7 deletions src/haz3lcore/lang/Form.re
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@ let undefined = "undefined";
let is_undefined = match(regexp("^" ++ undefined ++ "$"));

let is_livelit = str => {
let re = regexp("^(ll)([a-z][A-Za-z0-9_]*)$");
// print_endline("is_livelit");
// print_endline(str);
let re = regexp("^(\\^)([A-Za-z0-9_]*)$");
let result = match(re, str);
// print_endline(string_of_bool(result));
result;
};
let parse_livelit = str =>
if (String.length(str) > 1 && String.sub(str, 0, 1) == "^") {
String.sub(str, 1, String.length(str) - 1);
} else {
"invalid form";
};

let var_regexp =
regexp(
Expand Down Expand Up @@ -354,20 +357,34 @@ let delims: list(Token.t) =
|> List.sort_uniq(compare);

let atomic_molds: Token.t => list(Mold.t) =
s =>
s => {
print_endline("atomic_molds");
print_endline(s);
List.fold_left(
(acc, (_, (test, molds))) => test(s) ? molds @ acc : acc,
[],
atomic_forms,
);
};

let is_atomic = t => atomic_molds(t) != [];
let is_atomic = t => {
print_endline("is_atomic");
print_endline(t);
atomic_molds(t) != [];
};

let is_delim = t => List.mem(t, delims);

let is_valid_token = t => is_atomic(t) || is_secondary(t) || is_delim(t);
let is_valid_token = t => {
print_endline("is_valid_token");
print_endline(t);
is_atomic(t) || is_secondary(t) || is_delim(t);
};

let mk_atomic = (sort: Sort.t, t: Token.t) => {
print_endline("mk_atomic");
print_endline(t);

assert(is_atomic(t));
mk(ss, [t], Mold.(mk_op(sort, [])));
};
6 changes: 5 additions & 1 deletion src/haz3lcore/lang/Molds.re
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ let forms_assoc: list((Label.t, list(Mold.t))) =
Form.forms,
);

let get = (label: Label.t): list(Mold.t) =>
let get = (label: Label.t): list(Mold.t) => {
print_endline("Molds.get");
print_endline(String.concat(" ", label));

switch (label, List.assoc_opt(label, forms_assoc)) {
| ([t], Some(molds)) when Form.atomic_molds(t) != [] =>
Form.atomic_molds(t) @ molds
Expand Down Expand Up @@ -54,6 +57,7 @@ let get = (label: Label.t): list(Mold.t) =>
);
[Mold.mk_op(Any, [])];
};
};

let delayed_expansions: expansions =
List.filter_map(
Expand Down
8 changes: 4 additions & 4 deletions src/haz3lcore/lang/term/IdTagged.re
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type t('a) = {
};

// To be used if you want to remove the id from the debug output
// let pp: ((Format.formatter, 'a) => unit, Format.formatter, t('a)) => unit =
// (fmt_a, formatter, ta) => {
// fmt_a(formatter, ta.term);
// };
let pp: ((Format.formatter, 'a) => unit, Format.formatter, t('a)) => unit =
(fmt_a, formatter, ta) => {
fmt_a(formatter, ta.term);
};
let fresh = term => {
{ids: [Id.mk()], copied: false, term};
};
Expand Down
4 changes: 3 additions & 1 deletion src/haz3lcore/statics/MakeTerm.re
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ and exp_term: unsorted => (UExp.term, list(Id.t)) = {
ret(String(Form.strip_quotes(t)))
| ([t], []) when Form.is_float(t) => ret(Float(float_of_string(t)))
| ([t], []) when Form.is_livelit(t) =>
ret(LivelitInvocation("livelit name"))
ret(LivelitInvocation(Form.parse_livelit(t)))
| ([t], []) when Form.is_var(t) => ret(Var(t))
| ([t], []) when Form.is_ctr(t) =>
ret(Constructor(t, Unknown(Internal) |> Typ.temp))
Expand Down Expand Up @@ -258,6 +258,8 @@ and exp_term: unsorted => (UExp.term, list(Id.t)) = {
term: Deferral(InAp),
};
switch (arg.term) {
| Var(l) when Form.is_livelit(l) =>
ret(LivelitInvocation(Form.parse_livelit(l)))
| _ when UExp.is_deferral(arg) =>
ret(DeferredAp(l, [use_deferral(arg)]))
| Tuple(es) when List.exists(UExp.is_deferral, es) => (
Expand Down
1 change: 1 addition & 0 deletions src/haz3lcore/statics/TermBase.re
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ and Exp: {
ClosureEnvironment.id_equal(c1, c2) && fast_equal(e1, e2)
| (Cons(e1, e2), Cons(e3, e4)) =>
fast_equal(e1, e3) && fast_equal(e2, e4)
| (LivelitInvocation(s1), LivelitInvocation(s2)) => s1 == s2
| (ListConcat(e1, e2), ListConcat(e3, e4)) =>
fast_equal(e1, e3) && fast_equal(e2, e4)
| (UnOp(o1, e1), UnOp(o2, e2)) => o1 == o2 && fast_equal(e1, e2)
Expand Down
3 changes: 3 additions & 0 deletions test/Test_MakeTerm.re
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ let tests = [
"let = fun x -> in ",
)
}),
test_case("Livelit Invocation", `Quick, () => {
exp_check(LivelitInvocation("slider") |> Exp.fresh, "^slider")
}),
];

0 comments on commit b9d437b

Please sign in to comment.