@@ -108,6 +108,7 @@ import GHC.Exts (IsList (Item, fromList, toList))
108
108
import GHC.Generics (Generic )
109
109
import Optics.Core (lens , view , (%~) , (&) , (.~) , (^.) )
110
110
import Prelude hiding ((/) )
111
+ import Codec.CBOR.Cuddle.Comments (Comment )
111
112
112
113
data Named a = Named
113
114
{ name :: T. Text
@@ -432,7 +433,7 @@ unconstrained v = Constrained (CValue v) def []
432
433
-- | A constraint on a 'Value' is something applied via CtlOp or RangeOp on a
433
434
-- Type2, forming a Type1.
434
435
data ValueConstraint a = ValueConstraint
435
- { applyConstraint :: C. Type2 -> C. Type1
436
+ { applyConstraint :: C. Type2 Comment -> C. Type1 Comment
436
437
, showConstraint :: String
437
438
}
438
439
@@ -462,7 +463,7 @@ instance IsSizeable CGRefType
462
463
463
464
-- | Things which can be used on the RHS of the '.size' operator.
464
465
class IsSize a where
465
- sizeAsCDDL :: a -> C. Type2
466
+ sizeAsCDDL :: a -> C. Type2 Comment
466
467
sizeAsString :: a -> String
467
468
468
469
instance IsSize Word where
@@ -1062,15 +1063,15 @@ collectFromInit rules =
1062
1063
--------------------------------------------------------------------------------
1063
1064
1064
1065
-- | Convert from Huddle to CDDL, generating a top level root element.
1065
- toCDDL :: Huddle -> CDDL
1066
+ toCDDL :: Huddle -> CDDL Comment
1066
1067
toCDDL = toCDDL' True
1067
1068
1068
1069
-- | Convert from Huddle to CDDL, skipping a root element.
1069
- toCDDLNoRoot :: Huddle -> CDDL
1070
+ toCDDLNoRoot :: Huddle -> CDDL Comment
1070
1071
toCDDLNoRoot = toCDDL' False
1071
1072
1072
1073
-- | Convert from Huddle to CDDL for the purpose of pretty-printing.
1073
- toCDDL' :: Bool -> Huddle -> CDDL
1074
+ toCDDL' :: Bool -> Huddle -> CDDL Comment
1074
1075
toCDDL' mkPseudoRoot hdl =
1075
1076
C. fromRules
1076
1077
$ ( if mkPseudoRoot
@@ -1082,12 +1083,12 @@ toCDDL' mkPseudoRoot hdl =
1082
1083
toCDDLItem (HIRule r) = toCDDLRule r
1083
1084
toCDDLItem (HIGroup g) = toCDDLGroup g
1084
1085
toCDDLItem (HIGRule g) = toGenRuleDef g
1085
- toTopLevelPseudoRoot :: [Rule ] -> C. Rule
1086
+ toTopLevelPseudoRoot :: [Rule ] -> C. Rule Comment
1086
1087
toTopLevelPseudoRoot topRs =
1087
1088
toCDDLRule $
1088
1089
comment " Pseudo-rule introduced by Cuddle to collect root elements" $
1089
1090
" huddle_root_defs" =:= arr (fromList (fmap a topRs))
1090
- toCDDLRule :: Rule -> C. Rule
1091
+ toCDDLRule :: Rule -> C. Rule Comment
1091
1092
toCDDLRule (Named n t0 c) =
1092
1093
(\ x -> C. Rule (C. Name n mempty ) Nothing C. AssignEq x (foldMap C. Comment c))
1093
1094
. C. TOGType
@@ -1103,18 +1104,18 @@ toCDDL' mkPseudoRoot hdl =
1103
1104
toCDDLValue' (LText t) = C. VText t
1104
1105
toCDDLValue' (LBytes b) = C. VBytes b
1105
1106
1106
- mapToCDDLGroup :: Map -> C. Group
1107
+ mapToCDDLGroup :: Map -> C. Group Comment
1107
1108
mapToCDDLGroup xs = C. Group $ mapChoiceToCDDL <$> choiceToNE xs
1108
1109
1109
- mapChoiceToCDDL :: MapChoice -> C. GrpChoice
1110
+ mapChoiceToCDDL :: MapChoice -> C. GrpChoice Comment
1110
1111
mapChoiceToCDDL (MapChoice entries) = C. GrpChoice (fmap mapEntryToCDDL entries) mempty
1111
1112
1112
- mapEntryToCDDL :: MapEntry -> C. GroupEntry
1113
+ mapEntryToCDDL :: MapEntry -> C. GroupEntry Comment
1113
1114
mapEntryToCDDL (MapEntry k v occ cmnt) =
1114
1115
C. GroupEntry
1115
1116
(toOccurrenceIndicator occ)
1116
- cmnt
1117
1117
(C. GEType (Just $ toMemberKey k) (toCDDLType0 v))
1118
+ cmnt
1118
1119
1119
1120
toOccurrenceIndicator :: Occurs -> Maybe C. OccurrenceIndicator
1120
1121
toOccurrenceIndicator (Occurs Nothing Nothing ) = Nothing
@@ -1123,7 +1124,7 @@ toCDDL' mkPseudoRoot hdl =
1123
1124
toOccurrenceIndicator (Occurs (Just 1 ) Nothing ) = Just C. OIOneOrMore
1124
1125
toOccurrenceIndicator (Occurs lb ub) = Just $ C. OIBounded lb ub
1125
1126
1126
- toCDDLType1 :: Type2 -> C. Type1
1127
+ toCDDLType1 :: Type2 -> C. Type1 Comment
1127
1128
toCDDLType1 = \ case
1128
1129
T2Constrained (Constrained x constr _) ->
1129
1130
-- TODO Need to handle choices at the top level
@@ -1142,26 +1143,26 @@ toCDDL' mkPseudoRoot hdl =
1142
1143
T2Generic g -> C. Type1 (toGenericCall g) Nothing mempty
1143
1144
T2GenericRef (GRef n) -> C. Type1 (C. T2Name (C. Name n mempty ) Nothing ) Nothing mempty
1144
1145
1145
- toMemberKey :: Key -> C. MemberKey
1146
+ toMemberKey :: Key -> C. MemberKey Comment
1146
1147
toMemberKey (LiteralKey (Literal (LText t) _)) = C. MKBareword (C. Name t mempty )
1147
1148
toMemberKey (LiteralKey v) = C. MKValue $ toCDDLValue v
1148
1149
toMemberKey (TypeKey t) = C. MKType (toCDDLType1 t)
1149
1150
1150
- toCDDLType0 :: Type0 -> C. Type0
1151
+ toCDDLType0 :: Type0 -> C. Type0 Comment
1151
1152
toCDDLType0 = C. Type0 . fmap toCDDLType1 . choiceToNE
1152
1153
1153
- arrayToCDDLGroup :: Array -> C. Group
1154
+ arrayToCDDLGroup :: Array -> C. Group Comment
1154
1155
arrayToCDDLGroup xs = C. Group $ arrayChoiceToCDDL <$> choiceToNE xs
1155
1156
1156
- arrayChoiceToCDDL :: ArrayChoice -> C. GrpChoice
1157
+ arrayChoiceToCDDL :: ArrayChoice -> C. GrpChoice Comment
1157
1158
arrayChoiceToCDDL (ArrayChoice entries cmt) = C. GrpChoice (fmap arrayEntryToCDDL entries) cmt
1158
1159
1159
- arrayEntryToCDDL :: ArrayEntry -> C. GroupEntry
1160
+ arrayEntryToCDDL :: ArrayEntry -> C. GroupEntry Comment
1160
1161
arrayEntryToCDDL (ArrayEntry k v occ cmnt) =
1161
1162
C. GroupEntry
1162
1163
(toOccurrenceIndicator occ)
1163
- cmnt
1164
1164
(C. GEType (fmap toMemberKey k) (toCDDLType0 v))
1165
+ cmnt
1165
1166
1166
1167
toCDDLPostlude :: Value a -> C. Name
1167
1168
toCDDLPostlude VBool = C. Name " bool" mempty
@@ -1181,7 +1182,7 @@ toCDDL' mkPseudoRoot hdl =
1181
1182
CRef r -> C. Name (name r) mempty
1182
1183
CGRef (GRef n) -> C. Name n mempty
1183
1184
1184
- toCDDLRanged :: Ranged -> C. Type1
1185
+ toCDDLRanged :: Ranged -> C. Type1 Comment
1185
1186
toCDDLRanged (Unranged x) =
1186
1187
C. Type1 (C. T2Value $ toCDDLValue x) Nothing mempty
1187
1188
toCDDLRanged (Ranged lb ub rop) =
@@ -1190,18 +1191,18 @@ toCDDL' mkPseudoRoot hdl =
1190
1191
(Just (C. RangeOp rop, toCDDLRangeBound ub))
1191
1192
mempty
1192
1193
1193
- toCDDLRangeBound :: RangeBound -> C. Type2
1194
+ toCDDLRangeBound :: RangeBound -> C. Type2 Comment
1194
1195
toCDDLRangeBound (RangeBoundLiteral l) = C. T2Value $ toCDDLValue l
1195
1196
toCDDLRangeBound (RangeBoundRef (Named n _ _)) = C. T2Name (C. Name n mempty ) Nothing
1196
1197
1197
- toCDDLGroup :: Named Group -> C. Rule
1198
+ toCDDLGroup :: Named Group -> C. Rule Comment
1198
1199
toCDDLGroup (Named n (Group t0s) c) =
1199
1200
C. Rule
1200
1201
(C. Name n mempty )
1201
1202
Nothing
1202
1203
C. AssignEq
1203
1204
( C. TOGGroup
1204
- . C. GroupEntry Nothing mempty
1205
+ . ( \ x -> C. GroupEntry Nothing x mempty )
1205
1206
. C. GEGroup
1206
1207
. C. Group
1207
1208
. (NE. :| [] )
@@ -1212,13 +1213,13 @@ toCDDL' mkPseudoRoot hdl =
1212
1213
)
1213
1214
(foldMap C. Comment c)
1214
1215
1215
- toGenericCall :: GRuleCall -> C. Type2
1216
+ toGenericCall :: GRuleCall -> C. Type2 Comment
1216
1217
toGenericCall (Named n gr _) =
1217
1218
C. T2Name
1218
1219
(C. Name n mempty )
1219
1220
(Just . C. GenericArg $ fmap toCDDLType1 (args gr))
1220
1221
1221
- toGenRuleDef :: GRuleDef -> C. Rule
1222
+ toGenRuleDef :: GRuleDef -> C. Rule Comment
1222
1223
toGenRuleDef (Named n gr c) =
1223
1224
C. Rule
1224
1225
(C. Name n mempty )
0 commit comments