@@ -24,6 +24,13 @@ import Codec.CBOR.Cuddle.CDDL (
24
24
OccurrenceIndicator (.. ),
25
25
Value (.. ),
26
26
ValueVariant (.. ),
27
+ WrappedTerm ,
28
+ flattenWrappedList ,
29
+ pairTermList ,
30
+ singleTermList ,
31
+ pattern G ,
32
+ pattern P ,
33
+ pattern S ,
27
34
)
28
35
import Codec.CBOR.Cuddle.CDDL.CTree (CTree , CTreeRoot' (.. ))
29
36
import Codec.CBOR.Cuddle.CDDL.CTree qualified as CTree
@@ -207,48 +214,6 @@ genPostlude pt = case pt of
207
214
PTNil -> pure TNull
208
215
PTUndefined -> pure $ TSimple 23
209
216
210
- --------------------------------------------------------------------------------
211
- -- Kinds of terms
212
- --------------------------------------------------------------------------------
213
-
214
- data WrappedTerm
215
- = SingleTerm Term
216
- | PairTerm Term Term
217
- | GroupTerm [WrappedTerm ]
218
- deriving (Eq , Show )
219
-
220
- -- | Recursively flatten wrapped list. That is, expand any groups out to their
221
- -- individual entries.
222
- flattenWrappedList :: [WrappedTerm ] -> [WrappedTerm ]
223
- flattenWrappedList [] = []
224
- flattenWrappedList (GroupTerm xxs : xs) =
225
- flattenWrappedList xxs <> flattenWrappedList xs
226
- flattenWrappedList (y : xs) = y : flattenWrappedList xs
227
-
228
- pattern S :: Term -> WrappedTerm
229
- pattern S t = SingleTerm t
230
-
231
- -- | Convert a list of wrapped terms to a list of terms. If any 'PairTerm's are
232
- -- present, we just take their "value" part.
233
- singleTermList :: [WrappedTerm ] -> Maybe [Term ]
234
- singleTermList [] = Just []
235
- singleTermList (S x : xs) = (x : ) <$> singleTermList xs
236
- singleTermList (P _ y : xs) = (y : ) <$> singleTermList xs
237
- singleTermList _ = Nothing
238
-
239
- pattern P :: Term -> Term -> WrappedTerm
240
- pattern P t1 t2 = PairTerm t1 t2
241
-
242
- -- | Convert a list of wrapped terms to a list of pairs of terms, or fail if any
243
- -- 'SingleTerm's are present.
244
- pairTermList :: [WrappedTerm ] -> Maybe [(Term , Term )]
245
- pairTermList [] = Just []
246
- pairTermList (P x y : xs) = ((x, y) : ) <$> pairTermList xs
247
- pairTermList _ = Nothing
248
-
249
- pattern G :: [WrappedTerm ] -> WrappedTerm
250
- pattern G xs = GroupTerm xs
251
-
252
217
--------------------------------------------------------------------------------
253
218
-- Generator functions
254
219
--------------------------------------------------------------------------------
@@ -420,7 +385,7 @@ applyOccurenceIndicator (OIBounded mlb mub) oldGen =
420
385
genDepthBiasedRM (fromMaybe 0 mlb :: Word64 , fromMaybe 10 mub )
421
386
>>= \ i -> G <$> replicateM (fromIntegral i) oldGen
422
387
423
- genValue :: RandomGen g => Value -> M g Term
388
+ genValue :: RandomGen g => Value () -> M g Term
424
389
genValue (Value x _) = genValueVariant x
425
390
426
391
genValueVariant :: RandomGen g => ValueVariant -> M g Term
0 commit comments