1 {-# LANGUAGE DeriveGeneric #-}
3 module Distribution
.Parsec
.Position
13 import Distribution
.Compat
.Prelude
16 -- | 1-indexed row and column positions in a file.
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
38 zeroPos
= Position
0 0
41 positionCol
:: Position
-> Int
42 positionCol
(Position _ c
) = c
45 positionRow
:: Position
-> Int
46 positionRow
(Position r _
) = r