Skip to content

Commit f58e83d

Browse files
committed
Implement parsing and generation of major type 7
1 parent 70675b5 commit f58e83d

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

src/Codec/CBOR/Cuddle/CBOR/Gen.hs

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ genPostlude pt = case pt of
202202
PTText -> TString <$> genText 30
203203
PTAny -> pure $ TString "Any"
204204
PTNil -> pure TNull
205+
PTUndefined -> pure $ TSimple 23
205206

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

431433
--------------------------------------------------------------------------------
432434
-- Generator functions

src/Codec/CBOR/Cuddle/CDDL.hs

+1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ data Value
375375
| VFloat64 Double
376376
| VText T.Text
377377
| VBytes B.ByteString
378+
| VBool Bool
378379
deriving (Eq, Generic, Show)
379380
deriving anyclass (ToExpr)
380381

src/Codec/CBOR/Cuddle/CDDL/Postlude.hs

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ data PTerm
4949
| PTText
5050
| PTAny
5151
| PTNil
52+
| PTUndefined
5253
deriving (Eq, Generic, Ord, Show)
5354

5455
instance Hashable PTerm

src/Codec/CBOR/Cuddle/CDDL/Resolve.hs

+17
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,28 @@ buildRefCTree rules = CTreeRoot $ fmap toCTreeRule rules
191191
toCTreeT0 t0
192192
toCTreeT2 (T2Tag (Just tag) t0) =
193193
It . CTree.Tag tag $ toCTreeT0 t0
194+
toCTreeT2 (T2DataItem 7 (Just mmin)) =
195+
toCTreeDataItem mmin
194196
toCTreeT2 (T2DataItem _maj _mmin) =
195197
-- We don't validate numerical items yet
196198
It $ CTree.Postlude PTAny
197199
toCTreeT2 T2Any = It $ CTree.Postlude PTAny
198200

201+
toCTreeDataItem 20 =
202+
It . CTree.Literal $ VBool False
203+
toCTreeDataItem 21 =
204+
It . CTree.Literal $ VBool True
205+
toCTreeDataItem 25 =
206+
It $ CTree.Postlude PTHalf
207+
toCTreeDataItem 26 =
208+
It $ CTree.Postlude PTFloat
209+
toCTreeDataItem 27 =
210+
It $ CTree.Postlude PTDouble
211+
toCTreeDataItem 23 =
212+
It $ CTree.Postlude PTUndefined
213+
toCTreeDataItem _ =
214+
It $ CTree.Postlude PTAny
215+
199216
toCTreeGroupEntryNC :: WithComments GroupEntry -> CTree.Node OrRef
200217
toCTreeGroupEntryNC = toCTreeGroupEntry . stripComment
201218

src/Codec/CBOR/Cuddle/Pretty.hs

+2
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,5 @@ instance Pretty Value where
218218
pretty (VFloat64 i) = pretty i
219219
pretty (VText t) = enclose "\"" "\"" $ pretty t
220220
pretty (VBytes b) = fromString $ "h" <> "'" <> BS.unpack b <> "'"
221+
pretty (VBool True) = "true"
222+
pretty (VBool False) = "false"

0 commit comments

Comments
 (0)