Skip to content

Commit

Permalink
Fix pretty-printing mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
msprotz committed Jan 23, 2024
1 parent 8ce3c3d commit 48e3dc3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/PrintMiniRust.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ let print_op = function
let rec print_block_expression env e =
braces_with_nesting (print_statements env e)

and print_block_or_if_expression env e =
match e with
| IfThenElse _ -> print_expr env max_int e
| _ -> print_block_expression env e

(* print an expression that possibly already has a block structure... quite
confusing, but that's the terminology used by the rust reference *)
and print_expression_with_block env (e: expr): document =
Expand Down Expand Up @@ -319,10 +324,10 @@ and print_expr env (context: int) (e: expr): document =
| IfThenElse (e1, e2, e3) ->
group @@
group (string "if" ^/^ print_expr env max_int e1) ^/^
print_expression_with_block env e2 ^^
print_block_expression env e2 ^^
begin match e3 with
| Some e3 ->
break1 ^^ string "else" ^/^ print_expression_with_block env e3
break1 ^^ string "else" ^/^ print_block_or_if_expression env e3
| None ->
empty
end
Expand Down Expand Up @@ -383,7 +388,7 @@ and print_array_expr env (e: array_expr) =
match e with
| List es ->
group @@
brackets (nest 4 (separate_map (comma ^^ break1) (print_expr env max_int) es))
brackets (nest 4 (flow_map (comma ^^ break1) (print_expr env max_int) es))
| Repeat (e, n) ->
group @@
group (brackets (nest 4 (print_expr env max_int e ^^ semi ^/^ print_expr env max_int n)))
Expand Down

0 comments on commit 48e3dc3

Please sign in to comment.