names-th 0.1.0.0 → 0.1.0.1
raw patch · 2 files changed
+20/−4 lines, 2 filesdep +containersPVP ok
version bump matches the API change (PVP)
Dependencies added: containers
API changes (from Hackage documentation)
Files
names-th.cabal view
@@ -1,5 +1,5 @@ name: names-th-version: 0.1.0.0+version: 0.1.0.1 synopsis: Manipulate name strings for TH description: This package includes functions to manipulate name string and extra library functions for Template Haskell.@@ -17,7 +17,7 @@ exposed-modules: Language.Haskell.TH.Name.CamelCase Language.Haskell.TH.Lib.Extra- build-depends: base <5, template-haskell+ build-depends: base <5, containers, template-haskell hs-source-dirs: src ghc-options: -Wall
src/Language/Haskell/TH/Name/CamelCase.hs view
@@ -28,6 +28,7 @@ ) where import Data.Char (toUpper, toLower)+import Data.Set (Set, fromList, member) import Language.Haskell.TH (Name, mkName, TypeQ, conT, ExpQ, conE, varE, PatQ, varP) @@ -39,6 +40,21 @@ unCapitalize (c:cs) = toLower c : cs unCapitalize "" = "" +-- | rename the string that equals to reserved identifiers.+rename :: String -> String+rename cs | cs `member` reservedIds = cs ++ "_"+ | otherwise = cs+{-# INLINE rename #-}++-- | All reserved identifiers. Taken from section 2.4 of the 2010 Report.+reservedIds :: Set String+reservedIds = fromList [ "case", "class", "data", "default", "deriving"+ , "do", "else", "foreign", "if", "import", "in"+ , "infix", "infixl", "infixr", "instance", "let"+ , "module", "newtype", "of", "then", "type", "where"+ , "_" ]+{-# INLINE reservedIds #-}+ {- $nameTypes Wrap 'Name' to distinguish constructor names and variable names. -}@@ -48,14 +64,14 @@ -- | Make constructor name from 'String'. toConName :: String -> ConName-toConName = ConName . mkName . capitalize+toConName = ConName . mkName . rename . capitalize -- | Type to wrap variable\'s 'Name'. newtype VarName = VarName { varName :: Name {- ^ Get wrapped 'Name' -} } -- | Make variable name from 'String'. toVarName :: String -> VarName-toVarName = VarName . mkName . unCapitalize+toVarName = VarName . mkName . rename . unCapitalize -- | 'Char' set used from camel-cased names. nameChars :: String