make LTS branch pre-releases
[cabal.git] / Cabal-syntax / src / Distribution / Parsec / Position.hs
blob892fc8b8fda1e9b4a3f8d6589d07bf6d526916c6
1 {-# LANGUAGE DeriveGeneric #-}
3 module Distribution.Parsec.Position
4 ( Position (..)
5 , incPos
6 , retPos
7 , showPos
8 , zeroPos
9 , positionCol
10 , positionRow
11 ) where
13 import Distribution.Compat.Prelude
14 import Prelude ()
16 -- | 1-indexed row and column positions in a file.
17 data Position
18 = Position
19 {-# UNPACK #-} !Int -- row
20 {-# UNPACK #-} !Int -- column
21 deriving (Eq, Ord, Show, Generic)
23 instance Binary Position
24 instance NFData Position where rnf = genericRnf
26 -- | Shift position by n columns to the right.
27 incPos :: Int -> Position -> Position
28 incPos n (Position row col) = Position row (col + n)
30 -- | Shift position to beginning of next row.
31 retPos :: Position -> Position
32 retPos (Position row _col) = Position (row + 1) 1
34 showPos :: Position -> String
35 showPos (Position row col) = show row ++ ":" ++ show col
37 zeroPos :: Position
38 zeroPos = Position 0 0
40 -- | @since 3.0.0.0
41 positionCol :: Position -> Int
42 positionCol (Position _ c) = c
44 -- | @since 3.0.0.0
45 positionRow :: Position -> Int
46 positionRow (Position r _) = r