{-# LANGUAGE DeriveFunctor #-}
module Jikka.Common.Location where
import Data.String (IsString (..))
data Loc = Loc
{ Loc -> Int
line :: !Int,
Loc -> Int
column :: !Int,
Loc -> Int
width :: !Int
}
deriving (Loc -> Loc -> Bool
(Loc -> Loc -> Bool) -> (Loc -> Loc -> Bool) -> Eq Loc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Loc -> Loc -> Bool
$c/= :: Loc -> Loc -> Bool
== :: Loc -> Loc -> Bool
$c== :: Loc -> Loc -> Bool
Eq, Eq Loc
Eq Loc
-> (Loc -> Loc -> Ordering)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Bool)
-> (Loc -> Loc -> Loc)
-> (Loc -> Loc -> Loc)
-> Ord Loc
Loc -> Loc -> Bool
Loc -> Loc -> Ordering
Loc -> Loc -> Loc
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
min :: Loc -> Loc -> Loc
$cmin :: Loc -> Loc -> Loc
max :: Loc -> Loc -> Loc
$cmax :: Loc -> Loc -> Loc
>= :: Loc -> Loc -> Bool
$c>= :: Loc -> Loc -> Bool
> :: Loc -> Loc -> Bool
$c> :: Loc -> Loc -> Bool
<= :: Loc -> Loc -> Bool
$c<= :: Loc -> Loc -> Bool
< :: Loc -> Loc -> Bool
$c< :: Loc -> Loc -> Bool
compare :: Loc -> Loc -> Ordering
$ccompare :: Loc -> Loc -> Ordering
$cp1Ord :: Eq Loc
Ord, Int -> Loc -> ShowS
[Loc] -> ShowS
Loc -> String
(Int -> Loc -> ShowS)
-> (Loc -> String) -> ([Loc] -> ShowS) -> Show Loc
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Loc] -> ShowS
$cshowList :: [Loc] -> ShowS
show :: Loc -> String
$cshow :: Loc -> String
showsPrec :: Int -> Loc -> ShowS
$cshowsPrec :: Int -> Loc -> ShowS
Show, ReadPrec [Loc]
ReadPrec Loc
Int -> ReadS Loc
ReadS [Loc]
(Int -> ReadS Loc)
-> ReadS [Loc] -> ReadPrec Loc -> ReadPrec [Loc] -> Read Loc
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Loc]
$creadListPrec :: ReadPrec [Loc]
readPrec :: ReadPrec Loc
$creadPrec :: ReadPrec Loc
readList :: ReadS [Loc]
$creadList :: ReadS [Loc]
readsPrec :: Int -> ReadS Loc
$creadsPrec :: Int -> ReadS Loc
Read)
data WithLoc a = WithLoc
{ WithLoc a -> Loc
loc :: !Loc,
WithLoc a -> a
value :: !a
}
deriving (WithLoc a -> WithLoc a -> Bool
(WithLoc a -> WithLoc a -> Bool)
-> (WithLoc a -> WithLoc a -> Bool) -> Eq (WithLoc a)
forall a. Eq a => WithLoc a -> WithLoc a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WithLoc a -> WithLoc a -> Bool
$c/= :: forall a. Eq a => WithLoc a -> WithLoc a -> Bool
== :: WithLoc a -> WithLoc a -> Bool
$c== :: forall a. Eq a => WithLoc a -> WithLoc a -> Bool
Eq, Eq (WithLoc a)
Eq (WithLoc a)
-> (WithLoc a -> WithLoc a -> Ordering)
-> (WithLoc a -> WithLoc a -> Bool)
-> (WithLoc a -> WithLoc a -> Bool)
-> (WithLoc a -> WithLoc a -> Bool)
-> (WithLoc a -> WithLoc a -> Bool)
-> (WithLoc a -> WithLoc a -> WithLoc a)
-> (WithLoc a -> WithLoc a -> WithLoc a)
-> Ord (WithLoc a)
WithLoc a -> WithLoc a -> Bool
WithLoc a -> WithLoc a -> Ordering
WithLoc a -> WithLoc a -> WithLoc a
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
forall a. Ord a => Eq (WithLoc a)
forall a. Ord a => WithLoc a -> WithLoc a -> Bool
forall a. Ord a => WithLoc a -> WithLoc a -> Ordering
forall a. Ord a => WithLoc a -> WithLoc a -> WithLoc a
min :: WithLoc a -> WithLoc a -> WithLoc a
$cmin :: forall a. Ord a => WithLoc a -> WithLoc a -> WithLoc a
max :: WithLoc a -> WithLoc a -> WithLoc a
$cmax :: forall a. Ord a => WithLoc a -> WithLoc a -> WithLoc a
>= :: WithLoc a -> WithLoc a -> Bool
$c>= :: forall a. Ord a => WithLoc a -> WithLoc a -> Bool
> :: WithLoc a -> WithLoc a -> Bool
$c> :: forall a. Ord a => WithLoc a -> WithLoc a -> Bool
<= :: WithLoc a -> WithLoc a -> Bool
$c<= :: forall a. Ord a => WithLoc a -> WithLoc a -> Bool
< :: WithLoc a -> WithLoc a -> Bool
$c< :: forall a. Ord a => WithLoc a -> WithLoc a -> Bool
compare :: WithLoc a -> WithLoc a -> Ordering
$ccompare :: forall a. Ord a => WithLoc a -> WithLoc a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (WithLoc a)
Ord, Int -> WithLoc a -> ShowS
[WithLoc a] -> ShowS
WithLoc a -> String
(Int -> WithLoc a -> ShowS)
-> (WithLoc a -> String)
-> ([WithLoc a] -> ShowS)
-> Show (WithLoc a)
forall a. Show a => Int -> WithLoc a -> ShowS
forall a. Show a => [WithLoc a] -> ShowS
forall a. Show a => WithLoc a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WithLoc a] -> ShowS
$cshowList :: forall a. Show a => [WithLoc a] -> ShowS
show :: WithLoc a -> String
$cshow :: forall a. Show a => WithLoc a -> String
showsPrec :: Int -> WithLoc a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> WithLoc a -> ShowS
Show, ReadPrec [WithLoc a]
ReadPrec (WithLoc a)
Int -> ReadS (WithLoc a)
ReadS [WithLoc a]
(Int -> ReadS (WithLoc a))
-> ReadS [WithLoc a]
-> ReadPrec (WithLoc a)
-> ReadPrec [WithLoc a]
-> Read (WithLoc a)
forall a. Read a => ReadPrec [WithLoc a]
forall a. Read a => ReadPrec (WithLoc a)
forall a. Read a => Int -> ReadS (WithLoc a)
forall a. Read a => ReadS [WithLoc a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WithLoc a]
$creadListPrec :: forall a. Read a => ReadPrec [WithLoc a]
readPrec :: ReadPrec (WithLoc a)
$creadPrec :: forall a. Read a => ReadPrec (WithLoc a)
readList :: ReadS [WithLoc a]
$creadList :: forall a. Read a => ReadS [WithLoc a]
readsPrec :: Int -> ReadS (WithLoc a)
$creadsPrec :: forall a. Read a => Int -> ReadS (WithLoc a)
Read, a -> WithLoc b -> WithLoc a
(a -> b) -> WithLoc a -> WithLoc b
(forall a b. (a -> b) -> WithLoc a -> WithLoc b)
-> (forall a b. a -> WithLoc b -> WithLoc a) -> Functor WithLoc
forall a b. a -> WithLoc b -> WithLoc a
forall a b. (a -> b) -> WithLoc a -> WithLoc b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> WithLoc b -> WithLoc a
$c<$ :: forall a b. a -> WithLoc b -> WithLoc a
fmap :: (a -> b) -> WithLoc a -> WithLoc b
$cfmap :: forall a b. (a -> b) -> WithLoc a -> WithLoc b
Functor)
data WithLoc' a = WithLoc'
{ WithLoc' a -> Maybe Loc
loc' :: !(Maybe Loc),
WithLoc' a -> a
value' :: !a
}
deriving (WithLoc' a -> WithLoc' a -> Bool
(WithLoc' a -> WithLoc' a -> Bool)
-> (WithLoc' a -> WithLoc' a -> Bool) -> Eq (WithLoc' a)
forall a. Eq a => WithLoc' a -> WithLoc' a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WithLoc' a -> WithLoc' a -> Bool
$c/= :: forall a. Eq a => WithLoc' a -> WithLoc' a -> Bool
== :: WithLoc' a -> WithLoc' a -> Bool
$c== :: forall a. Eq a => WithLoc' a -> WithLoc' a -> Bool
Eq, Eq (WithLoc' a)
Eq (WithLoc' a)
-> (WithLoc' a -> WithLoc' a -> Ordering)
-> (WithLoc' a -> WithLoc' a -> Bool)
-> (WithLoc' a -> WithLoc' a -> Bool)
-> (WithLoc' a -> WithLoc' a -> Bool)
-> (WithLoc' a -> WithLoc' a -> Bool)
-> (WithLoc' a -> WithLoc' a -> WithLoc' a)
-> (WithLoc' a -> WithLoc' a -> WithLoc' a)
-> Ord (WithLoc' a)
WithLoc' a -> WithLoc' a -> Bool
WithLoc' a -> WithLoc' a -> Ordering
WithLoc' a -> WithLoc' a -> WithLoc' a
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
forall a. Ord a => Eq (WithLoc' a)
forall a. Ord a => WithLoc' a -> WithLoc' a -> Bool
forall a. Ord a => WithLoc' a -> WithLoc' a -> Ordering
forall a. Ord a => WithLoc' a -> WithLoc' a -> WithLoc' a
min :: WithLoc' a -> WithLoc' a -> WithLoc' a
$cmin :: forall a. Ord a => WithLoc' a -> WithLoc' a -> WithLoc' a
max :: WithLoc' a -> WithLoc' a -> WithLoc' a
$cmax :: forall a. Ord a => WithLoc' a -> WithLoc' a -> WithLoc' a
>= :: WithLoc' a -> WithLoc' a -> Bool
$c>= :: forall a. Ord a => WithLoc' a -> WithLoc' a -> Bool
> :: WithLoc' a -> WithLoc' a -> Bool
$c> :: forall a. Ord a => WithLoc' a -> WithLoc' a -> Bool
<= :: WithLoc' a -> WithLoc' a -> Bool
$c<= :: forall a. Ord a => WithLoc' a -> WithLoc' a -> Bool
< :: WithLoc' a -> WithLoc' a -> Bool
$c< :: forall a. Ord a => WithLoc' a -> WithLoc' a -> Bool
compare :: WithLoc' a -> WithLoc' a -> Ordering
$ccompare :: forall a. Ord a => WithLoc' a -> WithLoc' a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (WithLoc' a)
Ord, Int -> WithLoc' a -> ShowS
[WithLoc' a] -> ShowS
WithLoc' a -> String
(Int -> WithLoc' a -> ShowS)
-> (WithLoc' a -> String)
-> ([WithLoc' a] -> ShowS)
-> Show (WithLoc' a)
forall a. Show a => Int -> WithLoc' a -> ShowS
forall a. Show a => [WithLoc' a] -> ShowS
forall a. Show a => WithLoc' a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WithLoc' a] -> ShowS
$cshowList :: forall a. Show a => [WithLoc' a] -> ShowS
show :: WithLoc' a -> String
$cshow :: forall a. Show a => WithLoc' a -> String
showsPrec :: Int -> WithLoc' a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> WithLoc' a -> ShowS
Show, ReadPrec [WithLoc' a]
ReadPrec (WithLoc' a)
Int -> ReadS (WithLoc' a)
ReadS [WithLoc' a]
(Int -> ReadS (WithLoc' a))
-> ReadS [WithLoc' a]
-> ReadPrec (WithLoc' a)
-> ReadPrec [WithLoc' a]
-> Read (WithLoc' a)
forall a. Read a => ReadPrec [WithLoc' a]
forall a. Read a => ReadPrec (WithLoc' a)
forall a. Read a => Int -> ReadS (WithLoc' a)
forall a. Read a => ReadS [WithLoc' a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [WithLoc' a]
$creadListPrec :: forall a. Read a => ReadPrec [WithLoc' a]
readPrec :: ReadPrec (WithLoc' a)
$creadPrec :: forall a. Read a => ReadPrec (WithLoc' a)
readList :: ReadS [WithLoc' a]
$creadList :: forall a. Read a => ReadS [WithLoc' a]
readsPrec :: Int -> ReadS (WithLoc' a)
$creadsPrec :: forall a. Read a => Int -> ReadS (WithLoc' a)
Read, a -> WithLoc' b -> WithLoc' a
(a -> b) -> WithLoc' a -> WithLoc' b
(forall a b. (a -> b) -> WithLoc' a -> WithLoc' b)
-> (forall a b. a -> WithLoc' b -> WithLoc' a) -> Functor WithLoc'
forall a b. a -> WithLoc' b -> WithLoc' a
forall a b. (a -> b) -> WithLoc' a -> WithLoc' b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> WithLoc' b -> WithLoc' a
$c<$ :: forall a b. a -> WithLoc' b -> WithLoc' a
fmap :: (a -> b) -> WithLoc' a -> WithLoc' b
$cfmap :: forall a b. (a -> b) -> WithLoc' a -> WithLoc' b
Functor)
instance IsString a => IsString (WithLoc' a) where
fromString :: String -> WithLoc' a
fromString = Maybe Loc -> a -> WithLoc' a
forall a. Maybe Loc -> a -> WithLoc' a
WithLoc' Maybe Loc
forall a. Maybe a
Nothing (a -> WithLoc' a) -> (String -> a) -> String -> WithLoc' a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> a
forall a. IsString a => String -> a
fromString
withoutLoc :: a -> WithLoc' a
withoutLoc :: a -> WithLoc' a
withoutLoc = Maybe Loc -> a -> WithLoc' a
forall a. Maybe Loc -> a -> WithLoc' a
WithLoc' Maybe Loc
forall a. Maybe a
Nothing