{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}

-- | This modules provides data types that describe line-column locations
--   within a text.
module Text.Loc
  ( HasLoc(..)
  , LocLens(..)
  , Span(..)
  , SpannedLoc(..)
  , locStart
  , locEnd
  , spanOf
  , startOf
  , endOf
  , SpannedLens(..)
  , lStart
  , lEnd
  , lSpanOf
  , lEndOf
  , lStartOf
  , Located(..)
  , LineCol(..)
  , nextLine
  , nextCol
  , LineColLoc(..)
  , locLine
  , locCol
  , lineColOf
  , lineOf
  , colOf
  , LineColLens(..)
  , lLine
  , lCol
  , lLineColOf
  , lLineOf
  , lColOf
  , SrcLoc(..)
  , srcOf
  , SrcLens(..)
  , lSrcOf
  , InSrc(..)
  , FromLoc(..)
  , fromOf
  , FromLens(..)
  , lFromOf
  , Nested(..)
  ) where

import GHC.Generics (Generic)
import Data.Typeable (Typeable)
import Data.Foldable (Foldable)
import Data.Traversable (Traversable)
import Data.Hashable (Hashable(..))
import Data.Word (Word)

-- | Values with associated source locations.
class HasLoc α where
  type LocOf α
  locOf  α  LocOf α

-- | Values with editable associated source locations.
class HasLoc α  LocLens α where
  lLocOf  Functor f  (LocOf α  f (LocOf α))  α  f α

-- | A region of text between two locations.
data Span l = Span l l
              deriving (Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall l x. Rep (Span l) x -> Span l
forall l x. Span l -> Rep (Span l) x
$cto :: forall l x. Rep (Span l) x -> Span l
$cfrom :: forall l x. Span l -> Rep (Span l) x
Generic, Int -> Span l -> ShowS
forall l. Show l => Int -> Span l -> ShowS
forall l. Show l => [Span l] -> ShowS
forall l. Show l => Span l -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Span l] -> ShowS
$cshowList :: forall l. Show l => [Span l] -> ShowS
show :: Span l -> String
$cshow :: forall l. Show l => Span l -> String
showsPrec :: Int -> Span l -> ShowS
$cshowsPrec :: forall l. Show l => Int -> Span l -> ShowS
Show, ReadPrec [Span l]
ReadPrec (Span l)
ReadS [Span l]
forall l. Read l => ReadPrec [Span l]
forall l. Read l => ReadPrec (Span l)
forall l. Read l => Int -> ReadS (Span l)
forall l. Read l => ReadS [Span l]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Span l]
$creadListPrec :: forall l. Read l => ReadPrec [Span l]
readPrec :: ReadPrec (Span l)
$creadPrec :: forall l. Read l => ReadPrec (Span l)
readList :: ReadS [Span l]
$creadList :: forall l. Read l => ReadS [Span l]
readsPrec :: Int -> ReadS (Span l)
$creadsPrec :: forall l. Read l => Int -> ReadS (Span l)
Read, Span l -> Span l -> Bool
forall l. Eq l => Span l -> Span l -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Span l -> Span l -> Bool
$c/= :: forall l. Eq l => Span l -> Span l -> Bool
== :: Span l -> Span l -> Bool
$c== :: forall l. Eq l => Span l -> Span l -> Bool
Eq, Span l -> Span l -> Bool
Span l -> Span l -> Ordering
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 {l}. Ord l => Eq (Span l)
forall l. Ord l => Span l -> Span l -> Bool
forall l. Ord l => Span l -> Span l -> Ordering
forall l. Ord l => Span l -> Span l -> Span l
min :: Span l -> Span l -> Span l
$cmin :: forall l. Ord l => Span l -> Span l -> Span l
max :: Span l -> Span l -> Span l
$cmax :: forall l. Ord l => Span l -> Span l -> Span l
>= :: Span l -> Span l -> Bool
$c>= :: forall l. Ord l => Span l -> Span l -> Bool
> :: Span l -> Span l -> Bool
$c> :: forall l. Ord l => Span l -> Span l -> Bool
<= :: Span l -> Span l -> Bool
$c<= :: forall l. Ord l => Span l -> Span l -> Bool
< :: Span l -> Span l -> Bool
$c< :: forall l. Ord l => Span l -> Span l -> Bool
compare :: Span l -> Span l -> Ordering
$ccompare :: forall l. Ord l => Span l -> Span l -> Ordering
Ord,
                        forall a b. a -> Span b -> Span a
forall a b. (a -> b) -> Span a -> Span b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Span b -> Span a
$c<$ :: forall a b. a -> Span b -> Span a
fmap :: forall a b. (a -> b) -> Span a -> Span b
$cfmap :: forall a b. (a -> b) -> Span a -> Span b
Functor, forall a. Eq a => a -> Span a -> Bool
forall a. Num a => Span a -> a
forall a. Ord a => Span a -> a
forall m. Monoid m => Span m -> m
forall a. Span a -> Bool
forall a. Span a -> Int
forall a. Span a -> [a]
forall a. (a -> a -> a) -> Span a -> a
forall m a. Monoid m => (a -> m) -> Span a -> m
forall b a. (b -> a -> b) -> b -> Span a -> b
forall a b. (a -> b -> b) -> b -> Span a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Span a -> a
$cproduct :: forall a. Num a => Span a -> a
sum :: forall a. Num a => Span a -> a
$csum :: forall a. Num a => Span a -> a
minimum :: forall a. Ord a => Span a -> a
$cminimum :: forall a. Ord a => Span a -> a
maximum :: forall a. Ord a => Span a -> a
$cmaximum :: forall a. Ord a => Span a -> a
elem :: forall a. Eq a => a -> Span a -> Bool
$celem :: forall a. Eq a => a -> Span a -> Bool
length :: forall a. Span a -> Int
$clength :: forall a. Span a -> Int
null :: forall a. Span a -> Bool
$cnull :: forall a. Span a -> Bool
toList :: forall a. Span a -> [a]
$ctoList :: forall a. Span a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Span a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Span a -> a
foldr1 :: forall a. (a -> a -> a) -> Span a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Span a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Span a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Span a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Span a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Span a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Span a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Span a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Span a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Span a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Span a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Span a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Span a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Span a -> m
fold :: forall m. Monoid m => Span m -> m
$cfold :: forall m. Monoid m => Span m -> m
Foldable, Functor Span
Foldable Span
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Span (m a) -> m (Span a)
forall (f :: * -> *) a. Applicative f => Span (f a) -> f (Span a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Span a -> m (Span b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Span a -> f (Span b)
sequence :: forall (m :: * -> *) a. Monad m => Span (m a) -> m (Span a)
$csequence :: forall (m :: * -> *) a. Monad m => Span (m a) -> m (Span a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Span a -> m (Span b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Span a -> m (Span b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Span (f a) -> f (Span a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Span (f a) -> f (Span a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Span a -> f (Span b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Span a -> f (Span b)
Traversable)

instance Hashable l  Hashable (Span l) where
  hashWithSalt :: Int -> Span l -> Int
hashWithSalt Int
salt (Span l
s l
e) = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (l
s, l
e)
  {-# INLINE hashWithSalt #-}

instance HasLoc (Span l) where
  type LocOf (Span l) = Span l
  locOf :: Span l -> LocOf (Span l)
locOf = forall a. a -> a
id
  {-# INLINE locOf #-}

instance LocLens (Span l) where
  lLocOf :: forall (f :: * -> *).
Functor f =>
(LocOf (Span l) -> f (LocOf (Span l))) -> Span l -> f (Span l)
lLocOf = forall a. a -> a
id
  {-# INLINE lLocOf #-}

-- | Spanned locations.
class SpannedLoc l where
  type SpanLoc l
  locSpan  l  Span (SpanLoc l)

instance SpannedLoc (Span l) where
  type SpanLoc (Span l) = l
  locSpan :: Span l -> Span (SpanLoc (Span l))
locSpan = forall a. a -> a
id
  {-# INLINE locSpan #-}

-- | The start of a span.
locStart  SpannedLoc l  l  SpanLoc l
locStart :: forall l. SpannedLoc l => l -> SpanLoc l
locStart l
l = let Span SpanLoc l
s SpanLoc l
_ = forall l. SpannedLoc l => l -> Span (SpanLoc l)
locSpan l
l in SpanLoc l
s
{-# INLINE locStart #-}

-- | The end of a span.
locEnd  SpannedLoc l  l  SpanLoc l
locEnd :: forall l. SpannedLoc l => l -> SpanLoc l
locEnd l
l = let Span SpanLoc l
_ SpanLoc l
e = forall l. SpannedLoc l => l -> Span (SpanLoc l)
locSpan l
l in SpanLoc l
e
{-# INLINE locEnd #-}

-- | The span of the associated location.
spanOf  (HasLoc α, SpannedLoc (LocOf α))  α  Span (SpanLoc (LocOf α))
spanOf :: forall α.
(HasLoc α, SpannedLoc (LocOf α)) =>
α -> Span (SpanLoc (LocOf α))
spanOf = forall l. SpannedLoc l => l -> Span (SpanLoc l)
locSpan forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. HasLoc α => α -> LocOf α
locOf
{-# INLINE spanOf #-}

-- | The start of the associated location.
startOf  (HasLoc α, SpannedLoc (LocOf α))  α  SpanLoc (LocOf α)
startOf :: forall α.
(HasLoc α, SpannedLoc (LocOf α)) =>
α -> SpanLoc (LocOf α)
startOf = forall l. SpannedLoc l => l -> SpanLoc l
locStart forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. HasLoc α => α -> LocOf α
locOf
{-# INLINE startOf #-}

-- | The end of the associated location.
endOf  (HasLoc α, SpannedLoc (LocOf α))  α  SpanLoc (LocOf α)
endOf :: forall α.
(HasLoc α, SpannedLoc (LocOf α)) =>
α -> SpanLoc (LocOf α)
endOf = forall l. SpannedLoc l => l -> SpanLoc l
locEnd forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. HasLoc α => α -> LocOf α
locOf
{-# INLINE endOf #-}

-- | Editable spanned locations.
class SpannedLoc l  SpannedLens l where
  lSpan  Functor f  (Span (SpanLoc l)  f (Span (SpanLoc l)))  l  f l

instance SpannedLens (Span l) where
  lSpan :: forall (f :: * -> *).
Functor f =>
(Span (SpanLoc (Span l)) -> f (Span (SpanLoc (Span l))))
-> Span l -> f (Span l)
lSpan = forall a. a -> a
id
  {-# INLINE lSpan #-}

-- | Provides access to the start of a location.
lStart  (Functor f, SpannedLens l)  (SpanLoc l  f (SpanLoc l))  l  f l
lStart :: forall (f :: * -> *) l.
(Functor f, SpannedLens l) =>
(SpanLoc l -> f (SpanLoc l)) -> l -> f l
lStart SpanLoc l -> f (SpanLoc l)
f = forall l (f :: * -> *).
(SpannedLens l, Functor f) =>
(Span (SpanLoc l) -> f (Span (SpanLoc l))) -> l -> f l
lSpan (\(Span SpanLoc l
s SpanLoc l
e)  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall l. l -> l -> Span l
Span SpanLoc l
e) (SpanLoc l -> f (SpanLoc l)
f SpanLoc l
s))
{-# INLINE lStart #-}

-- | Provides access to the end of a location.
lEnd  (Functor f, SpannedLens l)  (SpanLoc l  f (SpanLoc l))  l  f l
lEnd :: forall (f :: * -> *) l.
(Functor f, SpannedLens l) =>
(SpanLoc l -> f (SpanLoc l)) -> l -> f l
lEnd SpanLoc l -> f (SpanLoc l)
f = forall l (f :: * -> *).
(SpannedLens l, Functor f) =>
(Span (SpanLoc l) -> f (Span (SpanLoc l))) -> l -> f l
lSpan (\(Span SpanLoc l
s SpanLoc l
e)  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall l. l -> l -> Span l
Span SpanLoc l
s) (SpanLoc l -> f (SpanLoc l)
f SpanLoc l
e))
{-# INLINE lEnd #-}

-- | Provides access to the span of the associated location.
lSpanOf  (Functor f, LocLens α, SpannedLens (LocOf α))
         (Span (SpanLoc (LocOf α))  f (Span (SpanLoc (LocOf α))))  α  f α
lSpanOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, SpannedLens (LocOf α)) =>
(Span (SpanLoc (LocOf α)) -> f (Span (SpanLoc (LocOf α))))
-> α -> f α
lSpanOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l (f :: * -> *).
(SpannedLens l, Functor f) =>
(Span (SpanLoc l) -> f (Span (SpanLoc l))) -> l -> f l
lSpan
{-# INLINE lSpanOf #-}

-- | Provides access to the start of the associated location.
lStartOf  (Functor f, LocLens α, SpannedLens (LocOf α))
          (SpanLoc (LocOf α)  f (SpanLoc (LocOf α)))  α  f α
lStartOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, SpannedLens (LocOf α)) =>
(SpanLoc (LocOf α) -> f (SpanLoc (LocOf α))) -> α -> f α
lStartOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) l.
(Functor f, SpannedLens l) =>
(SpanLoc l -> f (SpanLoc l)) -> l -> f l
lStart
{-# INLINE lStartOf #-}

-- | Provides access to the end of the associated location.
lEndOf  (Functor f, LocLens α, SpannedLens (LocOf α))
        (SpanLoc (LocOf α)  f (SpanLoc (LocOf α)))  α  f α
lEndOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, SpannedLens (LocOf α)) =>
(SpanLoc (LocOf α) -> f (SpanLoc (LocOf α))) -> α -> f α
lEndOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) l.
(Functor f, SpannedLens l) =>
(SpanLoc l -> f (SpanLoc l)) -> l -> f l
lEnd
{-# INLINE lEndOf #-}

-- | A simple way to attach location to a value.
data Located l α = Located { forall l α. Located l α -> l
locAt   l
                           , forall l α. Located l α -> α
locVal  α }
                   deriving (Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall l α x. Rep (Located l α) x -> Located l α
forall l α x. Located l α -> Rep (Located l α) x
$cto :: forall l α x. Rep (Located l α) x -> Located l α
$cfrom :: forall l α x. Located l α -> Rep (Located l α) x
Generic, Int -> Located l α -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall l α. (Show l, Show α) => Int -> Located l α -> ShowS
forall l α. (Show l, Show α) => [Located l α] -> ShowS
forall l α. (Show l, Show α) => Located l α -> String
showList :: [Located l α] -> ShowS
$cshowList :: forall l α. (Show l, Show α) => [Located l α] -> ShowS
show :: Located l α -> String
$cshow :: forall l α. (Show l, Show α) => Located l α -> String
showsPrec :: Int -> Located l α -> ShowS
$cshowsPrec :: forall l α. (Show l, Show α) => Int -> Located l α -> ShowS
Show, ReadPrec [Located l α]
ReadPrec (Located l α)
ReadS [Located l α]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall l α. (Read l, Read α) => ReadPrec [Located l α]
forall l α. (Read l, Read α) => ReadPrec (Located l α)
forall l α. (Read l, Read α) => Int -> ReadS (Located l α)
forall l α. (Read l, Read α) => ReadS [Located l α]
readListPrec :: ReadPrec [Located l α]
$creadListPrec :: forall l α. (Read l, Read α) => ReadPrec [Located l α]
readPrec :: ReadPrec (Located l α)
$creadPrec :: forall l α. (Read l, Read α) => ReadPrec (Located l α)
readList :: ReadS [Located l α]
$creadList :: forall l α. (Read l, Read α) => ReadS [Located l α]
readsPrec :: Int -> ReadS (Located l α)
$creadsPrec :: forall l α. (Read l, Read α) => Int -> ReadS (Located l α)
Read, Located l α -> Located l α -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall l α. (Eq l, Eq α) => Located l α -> Located l α -> Bool
/= :: Located l α -> Located l α -> Bool
$c/= :: forall l α. (Eq l, Eq α) => Located l α -> Located l α -> Bool
== :: Located l α -> Located l α -> Bool
$c== :: forall l α. (Eq l, Eq α) => Located l α -> Located l α -> Bool
Eq,
                             forall a b. a -> Located l b -> Located l a
forall a b. (a -> b) -> Located l a -> Located l b
forall l a b. a -> Located l b -> Located l a
forall l a b. (a -> b) -> Located l a -> Located l b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Located l b -> Located l a
$c<$ :: forall l a b. a -> Located l b -> Located l a
fmap :: forall a b. (a -> b) -> Located l a -> Located l b
$cfmap :: forall l a b. (a -> b) -> Located l a -> Located l b
Functor, forall a. Located l a -> Bool
forall l a. Eq a => a -> Located l a -> Bool
forall l a. Num a => Located l a -> a
forall l a. Ord a => Located l a -> a
forall m a. Monoid m => (a -> m) -> Located l a -> m
forall l m. Monoid m => Located l m -> m
forall l a. Located l a -> Bool
forall l a. Located l a -> Int
forall l a. Located l a -> [a]
forall a b. (a -> b -> b) -> b -> Located l a -> b
forall l a. (a -> a -> a) -> Located l a -> a
forall l m a. Monoid m => (a -> m) -> Located l a -> m
forall l b a. (b -> a -> b) -> b -> Located l a -> b
forall l a b. (a -> b -> b) -> b -> Located l a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Located l a -> a
$cproduct :: forall l a. Num a => Located l a -> a
sum :: forall a. Num a => Located l a -> a
$csum :: forall l a. Num a => Located l a -> a
minimum :: forall a. Ord a => Located l a -> a
$cminimum :: forall l a. Ord a => Located l a -> a
maximum :: forall a. Ord a => Located l a -> a
$cmaximum :: forall l a. Ord a => Located l a -> a
elem :: forall a. Eq a => a -> Located l a -> Bool
$celem :: forall l a. Eq a => a -> Located l a -> Bool
length :: forall a. Located l a -> Int
$clength :: forall l a. Located l a -> Int
null :: forall a. Located l a -> Bool
$cnull :: forall l a. Located l a -> Bool
toList :: forall a. Located l a -> [a]
$ctoList :: forall l a. Located l a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Located l a -> a
$cfoldl1 :: forall l a. (a -> a -> a) -> Located l a -> a
foldr1 :: forall a. (a -> a -> a) -> Located l a -> a
$cfoldr1 :: forall l a. (a -> a -> a) -> Located l a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Located l a -> b
$cfoldl' :: forall l b a. (b -> a -> b) -> b -> Located l a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Located l a -> b
$cfoldl :: forall l b a. (b -> a -> b) -> b -> Located l a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Located l a -> b
$cfoldr' :: forall l a b. (a -> b -> b) -> b -> Located l a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Located l a -> b
$cfoldr :: forall l a b. (a -> b -> b) -> b -> Located l a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Located l a -> m
$cfoldMap' :: forall l m a. Monoid m => (a -> m) -> Located l a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Located l a -> m
$cfoldMap :: forall l m a. Monoid m => (a -> m) -> Located l a -> m
fold :: forall m. Monoid m => Located l m -> m
$cfold :: forall l m. Monoid m => Located l m -> m
Foldable, forall l. Functor (Located l)
forall l. Foldable (Located l)
forall l (m :: * -> *) a.
Monad m =>
Located l (m a) -> m (Located l a)
forall l (f :: * -> *) a.
Applicative f =>
Located l (f a) -> f (Located l a)
forall l (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Located l a -> m (Located l b)
forall l (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Located l a -> f (Located l b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Located l a -> f (Located l b)
sequence :: forall (m :: * -> *) a.
Monad m =>
Located l (m a) -> m (Located l a)
$csequence :: forall l (m :: * -> *) a.
Monad m =>
Located l (m a) -> m (Located l a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Located l a -> m (Located l b)
$cmapM :: forall l (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Located l a -> m (Located l b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Located l (f a) -> f (Located l a)
$csequenceA :: forall l (f :: * -> *) a.
Applicative f =>
Located l (f a) -> f (Located l a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Located l a -> f (Located l b)
$ctraverse :: forall l (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Located l a -> f (Located l b)
Traversable)

instance (Hashable l, Hashable α)  Hashable (Located l α) where
  hashWithSalt :: Int -> Located l α -> Int
hashWithSalt Int
salt (Located l
l α
a) = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (l
l, α
a)
  {-# INLINE hashWithSalt #-}

instance HasLoc (Located l α) where
  type LocOf (Located l α) = l
  locOf :: Located l α -> LocOf (Located l α)
locOf = forall l α. Located l α -> l
locAt
  {-# INLINE locOf #-}

instance LocLens (Located l α) where
  lLocOf :: forall (f :: * -> *).
Functor f =>
(LocOf (Located l α) -> f (LocOf (Located l α)))
-> Located l α -> f (Located l α)
lLocOf LocOf (Located l α) -> f (LocOf (Located l α))
f (Located l
l α
a) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall l α. l -> α -> Located l α
Located α
a) (LocOf (Located l α) -> f (LocOf (Located l α))
f l
l)
  {-# INLINE lLocOf #-}

-- | Line-column location within a text.
data LineCol = LineCol {-# UNPACK #-} !Word {-# UNPACK #-} !Word
               deriving (Typeable, forall x. Rep LineCol x -> LineCol
forall x. LineCol -> Rep LineCol x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LineCol x -> LineCol
$cfrom :: forall x. LineCol -> Rep LineCol x
Generic, Int -> LineCol -> ShowS
[LineCol] -> ShowS
LineCol -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LineCol] -> ShowS
$cshowList :: [LineCol] -> ShowS
show :: LineCol -> String
$cshow :: LineCol -> String
showsPrec :: Int -> LineCol -> ShowS
$cshowsPrec :: Int -> LineCol -> ShowS
Show, ReadPrec [LineCol]
ReadPrec LineCol
Int -> ReadS LineCol
ReadS [LineCol]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [LineCol]
$creadListPrec :: ReadPrec [LineCol]
readPrec :: ReadPrec LineCol
$creadPrec :: ReadPrec LineCol
readList :: ReadS [LineCol]
$creadList :: ReadS [LineCol]
readsPrec :: Int -> ReadS LineCol
$creadsPrec :: Int -> ReadS LineCol
Read, LineCol -> LineCol -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LineCol -> LineCol -> Bool
$c/= :: LineCol -> LineCol -> Bool
== :: LineCol -> LineCol -> Bool
$c== :: LineCol -> LineCol -> Bool
Eq, Eq LineCol
LineCol -> LineCol -> Bool
LineCol -> LineCol -> Ordering
LineCol -> LineCol -> LineCol
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 :: LineCol -> LineCol -> LineCol
$cmin :: LineCol -> LineCol -> LineCol
max :: LineCol -> LineCol -> LineCol
$cmax :: LineCol -> LineCol -> LineCol
>= :: LineCol -> LineCol -> Bool
$c>= :: LineCol -> LineCol -> Bool
> :: LineCol -> LineCol -> Bool
$c> :: LineCol -> LineCol -> Bool
<= :: LineCol -> LineCol -> Bool
$c<= :: LineCol -> LineCol -> Bool
< :: LineCol -> LineCol -> Bool
$c< :: LineCol -> LineCol -> Bool
compare :: LineCol -> LineCol -> Ordering
$ccompare :: LineCol -> LineCol -> Ordering
Ord, LineCol
forall a. a -> a -> Bounded a
maxBound :: LineCol
$cmaxBound :: LineCol
minBound :: LineCol
$cminBound :: LineCol
Bounded)

instance Hashable LineCol where
  hashWithSalt :: Int -> LineCol -> Int
hashWithSalt Int
salt (LineCol Word
l Word
c) = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (Word
l, Word
c)
  {-# INLINE hashWithSalt #-}

instance HasLoc LineCol where
  type LocOf LineCol = LineCol
  locOf :: LineCol -> LocOf LineCol
locOf = forall a. a -> a
id
  {-# INLINE locOf #-}

-- | The location of the start of the next line.
nextLine  LineCol  LineCol
nextLine :: LineCol -> LineCol
nextLine (LineCol Word
l Word
_) = Word -> Word -> LineCol
LineCol (Word
l forall a. Num a => a -> a -> a
+ Word
1) Word
1
{-# INLINE nextLine #-}

-- | The location of the next column.
nextCol  LineCol  LineCol
nextCol :: LineCol -> LineCol
nextCol (LineCol Word
l Word
c) = Word -> Word -> LineCol
LineCol Word
l (Word
c forall a. Num a => a -> a -> a
+ Word
1)
{-# INLINE nextCol #-}

-- | Locations with line and column numbers.
class LineColLoc l where
  locLineCol  l  LineCol

instance LineColLoc LineCol where
  locLineCol :: LineCol -> LineCol
locLineCol = forall a. a -> a
id
  {-# INLINE locLineCol #-}

-- | The line number of a location.
locLine  LineColLoc l  l  Word
locLine :: forall l. LineColLoc l => l -> Word
locLine l
l = let LineCol Word
ln Word
_ = forall l. LineColLoc l => l -> LineCol
locLineCol l
l in Word
ln
{-# INLINE locLine #-}

-- | The column number of a location.
locCol  LineColLoc l  l  Word
locCol :: forall l. LineColLoc l => l -> Word
locCol l
l = let LineCol Word
_ Word
c = forall l. LineColLoc l => l -> LineCol
locLineCol l
l in Word
c
{-# INLINE locCol #-}

-- | The line-column numbers of the associated location.
lineColOf  (HasLoc α, LineColLoc (LocOf α))  α  LineCol
lineColOf :: forall α. (HasLoc α, LineColLoc (LocOf α)) => α -> LineCol
lineColOf = forall l. LineColLoc l => l -> LineCol
locLineCol forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. HasLoc α => α -> LocOf α
locOf
{-# INLINE lineColOf #-}

-- | The line number of the associated location.
lineOf  (HasLoc α, LineColLoc (LocOf α))  α  Word
lineOf :: forall α. (HasLoc α, LineColLoc (LocOf α)) => α -> Word
lineOf = forall l. LineColLoc l => l -> Word
locLine forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. (HasLoc α, LineColLoc (LocOf α)) => α -> LineCol
lineColOf
{-# INLINE lineOf #-}

-- | The column number of the associated location.
colOf  (HasLoc α, LineColLoc (LocOf α))  α  Word
colOf :: forall α. (HasLoc α, LineColLoc (LocOf α)) => α -> Word
colOf = forall l. LineColLoc l => l -> Word
locCol forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. (HasLoc α, LineColLoc (LocOf α)) => α -> LineCol
lineColOf
{-# INLINE colOf #-}

-- | Locations with editable line and column numbers.
class LineColLens l where
  lLineCol  Functor f  (LineCol  f LineCol)  l  f l

instance LineColLens LineCol where
  lLineCol :: forall (f :: * -> *).
Functor f =>
(LineCol -> f LineCol) -> LineCol -> f LineCol
lLineCol = forall a. a -> a
id
  {-# INLINE lLineCol #-}

-- | Provides access to the line number of a location.
lLine  (Functor f, LineColLens l)  (Word  f Word)  l  f l
lLine :: forall (f :: * -> *) l.
(Functor f, LineColLens l) =>
(Word -> f Word) -> l -> f l
lLine Word -> f Word
f = forall l (f :: * -> *).
(LineColLens l, Functor f) =>
(LineCol -> f LineCol) -> l -> f l
lLineCol (\(LineCol Word
l Word
c)  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip Word -> Word -> LineCol
LineCol Word
c) (Word -> f Word
f Word
l))
{-# INLINE lLine #-}

-- | Provides access to the column number of a location.
lCol  (Functor f, LineColLens l)  (Word  f Word)  l  f l
lCol :: forall (f :: * -> *) l.
(Functor f, LineColLens l) =>
(Word -> f Word) -> l -> f l
lCol Word -> f Word
f = forall l (f :: * -> *).
(LineColLens l, Functor f) =>
(LineCol -> f LineCol) -> l -> f l
lLineCol (\(LineCol Word
l Word
c)  forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Word -> Word -> LineCol
LineCol Word
l) (Word -> f Word
f Word
c))
{-# INLINE lCol #-}

-- | Provides access to the line-column numbers of the associated location.
lLineColOf  (Functor f, LocLens α, LineColLens (LocOf α))
            (LineCol  f LineCol)  α  f α
lLineColOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, LineColLens (LocOf α)) =>
(LineCol -> f LineCol) -> α -> f α
lLineColOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l (f :: * -> *).
(LineColLens l, Functor f) =>
(LineCol -> f LineCol) -> l -> f l
lLineCol
{-# INLINE lLineColOf #-}

-- | Provides access to the line number of the associated location.
lLineOf  (Functor f, LocLens α, LineColLens (LocOf α))
         (Word  f Word)  α  f α
lLineOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, LineColLens (LocOf α)) =>
(Word -> f Word) -> α -> f α
lLineOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) l.
(Functor f, LineColLens l) =>
(Word -> f Word) -> l -> f l
lLine
{-# INLINE lLineOf #-}

-- | Provides access to the column number of the associated location.
lColOf  (Functor f, LocLens α, LineColLens (LocOf α))
        (Word  f Word)  α  f α
lColOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, LineColLens (LocOf α)) =>
(Word -> f Word) -> α -> f α
lColOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) l.
(Functor f, LineColLens l) =>
(Word -> f Word) -> l -> f l
lCol
{-# INLINE lColOf #-}

-- | Locations with a source (e.g. file name).
class SrcLoc l where
  type LocSrc l
  locSrc  l  LocSrc l

-- | The source of the associated location.
srcOf  (HasLoc α, SrcLoc (LocOf α))  α  LocSrc (LocOf α)
srcOf :: forall α. (HasLoc α, SrcLoc (LocOf α)) => α -> LocSrc (LocOf α)
srcOf = forall l. SrcLoc l => l -> LocSrc l
locSrc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. HasLoc α => α -> LocOf α
locOf
{-# INLINE srcOf #-}

-- | Locations with editable source (e.g. file name).
class SrcLoc l  SrcLens l where
  lSrc  Functor f  (LocSrc l  f (LocSrc l))  l  f l

-- | Provides access to the source of the associated location.
lSrcOf  (Functor f, LocLens α, SrcLens (LocOf α))
        (LocSrc (LocOf α)  f (LocSrc (LocOf α)))  α  f α
lSrcOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, SrcLens (LocOf α)) =>
(LocSrc (LocOf α) -> f (LocSrc (LocOf α))) -> α -> f α
lSrcOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l (f :: * -> *).
(SrcLens l, Functor f) =>
(LocSrc l -> f (LocSrc l)) -> l -> f l
lSrc
{-# INLINE lSrcOf #-}

-- | A simple way to add source to a location.
data InSrc s l = InSrc { forall s l. InSrc s l -> s
srcSrc  s
                       , forall s l. InSrc s l -> l
srcLoc  l }
                 deriving (Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall s l x. Rep (InSrc s l) x -> InSrc s l
forall s l x. InSrc s l -> Rep (InSrc s l) x
$cto :: forall s l x. Rep (InSrc s l) x -> InSrc s l
$cfrom :: forall s l x. InSrc s l -> Rep (InSrc s l) x
Generic, Int -> InSrc s l -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall s l. (Show s, Show l) => Int -> InSrc s l -> ShowS
forall s l. (Show s, Show l) => [InSrc s l] -> ShowS
forall s l. (Show s, Show l) => InSrc s l -> String
showList :: [InSrc s l] -> ShowS
$cshowList :: forall s l. (Show s, Show l) => [InSrc s l] -> ShowS
show :: InSrc s l -> String
$cshow :: forall s l. (Show s, Show l) => InSrc s l -> String
showsPrec :: Int -> InSrc s l -> ShowS
$cshowsPrec :: forall s l. (Show s, Show l) => Int -> InSrc s l -> ShowS
Show, ReadPrec [InSrc s l]
ReadPrec (InSrc s l)
ReadS [InSrc s l]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall s l. (Read s, Read l) => ReadPrec [InSrc s l]
forall s l. (Read s, Read l) => ReadPrec (InSrc s l)
forall s l. (Read s, Read l) => Int -> ReadS (InSrc s l)
forall s l. (Read s, Read l) => ReadS [InSrc s l]
readListPrec :: ReadPrec [InSrc s l]
$creadListPrec :: forall s l. (Read s, Read l) => ReadPrec [InSrc s l]
readPrec :: ReadPrec (InSrc s l)
$creadPrec :: forall s l. (Read s, Read l) => ReadPrec (InSrc s l)
readList :: ReadS [InSrc s l]
$creadList :: forall s l. (Read s, Read l) => ReadS [InSrc s l]
readsPrec :: Int -> ReadS (InSrc s l)
$creadsPrec :: forall s l. (Read s, Read l) => Int -> ReadS (InSrc s l)
Read, InSrc s l -> InSrc s l -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall s l. (Eq s, Eq l) => InSrc s l -> InSrc s l -> Bool
/= :: InSrc s l -> InSrc s l -> Bool
$c/= :: forall s l. (Eq s, Eq l) => InSrc s l -> InSrc s l -> Bool
== :: InSrc s l -> InSrc s l -> Bool
$c== :: forall s l. (Eq s, Eq l) => InSrc s l -> InSrc s l -> Bool
Eq, InSrc s l -> InSrc s l -> Bool
InSrc s l -> InSrc s l -> Ordering
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 {s} {l}. (Ord s, Ord l) => Eq (InSrc s l)
forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> Bool
forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> Ordering
forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> InSrc s l
min :: InSrc s l -> InSrc s l -> InSrc s l
$cmin :: forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> InSrc s l
max :: InSrc s l -> InSrc s l -> InSrc s l
$cmax :: forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> InSrc s l
>= :: InSrc s l -> InSrc s l -> Bool
$c>= :: forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> Bool
> :: InSrc s l -> InSrc s l -> Bool
$c> :: forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> Bool
<= :: InSrc s l -> InSrc s l -> Bool
$c<= :: forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> Bool
< :: InSrc s l -> InSrc s l -> Bool
$c< :: forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> Bool
compare :: InSrc s l -> InSrc s l -> Ordering
$ccompare :: forall s l. (Ord s, Ord l) => InSrc s l -> InSrc s l -> Ordering
Ord)

instance (Hashable s, Hashable l)  Hashable (InSrc s l) where
  hashWithSalt :: Int -> InSrc s l -> Int
hashWithSalt Int
salt (InSrc s
s l
l) = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (s
s, l
l)
  {-# INLINE hashWithSalt #-}

instance HasLoc (InSrc s l) where
  type LocOf (InSrc s l) = InSrc s l
  locOf :: InSrc s l -> LocOf (InSrc s l)
locOf = forall a. a -> a
id
  {-# INLINE locOf #-}

instance LocLens (InSrc s l) where
  lLocOf :: forall (f :: * -> *).
Functor f =>
(LocOf (InSrc s l) -> f (LocOf (InSrc s l)))
-> InSrc s l -> f (InSrc s l)
lLocOf = forall a. a -> a
id
  {-# INLINE lLocOf #-}

instance SpannedLoc l  SpannedLoc (InSrc s l) where
  type SpanLoc (InSrc s l) = InSrc s (SpanLoc l)
  locSpan :: InSrc s l -> Span (SpanLoc (InSrc s l))
locSpan (InSrc s
s l
l) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s l. s -> l -> InSrc s l
InSrc s
s) (forall l. SpannedLoc l => l -> Span (SpanLoc l)
locSpan l
l)
  {-# INLINE locSpan #-}

instance SpannedLens l  SpannedLens (InSrc s l) where
  lSpan :: forall (f :: * -> *).
Functor f =>
(Span (SpanLoc (InSrc s l)) -> f (Span (SpanLoc (InSrc s l))))
-> InSrc s l -> f (InSrc s l)
lSpan Span (SpanLoc (InSrc s l)) -> f (Span (SpanLoc (InSrc s l)))
f (InSrc s
s l
l) =
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s l. s -> l -> InSrc s l
InSrc s
s) (forall l (f :: * -> *).
(SpannedLens l, Functor f) =>
(Span (SpanLoc l) -> f (Span (SpanLoc l))) -> l -> f l
lSpan (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall s l. InSrc s l -> l
srcLoc) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Span (SpanLoc (InSrc s l)) -> f (Span (SpanLoc (InSrc s l)))
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s l. s -> l -> InSrc s l
InSrc s
s)) l
l)
  {-# INLINE lSpan #-}

instance LineColLoc l  LineColLoc (InSrc s l) where
  locLineCol :: InSrc s l -> LineCol
locLineCol = forall l. LineColLoc l => l -> LineCol
locLineCol forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s l. InSrc s l -> l
srcLoc
  {-# INLINE locLineCol #-}

instance LineColLens l  LineColLens (InSrc s l) where
  lLineCol :: forall (f :: * -> *).
Functor f =>
(LineCol -> f LineCol) -> InSrc s l -> f (InSrc s l)
lLineCol LineCol -> f LineCol
f (InSrc s
s l
l) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s l. s -> l -> InSrc s l
InSrc s
s) (forall l (f :: * -> *).
(LineColLens l, Functor f) =>
(LineCol -> f LineCol) -> l -> f l
lLineCol LineCol -> f LineCol
f l
l)
  {-# INLINE lLineCol #-}

instance SrcLoc (InSrc s l) where
  type LocSrc (InSrc s l) = s
  locSrc :: InSrc s l -> LocSrc (InSrc s l)
locSrc = forall s l. InSrc s l -> s
srcSrc
  {-# INLINE locSrc #-}

instance SrcLens (InSrc s l) where
  lSrc :: forall (f :: * -> *).
Functor f =>
(LocSrc (InSrc s l) -> f (LocSrc (InSrc s l)))
-> InSrc s l -> f (InSrc s l)
lSrc LocSrc (InSrc s l) -> f (LocSrc (InSrc s l))
f (InSrc s
s l
l) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall s l. s -> l -> InSrc s l
InSrc l
l) (LocSrc (InSrc s l) -> f (LocSrc (InSrc s l))
f s
s)
  {-# INLINE lSrc #-}

-- | Locations that have parent locations.
class FromLoc l where
  type LocFrom l
  locFrom  l  LocFrom l

instance FromLoc l  FromLoc (InSrc s l) where
  type LocFrom (InSrc s l) = LocFrom l
  locFrom :: InSrc s l -> LocFrom (InSrc s l)
locFrom = forall l. FromLoc l => l -> LocFrom l
locFrom forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s l. InSrc s l -> l
srcLoc
  {-# INLINE locFrom #-}

instance FromLens l  FromLens (InSrc s l) where
  lFrom :: forall (f :: * -> *).
Functor f =>
(LocFrom (InSrc s l) -> f (LocFrom (InSrc s l)))
-> InSrc s l -> f (InSrc s l)
lFrom LocFrom (InSrc s l) -> f (LocFrom (InSrc s l))
f (InSrc s
s l
l) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall s l. s -> l -> InSrc s l
InSrc s
s) (forall l (f :: * -> *).
(FromLens l, Functor f) =>
(LocFrom l -> f (LocFrom l)) -> l -> f l
lFrom LocFrom (InSrc s l) -> f (LocFrom (InSrc s l))
f l
l)
  {-# INLINE lFrom #-}

-- | The parent of the associated location.
fromOf  (HasLoc α, FromLoc (LocOf α))  α  LocFrom (LocOf α)
fromOf :: forall α. (HasLoc α, FromLoc (LocOf α)) => α -> LocFrom (LocOf α)
fromOf = forall l. FromLoc l => l -> LocFrom l
locFrom forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall α. HasLoc α => α -> LocOf α
locOf
{-# INLINE fromOf #-}

-- | Locations with editable parent locations.
class FromLoc l  FromLens l where
  lFrom  Functor f  (LocFrom l  f (LocFrom l))  l  f l

-- | Provides access to the parent of the associated location.
lFromOf  (Functor f, LocLens α, FromLens (LocOf α))
         (LocFrom (LocOf α)  f (LocFrom (LocOf α)))  α  f α
lFromOf :: forall (f :: * -> *) α.
(Functor f, LocLens α, FromLens (LocOf α)) =>
(LocFrom (LocOf α) -> f (LocFrom (LocOf α))) -> α -> f α
lFromOf = forall α (f :: * -> *).
(LocLens α, Functor f) =>
(LocOf α -> f (LocOf α)) -> α -> f α
lLocOf forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l (f :: * -> *).
(FromLens l, Functor f) =>
(LocFrom l -> f (LocFrom l)) -> l -> f l
lFrom
{-# INLINE lFromOf #-}

-- | A simple way to nest a location.
data Nested l p = Nested { forall l p. Nested l p -> l
nestedLoc   l
                         , forall l p. Nested l p -> p
nestedFrom  p }
                  deriving (Typeable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall l p x. Rep (Nested l p) x -> Nested l p
forall l p x. Nested l p -> Rep (Nested l p) x
$cto :: forall l p x. Rep (Nested l p) x -> Nested l p
$cfrom :: forall l p x. Nested l p -> Rep (Nested l p) x
Generic, Int -> Nested l p -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall l p. (Show l, Show p) => Int -> Nested l p -> ShowS
forall l p. (Show l, Show p) => [Nested l p] -> ShowS
forall l p. (Show l, Show p) => Nested l p -> String
showList :: [Nested l p] -> ShowS
$cshowList :: forall l p. (Show l, Show p) => [Nested l p] -> ShowS
show :: Nested l p -> String
$cshow :: forall l p. (Show l, Show p) => Nested l p -> String
showsPrec :: Int -> Nested l p -> ShowS
$cshowsPrec :: forall l p. (Show l, Show p) => Int -> Nested l p -> ShowS
Show, ReadPrec [Nested l p]
ReadPrec (Nested l p)
ReadS [Nested l p]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall l p. (Read l, Read p) => ReadPrec [Nested l p]
forall l p. (Read l, Read p) => ReadPrec (Nested l p)
forall l p. (Read l, Read p) => Int -> ReadS (Nested l p)
forall l p. (Read l, Read p) => ReadS [Nested l p]
readListPrec :: ReadPrec [Nested l p]
$creadListPrec :: forall l p. (Read l, Read p) => ReadPrec [Nested l p]
readPrec :: ReadPrec (Nested l p)
$creadPrec :: forall l p. (Read l, Read p) => ReadPrec (Nested l p)
readList :: ReadS [Nested l p]
$creadList :: forall l p. (Read l, Read p) => ReadS [Nested l p]
readsPrec :: Int -> ReadS (Nested l p)
$creadsPrec :: forall l p. (Read l, Read p) => Int -> ReadS (Nested l p)
Read, Nested l p -> Nested l p -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall l p. (Eq l, Eq p) => Nested l p -> Nested l p -> Bool
/= :: Nested l p -> Nested l p -> Bool
$c/= :: forall l p. (Eq l, Eq p) => Nested l p -> Nested l p -> Bool
== :: Nested l p -> Nested l p -> Bool
$c== :: forall l p. (Eq l, Eq p) => Nested l p -> Nested l p -> Bool
Eq)

instance (Hashable l, Hashable p)  Hashable (Nested l p) where
  hashWithSalt :: Int -> Nested l p -> Int
hashWithSalt Int
salt (Nested l
l p
p) = forall a. Hashable a => Int -> a -> Int
hashWithSalt Int
salt (l
l, p
p)
  {-# INLINE hashWithSalt #-}

instance HasLoc (Nested l p) where
  type LocOf (Nested l p) = Nested l p
  locOf :: Nested l p -> LocOf (Nested l p)
locOf = forall a. a -> a
id
  {-# INLINE locOf #-}

instance LocLens (Nested l p) where
  lLocOf :: forall (f :: * -> *).
Functor f =>
(LocOf (Nested l p) -> f (LocOf (Nested l p)))
-> Nested l p -> f (Nested l p)
lLocOf = forall a. a -> a
id
  {-# INLINE lLocOf #-}

instance SpannedLoc l  SpannedLoc (Nested l p) where
  type SpanLoc (Nested l p) = Nested (SpanLoc l) p
  locSpan :: Nested l p -> Span (SpanLoc (Nested l p))
locSpan (Nested l
l p
p) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall l p. l -> p -> Nested l p
Nested p
p) (forall l. SpannedLoc l => l -> Span (SpanLoc l)
locSpan l
l)
  {-# INLINE locSpan #-}

instance SpannedLens l  SpannedLens (Nested l p) where
  lSpan :: forall (f :: * -> *).
Functor f =>
(Span (SpanLoc (Nested l p)) -> f (Span (SpanLoc (Nested l p))))
-> Nested l p -> f (Nested l p)
lSpan Span (SpanLoc (Nested l p)) -> f (Span (SpanLoc (Nested l p)))
f (Nested l
l p
p) =
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall l p. l -> p -> Nested l p
Nested p
p)
         (forall l (f :: * -> *).
(SpannedLens l, Functor f) =>
(Span (SpanLoc l) -> f (Span (SpanLoc l))) -> l -> f l
lSpan (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall l p. Nested l p -> l
nestedLoc) forall b c a. (b -> c) -> (a -> b) -> a -> c
. Span (SpanLoc (Nested l p)) -> f (Span (SpanLoc (Nested l p)))
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall l p. l -> p -> Nested l p
Nested p
p)) l
l)
  {-# INLINE lSpan #-}

instance LineColLoc l  LineColLoc (Nested l p) where
  locLineCol :: Nested l p -> LineCol
locLineCol = forall l. LineColLoc l => l -> LineCol
locLineCol forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l p. Nested l p -> l
nestedLoc
  {-# INLINE locLineCol #-}

instance LineColLens l  LineColLens (Nested l p) where
  lLineCol :: forall (f :: * -> *).
Functor f =>
(LineCol -> f LineCol) -> Nested l p -> f (Nested l p)
lLineCol LineCol -> f LineCol
f (Nested l
l p
p) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall l p. l -> p -> Nested l p
Nested p
p) (forall l (f :: * -> *).
(LineColLens l, Functor f) =>
(LineCol -> f LineCol) -> l -> f l
lLineCol LineCol -> f LineCol
f l
l)
  {-# INLINE lLineCol #-}

instance SrcLoc l  SrcLoc (Nested l p) where
  type LocSrc (Nested l p) = LocSrc l
  locSrc :: Nested l p -> LocSrc (Nested l p)
locSrc = forall l. SrcLoc l => l -> LocSrc l
locSrc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall l p. Nested l p -> l
nestedLoc
  {-# INLINE locSrc #-}

instance SrcLens l  SrcLens (Nested l p) where
  lSrc :: forall (f :: * -> *).
Functor f =>
(LocSrc (Nested l p) -> f (LocSrc (Nested l p)))
-> Nested l p -> f (Nested l p)
lSrc LocSrc (Nested l p) -> f (LocSrc (Nested l p))
f (Nested l
l p
p) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall l p. l -> p -> Nested l p
Nested p
p) (forall l (f :: * -> *).
(SrcLens l, Functor f) =>
(LocSrc l -> f (LocSrc l)) -> l -> f l
lSrc LocSrc (Nested l p) -> f (LocSrc (Nested l p))
f l
l)
  {-# INLINE lSrc #-}

instance FromLoc (Nested l p) where
  type LocFrom (Nested l p) = p
  locFrom :: Nested l p -> LocFrom (Nested l p)
locFrom = forall l p. Nested l p -> p
nestedFrom
  {-# INLINE locFrom #-}

instance FromLens (Nested l p) where
  lFrom :: forall (f :: * -> *).
Functor f =>
(LocFrom (Nested l p) -> f (LocFrom (Nested l p)))
-> Nested l p -> f (Nested l p)
lFrom LocFrom (Nested l p) -> f (LocFrom (Nested l p))
f (Nested l
l p
p) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall l p. l -> p -> Nested l p
Nested l
l) (LocFrom (Nested l p) -> f (LocFrom (Nested l p))
f p
p)
  {-# INLINE lFrom #-}