From c7d7124f744093bf254f2962664a40fae2913e7b Mon Sep 17 00:00:00 2001 From: Guillaume Claret Date: Fri, 13 Dec 2013 19:50:13 +0100 Subject: [PATCH] Bug fix for rendering of newlines in GroupOne --- smartPrint.ml | 6 +++--- test.ml | 13 +++++++------ test.out | 9 ++++++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/smartPrint.ml b/smartPrint.ml index ea53a2e..8d1479a 100644 --- a/smartPrint.ml +++ b/smartPrint.ml @@ -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) @@ -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 diff --git a/test.ml b/test.ml index 11b06e2..f2e2a66 100644 --- a/test.ml +++ b/test.ml @@ -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 () diff --git a/test.out b/test.out index a5e6cd5..97a733e 100644 --- a/test.out +++ b/test.out @@ -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 +*************************