Skip to content

Commit dd0fa69

Browse files
committed
Pretty printer improvements
Addresses (to an extent) #34 Note that this does not precisely match what is written in #34, because of group choices. That is, handling of something like the following: ``` credential = [0, addr_keyhash // 1, scripthash] ```
1 parent c3e54f4 commit dd0fa69

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@
88

99
* Rationalise the choice operators. Drop (//) and provide detailed comments
1010
explaining the use of (/).
11+
12+
## 0.3.0.1 -- 2024-07-31
13+
14+
* Improvements in the pretty printer - various groups should be formatted more
15+
cleanly

cuddle.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.4
22
name: cuddle
3-
version: 0.3.0.0
3+
version: 0.3.0.1
44
synopsis: CDDL Generator and test utilities
55

66
-- description:

src/Codec/CBOR/Cuddle/Pretty.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ instance Pretty Type1 where
6767
instance Pretty Type2 where
6868
pretty (T2Value v) = pretty v
6969
pretty (T2Name n mg) = pretty n <> pretty mg
70-
pretty (T2Group g) = enclose "(" ")" $ pretty g
71-
pretty (T2Map g) = enclose "{" "}" $ pretty g
72-
pretty (T2Array g) = enclose "[" "]" $ pretty g
70+
pretty (T2Group g) = align $ enclose "(" ")" $ pretty g
71+
pretty (T2Map g) = align $ enclose "{" "}" $ pretty g
72+
pretty (T2Array g) = brackets $ pretty g
7373
pretty (T2Unwrapped n mg) = "~" <+> pretty n <> pretty mg
7474
pretty (T2Enum g) = "&" <+> enclose "(" ")" (pretty g)
7575
pretty (T2EnumRef g mg) = "&" <+> pretty g <> pretty mg
@@ -92,9 +92,9 @@ instance Pretty OccurrenceIndicator where
9292

9393
instance Pretty Group where
9494
pretty (Group (NE.toList -> xs)) =
95-
align . encloseSep mempty mempty " // " $ fmap prettyGrpChoice xs
95+
align . vsep . punctuate " // " $ fmap prettyGrpChoice xs
9696
where
97-
prettyGrpChoice = align . encloseSep mempty mempty ", " . fmap pretty
97+
prettyGrpChoice = sep . punctuate "," . fmap pretty
9898

9999
instance Pretty GroupEntry where
100100
pretty (GEType moi mmk t) =

0 commit comments

Comments
 (0)