module Toml.Position (
Position(..),
startPos,
move,
) where
data Position = Position {
Position -> Int
posIndex :: {-# UNPACK #-} !Int,
Position -> Int
posLine :: {-# UNPACK #-} !Int,
Position -> Int
posColumn :: {-# UNPACK #-} !Int
} deriving (
ReadPrec [Position]
ReadPrec Position
Int -> ReadS Position
ReadS [Position]
(Int -> ReadS Position)
-> ReadS [Position]
-> ReadPrec Position
-> ReadPrec [Position]
-> Read Position
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Position
readsPrec :: Int -> ReadS Position
$creadList :: ReadS [Position]
readList :: ReadS [Position]
$creadPrec :: ReadPrec Position
readPrec :: ReadPrec Position
$creadListPrec :: ReadPrec [Position]
readListPrec :: ReadPrec [Position]
Read ,
Int -> Position -> ShowS
[Position] -> ShowS
Position -> String
(Int -> Position -> ShowS)
-> (Position -> String) -> ([Position] -> ShowS) -> Show Position
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Position -> ShowS
showsPrec :: Int -> Position -> ShowS
$cshow :: Position -> String
show :: Position -> String
$cshowList :: [Position] -> ShowS
showList :: [Position] -> ShowS
Show ,
Eq Position
Eq Position =>
(Position -> Position -> Ordering)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Bool)
-> (Position -> Position -> Position)
-> (Position -> Position -> Position)
-> Ord Position
Position -> Position -> Bool
Position -> Position -> Ordering
Position -> Position -> Position
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Position -> Position -> Ordering
compare :: Position -> Position -> Ordering
$c< :: Position -> Position -> Bool
< :: Position -> Position -> Bool
$c<= :: Position -> Position -> Bool
<= :: Position -> Position -> Bool
$c> :: Position -> Position -> Bool
> :: Position -> Position -> Bool
$c>= :: Position -> Position -> Bool
>= :: Position -> Position -> Bool
$cmax :: Position -> Position -> Position
max :: Position -> Position -> Position
$cmin :: Position -> Position -> Position
min :: Position -> Position -> Position
Ord ,
Position -> Position -> Bool
(Position -> Position -> Bool)
-> (Position -> Position -> Bool) -> Eq Position
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Position -> Position -> Bool
== :: Position -> Position -> Bool
$c/= :: Position -> Position -> Bool
/= :: Position -> Position -> Bool
Eq )
startPos :: Position
startPos :: Position
startPos = Position { posIndex :: Int
posIndex = Int
0, posLine :: Int
posLine = Int
1, posColumn :: Int
posColumn = Int
1 }
move :: Char -> Position -> Position
move :: Char -> Position -> Position
move Char
x Position{ posIndex :: Position -> Int
posIndex = Int
i, posLine :: Position -> Int
posLine = Int
l, posColumn :: Position -> Int
posColumn = Int
c} =
case Char
x of
Char
'\n' -> Position{ posIndex :: Int
posIndex = Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1, posLine :: Int
posLine = Int
lInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1, posColumn :: Int
posColumn = Int
1 }
Char
'\t' -> Position{ posIndex :: Int
posIndex = Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1, posLine :: Int
posLine = Int
l, posColumn :: Int
posColumn = (Int
c Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
7) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`quot` Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
8 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1 }
Char
_ -> Position{ posIndex :: Int
posIndex = Int
iInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1, posLine :: Int
posLine = Int
l, posColumn :: Int
posColumn = Int
cInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
1 }