From f290fca1afab9bf8aeb58ce0789b4d810abc9f66 Mon Sep 17 00:00:00 2001 From: Nathan Ringo Date: Wed, 24 Jan 2024 00:37:06 -0600 Subject: Adds space for letrec, some capture avoidance, remove binder arrows. --- discocaml/draw_tree.ml | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) (limited to 'discocaml/draw_tree.ml') diff --git a/discocaml/draw_tree.ml b/discocaml/draw_tree.ml index ecf1b71..6b6ce91 100644 --- a/discocaml/draw_tree.ml +++ b/discocaml/draw_tree.ml @@ -1,29 +1,10 @@ open Ast module IntSet = Set.Make (Int) -let break_to_subscript (s : string) : (string * string) option = - let rec loop (i : int) : (string * string) option = - if i < 0 then None - else - let ch = String.get s i in - if '0' <= ch && ch <= '9' then loop (i - 1) - else - let name = String.sub s 0 (i + 1) - and sub = String.sub s (i + 1) (String.length s - i - 1) in - if sub = "" then None else Some (name, sub) - in - loop (String.length s - 1) - -let%test "break_to_subscript fail" = break_to_subscript "x1y" = None -let%test "break_to_subscript simple" = break_to_subscript "x1" = Some ("x", "1") -let%test "break_to_subscript empty" = break_to_subscript "" = None -let%test "break_to_subscript number" = break_to_subscript "123" = None -let%test "break_to_subscript multi" = break_to_subscript "x12" = Some ("x", "12") - let fmt_with_possible_subscript (fmt : Format.formatter) (s : string) : unit = - match break_to_subscript s with + match Util.break_to_subscript s with | Some (name, sub) -> - Format.fprintf fmt "<%s%s>" name + Format.fprintf fmt "<%s%d>" name sub | None -> Format.fprintf fmt "%S" s @@ -51,7 +32,7 @@ let add_node (fmt : Format.formatter) (i : expr index) (expr : expr) : unit = Format.fprintf fmt " expr%d [fontname=\"CMU Typewriter Text Bold\", label=\"%s\"];\n" i.index - (if recursive then "letrec" else "let") + (if recursive then "let rec" else "let") | Nil -> Format.fprintf fmt " expr%d [fontname=\"CMU Typewriter Text Bold\", label=\"[]\"];\n" @@ -128,6 +109,7 @@ let draw_tree (ast : expr ast) : string = add_node fmt i (get_subexpr ast i)) !nodes; + (* get_binders ast |> Array.iteri (fun i -> function | Some j -> @@ -135,7 +117,7 @@ let draw_tree (ast : expr ast) : string = " expr%d -> expr%d_var [color=\"#cccccc\", constraint=false];\n" i j.index | None -> ()); - + *) Format.fprintf fmt "}\n"; Format.pp_print_flush fmt (); Buffer.contents buf -- cgit v1.2.3