diff --git a/generator/DearImGui/Generator.hs b/generator/DearImGui/Generator.hs index f2f2056..5c75e71 100644 --- a/generator/DearImGui/Generator.hs +++ b/generator/DearImGui/Generator.hs @@ -92,7 +92,7 @@ headers = $( do ( unlines ( map Megaparsec.parseErrorPretty . toList $ Megaparsec.bundleErrors err ) ) <> "\n" <> ( unlines ( map show prev ) <> "\n\n" <> unlines ( map show rest ) ) Right res -> pure res - TH.lift =<< generateNames basicHeaders + TH.lift $ generateNames basicHeaders ) -------------------------------------------------------------------------------- diff --git a/generator/DearImGui/Generator/Types.hs b/generator/DearImGui/Generator/Types.hs index 6f34968..56a9c0d 100644 --- a/generator/DearImGui/Generator/Types.hs +++ b/generator/DearImGui/Generator/Types.hs @@ -10,8 +10,8 @@ module DearImGui.Generator.Types where -- base -import Data.Traversable - ( for ) +import Data.Functor + ( (<&>) ) -- template-haskell import qualified Language.Haskell.TH as TH @@ -50,13 +50,16 @@ data Headers typeName { enums :: [ Enumeration typeName ] } deriving stock ( Show, TH.Lift ) -generateNames :: Headers () -> TH.Q ( Headers ( TH.Name, TH.Name ) ) -generateNames ( Headers { enums = basicEnums } ) = do - enums <- for basicEnums \ enum@( Enumeration { enumName } ) -> do - let - enumNameStr :: String - enumNameStr = Text.unpack enumName - tyName <- TH.newName enumNameStr - conName <- TH.newName enumNameStr - pure $ enum { enumTypeName = ( tyName, conName ) } - pure $ Headers { enums } +generateNames :: Headers () -> Headers ( TH.Name, TH.Name ) +generateNames ( Headers { enums = basicEnums } ) = Headers { enums = namedEnums } + where + namedEnums :: [ Enumeration ( TH.Name, TH.Name ) ] + namedEnums = basicEnums <&> \ enum@( Enumeration { enumName } ) -> + let + enumNameStr :: String + enumNameStr = Text.unpack enumName + tyName, conName :: TH.Name + tyName = TH.mkName enumNameStr + conName = TH.mkName enumNameStr + in + enum { enumTypeName = ( tyName, conName ) }