diff options
author | Nathan Ringo <nathan@remexre.com> | 2024-01-24 10:52:13 -0600 |
---|---|---|
committer | Nathan Ringo <nathan@remexre.com> | 2024-01-24 10:52:13 -0600 |
commit | 00d3ea6b17b73594c95318adf266802b02f65abb (patch) | |
tree | 37d5053d0a5ba4d06a1fc89c8f70945445c0e28b /discocaml/ast.ml | |
parent | 6fb1c813dbe2227dab3faac3fc405260be185eca (diff) |
Colors for overlapping binders.
Diffstat (limited to 'discocaml/ast.ml')
-rw-r--r-- | discocaml/ast.ml | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/discocaml/ast.ml b/discocaml/ast.ml index 92f368f..86630a6 100644 --- a/discocaml/ast.ml +++ b/discocaml/ast.ml @@ -267,7 +267,8 @@ let show_expr (expr : expr ast) : string = Format.pp_print_flush fmt (); Buffer.contents buf -type binders = expr index option array +type binder_info = [ `Binder of string | `Bound of expr index ] +type binders = binder_info option array let get_binders (ast : expr ast) : binders = let out = Array.make (Arraylist.length ast.subexprs) None in @@ -283,11 +284,15 @@ let get_binders (ast : expr ast) : binders = loop env cond; loop env then_; loop env else_ - | Lam (x, b) -> loop ((x, i) :: env) b + | Lam (x, b) -> + out.(i.index) <- Some (`Binder x); + loop ((x, i) :: env) b | Let (false, name, bound, body) -> + out.(i.index) <- Some (`Binder name); loop env bound; loop ((name, i) :: env) body | Let (true, name, bound, body) -> + out.(i.index) <- Some (`Binder name); loop ((name, i) :: env) bound; loop ((name, i) :: env) body | Prim (Add, (l, r)) -> @@ -302,7 +307,9 @@ let get_binders (ast : expr ast) : binders = | Prim (RelOp, (_, l, r)) -> loop env l; loop env r - | Var name -> out.(i.index) <- List.assoc_opt name env + | Var name -> + out.(i.index) <- + List.assoc_opt name env |> Option.map (fun j -> `Bound j) | Bool _ | Int _ | Nil -> () in loop [] ast.root; |