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: 2 additions & 0 deletions src/Codec/CBOR/Cuddle/CBOR/Gen.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ genPostlude pt = case pt of
PTText -> TString <$> genText 30
PTAny -> pure $ TString "Any"
PTNil -> pure TNull
PTUndefined -> pure $ TSimple 23

--------------------------------------------------------------------------------
-- Kinds of terms
Expand Down Expand Up @@ -427,6 +428,7 @@ genValue (VText t) = pure $ TString t
genValue (VBytes b) = case Base16.decode b of
Right bHex -> pure $ TBytes bHex
Left err -> error $ "Unable to parse hex encoded bytestring: " <> err
genValue (VBool b) = pure $ TBool b

--------------------------------------------------------------------------------
-- Generator functions
Expand Down
1 change: 1 addition & 0 deletions src/Codec/CBOR/Cuddle/CDDL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ data Value
| VFloat64 Double
| VText T.Text
| VBytes B.ByteString
| VBool Bool
deriving (Eq, Generic, Show)
deriving anyclass (ToExpr)

Expand Down
1 change: 1 addition & 0 deletions src/Codec/CBOR/Cuddle/CDDL/Postlude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ data PTerm
| PTText
| PTAny
| PTNil
| PTUndefined
deriving (Eq, Generic, Ord, Show)

instance Hashable PTerm
17 changes: 17 additions & 0 deletions src/Codec/CBOR/Cuddle/CDDL/Resolve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,28 @@ buildRefCTree rules = CTreeRoot $ fmap toCTreeRule rules
toCTreeT0 t0
toCTreeT2 (T2Tag (Just tag) t0) =
It . CTree.Tag tag $ toCTreeT0 t0
toCTreeT2 (T2DataItem 7 (Just mmin)) =
toCTreeDataItem mmin
toCTreeT2 (T2DataItem _maj _mmin) =
-- We don't validate numerical items yet
It $ CTree.Postlude PTAny
toCTreeT2 T2Any = It $ CTree.Postlude PTAny

toCTreeDataItem 20 =
It . CTree.Literal $ VBool False
toCTreeDataItem 21 =
It . CTree.Literal $ VBool True
toCTreeDataItem 25 =
It $ CTree.Postlude PTHalf
toCTreeDataItem 26 =
It $ CTree.Postlude PTFloat
toCTreeDataItem 27 =
It $ CTree.Postlude PTDouble
toCTreeDataItem 23 =
It $ CTree.Postlude PTUndefined
toCTreeDataItem _ =
It $ CTree.Postlude PTAny

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

Expand Down
2 changes: 2 additions & 0 deletions src/Codec/CBOR/Cuddle/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,5 @@ instance Pretty Value where
pretty (VFloat64 i) = pretty i
pretty (VText t) = enclose "\"" "\"" $ pretty t
pretty (VBytes b) = fromString $ "h" <> "'" <> BS.unpack b <> "'"
pretty (VBool True) = "true"
pretty (VBool False) = "false"