diff options
author | Son Ho | 2022-11-14 09:55:13 +0100 |
---|---|---|
committer | Son HO | 2022-11-14 14:21:04 +0100 |
commit | 019a9e34e6375a5e015e4978aad89aa8febc237c (patch) | |
tree | d49947453752ef5ecf17687e02c33c031d91995f /compiler | |
parent | 6eab7f1d8eeb7826d44c6bbacf24935965c8f7da (diff) |
Improve the formatting of [if then else] expressions
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/Extract.ml | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/compiler/Extract.ml b/compiler/Extract.ml index 9aaf753e..13c02bca 100644 --- a/compiler/Extract.ml +++ b/compiler/Extract.ml @@ -1476,25 +1476,34 @@ and extract_Switch (ctx : extraction_ctx) (fmt : F.formatter) (inside : bool) F.pp_open_hovbox fmt ctx.indent_incr; let then_or_else = if is_then then "then" else "else" in F.pp_print_string fmt then_or_else; - F.pp_print_space fmt (); - (* Open a box for the branch *) - F.pp_open_hovbox fmt ctx.indent_incr; - (* Print the [begin] if necessary *) let parenth = PureUtils.let_group_requires_parentheses e_branch in - let left_delim, right_delim = - match !backend with FStar -> ("begin", "end") | Coq -> ("(", ")") - in - if parenth then ( - F.pp_print_string fmt left_delim; - F.pp_print_space fmt ()); + (* Open a box for the branch - we do this only if it is not a parenthesized + group of nested let bindings. + *) + if not parenth then ( + F.pp_print_space fmt (); + F.pp_open_hovbox fmt ctx.indent_incr); + (* Open the parenthesized expression *) + (if parenth then + match !backend with + | FStar -> + F.pp_print_space fmt (); + F.pp_print_string fmt "begin"; + F.pp_print_space fmt () + | Coq -> + F.pp_print_string fmt " ("; + F.pp_print_cut fmt ()); (* Print the branch expression *) extract_texpression ctx fmt false e_branch; - (* Close the [begin ... end ] *) - if parenth then ( - F.pp_print_space fmt (); - F.pp_print_string fmt right_delim); + (* Close the parenthesized expression *) + (if parenth then + match !backend with + | FStar -> + F.pp_print_space fmt (); + F.pp_print_string fmt "end" + | Coq -> F.pp_print_string fmt ")"); (* Close the box for the branch *) - F.pp_close_box fmt (); + if not parenth then F.pp_close_box fmt (); (* Close the box for the then/else+branch *) F.pp_close_box fmt () in |