module Poseidon.Version ( VersionComponent (..), updateThreeComponentVersion, parseVersion ) where import Data.Version (Version (..), makeVersion) import qualified Text.Parsec as P import qualified Text.Parsec.String as P data VersionComponent = Major | Minor | Patch deriving Int -> VersionComponent -> ShowS [VersionComponent] -> ShowS VersionComponent -> String (Int -> VersionComponent -> ShowS) -> (VersionComponent -> String) -> ([VersionComponent] -> ShowS) -> Show VersionComponent forall a. (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a $cshowsPrec :: Int -> VersionComponent -> ShowS showsPrec :: Int -> VersionComponent -> ShowS $cshow :: VersionComponent -> String show :: VersionComponent -> String $cshowList :: [VersionComponent] -> ShowS showList :: [VersionComponent] -> ShowS Show updateThreeComponentVersion :: VersionComponent -> Version -> Version updateThreeComponentVersion :: VersionComponent -> Version -> Version updateThreeComponentVersion VersionComponent component Version v = let i :: [Int] i = Version -> [Int] versionBranch Version v r :: [Int] r = case VersionComponent component of VersionComponent Patch -> [ [Int] i [Int] -> Int -> Int forall a. HasCallStack => [a] -> Int -> a !! Int 0, [Int] i [Int] -> Int -> Int forall a. HasCallStack => [a] -> Int -> a !! Int 1, ([Int] i [Int] -> Int -> Int forall a. HasCallStack => [a] -> Int -> a !! Int 2) Int -> Int -> Int forall a. Num a => a -> a -> a + Int 1] VersionComponent Minor -> [ [Int] i [Int] -> Int -> Int forall a. HasCallStack => [a] -> Int -> a !! Int 0, ([Int] i [Int] -> Int -> Int forall a. HasCallStack => [a] -> Int -> a !! Int 1) Int -> Int -> Int forall a. Num a => a -> a -> a + Int 1, Int 0 ] VersionComponent Major -> [([Int] i [Int] -> Int -> Int forall a. HasCallStack => [a] -> Int -> a !! Int 0) Int -> Int -> Int forall a. Num a => a -> a -> a + Int 1, Int 0, Int 0 ] in [Int] -> Version makeVersion [Int] r parseVersion :: P.Parser Version parseVersion :: Parser Version parseVersion = do Int major <- String -> Int forall a. Read a => String -> a read (String -> Int) -> ParsecT String () Identity String -> ParsecT String () Identity Int forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ParsecT String () Identity Char -> ParsecT String () Identity String forall s (m :: * -> *) t u a. Stream s m t => ParsecT s u m a -> ParsecT s u m [a] P.many1 ParsecT String () Identity Char forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char P.digit Char _ <- String -> ParsecT String () Identity Char forall s (m :: * -> *) u. Stream s m Char => String -> ParsecT s u m Char P.oneOf String "." Int minor <- String -> Int forall a. Read a => String -> a read (String -> Int) -> ParsecT String () Identity String -> ParsecT String () Identity Int forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ParsecT String () Identity Char -> ParsecT String () Identity String forall s (m :: * -> *) t u a. Stream s m t => ParsecT s u m a -> ParsecT s u m [a] P.many1 ParsecT String () Identity Char forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char P.digit Char _ <- String -> ParsecT String () Identity Char forall s (m :: * -> *) u. Stream s m Char => String -> ParsecT s u m Char P.oneOf String "." Int patch <- String -> Int forall a. Read a => String -> a read (String -> Int) -> ParsecT String () Identity String -> ParsecT String () Identity Int forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> ParsecT String () Identity Char -> ParsecT String () Identity String forall s (m :: * -> *) t u a. Stream s m t => ParsecT s u m a -> ParsecT s u m [a] P.many1 ParsecT String () Identity Char forall s (m :: * -> *) u. Stream s m Char => ParsecT s u m Char P.digit Version -> Parser Version forall a. a -> ParsecT String () Identity a forall (m :: * -> *) a. Monad m => a -> m a return ([Int] -> Version makeVersion [Int major, Int minor, Int patch])