diff --git a/ucd.sh b/ucd.sh index 58f95e34..23904d20 100755 --- a/ucd.sh +++ b/ucd.sh @@ -97,9 +97,6 @@ run_generator() { --core-prop Pattern_Syntax \ --core-prop Pattern_White_Space \ --unicode-version "$VERSION" - # Update unicodeVersion in Unicode.Char - VERSION_AS_LIST=$(echo "$VERSION" | sed "s/\./, /g") - sed -ri "s/^(unicodeVersion = makeVersion \[)[^]]*\]/\1$VERSION_AS_LIST\]/" "unicode-data/lib/Unicode/Char.hs" } # Print help text diff --git a/ucd2haskell/exe/UCD2Haskell/Generator.hs b/ucd2haskell/exe/UCD2Haskell/Generator.hs index 9992f8cc..b5ad6754 100644 --- a/ucd2haskell/exe/UCD2Haskell/Generator.hs +++ b/ucd2haskell/exe/UCD2Haskell/Generator.hs @@ -10,6 +10,7 @@ module UCD2Haskell.Generator -- * Generator , runGenerator , moduleToFileName + , dirFromFileName -- * Bitmap , genBitmap , genEnumBitmap diff --git a/ucd2haskell/exe/UCD2Haskell/Generator/Core.hs b/ucd2haskell/exe/UCD2Haskell/Generator/Core.hs index d8e773f5..f3aa4a2b 100644 --- a/ucd2haskell/exe/UCD2Haskell/Generator/Core.hs +++ b/ucd2haskell/exe/UCD2Haskell/Generator/Core.hs @@ -29,6 +29,7 @@ import qualified UCD2Haskell.Modules.UnicodeData.Composition as Composition import qualified UCD2Haskell.Modules.UnicodeData.Decomposition as Decomposition import qualified UCD2Haskell.Modules.UnicodeData.GeneralCategory as GeneralCategory import qualified UCD2Haskell.Modules.UnicodeData.SimpleCaseMappings as SimpleCaseMappings +import qualified UCD2Haskell.Modules.Version as Version import UCD2Haskell.Generator (runGenerator) generateModules :: Version -> FilePath -> FilePath -> [String] -> IO () @@ -96,3 +97,9 @@ generateModules version indir outdir props = do CF.parse outdir [ CaseFoldings.recipe ] + + Version.writeModule + version + outdir + "Unicode.Internal.Char.Version" + "0.3.0" diff --git a/ucd2haskell/exe/UCD2Haskell/Modules/Version.hs b/ucd2haskell/exe/UCD2Haskell/Modules/Version.hs new file mode 100644 index 00000000..c37e751d --- /dev/null +++ b/ucd2haskell/exe/UCD2Haskell/Modules/Version.hs @@ -0,0 +1,52 @@ +-- | +-- Copyright : (c) 2024 Pierre Le Marre +-- License : Apache-2.0 +-- Maintainer : streamly@composewell.com +-- Stability : experimental +-- +-- Unicode version module +module UCD2Haskell.Modules.Version + ( writeModule + ) where + +import qualified Data.ByteString as B +import qualified Data.ByteString.Builder as BB +import qualified Data.ByteString.Short as BS +import Data.Version (Version, showVersion, versionBranch) +import System.Directory (createDirectoryIfMissing) +import System.FilePath ((), (<.>)) + +import UCD2Haskell.Generator (moduleToFileName, unlinesBB, apacheLicense, dirFromFileName) + +writeModule :: + Version -> + FilePath -> + String -> + BS.ShortByteString -> + IO () +writeModule version outDir moduleName since = do + let outFile = outDir moduleToFileName moduleName <.> "hs" + let outFileDir = dirFromFileName outFile + createDirectoryIfMissing True outFileDir + B.writeFile outFile . B.toStrict . BB.toLazyByteString . unlinesBB $ + [ "-- DO NOT EDIT MANUALLY: autogenerated by ucd2haskell" + , "{-# OPTIONS_HADDOCK hide #-}" + , "" + , apacheLicense 2024 (BB.string7 moduleName) + , "module " <> BB.string7 moduleName <> " (unicodeVersion) where" + , "" + , "import Data.Version (Version, makeVersion)" + , "" + , "-- | Version of the Unicode standard used by this package:" + , mconcat + [ "-- [" + , BB.string7 (showVersion version) + , "](https://www.unicode.org/versions/Unicode" + , BB.string7 (showVersion version) + , "/)." ] + , "--" + , "-- @since " <> BB.shortByteString since + , "unicodeVersion :: Version" + , "unicodeVersion = makeVersion " + <> BB.string7 (show (versionBranch version)) + ] diff --git a/ucd2haskell/ucd2haskell.cabal b/ucd2haskell/ucd2haskell.cabal index 95e59ec1..ecf70c1b 100644 --- a/ucd2haskell/ucd2haskell.cabal +++ b/ucd2haskell/ucd2haskell.cabal @@ -91,6 +91,7 @@ executable ucd2haskell UCD2Haskell.Modules.UnicodeData.GeneralCategory UCD2Haskell.Modules.UnicodeData.NameAliases UCD2Haskell.Modules.UnicodeData.SimpleCaseMappings + UCD2Haskell.Modules.Version if flag(ucd2haskell) buildable: True build-depends: diff --git a/unicode-data/lib/Unicode/Char.hs b/unicode-data/lib/Unicode/Char.hs index c12dadaf..dc0f5742 100644 --- a/unicode-data/lib/Unicode/Char.hs +++ b/unicode-data/lib/Unicode/Char.hs @@ -26,14 +26,14 @@ -- module Unicode.Char - ( module Unicode.Char.General + ( unicodeVersion + , module Unicode.Char.General , module Unicode.Char.General.Compat , module Unicode.Char.Case , module Unicode.Char.Case.Compat , module Unicode.Char.Numeric , module Unicode.Char.Normalization , module Unicode.Char.Identifiers - , unicodeVersion -- * Re-export from @base@ , ord @@ -42,7 +42,6 @@ module Unicode.Char where import Data.Char (chr, ord) -import Data.Version (Version, makeVersion) import Unicode.Char.Case hiding (Unfold(..), Step(..)) import Unicode.Char.Case.Compat hiding (isLower, isUpper) import Unicode.Char.General @@ -50,9 +49,4 @@ import Unicode.Char.General.Compat hiding (isLetter, isSpace) import Unicode.Char.Identifiers import Unicode.Char.Numeric import Unicode.Char.Normalization - --- | Version of Unicode standard used by @unicode-data@. --- --- @since 0.3.0 -unicodeVersion :: Version -unicodeVersion = makeVersion [15, 0, 0] +import Unicode.Internal.Char.Version (unicodeVersion) diff --git a/unicode-data/lib/Unicode/Internal/Char/Version.hs b/unicode-data/lib/Unicode/Internal/Char/Version.hs new file mode 100644 index 00000000..ab57c454 --- /dev/null +++ b/unicode-data/lib/Unicode/Internal/Char/Version.hs @@ -0,0 +1,20 @@ +-- DO NOT EDIT MANUALLY: autogenerated by ucd2haskell +{-# OPTIONS_HADDOCK hide #-} + +-- | +-- Module : Unicode.Internal.Char.Version +-- Copyright : (c) 2024 Composewell Technologies and Contributors +-- License : Apache-2.0 +-- Maintainer : streamly@composewell.com +-- Stability : experimental + +module Unicode.Internal.Char.Version (unicodeVersion) where + +import Data.Version (Version, makeVersion) + +-- | Version of the Unicode standard used by this package: +-- [15.0.0](https://www.unicode.org/versions/Unicode15.0.0/). +-- +-- @since 0.3.0 +unicodeVersion :: Version +unicodeVersion = makeVersion [15,0,0] diff --git a/unicode-data/unicode-data.cabal b/unicode-data/unicode-data.cabal index 243cdf85..348ea65d 100644 --- a/unicode-data/unicode-data.cabal +++ b/unicode-data/unicode-data.cabal @@ -106,6 +106,7 @@ library Unicode.Internal.Char.UnicodeData.SimpleLowerCaseMapping Unicode.Internal.Char.UnicodeData.SimpleTitleCaseMapping Unicode.Internal.Char.UnicodeData.SimpleUpperCaseMapping + Unicode.Internal.Char.Version hs-source-dirs: lib ghc-options: -O2