| 1 |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} |
| 2 |
|
| 3 |
module Text.RE.ZeInternals.Types.LineNo where |
| 4 |
|
| 5 |
|
| 6 |
-- | our line numbers are of the proper zero-based kind |
| 7 |
newtype LineNo = |
| 8 |
ZeroBasedLineNo { getZeroBasedLineNo :: Int } |
| 9 |
deriving (Show,Enum) |
| 10 |
|
| 11 |
-- | the first line in a file |
| 12 |
firstLine :: LineNo |
| 13 |
firstLine = ZeroBasedLineNo 0 |
| 14 |
|
| 15 |
-- | extract a conventional 1-based line number |
| 16 |
getLineNo :: LineNo -> Int |
| 17 |
getLineNo = succ . getZeroBasedLineNo |
| 18 |
|
| 19 |
-- | inject a conventional 1-based line number |
| 20 |
lineNo :: Int -> LineNo |
| 21 |
lineNo = ZeroBasedLineNo . pred |