Skip to content

Commit 641b777

Browse files
authored
Merge pull request #44 from input-output-hk/nc/group-keys
Support keys in group entries
2 parents 50c0e90 + d65c418 commit 641b777

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@
3838
additional hints are required to type literal numerics correctly. Typically
3939
this is most easily fixed by adding a call `int` for any numeric literals in
4040
ranges. An example is shown in `example/Conway.hs`
41+
42+
## 0.3.6.0 -- 2024-12-02
43+
* Support having keys in group entries. This is needed when using a group to
44+
define a map, or when wishing to include keys in for-use-in-array groups for
45+
documentation purposes. This may introduce problems with existing specifications
46+
where some type hints (using 'a') are needed to properly type entries in groups,
47+
where previously they were unambiguous.
48+
49+
Note that it is not yet supported to use a group inside a map, where the
50+
issue of merging keys arises.

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.5.0
3+
version: 0.3.6.0
44
synopsis: CDDL Generator and test utilities
55

66
-- description:

example/Conway.hs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,30 @@ parameter_change_action =
159159
"parameter_change_action"
160160
=:~ grp
161161
[ 0,
162-
gov_action_id / VNil,
162+
a (gov_action_id / VNil),
163163
a protocol_param_update,
164-
policy_hash / VNil
164+
a (policy_hash / VNil)
165165
]
166166

167167
hard_fork_initiation_action :: Named Group
168168
hard_fork_initiation_action =
169169
"hard_fork_initiation_action"
170-
=:~ grp [1, gov_action_id / VNil, a (arr [a protocol_version])]
170+
=:~ grp [1, a (gov_action_id / VNil), a (arr [a protocol_version])]
171171

172172
treasury_withdrawals_action :: Named Group
173173
treasury_withdrawals_action =
174174
"treasury_withdrawals_action"
175-
=:~ grp [2, a (arr [asKey reward_account ==> coin / VInt]), policy_hash / VNil]
175+
=:~ grp [2, a (arr [asKey reward_account ==> coin / VInt]), a (policy_hash / VNil)]
176176

177177
no_confidence :: Named Group
178-
no_confidence = "no_confidence" =:~ grp [3, gov_action_id / VNil]
178+
no_confidence = "no_confidence" =:~ grp [3, a (gov_action_id / VNil)]
179179

180180
update_committee :: Named Group
181181
update_committee =
182182
"update_committee"
183183
=:~ grp
184184
[ 4,
185-
gov_action_id / VNil,
185+
a (gov_action_id / VNil),
186186
a (set committee_cold_credential),
187187
a (arr [asKey committee_cold_credential ==> epoch]),
188188
a unit_interval
@@ -191,7 +191,7 @@ update_committee =
191191
new_constitution :: Named Group
192192
new_constitution =
193193
"new_constitution"
194-
=:~ grp [5, gov_action_id / VNil, a constitution]
194+
=:~ grp [5, a (gov_action_id / VNil), a constitution]
195195

196196
constitution :: Rule
197197
constitution =
@@ -356,16 +356,16 @@ auth_committee_hot_cert =
356356
resign_committee_cold_cert :: Named Group
357357
resign_committee_cold_cert =
358358
"resign_committee_cold_cert"
359-
=:~ grp [15, a committee_cold_credential, anchor / VNil]
359+
=:~ grp [15, a committee_cold_credential, a (anchor / VNil)]
360360

361361
reg_drep_cert :: Named Group
362-
reg_drep_cert = "reg_drep_cert" =:~ grp [16, a drep_credential, a coin, anchor / VNil]
362+
reg_drep_cert = "reg_drep_cert" =:~ grp [16, a drep_credential, a coin, a (anchor / VNil)]
363363

364364
unreg_drep_cert :: Named Group
365365
unreg_drep_cert = "unreg_drep_cert" =:~ grp [17, a drep_credential, a coin]
366366

367367
update_drep_cert :: Named Group
368-
update_drep_cert = "update_drep_cert" =:~ grp [18, a drep_credential, anchor / VNil]
368+
update_drep_cert = "update_drep_cert" =:~ grp [18, a drep_credential, a (anchor / VNil)]
369369

370370
delta_coin :: Rule
371371
delta_coin = "delta_coin" =:= VUInt
@@ -429,17 +429,17 @@ single_host_addr =
429429
"single_host_addr"
430430
=:~ grp
431431
[ 0,
432-
port / VNil,
433-
ipv4 / VNil,
434-
ipv6 / VNil
432+
a (port / VNil),
433+
a (ipv4 / VNil),
434+
a (ipv6 / VNil)
435435
]
436436

437437
single_host_name :: Named Group
438438
single_host_name =
439439
"single_host_name"
440440
=:~ grp
441441
[ 1,
442-
port / VNil,
442+
a (port / VNil),
443443
a dns_name -- An A or AAAA DNS record
444444
]
445445

noindex.cache

24 Bytes
Binary file not shown.

src/Codec/CBOR/Cuddle/Huddle.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ instance IsList ArrayChoice where
254254

255255
type Array = Choice ArrayChoice
256256

257-
newtype Group = Group {unGroup :: [Type0]}
257+
newtype Group = Group {unGroup :: [ArrayEntry]}
258258
deriving (Show, Monoid, Semigroup)
259259

260260
instance IsList Group where
261-
type Item Group = Type0
261+
type Item Group = ArrayEntry
262262

263263
fromList = Group
264264
toList (Group l) = l
@@ -991,7 +991,7 @@ collectFrom topRs =
991991
goMapEntry (MapEntry k t0 _ _) = goKey k >> goT0 t0
992992
goKey (TypeKey k) = goT2 k
993993
goKey _ = pure ()
994-
goGroup (Group g) = mapM_ goT0 g
994+
goGroup (Group g) = mapM_ goArrayEntry g
995995
goRanged (Unranged _) = pure ()
996996
goRanged (Ranged lb ub _) = goRangeBound lb >> goRangeBound ub
997997
goRangeBound (RangeBoundLiteral _) = pure ()
@@ -1148,7 +1148,7 @@ toCDDL' mkPseudoRoot hdl =
11481148
. C.GEGroup Nothing
11491149
. C.Group
11501150
. (NE.:| [])
1151-
$ fmap (C.noComment . C.GEType Nothing Nothing . toCDDLType0) t0s
1151+
$ fmap arrayEntryToCDDL t0s
11521152
)
11531153
(fmap C.Comment c)
11541154

test/Test/Codec/CBOR/Cuddle/Huddle.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ huddleSpec = describe "huddle" $ do
2020
basicAssign
2121
arraySpec
2222
mapSpec
23+
grpSpec
2324
nestedSpec
2425
genericSpec
2526
constraintSpec
@@ -85,6 +86,21 @@ mapSpec = describe "Maps" $ do
8586
toSortedCDDL ["mir" =:= arr [a (int 0 / int 1), a $ mp [0 <+ "test" ==> VUInt]]]
8687
`shouldMatchParseCDDL` "mir = [ 0 / 1, { * test : uint }]"
8788

89+
grpSpec :: Spec
90+
grpSpec = describe "Groups" $ do
91+
it "Can handle a choice in a group entry" $
92+
let g1 = "g1" =:~ grp [a (VUInt / VBytes), a VUInt]
93+
in toSortedCDDL (collectFrom ["a1" =:= arr [a g1]])
94+
`shouldMatchParseCDDL` "a1 = [g1]\n g1 = ( uint / bytes, uint )"
95+
it "Can handle keys in a group entry" $
96+
let g1 = "g1" =:~ grp ["bytes"==> VBytes]
97+
in toSortedCDDL (collectFrom ["a1" =:= arr [a g1]])
98+
`shouldMatchParseCDDL` "a1 = [g1]\n g1 = (bytes : bytes)"
99+
-- it "Can handle a group in a map" $
100+
-- let g1 = "g1" =:~ grp ["bytes"==> VBytes]
101+
-- in toSortedCDDL (collectFrom ["a1" =:= mp [g1]])
102+
-- `shouldMatchParseCDDL` "a1 = [g1]\n g1 = (bytes : bytes)"
103+
88104
nestedSpec :: Spec
89105
nestedSpec =
90106
describe "Nesting" $

0 commit comments

Comments
 (0)