module Prosidy.Optics.Source
(
HasLocation(..)
, offset
, column
, line
, source
, sparse
)
where
import Prosidy.Types
import Prosidy.Source
import Prosidy.Optics.Internal
class HasLocation t where
location :: Affine' t Location
instance HasLocation Location where
location :: Optic p f Location Location Location Location
location = Optic p f Location Location Location Location
forall a. a -> a
id
{-# INLINE location #-}
instance HasLocation (Tag a) where
location :: Optic p f (Tag a) (Tag a) Location Location
location = (Tag a -> Maybe Location)
-> (Tag a -> Location -> Tag a) -> Affine' (Tag a) Location
forall s a b. (s -> Maybe a) -> (s -> b -> s) -> Affine s s a b
affine' Tag a -> Maybe Location
forall a. Tag a -> Maybe Location
tagLocation (\d :: Tag a
d l :: Location
l -> Tag a
d { tagLocation :: Maybe Location
tagLocation = Location -> Maybe Location
forall a. a -> Maybe a
Just Location
l })
{-# INLINE location #-}
instance HasLocation (Region a) where
location :: Optic p f (Region a) (Region a) Location Location
location = (Region a -> Maybe Location)
-> (Region a -> Location -> Region a)
-> Affine' (Region a) Location
forall s a b. (s -> Maybe a) -> (s -> b -> s) -> Affine s s a b
affine' Region a -> Maybe Location
forall a. Region a -> Maybe Location
regionLocation (\d :: Region a
d l :: Location
l -> Region a
d { regionLocation :: Maybe Location
regionLocation = Location -> Maybe Location
forall a. a -> Maybe a
Just Location
l })
{-# INLINE location #-}
instance HasLocation Paragraph where
location :: Optic p f Paragraph Paragraph Location Location
location =
(Paragraph -> Maybe Location)
-> (Paragraph -> Location -> Paragraph)
-> Affine' Paragraph Location
forall s a b. (s -> Maybe a) -> (s -> b -> s) -> Affine s s a b
affine' Paragraph -> Maybe Location
paragraphLocation (\d :: Paragraph
d l :: Location
l -> Paragraph
d { paragraphLocation :: Maybe Location
paragraphLocation = Location -> Maybe Location
forall a. a -> Maybe a
Just Location
l })
{-# INLINE location #-}
offset :: HasLocation l => Affine' l Offset
offset :: Affine' l Offset
offset = Optic p f l l Location Location
forall t. HasLocation t => Affine' t Location
location Optic p f l l Location Location
-> (p Offset (f Offset) -> p Location (f Location))
-> p Offset (f Offset)
-> p l (f l)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Optic p f Location Location SparseLocation SparseLocation
Iso' Location SparseLocation
sparse Optic p f Location Location SparseLocation SparseLocation
-> (p Offset (f Offset) -> p SparseLocation (f SparseLocation))
-> p Offset (f Offset)
-> p Location (f Location)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SparseLocation -> Offset)
-> (SparseLocation -> Offset -> SparseLocation)
-> Lens SparseLocation SparseLocation Offset Offset
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens
SparseLocation -> Offset
sparseLocationOffset
(\sl :: SparseLocation
sl x :: Offset
x -> SparseLocation
sl { sparseLocationOffset :: Offset
sparseLocationOffset = Offset
x })
{-# INLINE offset #-}
column
:: (HasLocation l, Contravariant f, Applicative f) => Optic' (->) f l Column
column :: Optic' (->) f l Column
column = Optic (->) f l l Location Location
forall t. HasLocation t => Affine' t Location
location Optic (->) f l l Location Location
-> ((Column -> f Column) -> Location -> f Location)
-> Optic' (->) f l Column
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Location -> Column) -> Getter Location Column
forall s a. (s -> a) -> Getter s a
to Location -> Column
locationColumn
{-# INLINE column #-}
line :: (HasLocation l, Contravariant f, Applicative f) => Optic' (->) f l Line
line :: Optic' (->) f l Line
line = Optic (->) f l l Location Location
forall t. HasLocation t => Affine' t Location
location Optic (->) f l l Location Location
-> ((Line -> f Line) -> Location -> f Location)
-> Optic' (->) f l Line
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Location -> Line) -> Getter Location Line
forall s a. (s -> a) -> Getter s a
to Location -> Line
locationLine
{-# INLINE line #-}
source
:: (HasLocation l, Contravariant f, Applicative f) => Optic' (->) f l Source
source :: Optic' (->) f l Source
source = Optic (->) f l l Location Location
forall t. HasLocation t => Affine' t Location
location Optic (->) f l l Location Location
-> ((Source -> f Source) -> Location -> f Location)
-> Optic' (->) f l Source
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Location -> Source) -> Getter Location Source
forall s a. (s -> a) -> Getter s a
to Location -> Source
locationSource
{-# INLINE source #-}
sparse :: Iso' Location SparseLocation
sparse :: Optic p f Location Location SparseLocation SparseLocation
sparse = (Location -> SparseLocation)
-> (SparseLocation -> Location) -> Iso' Location SparseLocation
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso Location -> SparseLocation
stripLocation SparseLocation -> Location
enrichLocation
{-# INLINE sparse #-}