Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid regex for debug indentation #97

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions libASL/dis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,19 @@ module DisEnv = struct
let num, s = LocalEnv.incNumSymbols s in
(Ident (prefix ^ string_of_int num),s,empty)

let indent: string rws =
let indent: string list rws =
let+ i = gets (fun l -> l.indent) in
let h = i / 2 in
let s = String.concat "" (List.init h (fun _ -> "\u{2502} \u{250a} ")) in
if i mod 2 == 0 then
s ^ ""
else
s ^ "\u{2502} "
(* when concatenated, produces a string of the form:
"| I | I | ..." where | and I are
alternating unicode box-drawing lines *)
List.init i (fun i -> if i mod 2 == 0 then "\u{2502} " else "\u{250a} ")

let debug (minLevel: int) (s: string): unit rws =
if !debug_level >= minLevel then
let+ i = indent in
let s' = Str.global_replace (Str.regexp "\n") ("\n"^i) s in
Printf.printf "%s%s\n" i s';
List.iter
(fun l -> List.iter print_string i; print_endline l)
(String.split_on_char '\n' s);
()
else
unit
Expand Down