versions 6.0.1 → 6.0.2
raw patch · 5 files changed
+64/−10 lines, 5 filesdep +template-haskell
Dependencies added: template-haskell
Files
- CHANGELOG.md +22/−0
- Data/Versions.hs +11/−9
- test/TH.hs +19/−0
- test/Test.hs +9/−0
- versions.cabal +3/−1
CHANGELOG.md view
@@ -1,5 +1,27 @@ # Changelog +## 6.0.2 (2023-10-12)++#### Added++- `Lift` instances for the various types, which allows parsing version numbers+ at compile time within Template Haskell quotes. Currently there is no exported+ function that supports this directly, but you could write one like:++```haskell+-- | Parse a `Versioning` at compile time.+thVer :: Text -> Q Exp+thVer nm =+ case versioning nm of+ Left err -> fail (errorBundlePretty err)+ Right v -> lift v+```++#### Changed++- Due to the new dependency on `template-haskell`, GHC 8.8 is now the lowest+ supported compiler version.+ ## 6.0.1 (2023-05-08) #### Fixed
Data/Versions.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE CPP #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE DeriveLift #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE Rank2Types #-}@@ -85,6 +86,7 @@ import qualified Data.Text as T import Data.Void (Void) import GHC.Generics (Generic)+import Language.Haskell.TH.Syntax (Lift) import Text.Megaparsec hiding (chunk) import Text.Megaparsec.Char import qualified Text.Megaparsec.Char.Lexer as L@@ -97,7 +99,7 @@ -- composed. This is useful for specifying custom behaviour for when a certain -- parser fails. data Versioning = Ideal SemVer | General Version | Complex Mess- deriving (Eq, Show, Generic, NFData, Hashable)+ deriving (Eq, Show, Generic, NFData, Hashable, Lift) -- | Short-hand for detecting a `SemVer`. isIdeal :: Versioning -> Bool@@ -384,7 +386,7 @@ , _svPatch :: !Word , _svPreRel :: !(Maybe Release) , _svMeta :: !(Maybe Text) }- deriving stock (Show, Generic)+ deriving stock (Show, Generic, Lift) deriving anyclass (NFData, Hashable) -- | Two SemVers are equal if all fields except metadata are equal.@@ -425,7 +427,7 @@ -- | `Chunk`s have comparison behaviour according to SemVer's rules for preleases. newtype Release = Release (NonEmpty Chunk)- deriving stock (Eq, Show, Read, Generic)+ deriving stock (Eq, Show, Read, Generic, Lift) deriving anyclass (NFData, Hashable) instance Ord Release where@@ -457,7 +459,7 @@ -- 0rc1-abc3 -- @ data Chunk = Numeric Word | Alphanum Text- deriving stock (Eq, Show, Read, Generic)+ deriving stock (Eq, Show, Read, Generic, Lift) deriving anyclass (NFData, Hashable) toMChunk :: Chunk -> MChunk@@ -575,7 +577,7 @@ , _vChunks :: !Chunks , _vRel :: !(Maybe Release) , _vMeta :: !(Maybe Text) }- deriving stock (Eq, Show, Generic)+ deriving stock (Eq, Show, Generic, Lift) deriving anyclass (NFData, Hashable) -- | Customized. As in SemVer, metadata is ignored for the purpose of@@ -629,7 +631,7 @@ -- | `Chunk`s that have a comparison behaviour specific to `Version`. newtype Chunks = Chunks (NonEmpty Chunk)- deriving stock (Eq, Show, Generic)+ deriving stock (Eq, Show, Generic, Lift) deriving anyclass (NFData, Hashable) instance Ord Chunks where@@ -657,7 +659,7 @@ -- ^ A numeric value preceeded by an @r@, indicating a revision. | MPlain Text -- ^ Anything else.- deriving stock (Eq, Show, Generic)+ deriving stock (Eq, Show, Generic, Lift) deriving anyclass (NFData, Hashable) instance Ord MChunk where@@ -686,7 +688,7 @@ -- internal tests show consistency. `messMajor`, etc., are used internally where -- appropriate to enhance accuracy. data Mess = Mess !(NonEmpty MChunk) !(Maybe (VSep, Mess))- deriving stock (Eq, Show, Generic)+ deriving stock (Eq, Show, Generic, Lift) deriving anyclass (NFData, Hashable) -- | Try to extract the "major" version number from `Mess`, as if it were a@@ -761,7 +763,7 @@ -- * A plus (+). Stop using this outside of metadata if you are. Example: @10.2+0.93+1-1@ -- * An underscore (_). Stop using this if you are. data VSep = VColon | VHyphen | VPlus | VUnder | VTilde- deriving stock (Eq, Show, Generic)+ deriving stock (Eq, Show, Generic, Lift) deriving anyclass (NFData, Hashable) --------------------------------------------------------------------------------
+ test/TH.hs view
@@ -0,0 +1,19 @@+-- | Template Haskell seems picky about compilation stages. The code here must+-- be defined in a module separate from the one it's being used in.++module TH (thVer) where++import qualified Data.Text as T+import Data.Versions+import Language.Haskell.TH (Exp, Q)+import Language.Haskell.TH.Syntax (lift)++---++-- | Parse a `Versioning` at compile time.+thVer :: T.Text -> Q Exp+thVer nm =+ case versioning nm of+ Left err -> fail (errorBundlePretty err)+ Right v -> lift v+
test/Test.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell #-} {-# OPTIONS_GHC -fno-warn-orphans #-} @@ -10,12 +11,14 @@ import qualified Data.Text as T import Data.Versions import Data.Void (Void)+import Language.Haskell.TH (recover) import Lens.Micro import Test.Tasty import Test.Tasty.HUnit import Text.Megaparsec import Text.Megaparsec.Char import Text.Printf (printf)+import TH (thVer) --- @@ -180,6 +183,12 @@ [ testCase "SemVer - Increment Patch" incPatch , testCase "SemVer - Increment Patch from Text" incFromT , testCase "SemVer - Get patches" patches+ ]+ , testGroup "Template Haskell"+ [ testCase "SemVer" $ prettyV $(thVer "1.2.3") @?= "1.2.3"+ , testCase "Version" $ prettyV $(thVer "1.2.3.4") @?= "1.2.3.4"+ , testCase "Mess" $ prettyV $(thVer "003.03-3") @?= "003.03-3"+ , testCase "Failure" $ $(recover [| () |] (thVer "!!!")) @?= () ] , testGroup "Megaparsec Behaviour" [ testCase "manyTill" $ parse nameGrab "manyTill" "linux-firmware-3.2.14-1-x86_64.pkg.tar.xz" @?= Right "linux-firmware"
versions.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.2 name: versions-version: 6.0.1+version: 6.0.2 synopsis: Types and parsers for software version numbers. description: A library for parsing and comparing software version numbers. We like to give@@ -43,6 +43,7 @@ , base >=4.10 && <4.19 , megaparsec >=7 , text ^>=1.2 || ^>= 2.0+ , template-haskell >= 2.15 library import: commons@@ -58,6 +59,7 @@ main-is: Test.hs hs-source-dirs: test ghc-options: -threaded -with-rtsopts=-N+ other-modules: TH build-depends: , microlens >=0.4 , tasty >=0.10.1.2