Skip to content

Commit

Permalink
unicode-data: Add new internal module Unicode.Internal.Char.Version
Browse files Browse the repository at this point in the history
Everything generated by `ucd2haskell` should be in internal modules. This
commit will prevent breaking the update of `Unicode.Char.unicodeVersion`,
as it is will be a mere re-export of `Unicode.Internal.Char.Version`.
  • Loading branch information
wismill committed Jun 10, 2024
1 parent de8c5d7 commit abc248b
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 12 deletions.
3 changes: 0 additions & 3 deletions ucd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ucd2haskell/exe/UCD2Haskell/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module UCD2Haskell.Generator
-- * Generator
, runGenerator
, moduleToFileName
, dirFromFileName
-- * Bitmap
, genBitmap
, genEnumBitmap
Expand Down
7 changes: 7 additions & 0 deletions ucd2haskell/exe/UCD2Haskell/Generator/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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"
52 changes: 52 additions & 0 deletions ucd2haskell/exe/UCD2Haskell/Modules/Version.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- |
-- Copyright : (c) 2024 Pierre Le Marre
-- License : Apache-2.0
-- Maintainer : [email protected]
-- 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))
]
1 change: 1 addition & 0 deletions ucd2haskell/ucd2haskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 3 additions & 9 deletions unicode-data/lib/Unicode/Char.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,17 +42,11 @@ 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
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)
20 changes: 20 additions & 0 deletions unicode-data/lib/Unicode/Internal/Char/Version.hs
Original file line number Diff line number Diff line change
@@ -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 : [email protected]
-- 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]
1 change: 1 addition & 0 deletions unicode-data/unicode-data.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit abc248b

Please sign in to comment.