@@ -869,15 +869,28 @@ though can it ever be anything other than KStar?)
869869optional "deriving (Class, Class, ...)" clause
870870returns names of classes to be derived, or error if deriving not permitted
871871
872- > pDerivationsIf :: Bool -> SV_Parser [CTypeclass ]
872+ > pDerivationsIf :: Bool -> SV_Parser [CDeriving ]
873873> pDerivationsIf False = option [] $
874874> do pos <- getPos
875875> pKeyword SV_KW_deriving
876876> failWithErr (pos, EForbiddenDeriving )
877- > pDerivationsIf True = option [] $
878- > do pKeyword SV_KW_deriving
879- > pInParens (pCommaSep1 (pTypeclass <?> " typeclass name" ))
877+ > pDerivationsIf True = many pDeriving
880878
879+ > pDeriving :: SV_Parser CDeriving
880+ > pDeriving = pKeyword SV_KW_deriving
881+ > *> ( pDerivingStock
882+ > -- <|> pDerivingVia
883+ > )
884+
885+ > pDerivingStock :: SV_Parser CDeriving
886+ > pDerivingStock = CStock <$> pInParens (pCommaSep1 (pTypeclass <?> " typeclass name" ))
887+
888+ For now Deriving Via is disabled for bsv.
889+ pDerivingVia :: SV_Parser CDeriving
890+ pDerivingVia = CVia
891+ <$ > (pTypeclass <?> "typeclass name")
892+ *> pKeyword SV_KW_via
893+ <*> (pIdentifier <?> "via target")
881894
882895> pTypeclass :: SV_Parser CTypeclass
883896> pTypeclass = CTypeclass <$ > pQualConstructor
@@ -895,7 +908,7 @@ if prefix is provided, sub-union and sub-struct constructors start with it
895908> pTypedefStructField ::
896909> SV_Parser (Maybe Id {- constructor ID prefix -}
897910> -> [(Id , PartialKind )] {- type parameters collected thus far -}
898- > -> [CTypeclass ] {- derivings collected thus far -}
911+ > -> [CDeriving ] {- derivings collected thus far -}
899912> -> (CField , [CDefn ] {- accum'd defs -} ))
900913> pTypedefStructField =
901914> do mkSubUnion <- pTypedefTaggedUnionType False False
@@ -919,7 +932,7 @@ if prefix is provided, sub-union and sub-struct constructors start with it
919932> cf_type = typ,
920933> cf_default = []
921934> }
922- > return (const $ const $ const (field, [] ))
935+ > return (const $ const $ const (field, [] ))
923936
924937many struct fields
925938returns a function which requires a supertype prefix
@@ -928,7 +941,7 @@ if prefix is provided, sub-union and sub-struct constructors start with it
928941> pTypedefStructFields ::
929942> SV_Parser (Maybe Id {- constructor ID prefix -}
930943> -> [(Id , PartialKind )] {- type parameters accumulated thus far -}
931- > -> [CTypeclass ] {- derivations accumulated thus far -}
944+ > -> [CDeriving ] {- derivations accumulated thus far -}
932945> -> [(CField , [CDefn ] {- accum'd defs -} )])
933946> pTypedefStructFields =
934947> do mks <- many pTypedefStructField
@@ -946,7 +959,7 @@ if prefix is provided, sub-union and sub-struct constructors start with it
946959> -> SV_Parser
947960> (Maybe Id {- constructor ID prefix -}
948961> -> [(Id , PartialKind )] {- type parameters collected thus far -}
949- > -> [CTypeclass ] {- derivations collected thus far -}
962+ > -> [CDeriving ] {- derivations collected thus far -}
950963> -> ((Id , CType , [Id ], [CQType ]), [CDefn ]))
951964> pTypedefStructType isTopLevel =
952965> do pKeyword SV_KW_struct
@@ -981,7 +994,7 @@ if prefix is provided, sub-union and sub-struct constructors start with it
981994> SV_Parser (Maybe Id {- constructor ID prefix -}
982995> -> Integer {- tag encoding -}
983996> -> [(Id , PartialKind )] {- type parameters collected thus far -}
984- > -> [CTypeclass ] {- derivations collected thus far -}
997+ > -> [CDeriving ] {- derivations collected thus far -}
985998> -> (TaggedUnionField , [CDefn ] {- accum'd defs -} ))
986999> pTypedefTaggedUnionField =
9871000> do mkSubStruct <- pTypedefStructType False
@@ -1052,7 +1065,7 @@ if prefix is provided, sub-union and sub-struct constructors start with it
10521065> pTypedefTaggedUnionFields ::
10531066> SV_Parser (Maybe Id {- constructor ID prefix -}
10541067> -> [(Id , PartialKind )] {- type parameters collected thus far -}
1055- > -> [CTypeclass ] {- derivations collected thus far -}
1068+ > -> [CDeriving ] {- derivations collected thus far -}
10561069> -> [(TaggedUnionField , [CDefn ])])
10571070> pTypedefTaggedUnionFields =
10581071> do mks <- many1 pTypedefTaggedUnionField
@@ -1075,7 +1088,7 @@ will be a field inside a struct and should be an identifier
10751088> -> SV_Parser
10761089> (Maybe Id {- constructor ID prefix -}
10771090> -> [(Id , PartialKind )] {- type params collected thus far -}
1078- > -> [CTypeclass ] {- derivations collected thus far -}
1091+ > -> [CDeriving ] {- derivations collected thus far -}
10791092> -> ((Id , CType , [CQType ]), [CDefn ]))
10801093> pTypedefTaggedUnionType isTopLevel uppercaseName =
10811094> do pKeyword SV_KW_union >> pKeyword SV_KW_tagged
0 commit comments