1{-# LANGUAGE DeriveDataTypeable, TemplateHaskell #-}
2module Elm.Internal.Version where
4import Control.Applicative
7import Data.Char (isDigit)
8import qualified Data.List as List
10import qualified Data.Text as T
11import qualified Paths_Elm as This
12import qualified Data.Version as Version
16 where (Version.Version ns _) = This.version
20data Version = V [Int] String
21 deriving (Typeable,Eq)
23instance Ord Version where
24 compare (V ns tag) (V ns' tag') =
25 case compare ns ns' of
26 EQ -> compare tag' tag -- reverse comparison to favor ""
29instance Show Version where
31 List.intercalate "." (map show ns) ++ if null tag then "" else "-" ++ tag
33instance Binary Version where
34 get = V <$> get <*> get
35 put (V ns tag) = do put ns
38tagless :: Version -> Bool
39tagless (V _ tag) = null tag
41fromString :: String -> Maybe Version
42fromString version = V <$> splitNumbers possibleNumbers <*> tag
44 (possibleNumbers, possibleTag) = break (=='-') version
46 tag = case possibleTag of
51 splitNumbers :: String -> Maybe [Int]
53 case span isDigit ns of
55 (number, []) -> Just [read number]
56 (number, '.':rest) -> (read number :) <$> splitNumbers rest
59instance FromJSON Version where
60 parseJSON (String text) =
61 let string = T.unpack text in
62 case fromString string of
64 Nothing -> fail $ unlines
65 [ "Dependency file has an invalid version number: " ++ string
66 , "Must have format 0.1.2 or 0.1.2-tag"
69 parseJSON _ = fail "Version number must be stored as a string."
71instance ToJSON Version where
72 toJSON version = toJSON (show version)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list