-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Implement 'shrink' for Docs by hand #113
base: master
Are you sure you want to change the base?
Conversation
If I cause the fusion tests to fail, for example with --- a/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
+++ b/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
@@ -551,7 +551,7 @@ changesUponFlattening :: Doc ann -> Maybe (Doc ann)
changesUponFlattening = \doc -> case doc of
FlatAlt _ y -> Just (flatten y)
Line -> Just Fail
- Union x _ -> changesUponFlattening x <|> Just x
+ Union x _ -> Nothing
Nest i x -> fmap (Nest i) (changesUponFlattening x)
Annotated ann x -> fmap (Annotated ann) (changesUponFlattening x) …
I think what could help is to filter the raw Such a |
Nest _ x -> go mayFail x | ||
Union x y -> go True x && go mayFail y | ||
Column f -> all (go mayFail) (map f [0..80]) | ||
WithPageWidth f -> all (go mayFail) (map f (Unbounded : [AvailablePerLine c r | c <- [1..80], r <- [0, 0.1 .. 1]])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is 0
a valid ribbon width at all? Not sure how to interpret the docs there:
prettyprinter/prettyprinter/src/Data/Text/Prettyprint/Doc/Internal.hs
Lines 1609 to 1618 in ff555e1
= AvailablePerLine Int Double | |
-- ^ Layouters should not exceed the specified space per line. | |
-- | |
-- - The 'Int' is the number of characters, including whitespace, that | |
-- fit in a line. A typical value is 80. | |
-- | |
-- - The 'Double' is the ribbon with, i.e. the fraction of the total | |
-- page width that can be printed on. This allows limiting the length | |
-- of printable text per line. Values must be between 0 and 1, and | |
-- 0.4 to 1 is typical. |
WithPageWidth f -> all (go mayFail) (map f (Unbounded : [AvailablePerLine c r | c <- [1..80], r <- [0, 0.1 .. 1]])) | |
WithPageWidth f -> all (go mayFail) (map f (Unbounded : [AvailablePerLine c r | c <- [1..80], r <- [0.1, 0.2 .. 1]])) |
Cat x y -> go mayFail x && go mayFail y | ||
Nest _ x -> go mayFail x | ||
Union x y -> go True x && go mayFail y | ||
Column f -> all (go mayFail) (map f [0..80]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how to best handle these functions. Checking them exhaustively would take too long. Even the current check with "typical" values 0..80 seems excessive.
9be59a9
to
f27ae11
Compare
shrink doc = filter valid $ case doc of | ||
Fail -> [Empty] | ||
Empty -> [] | ||
Char c -> Empty : map Char (filter (/= '\n') (shrink c)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be one of the few places where a list comprehension is nicer to read! :-)
No description provided.