Skip to content

Commit

Permalink
Don't list empty fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinWonho committed Jan 29, 2025
1 parent b9872dc commit a0b25ce
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 177 deletions.
16 changes: 12 additions & 4 deletions spectec/src/backend-prose/print.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ let rec string_of_iter = function
(* Expressions *)

and string_of_record_expr r =
Util.Record.fold
(fun a v acc -> acc ^ string_of_atom a ^ ": " ^ string_of_expr v ^ "; ")
r "{ "
^ "}"
let open Util in

let record_fields =
r
|> Record.to_list
(* Don't list empty field *)
|> List.filter (fun (_, v) -> v.it <> ListE [])
|> List.map (fun (a, v) -> string_of_atom a ^ ": " ^ string_of_expr v)
|> String.concat "; "
in

if record_fields = "" then "{}" else "{ " ^ record_fields ^ " }"

and string_of_expr expr =
match expr.it with
Expand Down
9 changes: 6 additions & 3 deletions spectec/src/backend-prose/render.ml
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@ and al_to_el_record record =
Util.Record.fold
(fun a e expfield ->
let* expfield = expfield in
let* ele = al_to_el_expr e in
let elelem = El.Ast.Elem (a, ele) in
Some (expfield @ [ elelem ]))
(* Don't list empty field *)
if e.it = Al.Ast.ListE [] then Some (expfield)
else
let* ele = al_to_el_expr e in
let elelem = El.Ast.Elem (a, ele) in
Some (expfield @ [ elelem ]))
record (Some [])


Expand Down
Loading

0 comments on commit a0b25ce

Please sign in to comment.