Skip to content
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

Prettyprinter fixes #1276

Merged
merged 5 commits into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/ProgrammingCryptol/crashCourse/CrashCourse.tex
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,8 @@ \subsection{Comprehensions}\indComp
\end{replinVerb}
produces:
\begin{reploutVerb}
[[(1, 1), (1, 2), (1, 3)], [(2, 1), (2, 2), (2, 3)], [(3, 1), (3,
2), (3, 3)]]
[[(1, 1), (1, 2), (1, 3)], [(2, 1), (2, 2), (2, 3)],
[(3, 1), (3, 2), (3, 3)]]
\end{reploutVerb}
The outer comprehension is a comprehension (and hence is nested). In
particular the expression is:
Expand Down
10 changes: 8 additions & 2 deletions src/Cryptol/Utils/PP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ runDoc :: NameDisp -> Doc -> PP.Doc Void
runDoc names (Doc f) = f names

instance Show Doc where
show d = PP.renderString (PP.layoutSmart opts (runDoc mempty d))
show d = PP.renderString (PP.layoutPretty opts (runDoc mempty d))
where opts = PP.defaultLayoutOptions{ PP.layoutPageWidth = PP.AvailablePerLine 100 0.666 }

instance IsString Doc where
Expand Down Expand Up @@ -298,8 +298,14 @@ quotes = liftPP1 PP.squotes
commaSep :: [Doc] -> Doc
commaSep xs = Doc (\e -> PP.sep (PP.punctuate PP.comma [ d e | Doc d <- xs ]))

-- | Print a comma-separated list. Lay out each item on a single line
-- if it will fit. If an item requires multiple lines, then start it
-- on its own line.
commaSepFill :: [Doc] -> Doc
commaSepFill xs = Doc (\e -> PP.fillSep (PP.punctuate PP.comma [ d e | Doc d <- xs ]))
commaSepFill xs = Doc (\e -> fillSep (PP.punctuate PP.comma [ d e | Doc d <- xs ]))
where
fillSep [] = mempty
fillSep (d0 : ds) = foldl (\a d -> a <> PP.group (PP.line <> d)) d0 ds

ppList :: [Doc] -> Doc
ppList xs = group (nest 1 (brackets (commaSepFill xs)))
Expand Down
4 changes: 2 additions & 2 deletions tests/issues/issue226.icry.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ Symbols
fromThenTo :
{first, next, last, a, len}
(fin first, fin next, fin last, Literal first a, Literal next a,
Literal last a, first != next, lengthFromThenTo first next last ==
len) =>
Literal last a, first != next,
lengthFromThenTo first next last == len) =>
[len]a
fromTo :
{first, last, a}
Expand Down
12 changes: 6 additions & 6 deletions tests/issues/issue268.icry.stdout
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Loading module Cryptol
Loading module Cryptol
Loading module Main
[(0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00,
0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00),
(0x00, 0x00)]
[(0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00,
0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00),
(0x00, 0x00)]
[(0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00),
(0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00),
(0x00, 0x00), (0x00, 0x00)]
[(0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00),
(0x00, 0x00), (0x00, 0x00), (0x00, 0x00), (0x00, 0x00),
(0x00, 0x00), (0x00, 0x00)]
7 changes: 4 additions & 3 deletions tests/issues/issue407.icry.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Loading module Cryptol
[[False, False, False, False, False, ...], [False, False, False,
False, True, ...], [False, False, True, True, False, ...], [False,
True, False, True, False, ...]]
[[False, False, False, False, False, ...],
[False, False, False, False, True, ...],
[False, False, True, True, False, ...],
[False, True, False, True, False, ...]]
Counterexample
(\(x : [4]) -> (transpose [x ...]) @ 0 @ 0 == False) 0x8 = False
Q.E.D.
Expand Down
4 changes: 2 additions & 2 deletions tests/issues/padding.icry.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ Loading module Cryptol
Showing a specific instance of polymorphic result:
* Using 'Integer' for type argument 'a' of 'Cryptol::fromTo'
* Using 'inf' for type argument 'parts' of 'Cryptol::groupBy'
[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15], [16, 17,
18, 19, 20], [21, 22, 23, 24, 0], ...]
[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15],
[16, 17, 18, 19, 20], [21, 22, 23, 24, 0], ...]
8 changes: 4 additions & 4 deletions tests/regression/rec-update.icry.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Loading module Cryptol
Loading module Cryptol
Loading module Main
[{x = 0x02, y = True}, {x = 0x03, y = True}, {x = 0x04,
y = False}, {x = 0x05, y = False}]
[{x = 0x07, y = True}, {x = 0x08, y = True}, {x = 0x09,
y = False}, {x = 0x0a, y = False}]
[{x = 0x02, y = True}, {x = 0x03, y = True},
{x = 0x04, y = False}, {x = 0x05, y = False}]
[{x = 0x07, y = True}, {x = 0x08, y = True},
{x = 0x09, y = False}, {x = 0x0a, y = False}]
8 changes: 4 additions & 4 deletions tests/regression/sort.icry.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ Loading module Cryptol
(18, 8), (12, 9), (8, 10), (6, 11), (6, 12), (8, 13), (12, 14),
(18, 15), (3, 16), (13, 17), (2, 18), (16, 19), (9, 20), (4, 21),
(1, 22)]
[(0, 0), (1, 1), (1, 22), (2, 5), (2, 18), (3, 7), (3, 16), (4,
2), (4, 21), (6, 11), (6, 12), (8, 10), (8, 13), (9, 3), (9, 20),
(12, 9), (12, 14), (13, 6), (13, 17), (16, 4), (16, 19), (18, 8),
(18, 15)]
[(0, 0), (1, 1), (1, 22), (2, 5), (2, 18), (3, 7), (3, 16),
(4, 2), (4, 21), (6, 11), (6, 12), (8, 10), (8, 13), (9, 3),
(9, 20), (12, 9), (12, 14), (13, 6), (13, 17), (16, 4), (16, 19),
(18, 8), (18, 15)]
[(1, 22), (4, 21), (9, 20), (16, 19), (2, 18), (13, 17), (3, 16),
(18, 15), (12, 14), (8, 13), (6, 12), (6, 11), (8, 10), (12, 9),
(18, 8), (3, 7), (13, 6), (2, 5), (16, 4), (9, 3), (4, 2), (1, 1),
Expand Down