Skip to content
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
2 changes: 1 addition & 1 deletion cuddle.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4
name: cuddle
version: 0.3.3.0
version: 0.3.4.0
synopsis: CDDL Generator and test utilities

-- description:
Expand Down
9 changes: 5 additions & 4 deletions example/Conway.hs
Original file line number Diff line number Diff line change
Expand Up @@ -956,13 +956,14 @@ bounded_bytes = "bounded_bytes" =:= VBytes `sized` (0 :: Word64, 64 :: Word64)

-- a type for distinct values.
-- The type parameter must support .size, for example: bytes or uint
distinct :: (IsSizeable s) => Value s -> Rule
distinct x =
"distinct_"
<> T.pack (show x)

distinct :: (IsType0 a, IsConstrainable a b) => a -> GRuleCall
distinct = binding $ \x ->
"distinct"
=:= (x `sized` (8 :: Word64))
/ (x `sized` (16 :: Word64))
/ (x `sized` (20 :: Word64))
/ (x `sized` (24 :: Word64))
/ (x `sized` (30 :: Word64))
/ (x `sized` (32 :: Word64))

6 changes: 3 additions & 3 deletions example/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ spec2 =
_transaction <-
"transaction"
=:= mp
[ idx 0 ==> set txIn,
idx 1 ==> set txOut,
idx 2 ==> metadata
[ comment "Transaction inputs" $ idx 0 ==> set txIn,
comment "Transaction outputs" $ idx 1 ==> set txOut,
comment "Metadata" $ idx 2 ==> metadata
]
metadata <- "metadata" =:= VBytes
_value <- "value" =:= mp ["token" ==> VText, "quantity" ==> VUInt]
Expand Down
2 changes: 1 addition & 1 deletion src/Codec/CBOR/Cuddle/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ instance Hashable OccurrenceIndicator
newtype Group = Group (NE.NonEmpty GrpChoice)
deriving (Eq, Generic, Show, Semigroup)

type GrpChoice = [GroupEntry]
type GrpChoice = [WithComments GroupEntry]

-- |
-- A group entry can be given by a value type, which needs to be matched
Expand Down
19 changes: 11 additions & 8 deletions src/Codec/CBOR/Cuddle/CDDL/Resolve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ buildRefCTree rules = CTreeRoot $ fmap toCTreeRule rules
It $ CTree.Postlude PTAny
toCTreeT2 T2Any = It $ CTree.Postlude PTAny

toCTreeGroupEntryNC :: WithComments GroupEntry -> CTree.Node OrRef
toCTreeGroupEntryNC = toCTreeGroupEntry . stripComment

toCTreeGroupEntry :: GroupEntry -> CTree.Node OrRef
toCTreeGroupEntry (GEType (Just occi) mmkey t0) =
It $
Expand Down Expand Up @@ -223,18 +226,18 @@ buildRefCTree rules = CTreeRoot $ fmap toCTreeRule rules
-- choice options
toCTreeEnum :: Group -> CTree.Node OrRef
toCTreeEnum (Group (a NE.:| [])) =
It . CTree.Enum . It . CTree.Group $ fmap toCTreeGroupEntry a
It . CTree.Enum . It . CTree.Group $ fmap toCTreeGroupEntryNC a
toCTreeEnum (Group xs) =
It . CTree.Choice $
fmap (It . CTree.Enum . It . CTree.Group . fmap toCTreeGroupEntry) xs
fmap (It . CTree.Enum . It . CTree.Group . fmap toCTreeGroupEntryNC) xs

-- Embed a group in another group, again floating out the choice options
groupToGroup :: Group -> CTree.Node OrRef
groupToGroup (Group (a NE.:| [])) =
It . CTree.Group $ fmap toCTreeGroupEntry a
It . CTree.Group $ fmap toCTreeGroupEntryNC a
groupToGroup (Group xs) =
It . CTree.Choice $
fmap (It . CTree.Group . fmap toCTreeGroupEntry) xs
fmap (It . CTree.Group . fmap toCTreeGroupEntryNC) xs

toKVPair :: Maybe MemberKey -> Type0 -> CTree.Node OrRef
toKVPair Nothing t0 = toCTreeT0 t0
Expand All @@ -249,20 +252,20 @@ buildRefCTree rules = CTreeRoot $ fmap toCTreeRule rules

-- Interpret a group as a map. Note that we float out the choice options
toCTreeMap :: Group -> CTree.Node OrRef
toCTreeMap (Group (a NE.:| [])) = It . CTree.Map $ fmap toCTreeGroupEntry a
toCTreeMap (Group (a NE.:| [])) = It . CTree.Map $ fmap toCTreeGroupEntryNC a
toCTreeMap (Group xs) =
It
. CTree.Choice
$ fmap (It . CTree.Map . fmap toCTreeGroupEntry) xs
$ fmap (It . CTree.Map . fmap toCTreeGroupEntryNC) xs

-- Interpret a group as an array. Note that we float out the choice
-- options
toCTreeArray :: Group -> CTree.Node OrRef
toCTreeArray (Group (a NE.:| [])) =
It . CTree.Array $ fmap toCTreeGroupEntry a
It . CTree.Array $ fmap toCTreeGroupEntryNC a
toCTreeArray (Group xs) =
It . CTree.Choice $
fmap (It . CTree.Array . fmap toCTreeGroupEntry) xs
fmap (It . CTree.Array . fmap toCTreeGroupEntryNC) xs

toCTreeMemberKey :: MemberKey -> CTree.Node OrRef
toCTreeMemberKey (MKValue v) = It $ CTree.Literal v
Expand Down
Loading
Loading