1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE BangPatterns, UnboxedTuples #-}
21import Prelude hiding (max)
22import Control.Monad (liftM3)
23import Data.Binary (Binary, get, put, getWord8, putWord8)
24import qualified Data.Version as Version
25import Data.Word (Word8, Word16)
26import Foreign.Ptr (Ptr, plusPtr, minusPtr)
27import qualified Paths_elm
29import qualified Json.Decode as D
30import qualified Json.Encode as E
31import qualified Parse.Primitives as P
32import Parse.Primitives (Row, Col)
41 { _major :: {-# UNPACK #-} !Word16
42 , _minor :: {-# UNPACK #-} !Word16
43 , _patch :: {-# UNPACK #-} !Word16
60 case map fromIntegral (Version.versionBranch Paths_elm.version) of
61 major : minor : patch : _ ->
62 Version major minor patch
71 error "could not detect version of elm-compiler you are using"
78bumpPatch :: Version -> Version
79bumpPatch (Version major minor patch) =
80 Version major minor (patch + 1)
83bumpMinor :: Version -> Version
84bumpMinor (Version major minor _patch) =
85 Version major (minor + 1) 0
88bumpMajor :: Version -> Version
89bumpMajor (Version major _minor _patch) =
90 Version (major + 1) 0 0
97toChars :: Version -> [Char]
98toChars (Version major minor patch) =
99 show major ++ '.' : show minor ++ '.' : show patch
106decoder :: D.Decoder (Row, Col) Version
108 D.customString parser (,)
111encode :: Version -> E.Value
113 E.chars (toChars version)
120instance Binary Version where
124 then liftM3 Version get get get
128 return (Version (fromIntegral word) (fromIntegral minor) (fromIntegral patch))
130 put (Version major minor patch) =
131 if major < 255 && minor < 256 && patch < 256 then
132 do putWord8 (fromIntegral major)
133 putWord8 (fromIntegral minor)
134 putWord8 (fromIntegral patch)
146parser :: P.Parser (Row, Col) Version
148 do major <- numberParser
149 P.word1 0x2E {-.-} (,)
150 minor <- numberParser
151 P.word1 0x2E {-.-} (,)
152 patch <- numberParser
153 return (Version major minor patch)
156numberParser :: P.Parser (Row, Col) Word16
158 P.Parser $ \(P.State src pos end indent row col) cok _ _ eerr ->
162 let !word = P.unsafeIndex pos in
163 if word == 0x30 {-0-} then
166 !newState = P.State src (plusPtr pos 1) end indent row (col + 1)
170 else if isDigit word then
173 (# total, newPos #) = chompWord16 (plusPtr pos 1) end (fromIntegral (word - 0x30))
174 !newState = P.State src newPos end indent row (col + fromIntegral (minusPtr newPos pos))
182chompWord16 :: Ptr Word8 -> Ptr Word8 -> Word16 -> (# Word16, Ptr Word8 #)
183chompWord16 pos end total =
187 let !word = P.unsafeIndex pos in
189 chompWord16 (plusPtr pos 1) end (10 * total + fromIntegral (word - 0x30))
194isDigit :: Word8 -> Bool
196 0x30 {-0-} <= word && word <= 0x39 {-9-}
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