Skip to content

Commit

Permalink
Bug fix for rendering of newlines in GroupOne
Browse files Browse the repository at this point in the history
  • Loading branch information
clarus committed Dec 13, 2013
1 parent a44e37c commit c7d7124
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions smartPrint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module Atom = struct
try_return (p + 1, Some Break.Space)
else
try_return (p, last_break)
| Break Break.Newline -> (0, Some Break.Newline)
| Break Break.Newline -> raise Overflow
| GroupOne (can_nest, _as) ->
let (p, last_break) = try_eval_list_flat width tab (i + tab) _as p last_break in
(p, last_break)
Expand Down Expand Up @@ -118,9 +118,9 @@ module Atom = struct
let (_as, p, last_break) =
(* If there is an explicit newline we always undo the nesting. *)
if in_nest then
try_eval_list_one width tab (i - tab) _as 0 last_break can_fail can_nest false
try_eval_list_one width tab (i - tab) _as 0 (Some Break.Newline) false can_nest false
else
try_eval_list_one width tab i _as 0 last_break can_fail can_nest in_nest in
try_eval_list_one width tab i _as 0 (Some Break.Newline) false can_nest false in
if in_nest then
([Break Break.Newline; Indent (- 1, GroupOne (false, _as))], p, last_break)
else
Expand Down
13 changes: 7 additions & 6 deletions test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ let main () =
print_document (!^ "hello" ^^ !^ "world" ^^ newline ^^ nest (!^ "gre" ^^ nest_all (!^ "arg" ^^ !^ "arg")));
es |> List.iter (fun e ->
print_document @@ pp false e);
print_document (sub_string "hfgs_kjl_df" 5 3);
print_document (words "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
print_document (lines "adipisicing elit,\nsed do eiusmod tempor\nincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud ");
print_document (nest @@ lines "adipisicing elit,\n\nsed do eiusmod tempo incididunt ut labore et dolore");
print_document (indent @@ nest @@ lines "adipisicing elit,\n\nsed do eiusmod tempo incididunt ut labore et dolore");
print_document @@ indent @@ pp false @@ Let ("x", Var "x", Let ("x", Var "x", Var "y"))
print_document @@ sub_string "hfgs_kjl_df" 5 3;
print_document @@ words "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
print_document @@ lines "adipisicing elit,\nsed do eiusmod tempor\nincididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud ";
print_document @@ nest @@ lines "adipisicing elit,\n\nsed do eiusmod tempo incididunt ut labore et dolore";
print_document @@ indent @@ nest @@ lines "adipisicing elit,\n\nsed do eiusmod tempo incididunt ut labore et dolore";
print_document @@ indent @@ pp false @@ Let ("x", Var "x", Let ("x", Var "x", Var "y"));
print_document @@ pp false @@ App (Var "f", Let ("x", Var "x", Var "y"))

;;main ()
9 changes: 8 additions & 1 deletion test.out
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,16 @@ GroupOne (false,
"in",
Space,
Newline,
GroupOne (true, "let", Space, "x", Space, "=", Space, "x", Space, "in", Space, Newline, Space, "y"))))
GroupOne (true, "let", Space, "x", Space, "=", Space, "x", Space, "in", Space, Newline, "y"))))
*************************
let x = x in
let x = x in
y
*************************
GroupOne (false,
GroupOne (true, "f", Newline, Indent (1, GroupOne (false, GroupOne (true, "let", Space, "x", Space, "=", Space, "x", Space, "in", Space, Newline, "y")))))
*************************
f
let x = x in
y
*************************

0 comments on commit c7d7124

Please sign in to comment.