{-# LANGUAGE DeriveGeneric #-}
module Distribution.Parsec.Position (
Position (..),
incPos,
retPos,
showPos,
zeroPos,
positionCol,
positionRow,
) where
import Distribution.Compat.Prelude
import Prelude ()
data Position = Position
{-# UNPACK #-} !Int
{-# UNPACK #-} !Int
deriving (Eq, Ord, Show, Generic)
instance Binary Position
instance NFData Position where rnf = genericRnf
incPos :: Int -> Position -> Position
incPos n (Position row col) = Position row (col + n)
retPos :: Position -> Position
retPos (Position row _col) = Position (row + 1) 1
showPos :: Position -> String
showPos (Position row col) = show row ++ ":" ++ show col
zeroPos :: Position
zeroPos = Position 0 0
positionCol :: Position -> Int
positionCol (Position _ c) = c
positionRow :: Position -> Int
positionRow (Position r _) = r