{-# LANGUAGE Haskell2010, DeriveDataTypeable #-}
module Data.Monoid.Instances.Positioned (
OffsetPositioned, LinePositioned, extract, position, line, column
)
where
import Control.Applicative
import qualified Data.List as List
import Data.String (IsString(..))
import Data.Data (Data, Typeable)
import Data.Semigroup (Semigroup(..))
import Data.Monoid (Monoid(..), Endo(..))
import Data.Semigroup.Cancellative (LeftReductive(..), RightReductive(..))
import Data.Semigroup.Factorial (Factorial(..), StableFactorial)
import Data.Monoid.GCD (LeftGCDMonoid(..), RightGCDMonoid(..))
import Data.Monoid.Null (MonoidNull(null), PositiveMonoid)
import Data.Monoid.Factorial (FactorialMonoid(..))
import Data.Monoid.Textual (TextualMonoid(..))
import qualified Data.Semigroup.Factorial as Factorial
import qualified Data.Monoid.Factorial as Factorial
import qualified Data.Monoid.Textual as Textual
import Prelude hiding (all, any, break, filter, foldl, foldl1, foldr, foldr1, lines, map, concatMap,
length, null, reverse, scanl, scanr, scanl1, scanr1, span, splitAt)
class Positioned p where
:: p a -> a
position :: p a -> Int
data OffsetPositioned m = OffsetPositioned{forall m. OffsetPositioned m -> Int
offset :: !Int,
:: m} deriving (OffsetPositioned m -> DataType
OffsetPositioned m -> Constr
forall {m}. Data m => Typeable (OffsetPositioned m)
forall m. Data m => OffsetPositioned m -> DataType
forall m. Data m => OffsetPositioned m -> Constr
forall m.
Data m =>
(forall b. Data b => b -> b)
-> OffsetPositioned m -> OffsetPositioned m
forall m u.
Data m =>
Int -> (forall d. Data d => d -> u) -> OffsetPositioned m -> u
forall m u.
Data m =>
(forall d. Data d => d -> u) -> OffsetPositioned m -> [u]
forall m r r'.
Data m =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetPositioned m -> r
forall m r r'.
Data m =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetPositioned m -> r
forall m (m :: * -> *).
(Data m, Monad m) =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
forall m (c :: * -> *).
Data m =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OffsetPositioned m)
forall m (c :: * -> *).
Data m =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> OffsetPositioned m
-> c (OffsetPositioned m)
forall m (t :: * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (OffsetPositioned m))
forall m (t :: * -> * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (OffsetPositioned m))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OffsetPositioned m)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> OffsetPositioned m
-> c (OffsetPositioned m)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (OffsetPositioned m))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
$cgmapMo :: forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
$cgmapMp :: forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
$cgmapM :: forall m (m :: * -> *).
(Data m, Monad m) =>
(forall d. Data d => d -> m d)
-> OffsetPositioned m -> m (OffsetPositioned m)
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> OffsetPositioned m -> u
$cgmapQi :: forall m u.
Data m =>
Int -> (forall d. Data d => d -> u) -> OffsetPositioned m -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> OffsetPositioned m -> [u]
$cgmapQ :: forall m u.
Data m =>
(forall d. Data d => d -> u) -> OffsetPositioned m -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetPositioned m -> r
$cgmapQr :: forall m r r'.
Data m =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetPositioned m -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetPositioned m -> r
$cgmapQl :: forall m r r'.
Data m =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OffsetPositioned m -> r
gmapT :: (forall b. Data b => b -> b)
-> OffsetPositioned m -> OffsetPositioned m
$cgmapT :: forall m.
Data m =>
(forall b. Data b => b -> b)
-> OffsetPositioned m -> OffsetPositioned m
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (OffsetPositioned m))
$cdataCast2 :: forall m (t :: * -> * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (OffsetPositioned m))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (OffsetPositioned m))
$cdataCast1 :: forall m (t :: * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (OffsetPositioned m))
dataTypeOf :: OffsetPositioned m -> DataType
$cdataTypeOf :: forall m. Data m => OffsetPositioned m -> DataType
toConstr :: OffsetPositioned m -> Constr
$ctoConstr :: forall m. Data m => OffsetPositioned m -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OffsetPositioned m)
$cgunfold :: forall m (c :: * -> *).
Data m =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (OffsetPositioned m)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> OffsetPositioned m
-> c (OffsetPositioned m)
$cgfoldl :: forall m (c :: * -> *).
Data m =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g)
-> OffsetPositioned m
-> c (OffsetPositioned m)
Data, Typeable)
data LinePositioned m = LinePositioned{forall m. LinePositioned m -> Int
fullOffset :: !Int,
forall m. LinePositioned m -> Int
line :: !Int,
forall m. LinePositioned m -> Int
lineStart :: !Int,
:: m} deriving (LinePositioned m -> DataType
LinePositioned m -> Constr
forall {m}. Data m => Typeable (LinePositioned m)
forall m. Data m => LinePositioned m -> DataType
forall m. Data m => LinePositioned m -> Constr
forall m.
Data m =>
(forall b. Data b => b -> b)
-> LinePositioned m -> LinePositioned m
forall m u.
Data m =>
Int -> (forall d. Data d => d -> u) -> LinePositioned m -> u
forall m u.
Data m =>
(forall d. Data d => d -> u) -> LinePositioned m -> [u]
forall m r r'.
Data m =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LinePositioned m -> r
forall m r r'.
Data m =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LinePositioned m -> r
forall m (m :: * -> *).
(Data m, Monad m) =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
forall m (c :: * -> *).
Data m =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LinePositioned m)
forall m (c :: * -> *).
Data m =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LinePositioned m -> c (LinePositioned m)
forall m (t :: * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (LinePositioned m))
forall m (t :: * -> * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LinePositioned m))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LinePositioned m)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LinePositioned m -> c (LinePositioned m)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (LinePositioned m))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
$cgmapMo :: forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
$cgmapMp :: forall m (m :: * -> *).
(Data m, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
$cgmapM :: forall m (m :: * -> *).
(Data m, Monad m) =>
(forall d. Data d => d -> m d)
-> LinePositioned m -> m (LinePositioned m)
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> LinePositioned m -> u
$cgmapQi :: forall m u.
Data m =>
Int -> (forall d. Data d => d -> u) -> LinePositioned m -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> LinePositioned m -> [u]
$cgmapQ :: forall m u.
Data m =>
(forall d. Data d => d -> u) -> LinePositioned m -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LinePositioned m -> r
$cgmapQr :: forall m r r'.
Data m =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> LinePositioned m -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LinePositioned m -> r
$cgmapQl :: forall m r r'.
Data m =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> LinePositioned m -> r
gmapT :: (forall b. Data b => b -> b)
-> LinePositioned m -> LinePositioned m
$cgmapT :: forall m.
Data m =>
(forall b. Data b => b -> b)
-> LinePositioned m -> LinePositioned m
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LinePositioned m))
$cdataCast2 :: forall m (t :: * -> * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (LinePositioned m))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (LinePositioned m))
$cdataCast1 :: forall m (t :: * -> *) (c :: * -> *).
(Data m, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (LinePositioned m))
dataTypeOf :: LinePositioned m -> DataType
$cdataTypeOf :: forall m. Data m => LinePositioned m -> DataType
toConstr :: LinePositioned m -> Constr
$ctoConstr :: forall m. Data m => LinePositioned m -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LinePositioned m)
$cgunfold :: forall m (c :: * -> *).
Data m =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (LinePositioned m)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LinePositioned m -> c (LinePositioned m)
$cgfoldl :: forall m (c :: * -> *).
Data m =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> LinePositioned m -> c (LinePositioned m)
Data, Typeable)
column :: LinePositioned m -> Int
column :: forall m. LinePositioned m -> Int
column LinePositioned m
lp = forall (p :: * -> *) a. Positioned p => p a -> Int
position LinePositioned m
lp forall a. Num a => a -> a -> a
- forall m. LinePositioned m -> Int
lineStart LinePositioned m
lp
instance Functor OffsetPositioned where
fmap :: forall a b. (a -> b) -> OffsetPositioned a -> OffsetPositioned b
fmap a -> b
f (OffsetPositioned Int
p a
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (a -> b
f a
c)
instance Functor LinePositioned where
fmap :: forall a b. (a -> b) -> LinePositioned a -> LinePositioned b
fmap a -> b
f (LinePositioned Int
p Int
l Int
lp a
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (a -> b
f a
c)
instance Applicative OffsetPositioned where
pure :: forall a. a -> OffsetPositioned a
pure = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
0
OffsetPositioned Int
_ a -> b
f <*> :: forall a b.
OffsetPositioned (a -> b)
-> OffsetPositioned a -> OffsetPositioned b
<*> OffsetPositioned Int
p a
c = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (a -> b
f a
c)
instance Applicative LinePositioned where
pure :: forall a. a -> LinePositioned a
pure = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
0 Int
0 (-Int
1)
LinePositioned Int
_ Int
_ Int
_ a -> b
f <*> :: forall a b.
LinePositioned (a -> b) -> LinePositioned a -> LinePositioned b
<*> LinePositioned Int
p Int
l Int
lp a
c = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (a -> b
f a
c)
instance Positioned OffsetPositioned where
extract :: forall m. OffsetPositioned m -> m
extract = forall m. OffsetPositioned m -> m
extractOffset
position :: forall m. OffsetPositioned m -> Int
position = forall m. OffsetPositioned m -> Int
offset
instance Positioned LinePositioned where
extract :: forall m. LinePositioned m -> m
extract = forall m. LinePositioned m -> m
extractLines
position :: forall m. LinePositioned m -> Int
position = forall m. LinePositioned m -> Int
fullOffset
instance Eq m => Eq (OffsetPositioned m) where
OffsetPositioned{extractOffset :: forall m. OffsetPositioned m -> m
extractOffset= m
a} == :: OffsetPositioned m -> OffsetPositioned m -> Bool
== OffsetPositioned{extractOffset :: forall m. OffsetPositioned m -> m
extractOffset= m
b} = m
a forall a. Eq a => a -> a -> Bool
== m
b
instance Eq m => Eq (LinePositioned m) where
LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines= m
a} == :: LinePositioned m -> LinePositioned m -> Bool
== LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines= m
b} = m
a forall a. Eq a => a -> a -> Bool
== m
b
instance Ord m => Ord (OffsetPositioned m) where
compare :: OffsetPositioned m -> OffsetPositioned m -> Ordering
compare OffsetPositioned{extractOffset :: forall m. OffsetPositioned m -> m
extractOffset= m
a} OffsetPositioned{extractOffset :: forall m. OffsetPositioned m -> m
extractOffset= m
b} = forall a. Ord a => a -> a -> Ordering
compare m
a m
b
instance Ord m => Ord (LinePositioned m) where
compare :: LinePositioned m -> LinePositioned m -> Ordering
compare LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines= m
a} LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines= m
b} = forall a. Ord a => a -> a -> Ordering
compare m
a m
b
instance Show m => Show (OffsetPositioned m) where
showsPrec :: Int -> OffsetPositioned m -> ShowS
showsPrec Int
prec (OffsetPositioned Int
0 m
c) = forall a. Show a => Int -> a -> ShowS
showsPrec Int
prec m
c
showsPrec Int
prec (OffsetPositioned Int
pos m
c) = forall a. Show a => a -> ShowS
shows Int
pos forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
": " forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
prec m
c
instance Show m => Show (LinePositioned m) where
showsPrec :: Int -> LinePositioned m -> ShowS
showsPrec Int
prec (LinePositioned Int
0 Int
0 (-1) m
c) = forall a. Show a => Int -> a -> ShowS
showsPrec Int
prec m
c
showsPrec Int
prec (LinePositioned Int
pos Int
l Int
lpos m
c) =
(String
"Line " forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows Int
l forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
", column " forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> ShowS
shows (Int
pos forall a. Num a => a -> a -> a
- Int
lpos) forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String
": " forall a. [a] -> [a] -> [a]
++) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => Int -> a -> ShowS
showsPrec Int
prec m
c
instance StableFactorial m => Semigroup (OffsetPositioned m) where
OffsetPositioned Int
p1 m
c1 <> :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m
<> OffsetPositioned Int
p2 m
c2 =
forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (if Int
p1 forall a. Eq a => a -> a -> Bool
/= Int
0 Bool -> Bool -> Bool
|| Int
p2 forall a. Eq a => a -> a -> Bool
== Int
0 then Int
p1 else forall a. Ord a => a -> a -> a
max Int
0 forall a b. (a -> b) -> a -> b
$ Int
p2 forall a. Num a => a -> a -> a
- forall m. Factorial m => m -> Int
length m
c1) (m
c1 forall a. Semigroup a => a -> a -> a
<> m
c2)
{-# INLINE (<>) #-}
instance (FactorialMonoid m, StableFactorial m) => Monoid (OffsetPositioned m) where
mempty :: OffsetPositioned m
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
mappend :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m
mappend = forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE mempty #-}
{-# INLINE mappend #-}
instance (StableFactorial m, TextualMonoid m) => Semigroup (LinePositioned m) where
LinePositioned Int
p1 Int
l1 Int
lp1 m
c1 <> :: LinePositioned m -> LinePositioned m -> LinePositioned m
<> LinePositioned Int
p2 Int
l2 Int
lp2 m
c2
| Int
p1 forall a. Eq a => a -> a -> Bool
/= Int
0 Bool -> Bool -> Bool
|| Int
p2 forall a. Eq a => a -> a -> Bool
== Int
0 = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p1 Int
l1 Int
lp1 m
c
| Bool
otherwise = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p2' Int
l2' Int
lp2' m
c
where c :: m
c = forall a. Monoid a => a -> a -> a
mappend m
c1 m
c2
p2' :: Int
p2' = forall a. Ord a => a -> a -> a
max Int
0 forall a b. (a -> b) -> a -> b
$ Int
p2 forall a. Num a => a -> a -> a
- forall m. Factorial m => m -> Int
length m
c1
lp2' :: Int
lp2' = Int
p2' forall a. Num a => a -> a -> a
- (Int
p2 forall a. Num a => a -> a -> a
- Int
lp2 forall a. Num a => a -> a -> a
- Int
cd forall a. Num a => a -> a -> a
+ Int
1)
l2' :: Int
l2' = if Int
l2 forall a. Eq a => a -> a -> Bool
== Int
0 then Int
0 else forall a. Ord a => a -> a -> a
max Int
0 (Int
l2 forall a. Num a => a -> a -> a
- Int
ld)
(Int
ld, Int
cd) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
c1
{-# INLINE (<>) #-}
instance (StableFactorial m, TextualMonoid m) => Monoid (LinePositioned m) where
mempty :: LinePositioned m
mempty = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a. Monoid a => a
mempty
mappend :: LinePositioned m -> LinePositioned m -> LinePositioned m
mappend = forall a. Semigroup a => a -> a -> a
(<>)
{-# INLINE mempty #-}
instance (StableFactorial m, FactorialMonoid m) => MonoidNull (OffsetPositioned m) where
null :: OffsetPositioned m -> Bool
null = forall m. MonoidNull m => m -> Bool
null forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. OffsetPositioned m -> m
extractOffset
{-# INLINE null #-}
instance (StableFactorial m, TextualMonoid m, MonoidNull m) => MonoidNull (LinePositioned m) where
null :: LinePositioned m -> Bool
null = forall m. MonoidNull m => m -> Bool
null forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. LinePositioned m -> m
extractLines
{-# INLINE null #-}
instance (StableFactorial m, FactorialMonoid m) => PositiveMonoid (OffsetPositioned m)
instance (StableFactorial m, TextualMonoid m) => PositiveMonoid (LinePositioned m)
instance (StableFactorial m, LeftReductive m) => LeftReductive (OffsetPositioned m) where
isPrefixOf :: OffsetPositioned m -> OffsetPositioned m -> Bool
isPrefixOf (OffsetPositioned Int
_ m
c1) (OffsetPositioned Int
_ m
c2) = forall m. LeftReductive m => m -> m -> Bool
isPrefixOf m
c1 m
c2
stripPrefix :: OffsetPositioned m
-> OffsetPositioned m -> Maybe (OffsetPositioned m)
stripPrefix (OffsetPositioned Int
_ m
c1) (OffsetPositioned Int
p m
c2) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
c1)) (forall m. LeftReductive m => m -> m -> Maybe m
stripPrefix m
c1 m
c2)
{-# INLINE isPrefixOf #-}
{-# INLINE stripPrefix #-}
instance (StableFactorial m, TextualMonoid m) => LeftReductive (LinePositioned m) where
isPrefixOf :: LinePositioned m -> LinePositioned m -> Bool
isPrefixOf LinePositioned m
a LinePositioned m
b = forall m. LeftReductive m => m -> m -> Bool
isPrefixOf (forall m. LinePositioned m -> m
extractLines LinePositioned m
a) (forall m. LinePositioned m -> m
extractLines LinePositioned m
b)
stripPrefix :: LinePositioned m -> LinePositioned m -> Maybe (LinePositioned m)
stripPrefix LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines= m
c1} (LinePositioned Int
p Int
l Int
lpos m
c2) =
let (Int
lines, Int
columns) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
c1
len :: Int
len = forall m. Factorial m => m -> Int
length m
c1
in forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned (Int
p forall a. Num a => a -> a -> a
+ Int
len) (Int
l forall a. Num a => a -> a -> a
+ Int
lines) (Int
lpos forall a. Num a => a -> a -> a
+ Int
len forall a. Num a => a -> a -> a
- Int
columns)) (forall m. LeftReductive m => m -> m -> Maybe m
stripPrefix m
c1 m
c2)
{-# INLINE isPrefixOf #-}
{-# INLINE stripPrefix #-}
instance (StableFactorial m, FactorialMonoid m, LeftGCDMonoid m) => LeftGCDMonoid (OffsetPositioned m) where
commonPrefix :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m
commonPrefix (OffsetPositioned Int
p1 m
c1) (OffsetPositioned Int
p2 m
c2) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (forall a. Ord a => a -> a -> a
min Int
p1 Int
p2) (forall m. LeftGCDMonoid m => m -> m -> m
commonPrefix m
c1 m
c2)
stripCommonPrefix :: OffsetPositioned m
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, OffsetPositioned m)
stripCommonPrefix (OffsetPositioned Int
p1 m
c1) (OffsetPositioned Int
p2 m
c2) =
(forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (forall a. Ord a => a -> a -> a
min Int
p1 Int
p2) m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p1 forall a. Num a => a -> a -> a
+ Int
l) m
c1', forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p2 forall a. Num a => a -> a -> a
+ Int
l) m
c2')
where (m
prefix, m
c1', m
c2') = forall m. LeftGCDMonoid m => m -> m -> (m, m, m)
stripCommonPrefix m
c1 m
c2
l :: Int
l = forall m. Factorial m => m -> Int
length m
prefix
{-# INLINE commonPrefix #-}
{-# INLINE stripCommonPrefix #-}
instance (StableFactorial m, TextualMonoid m, LeftGCDMonoid m) => LeftGCDMonoid (LinePositioned m) where
commonPrefix :: LinePositioned m -> LinePositioned m -> LinePositioned m
commonPrefix (LinePositioned Int
p1 Int
l1 Int
lp1 m
c1) (LinePositioned Int
p2 Int
l2 Int
lp2 m
c2) =
if Int
p1 forall a. Ord a => a -> a -> Bool
<= Int
p2
then forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p1 Int
l1 Int
lp1 (forall m. LeftGCDMonoid m => m -> m -> m
commonPrefix m
c1 m
c2)
else forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p2 Int
l2 Int
lp2 (forall m. LeftGCDMonoid m => m -> m -> m
commonPrefix m
c1 m
c2)
stripCommonPrefix :: LinePositioned m
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, LinePositioned m)
stripCommonPrefix (LinePositioned Int
p1 Int
l1 Int
lp1 m
c1) (LinePositioned Int
p2 Int
l2 Int
lp2 m
c2) =
let (m
prefix, m
c1', m
c2') = forall m. LeftGCDMonoid m => m -> m -> (m, m, m)
stripCommonPrefix m
c1 m
c2
(Int
lines, Int
columns) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
prefix
len :: Int
len = forall m. Factorial m => m -> Int
length m
prefix
in (if Int
p1 forall a. Ord a => a -> a -> Bool
<= Int
p2 then forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p1 Int
l1 Int
lp1 m
prefix else forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p2 Int
l2 Int
lp2 m
prefix,
forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned (Int
p1 forall a. Num a => a -> a -> a
+ Int
len) (Int
l1 forall a. Num a => a -> a -> a
+ Int
lines) (Int
lp1 forall a. Num a => a -> a -> a
+ Int
len forall a. Num a => a -> a -> a
- Int
columns) m
c1',
forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned (Int
p2 forall a. Num a => a -> a -> a
+ Int
len) (Int
l2 forall a. Num a => a -> a -> a
+ Int
lines) (Int
lp2 forall a. Num a => a -> a -> a
+ Int
len forall a. Num a => a -> a -> a
- Int
columns) m
c2')
{-# INLINE commonPrefix #-}
{-# INLINE stripCommonPrefix #-}
instance (StableFactorial m, FactorialMonoid m, RightReductive m) => RightReductive (OffsetPositioned m) where
isSuffixOf :: OffsetPositioned m -> OffsetPositioned m -> Bool
isSuffixOf (OffsetPositioned Int
_ m
c1) (OffsetPositioned Int
_ m
c2) = forall m. RightReductive m => m -> m -> Bool
isSuffixOf m
c1 m
c2
stripSuffix :: OffsetPositioned m
-> OffsetPositioned m -> Maybe (OffsetPositioned m)
stripSuffix (OffsetPositioned Int
_ m
c1) (OffsetPositioned Int
p m
c2) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p) (forall m. RightReductive m => m -> m -> Maybe m
stripSuffix m
c1 m
c2)
{-# INLINE isSuffixOf #-}
{-# INLINE stripSuffix #-}
instance (StableFactorial m, TextualMonoid m, RightReductive m) => RightReductive (LinePositioned m) where
isSuffixOf :: LinePositioned m -> LinePositioned m -> Bool
isSuffixOf LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines=m
c1} LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines=m
c2} = forall m. RightReductive m => m -> m -> Bool
isSuffixOf m
c1 m
c2
stripSuffix :: LinePositioned m -> LinePositioned m -> Maybe (LinePositioned m)
stripSuffix (LinePositioned Int
p Int
l Int
lp m
c1) LinePositioned{extractLines :: forall m. LinePositioned m -> m
extractLines=m
c2} =
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp) (forall m. RightReductive m => m -> m -> Maybe m
stripSuffix m
c1 m
c2)
{-# INLINE isSuffixOf #-}
{-# INLINE stripSuffix #-}
instance (StableFactorial m, FactorialMonoid m, RightGCDMonoid m) => RightGCDMonoid (OffsetPositioned m) where
commonSuffix :: OffsetPositioned m -> OffsetPositioned m -> OffsetPositioned m
commonSuffix (OffsetPositioned Int
p1 m
c1) (OffsetPositioned Int
p2 m
c2) =
forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (forall a. Ord a => a -> a -> a
min (Int
p1 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
c1) (Int
p2 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
c2) forall a. Num a => a -> a -> a
- forall m. Factorial m => m -> Int
length m
suffix) m
suffix
where suffix :: m
suffix = forall m. RightGCDMonoid m => m -> m -> m
commonSuffix m
c1 m
c2
stripCommonSuffix :: OffsetPositioned m
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, OffsetPositioned m)
stripCommonSuffix (OffsetPositioned Int
p1 m
c1) (OffsetPositioned Int
p2 m
c2) =
(forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p1 m
c1', forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p2 m
c2',
forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (forall a. Ord a => a -> a -> a
min (Int
p1 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
c1') (Int
p2 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
c2')) m
suffix)
where (m
c1', m
c2', m
suffix) = forall m. RightGCDMonoid m => m -> m -> (m, m, m)
stripCommonSuffix m
c1 m
c2
{-# INLINE commonSuffix #-}
{-# INLINE stripCommonSuffix #-}
instance (StableFactorial m, TextualMonoid m, RightGCDMonoid m) => RightGCDMonoid (LinePositioned m) where
stripCommonSuffix :: LinePositioned m
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, LinePositioned m)
stripCommonSuffix (LinePositioned Int
p1 Int
l1 Int
lp1 m
c1) (LinePositioned Int
p2 Int
l2 Int
lp2 m
c2) =
(forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p1 Int
l1 Int
lp1 m
c1', forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p2 Int
l2 Int
lp2 m
c2',
if Int
p1 forall a. Ord a => a -> a -> Bool
< Int
p2
then forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned (Int
p1 forall a. Num a => a -> a -> a
+ Int
len1) (Int
l1 forall a. Num a => a -> a -> a
+ Int
lines1) (Int
lp1 forall a. Num a => a -> a -> a
+ Int
len1 forall a. Num a => a -> a -> a
- Int
columns1) m
suffix
else forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned (Int
p2 forall a. Num a => a -> a -> a
+ Int
len2) (Int
l2 forall a. Num a => a -> a -> a
+ Int
lines2) (Int
lp2 forall a. Num a => a -> a -> a
+ Int
len2 forall a. Num a => a -> a -> a
- Int
columns2) m
suffix)
where (m
c1', m
c2', m
suffix) = forall m. RightGCDMonoid m => m -> m -> (m, m, m)
stripCommonSuffix m
c1 m
c2
len1 :: Int
len1 = forall m. Factorial m => m -> Int
length m
c1'
len2 :: Int
len2 = forall m. Factorial m => m -> Int
length m
c2'
(Int
lines1, Int
columns1) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
c1'
(Int
lines2, Int
columns2) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
c2'
instance StableFactorial m => Factorial (OffsetPositioned m) where
factors :: OffsetPositioned m -> [OffsetPositioned m]
factors (OffsetPositioned Int
p m
c) = forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
List.mapAccumL forall {m}. Int -> m -> (Int, OffsetPositioned m)
next Int
p (forall m. Factorial m => m -> [m]
factors m
c)
where next :: Int -> m -> (Int, OffsetPositioned m)
next Int
p1 m
c1 = (forall a. Enum a => a -> a
succ Int
p1, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p1 m
c1)
primePrefix :: OffsetPositioned m -> OffsetPositioned m
primePrefix (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall m. Factorial m => m -> m
primePrefix m
c)
foldl :: forall a.
(a -> OffsetPositioned m -> a) -> a -> OffsetPositioned m -> a
foldl a -> OffsetPositioned m -> a
f a
a0 (OffsetPositioned Int
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl (a, Int) -> m -> (a, Int)
f' (a
a0, Int
p0) m
c0
where f' :: (a, Int) -> m -> (a, Int)
f' (a
a, Int
p) m
c = (a -> OffsetPositioned m -> a
f a
a (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
c), forall a. Enum a => a -> a
succ Int
p)
foldl' :: forall a.
(a -> OffsetPositioned m -> a) -> a -> OffsetPositioned m -> a
foldl' a -> OffsetPositioned m -> a
f a
a0 (OffsetPositioned Int
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl' (a, Int) -> m -> (a, Int)
f' (a
a0, Int
p0) m
c0
where f' :: (a, Int) -> m -> (a, Int)
f' (a
a, Int
p) m
c = let a' :: a
a' = a -> OffsetPositioned m -> a
f a
a (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
c) in seq :: forall a b. a -> b -> b
seq a
a' (a
a', forall a. Enum a => a -> a
succ Int
p)
foldr :: forall a.
(OffsetPositioned m -> a -> a) -> a -> OffsetPositioned m -> a
foldr OffsetPositioned m -> a -> a
f a
a0 (OffsetPositioned Int
p0 m
c0) = forall m a. Factorial m => (m -> a -> a) -> a -> m -> a
Factorial.foldr m -> (Int -> a) -> Int -> a
f' (forall a b. a -> b -> a
const a
a0) m
c0 Int
p0
where f' :: m -> (Int -> a) -> Int -> a
f' m
c Int -> a
cont Int
p = OffsetPositioned m -> a -> a
f (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
c) (Int -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p)
foldMap :: forall n.
Monoid n =>
(OffsetPositioned m -> n) -> OffsetPositioned m -> n
foldMap OffsetPositioned m -> n
f (OffsetPositioned Int
p m
c) = forall a. Endo a -> a -> a
appEndo (forall m n. (Factorial m, Monoid n) => (m -> n) -> m -> n
Factorial.foldMap m -> Endo (Int -> n)
f' m
c) (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) Int
p
where
f' :: m -> Endo (Int -> n)
f' m
prime = forall a. (a -> a) -> Endo a
Endo (\Int -> n
cont Int
pos-> OffsetPositioned m -> n
f (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
pos m
prime) forall a. Monoid a => a -> a -> a
`mappend` Int -> n
cont (forall a. Enum a => a -> a
succ Int
pos))
length :: OffsetPositioned m -> Int
length (OffsetPositioned Int
_ m
c) = forall m. Factorial m => m -> Int
length m
c
reverse :: OffsetPositioned m -> OffsetPositioned m
reverse (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall m. Factorial m => m -> m
Factorial.reverse m
c)
{-# INLINE primePrefix #-}
{-# INLINE foldl #-}
{-# INLINE foldl' #-}
{-# INLINE foldr #-}
{-# INLINE foldMap #-}
instance (StableFactorial m, FactorialMonoid m) => FactorialMonoid (OffsetPositioned m) where
splitPrimePrefix :: OffsetPositioned m
-> Maybe (OffsetPositioned m, OffsetPositioned m)
splitPrimePrefix (OffsetPositioned Int
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {m} {m}.
MonoidNull m =>
(m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimePrefix m
c)
where rewrap :: (m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (m
cp, m
cs) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
cp, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (if forall m. MonoidNull m => m -> Bool
null m
cs then Int
0 else forall a. Enum a => a -> a
succ Int
p) m
cs)
splitPrimeSuffix :: OffsetPositioned m
-> Maybe (OffsetPositioned m, OffsetPositioned m)
splitPrimeSuffix (OffsetPositioned Int
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {m} {m}.
Factorial m =>
(m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimeSuffix m
c)
where rewrap :: (m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (m
cp, m
cs) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
cp, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
cp) m
cs)
spanMaybe :: forall s.
s
-> (s -> OffsetPositioned m -> Maybe s)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, s)
spanMaybe s
s0 s -> OffsetPositioned m -> Maybe s
f (OffsetPositioned Int
p0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe (s
s0, Int
p0) (s, Int) -> m -> Maybe (s, Int)
f' m
t
where f' :: (s, Int) -> m -> Maybe (s, Int)
f' (s
s, Int
p) m
prime = do s
s' <- s -> OffsetPositioned m -> Maybe s
f s
s (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq Int
p' (s
s', Int
p')
rewrap :: (m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p)) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix, c
s)
spanMaybe' :: forall s.
s
-> (s -> OffsetPositioned m -> Maybe s)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, s)
spanMaybe' s
s0 s -> OffsetPositioned m -> Maybe s
f (OffsetPositioned Int
p0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe' (s
s0, Int
p0) (s, Int) -> m -> Maybe (s, Int)
f' m
t
where f' :: (s, Int) -> m -> Maybe (s, Int)
f' (s
s, Int
p) m
prime = do s
s' <- s -> OffsetPositioned m -> Maybe s
f s
s (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` Int
p' seq :: forall a b. a -> b -> b
`seq` (s
s', Int
p')
rewrap :: (m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p)) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix, c
s)
span :: (OffsetPositioned m -> Bool)
-> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m)
span OffsetPositioned m -> Bool
f (OffsetPositioned Int
p0 m
t) = forall {m} {m}.
(m, m, Int) -> (OffsetPositioned m, OffsetPositioned m)
rewrap forall a b. (a -> b) -> a -> b
$ forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe' Int
p0 Int -> m -> Maybe Int
f' m
t
where f' :: Int -> m -> Maybe Int
f' Int
p m
prime = if OffsetPositioned m -> Bool
f (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
prime)
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p
else forall a. Maybe a
Nothing
rewrap :: (m, m, Int) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (m
prefix, m
suffix, Int
p) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix)
splitAt :: Int
-> OffsetPositioned m -> (OffsetPositioned m, OffsetPositioned m)
splitAt Int
n m :: OffsetPositioned m
m@(OffsetPositioned Int
p m
c) | Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 = (forall a. Monoid a => a
mempty, OffsetPositioned m
m)
| Int
n forall a. Ord a => a -> a -> Bool
>= forall m. Factorial m => m -> Int
length m
c = (OffsetPositioned m
m, forall a. Monoid a => a
mempty)
| Bool
otherwise = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p forall a. Num a => a -> a -> a
+ Int
n) m
suffix)
where (m
prefix, m
suffix) = forall m. FactorialMonoid m => Int -> m -> (m, m)
splitAt Int
n m
c
drop :: Int -> OffsetPositioned m -> OffsetPositioned m
drop Int
n (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p forall a. Num a => a -> a -> a
+ Int
n) (forall m. FactorialMonoid m => Int -> m -> m
Factorial.drop Int
n m
c)
take :: Int -> OffsetPositioned m -> OffsetPositioned m
take Int
n (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall m. FactorialMonoid m => Int -> m -> m
Factorial.take Int
n m
c)
{-# INLINE splitPrimePrefix #-}
{-# INLINE splitPrimeSuffix #-}
{-# INLINE span #-}
{-# INLINE splitAt #-}
{-# INLINE take #-}
{-# INLINE drop #-}
instance (StableFactorial m, TextualMonoid m) => Factorial (LinePositioned m) where
factors :: LinePositioned m -> [LinePositioned m]
factors (LinePositioned Int
p0 Int
l0 Int
lp0 m
c) = forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) s a b.
Traversable t =>
(s -> a -> (s, b)) -> s -> t a -> (s, t b)
List.mapAccumL forall {m}.
TextualMonoid m =>
(Int, Int, Int) -> m -> ((Int, Int, Int), LinePositioned m)
next (Int
p0, Int
l0, Int
lp0) (forall m. Factorial m => m -> [m]
factors m
c)
where next :: (Int, Int, Int) -> m -> ((Int, Int, Int), LinePositioned m)
next (Int
p, Int
l, Int
lp) m
c1 = let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
in Int
p' seq :: forall a b. a -> b -> b
`seq` case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
c1
of Just Char
'\n' -> ((Int
p', forall a. Enum a => a -> a
succ Int
l, Int
p), forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c1)
Just Char
'\f' -> ((Int
p', forall a. Enum a => a -> a
succ Int
l, Int
p), forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c1)
Just Char
'\r' -> ((Int
p', Int
l, Int
p), forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c1)
Just Char
'\t' -> ((Int
p', Int
l, Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8),
forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c1)
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> ((Int
p, Int
l, Int
lp), forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c1)
Maybe Char
_ -> ((Int
p', Int
l, Int
lp), forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c1)
primePrefix :: LinePositioned m -> LinePositioned m
primePrefix (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall m. Factorial m => m -> m
primePrefix m
c)
foldl :: forall a.
(a -> LinePositioned m -> a) -> a -> LinePositioned m -> a
foldl a -> LinePositioned m -> a
f a
a0 (LinePositioned Int
p0 Int
l0 Int
lp0 m
c0) = forall a b c d. (a, b, c, d) -> a
fstOf4 forall a b. (a -> b) -> a -> b
$! forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
f' (a
a0, Int
p0, Int
l0, Int
lp0) m
c0
where f' :: (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
f' (a
a, Int
p, Int
l, Int
lp) m
c = case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
c
of Just Char
'\n' -> (a -> LinePositioned m -> a
f a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c), forall a. Enum a => a -> a
succ Int
p, forall a. Enum a => a -> a
succ Int
l, Int
p)
Just Char
'\f' -> (a -> LinePositioned m -> a
f a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c), forall a. Enum a => a -> a
succ Int
p, forall a. Enum a => a -> a
succ Int
l, Int
p)
Just Char
'\r' -> (a -> LinePositioned m -> a
f a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c), forall a. Enum a => a -> a
succ Int
p, Int
l, Int
p)
Just Char
'\t' -> (a -> LinePositioned m -> a
f a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c), forall a. Enum a => a -> a
succ Int
p, Int
l, Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8)
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> (a -> LinePositioned m -> a
f a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c), Int
p, Int
l, Int
lp)
Maybe Char
_ -> (a -> LinePositioned m -> a
f a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c), forall a. Enum a => a -> a
succ Int
p, Int
l, Int
lp)
foldl' :: forall a.
(a -> LinePositioned m -> a) -> a -> LinePositioned m -> a
foldl' a -> LinePositioned m -> a
f a
a0 (LinePositioned Int
p0 Int
l0 Int
lp0 m
c0) = forall a b c d. (a, b, c, d) -> a
fstOf4 forall a b. (a -> b) -> a -> b
$! forall m a. Factorial m => (a -> m -> a) -> a -> m -> a
Factorial.foldl' (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
f' (a
a0, Int
p0, Int
l0, Int
lp0) m
c0
where f' :: (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
f' (a
a, Int
p, Int
l, Int
lp) m
c = let a' :: a
a' = a -> LinePositioned m -> a
f a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c)
in seq :: forall a b. a -> b -> b
seq a
a' (case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
c
of Just Char
'\n' -> (a
a', forall a. Enum a => a -> a
succ Int
p, forall a. Enum a => a -> a
succ Int
l, Int
p)
Just Char
'\f' -> (a
a', forall a. Enum a => a -> a
succ Int
p, forall a. Enum a => a -> a
succ Int
l, Int
p)
Just Char
'\r' -> (a
a', forall a. Enum a => a -> a
succ Int
p, Int
l, Int
p)
Just Char
'\t' -> (a
a', forall a. Enum a => a -> a
succ Int
p, Int
l, Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8)
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> (a
a', Int
p, Int
l, Int
lp)
Maybe Char
_ -> (a
a', forall a. Enum a => a -> a
succ Int
p, Int
l, Int
lp))
foldr :: forall a.
(LinePositioned m -> a -> a) -> a -> LinePositioned m -> a
foldr LinePositioned m -> a -> a
f a
a0 (LinePositioned Int
p0 Int
l0 Int
lp0 m
c0) = forall m a. Factorial m => (m -> a -> a) -> a -> m -> a
Factorial.foldr m -> (Int -> Int -> Int -> a) -> Int -> Int -> Int -> a
f' (forall a b c d. a -> b -> c -> d -> a
const3 a
a0) m
c0 Int
p0 Int
l0 Int
lp0
where f' :: m -> (Int -> Int -> Int -> a) -> Int -> Int -> Int -> a
f' m
c Int -> Int -> Int -> a
cont Int
p Int
l Int
lp = case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
c
of Just Char
'\n' -> LinePositioned m -> a -> a
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c) forall a b. (a -> b) -> a -> b
$ ((Int -> Int -> Int -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p) forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
l) Int
p
Just Char
'\f' -> LinePositioned m -> a -> a
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c) forall a b. (a -> b) -> a -> b
$ ((Int -> Int -> Int -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p) forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
l) Int
p
Just Char
'\r' -> LinePositioned m -> a -> a
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c) forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p) Int
l Int
p
Just Char
'\t' -> LinePositioned m -> a -> a
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c) forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p) Int
l
forall a b. (a -> b) -> a -> b
$! Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> LinePositioned m -> a -> a
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c) forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int -> a
cont Int
p) Int
l Int
lp
Maybe Char
_ -> LinePositioned m -> a -> a
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c) forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p) Int
l Int
lp
foldMap :: forall n.
Monoid n =>
(LinePositioned m -> n) -> LinePositioned m -> n
foldMap LinePositioned m -> n
f (LinePositioned Int
p0 Int
l0 Int
lp0 m
c) = forall a. Endo a -> a -> a
appEndo (forall m n. (Factorial m, Monoid n) => (m -> n) -> m -> n
Factorial.foldMap m -> Endo (Int -> Int -> Int -> n)
f' m
c) (forall a b. a -> b -> a
const forall a. Monoid a => a
mempty) Int
p0 Int
l0 Int
lp0
where
f' :: m -> Endo (Int -> Int -> Int -> n)
f' m
prime = forall a. (a -> a) -> Endo a
Endo (\Int -> Int -> Int -> n
cont Int
p Int
l Int
lp-> LinePositioned m -> n
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prime)
forall a. Monoid a => a -> a -> a
`mappend`
case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
prime
of Just Char
'\n' -> Int -> Int -> Int -> n
cont (forall a. Enum a => a -> a
succ Int
p) (forall a. Enum a => a -> a
succ Int
l) Int
p
Just Char
'\f' -> Int -> Int -> Int -> n
cont (forall a. Enum a => a -> a
succ Int
p) (forall a. Enum a => a -> a
succ Int
l) Int
p
Just Char
'\r' -> Int -> Int -> Int -> n
cont (forall a. Enum a => a -> a
succ Int
p) Int
l Int
p
Just Char
'\t' -> Int -> Int -> Int -> n
cont (forall a. Enum a => a -> a
succ Int
p) Int
l (Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8)
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> Int -> Int -> Int -> n
cont Int
p Int
l Int
lp
Maybe Char
_ -> Int -> Int -> Int -> n
cont (forall a. Enum a => a -> a
succ Int
p) Int
l Int
lp)
length :: LinePositioned m -> Int
length = forall m. Factorial m => m -> Int
length forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. LinePositioned m -> m
extractLines
reverse :: LinePositioned m -> LinePositioned m
reverse (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall m. Factorial m => m -> m
Factorial.reverse m
c)
{-# INLINE primePrefix #-}
{-# INLINE foldl #-}
{-# INLINE foldl' #-}
{-# INLINE foldr #-}
{-# INLINE foldMap #-}
{-# INLINE length #-}
{-# INLINE reverse #-}
instance (StableFactorial m, TextualMonoid m) => FactorialMonoid (LinePositioned m) where
splitPrimePrefix :: LinePositioned m -> Maybe (LinePositioned m, LinePositioned m)
splitPrimePrefix (LinePositioned Int
p Int
l Int
lp m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {m} {t}.
(StableFactorial m, TextualMonoid m, TextualMonoid t) =>
(t, m) -> (LinePositioned t, LinePositioned m)
rewrap (forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimePrefix m
c)
where rewrap :: (t, m) -> (LinePositioned t, LinePositioned m)
rewrap (t
cp, m
cs) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp t
cp,
if forall m. MonoidNull m => m -> Bool
null m
cs then forall a. Monoid a => a
mempty
else case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix t
cp
of Just Char
'\n' -> forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' (forall a. Enum a => a -> a
succ Int
l) Int
p m
cs
Just Char
'\f' -> forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' (forall a. Enum a => a -> a
succ Int
l) Int
p m
cs
Just Char
'\r' -> forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' Int
l Int
p m
cs
Just Char
'\t' -> forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' Int
l (Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8) m
cs
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
cs
Maybe Char
_ -> forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' Int
l Int
lp m
cs)
p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
splitPrimeSuffix :: LinePositioned m -> Maybe (LinePositioned m, LinePositioned m)
splitPrimeSuffix (LinePositioned Int
p Int
l Int
lp m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {m} {m}.
TextualMonoid m =>
(m, m) -> (LinePositioned m, LinePositioned m)
rewrap (forall m. FactorialMonoid m => m -> Maybe (m, m)
splitPrimeSuffix m
c)
where rewrap :: (m, m) -> (LinePositioned m, LinePositioned m)
rewrap (m
cp, m
cs) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
cp, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' (Int
l forall a. Num a => a -> a -> a
+ Int
lines) (Int
p' forall a. Num a => a -> a -> a
- Int
columns) m
cs)
where len :: Int
len = forall m. Factorial m => m -> Int
length m
cp
(Int
lines, Int
columns) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns m
cp
p' :: Int
p' = Int
p forall a. Num a => a -> a -> a
+ Int
len
spanMaybe :: forall s.
s
-> (s -> LinePositioned m -> Maybe s)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, s)
spanMaybe s
s0 s -> LinePositioned m -> Maybe s
f (LinePositioned Int
p0 Int
l0 Int
lp0 m
c) = forall {m} {m} {c}.
(m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe (s
s0, Int
p0, Int
l0, Int
lp0) (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
f' m
c
where f' :: (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
f' (s
s, Int
p, Int
l, Int
lp) m
prime = do s
s' <- s -> LinePositioned m -> Maybe s
f s
s (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
l' :: Int
l' = forall a. Enum a => a -> a
succ Int
l
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! Int
p' seq :: forall a b. a -> b -> b
`seq` case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
prime
of Just Char
'\n' -> Int
l' seq :: forall a b. a -> b -> b
`seq` (s
s', Int
p', Int
l', Int
p)
Just Char
'\f' -> Int
l' seq :: forall a b. a -> b -> b
`seq` (s
s', Int
p', Int
l', Int
p)
Just Char
'\r' -> (s
s', Int
p', Int
l, Int
p)
Just Char
'\t' -> (s
s', Int
p', Int
l, Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8)
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> (s
s', Int
p, Int
l, Int
lp)
Maybe Char
_ -> (s
s', Int
p', Int
l, Int
lp)
rewrap :: (m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p, Int
l, Int
lp)) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
suffix, c
s)
spanMaybe' :: forall s.
s
-> (s -> LinePositioned m -> Maybe s)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, s)
spanMaybe' s
s0 s -> LinePositioned m -> Maybe s
f (LinePositioned Int
p0 Int
l0 Int
lp0 m
c) = forall {m} {m} {c}.
(m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe' (s
s0, Int
p0, Int
l0, Int
lp0) (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
f' m
c
where f' :: (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
f' (s
s, Int
p, Int
l, Int
lp) m
prime = do s
s' <- s -> LinePositioned m -> Maybe s
f s
s (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
l' :: Int
l' = forall a. Enum a => a -> a
succ Int
l
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` Int
p' seq :: forall a b. a -> b -> b
`seq` case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
prime
of Just Char
'\n' -> Int
l' seq :: forall a b. a -> b -> b
`seq` (s
s', Int
p', Int
l', Int
p)
Just Char
'\f' -> Int
l' seq :: forall a b. a -> b -> b
`seq` (s
s', Int
p', Int
l', Int
p)
Just Char
'\r' -> (s
s', Int
p', Int
l, Int
p)
Just Char
'\t' -> (s
s', Int
p', Int
l, Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8)
Just Char
ch | Char -> Bool
isZeroWidth Char
ch -> (s
s', Int
p, Int
l, Int
lp)
Maybe Char
_ -> (s
s', Int
p', Int
l, Int
lp)
rewrap :: (m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p, Int
l, Int
lp)) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
suffix, c
s)
span :: (LinePositioned m -> Bool)
-> LinePositioned m -> (LinePositioned m, LinePositioned m)
span LinePositioned m -> Bool
f (LinePositioned Int
p0 Int
l0 Int
lp0 m
t) = forall {m} {m}.
(m, m, (Int, Int, Int)) -> (LinePositioned m, LinePositioned m)
rewrap forall a b. (a -> b) -> a -> b
$ forall m s.
FactorialMonoid m =>
s -> (s -> m -> Maybe s) -> m -> (m, m, s)
Factorial.spanMaybe' (Int
p0, Int
l0, Int
lp0) (Int, Int, Int) -> m -> Maybe (Int, Int, Int)
f' m
t
where f' :: (Int, Int, Int) -> m -> Maybe (Int, Int, Int)
f' (Int
p, Int
l, Int
lp) m
prime = if LinePositioned m -> Bool
f (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prime)
then let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
l' :: Int
l' = forall a. Enum a => a -> a
succ Int
l
in forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! Int
p' seq :: forall a b. a -> b -> b
`seq` case forall t. TextualMonoid t => t -> Maybe Char
characterPrefix m
prime
of Just Char
'\n' -> Int
l' seq :: forall a b. a -> b -> b
`seq` (Int
p', Int
l', Int
p)
Just Char
'\f' -> Int
l' seq :: forall a b. a -> b -> b
`seq` (Int
p', Int
l', Int
p)
Just Char
'\r' -> (Int
p', Int
l, Int
p)
Just Char
'\t' -> (Int
p', Int
l, Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8)
Just Char
c | Char -> Bool
isZeroWidth Char
c -> (Int
p, Int
l, Int
lp)
Maybe Char
_ -> (Int
p', Int
l, Int
lp)
else forall a. Maybe a
Nothing
rewrap :: (m, m, (Int, Int, Int)) -> (LinePositioned m, LinePositioned m)
rewrap (m
prefix, m
suffix, (Int
p, Int
l, Int
lp)) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
suffix)
splitAt :: Int -> LinePositioned m -> (LinePositioned m, LinePositioned m)
splitAt Int
n m :: LinePositioned m
m@(LinePositioned Int
p Int
l Int
lp m
c) | Int
n forall a. Ord a => a -> a -> Bool
<= Int
0 = (forall a. Monoid a => a
mempty, LinePositioned m
m)
| Int
n forall a. Ord a => a -> a -> Bool
>= forall m. Factorial m => m -> Int
length m
c = (LinePositioned m
m, forall a. Monoid a => a
mempty)
| Bool
otherwise = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prefix,
forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' (Int
l forall a. Num a => a -> a -> a
+ Int
lines) (Int
p' forall a. Num a => a -> a -> a
- Int
columns) m
suffix)
where (m
prefix, m
suffix) = forall m. FactorialMonoid m => Int -> m -> (m, m)
splitAt Int
n m
c
(Int
lines, Int
columns) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns m
prefix
p' :: Int
p' = Int
p forall a. Num a => a -> a -> a
+ Int
n
take :: Int -> LinePositioned m -> LinePositioned m
take Int
n (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall m. FactorialMonoid m => Int -> m -> m
Factorial.take Int
n m
c)
{-# INLINE splitPrimePrefix #-}
{-# INLINE splitPrimeSuffix #-}
{-# INLINE span #-}
{-# INLINE splitAt #-}
{-# INLINE take #-}
instance StableFactorial m => StableFactorial (OffsetPositioned m)
instance (StableFactorial m, TextualMonoid m) => StableFactorial (LinePositioned m)
instance IsString m => IsString (OffsetPositioned m) where
fromString :: String -> OffsetPositioned m
fromString = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
instance IsString m => IsString (LinePositioned m) where
fromString :: String -> LinePositioned m
fromString = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString
instance (StableFactorial m, TextualMonoid m) => TextualMonoid (OffsetPositioned m) where
splitCharacterPrefix :: OffsetPositioned m -> Maybe (Char, OffsetPositioned m)
splitCharacterPrefix (OffsetPositioned Int
p m
t) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {m} {a}.
(FactorialMonoid m, StableFactorial m) =>
(a, m) -> (a, OffsetPositioned m)
rewrap (forall t. TextualMonoid t => t -> Maybe (Char, t)
splitCharacterPrefix m
t)
where rewrap :: (a, m) -> (a, OffsetPositioned m)
rewrap (a
c, m
cs) = if forall m. MonoidNull m => m -> Bool
null m
cs then (a
c, forall a. Monoid a => a
mempty) else (a
c, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (forall a. Enum a => a -> a
succ Int
p) m
cs)
fromText :: Text -> OffsetPositioned m
fromText = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Text -> t
fromText
singleton :: Char -> OffsetPositioned m
singleton = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Char -> t
singleton
characterPrefix :: OffsetPositioned m -> Maybe Char
characterPrefix = forall t. TextualMonoid t => t -> Maybe Char
characterPrefix forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. OffsetPositioned m -> m
extractOffset
map :: (Char -> Char) -> OffsetPositioned m -> OffsetPositioned m
map Char -> Char
f (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall t. TextualMonoid t => (Char -> Char) -> t -> t
map Char -> Char
f m
c)
concatMap :: (Char -> OffsetPositioned m)
-> OffsetPositioned m -> OffsetPositioned m
concatMap Char -> OffsetPositioned m
f (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall t. TextualMonoid t => (Char -> t) -> t -> t
concatMap (forall m. OffsetPositioned m -> m
extractOffset forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> OffsetPositioned m
f) m
c)
all :: (Char -> Bool) -> OffsetPositioned m -> Bool
all Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
all Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. OffsetPositioned m -> m
extractOffset
any :: (Char -> Bool) -> OffsetPositioned m -> Bool
any Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
any Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. OffsetPositioned m -> m
extractOffset
foldl :: forall a.
(a -> OffsetPositioned m -> a)
-> (a -> Char -> a) -> a -> OffsetPositioned m -> a
foldl a -> OffsetPositioned m -> a
ft a -> Char -> a
fc a
a0 (OffsetPositioned Int
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl (a, Int) -> m -> (a, Int)
ft' forall {b}. Enum b => (a, b) -> Char -> (a, b)
fc' (a
a0, Int
p0) m
c0
where ft' :: (a, Int) -> m -> (a, Int)
ft' (a
a, Int
p) m
c = (a -> OffsetPositioned m -> a
ft a
a (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
c), forall a. Enum a => a -> a
succ Int
p)
fc' :: (a, b) -> Char -> (a, b)
fc' (a
a, b
p) Char
c = (a -> Char -> a
fc a
a Char
c, forall a. Enum a => a -> a
succ b
p)
foldl' :: forall a.
(a -> OffsetPositioned m -> a)
-> (a -> Char -> a) -> a -> OffsetPositioned m -> a
foldl' a -> OffsetPositioned m -> a
ft a -> Char -> a
fc a
a0 (OffsetPositioned Int
p0 m
c0) = forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl' (a, Int) -> m -> (a, Int)
ft' forall {a}. Enum a => (a, a) -> Char -> (a, a)
fc' (a
a0, Int
p0) m
c0
where ft' :: (a, Int) -> m -> (a, Int)
ft' (a
a, Int
p) m
c = ((,) forall a b. (a -> b) -> a -> b
$! a -> OffsetPositioned m -> a
ft a
a (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
c)) forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p
fc' :: (a, a) -> Char -> (a, a)
fc' (a
a, a
p) Char
c = ((,) forall a b. (a -> b) -> a -> b
$! a -> Char -> a
fc a
a Char
c) forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ a
p
foldr :: forall a.
(OffsetPositioned m -> a -> a)
-> (Char -> a -> a) -> a -> OffsetPositioned m -> a
foldr OffsetPositioned m -> a -> a
ft Char -> a -> a
fc a
a0 (OffsetPositioned Int
p0 m
c0) = forall a b. (a, b) -> b
snd forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
Textual.foldr m -> (Int, a) -> (Int, a)
ft' forall {a}. Enum a => Char -> (a, a) -> (a, a)
fc' (Int
p0, a
a0) m
c0
where ft' :: m -> (Int, a) -> (Int, a)
ft' m
c (Int
p, a
a) = (forall a. Enum a => a -> a
succ Int
p, OffsetPositioned m -> a -> a
ft (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
c) a
a)
fc' :: Char -> (a, a) -> (a, a)
fc' Char
c (a
p, a
a) = (forall a. Enum a => a -> a
succ a
p, Char -> a -> a
fc Char
c a
a)
scanl :: (Char -> Char -> Char)
-> Char -> OffsetPositioned m -> OffsetPositioned m
scanl Char -> Char -> Char
f Char
ch (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> t -> t
Textual.scanl Char -> Char -> Char
f Char
ch m
c)
scanl1 :: (Char -> Char -> Char) -> OffsetPositioned m -> OffsetPositioned m
scanl1 Char -> Char -> Char
f (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall t. TextualMonoid t => (Char -> Char -> Char) -> t -> t
Textual.scanl1 Char -> Char -> Char
f m
c)
scanr :: (Char -> Char -> Char)
-> Char -> OffsetPositioned m -> OffsetPositioned m
scanr Char -> Char -> Char
f Char
ch (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> t -> t
Textual.scanr Char -> Char -> Char
f Char
ch m
c)
scanr1 :: (Char -> Char -> Char) -> OffsetPositioned m -> OffsetPositioned m
scanr1 Char -> Char -> Char
f (OffsetPositioned Int
p m
c) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall t. TextualMonoid t => (Char -> Char -> Char) -> t -> t
Textual.scanr1 Char -> Char -> Char
f m
c)
mapAccumL :: forall a.
(a -> Char -> (a, Char))
-> a -> OffsetPositioned m -> (a, OffsetPositioned m)
mapAccumL a -> Char -> (a, Char)
f a
a0 (OffsetPositioned Int
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p) (forall t a.
TextualMonoid t =>
(a -> Char -> (a, Char)) -> a -> t -> (a, t)
Textual.mapAccumL a -> Char -> (a, Char)
f a
a0 m
c)
mapAccumR :: forall a.
(a -> Char -> (a, Char))
-> a -> OffsetPositioned m -> (a, OffsetPositioned m)
mapAccumR a -> Char -> (a, Char)
f a
a0 (OffsetPositioned Int
p m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p) (forall t a.
TextualMonoid t =>
(a -> Char -> (a, Char)) -> a -> t -> (a, t)
Textual.mapAccumR a -> Char -> (a, Char)
f a
a0 m
c)
spanMaybe :: forall s.
s
-> (s -> OffsetPositioned m -> Maybe s)
-> (s -> Char -> Maybe s)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, s)
spanMaybe s
s0 s -> OffsetPositioned m -> Maybe s
ft s -> Char -> Maybe s
fc (OffsetPositioned Int
p0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe (s
s0, Int
p0) (s, Int) -> m -> Maybe (s, Int)
ft' forall {b}. Enum b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
where ft' :: (s, Int) -> m -> Maybe (s, Int)
ft' (s
s, Int
p) m
prime = do s
s' <- s -> OffsetPositioned m -> Maybe s
ft s
s (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq Int
p' (s
s', Int
p')
fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
let p' :: b
p' = forall a. Enum a => a -> a
succ b
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq b
p' (s
s', b
p')
rewrap :: (m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p)) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix, c
s)
spanMaybe' :: forall s.
s
-> (s -> OffsetPositioned m -> Maybe s)
-> (s -> Char -> Maybe s)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, s)
spanMaybe' s
s0 s -> OffsetPositioned m -> Maybe s
ft s -> Char -> Maybe s
fc (OffsetPositioned Int
p0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe' (s
s0, Int
p0) (s, Int) -> m -> Maybe (s, Int)
ft' forall {b}. Enum b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
where ft' :: (s, Int) -> m -> Maybe (s, Int)
ft' (s
s, Int
p) m
prime = do s
s' <- s -> OffsetPositioned m -> Maybe s
ft s
s (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` Int
p' seq :: forall a b. a -> b -> b
`seq` (s
s', Int
p')
fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
let p' :: b
p' = forall a. Enum a => a -> a
succ b
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` b
p' seq :: forall a b. a -> b -> b
`seq` (s
s', b
p')
rewrap :: (m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p)) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix, c
s)
span :: (OffsetPositioned m -> Bool)
-> (Char -> Bool)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m)
span OffsetPositioned m -> Bool
ft Char -> Bool
fc (OffsetPositioned Int
p0 m
t) = forall {m} {m}.
(m, m, Int) -> (OffsetPositioned m, OffsetPositioned m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe' Int
p0 Int -> m -> Maybe Int
ft' forall {a}. Enum a => a -> Char -> Maybe a
fc' m
t
where ft' :: Int -> m -> Maybe Int
ft' Int
p m
prime = if OffsetPositioned m -> Bool
ft (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
prime)
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p
else forall a. Maybe a
Nothing
fc' :: a -> Char -> Maybe a
fc' a
p Char
c = if Char -> Bool
fc Char
c
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ a
p
else forall a. Maybe a
Nothing
rewrap :: (m, m, Int) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (m
prefix, m
suffix, Int
p) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix)
split :: (Char -> Bool) -> OffsetPositioned m -> [OffsetPositioned m]
split Char -> Bool
f (OffsetPositioned Int
p0 m
c0) = forall {m}. Factorial m => Int -> [m] -> [OffsetPositioned m]
rewrap Int
p0 (forall t. TextualMonoid t => (Char -> Bool) -> t -> [t]
Textual.split Char -> Bool
f m
c0)
where rewrap :: Int -> [m] -> [OffsetPositioned m]
rewrap Int
_ [] = []
rewrap Int
p (m
c:[m]
rest) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
c forall a. a -> [a] -> [a]
: Int -> [m] -> [OffsetPositioned m]
rewrap (Int
p forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
c) [m]
rest
find :: (Char -> Bool) -> OffsetPositioned m -> Maybe Char
find Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Maybe Char
find Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. OffsetPositioned m -> m
extractOffset
foldl_ :: forall a. (a -> Char -> a) -> a -> OffsetPositioned m -> a
foldl_ a -> Char -> a
fc a
a0 (OffsetPositioned Int
_ m
c) = forall t a. TextualMonoid t => (a -> Char -> a) -> a -> t -> a
Textual.foldl_ a -> Char -> a
fc a
a0 m
c
foldl_' :: forall a. (a -> Char -> a) -> a -> OffsetPositioned m -> a
foldl_' a -> Char -> a
fc a
a0 (OffsetPositioned Int
_ m
c) = forall t a. TextualMonoid t => (a -> Char -> a) -> a -> t -> a
Textual.foldl_' a -> Char -> a
fc a
a0 m
c
foldr_ :: forall a. (Char -> a -> a) -> a -> OffsetPositioned m -> a
foldr_ Char -> a -> a
fc a
a0 (OffsetPositioned Int
_ m
c) = forall t a. TextualMonoid t => (Char -> a -> a) -> a -> t -> a
Textual.foldr_ Char -> a -> a
fc a
a0 m
c
spanMaybe_ :: forall s.
s
-> (s -> Char -> Maybe s)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, s)
spanMaybe_ s
s0 s -> Char -> Maybe s
fc (OffsetPositioned Int
p0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe_' (s
s0, Int
p0) forall {b}. Enum b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
where fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
let p' :: b
p' = forall a. Enum a => a -> a
succ b
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq b
p' (s
s', b
p')
rewrap :: (m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p)) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix, c
s)
spanMaybe_' :: forall s.
s
-> (s -> Char -> Maybe s)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m, s)
spanMaybe_' s
s0 s -> Char -> Maybe s
fc (OffsetPositioned Int
p0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall t s.
TextualMonoid t =>
s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe_' (s
s0, Int
p0) forall {b}. Enum b => (s, b) -> Char -> Maybe (s, b)
fc' m
t
where fc' :: (s, b) -> Char -> Maybe (s, b)
fc' (s
s, b
p) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
let p' :: b
p' = forall a. Enum a => a -> a
succ b
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` b
p' seq :: forall a b. a -> b -> b
`seq` (s
s', b
p')
rewrap :: (m, m, (c, Int)) -> (OffsetPositioned m, OffsetPositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p)) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p m
suffix, c
s)
span_ :: Bool
-> (Char -> Bool)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m)
span_ Bool
bt Char -> Bool
fc (OffsetPositioned Int
p0 m
t) = forall {m} {m}.
Factorial m =>
(m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
Textual.span_ Bool
bt Char -> Bool
fc m
t
where rewrap :: (m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (m
prefix, m
suffix) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p0 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
prefix) m
suffix)
break_ :: Bool
-> (Char -> Bool)
-> OffsetPositioned m
-> (OffsetPositioned m, OffsetPositioned m)
break_ Bool
bt Char -> Bool
fc (OffsetPositioned Int
p0 m
t) = forall {m} {m}.
Factorial m =>
(m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
Textual.break_ Bool
bt Char -> Bool
fc m
t
where rewrap :: (m, m) -> (OffsetPositioned m, OffsetPositioned m)
rewrap (m
prefix, m
suffix) = (forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p0 m
prefix, forall m. Int -> m -> OffsetPositioned m
OffsetPositioned (Int
p0 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
prefix) m
suffix)
dropWhile_ :: Bool -> (Char -> Bool) -> OffsetPositioned m -> OffsetPositioned m
dropWhile_ Bool
bt Char -> Bool
fc OffsetPositioned m
t = forall a b. (a, b) -> b
snd (forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
span_ Bool
bt Char -> Bool
fc OffsetPositioned m
t)
takeWhile_ :: Bool -> (Char -> Bool) -> OffsetPositioned m -> OffsetPositioned m
takeWhile_ Bool
bt Char -> Bool
fc (OffsetPositioned Int
p m
t) = forall m. Int -> m -> OffsetPositioned m
OffsetPositioned Int
p (forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> t
takeWhile_ Bool
bt Char -> Bool
fc m
t)
toString :: (OffsetPositioned m -> String) -> OffsetPositioned m -> String
toString OffsetPositioned m -> String
ft (OffsetPositioned Int
_ m
t) = forall t. TextualMonoid t => (t -> String) -> t -> String
toString (OffsetPositioned m -> String
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure) m
t
toText :: (OffsetPositioned m -> Text) -> OffsetPositioned m -> Text
toText OffsetPositioned m -> Text
ft (OffsetPositioned Int
_ m
t) = forall t. TextualMonoid t => (t -> Text) -> t -> Text
toText (OffsetPositioned m -> Text
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure) m
t
{-# INLINE characterPrefix #-}
{-# INLINE splitCharacterPrefix #-}
{-# INLINE map #-}
{-# INLINE concatMap #-}
{-# INLINE foldl' #-}
{-# INLINE foldr #-}
{-# INLINABLE spanMaybe #-}
{-# INLINABLE spanMaybe' #-}
{-# INLINABLE span #-}
{-# INLINE foldl_' #-}
{-# INLINE foldr_ #-}
{-# INLINE any #-}
{-# INLINE all #-}
{-# INLINABLE spanMaybe_ #-}
{-# INLINABLE spanMaybe_' #-}
{-# INLINE span_ #-}
{-# INLINE break_ #-}
{-# INLINE dropWhile_ #-}
{-# INLINE takeWhile_ #-}
{-# INLINE split #-}
{-# INLINE find #-}
instance (StableFactorial m, TextualMonoid m) => TextualMonoid (LinePositioned m) where
splitCharacterPrefix :: LinePositioned m -> Maybe (Char, LinePositioned m)
splitCharacterPrefix (LinePositioned Int
p Int
l Int
lp m
t) =
case forall t. TextualMonoid t => t -> Maybe (Char, t)
splitCharacterPrefix m
t
of Maybe (Char, m)
Nothing -> forall a. Maybe a
Nothing
Just (Char
c, m
rest) | forall m. MonoidNull m => m -> Bool
null m
rest -> forall a. a -> Maybe a
Just (Char
c, forall a. Monoid a => a
mempty)
Just (Char
'\n', m
rest) -> forall a. a -> Maybe a
Just (Char
'\n', forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' (forall a. Enum a => a -> a
succ Int
l) Int
p m
rest)
Just (Char
'\f', m
rest) -> forall a. a -> Maybe a
Just (Char
'\f', forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' (forall a. Enum a => a -> a
succ Int
l) Int
p m
rest)
Just (Char
'\r', m
rest) -> forall a. a -> Maybe a
Just (Char
'\r', forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' Int
l Int
p m
rest)
Just (Char
'\t', m
rest) -> forall a. a -> Maybe a
Just (Char
'\t', forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' Int
l (Int
lp forall a. Num a => a -> a -> a
+ (Int
p forall a. Num a => a -> a -> a
- Int
lp) forall a. Integral a => a -> a -> a
`mod` Int
8 forall a. Num a => a -> a -> a
- Int
8) m
rest)
Just (Char
ch, m
rest)
| Char -> Bool
isZeroWidth Char
ch -> forall a. a -> Maybe a
Just (Char
ch, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
rest)
| Bool
otherwise -> forall a. a -> Maybe a
Just (Char
ch, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p' Int
l Int
lp m
rest)
where p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
fromText :: Text -> LinePositioned m
fromText = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Text -> t
fromText
singleton :: Char -> LinePositioned m
singleton = forall (f :: * -> *) a. Applicative f => a -> f a
pure forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall t. TextualMonoid t => Char -> t
singleton
characterPrefix :: LinePositioned m -> Maybe Char
characterPrefix = forall t. TextualMonoid t => t -> Maybe Char
characterPrefix forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. LinePositioned m -> m
extractLines
map :: (Char -> Char) -> LinePositioned m -> LinePositioned m
map Char -> Char
f (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall t. TextualMonoid t => (Char -> Char) -> t -> t
map Char -> Char
f m
c)
concatMap :: (Char -> LinePositioned m) -> LinePositioned m -> LinePositioned m
concatMap Char -> LinePositioned m
f (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall t. TextualMonoid t => (Char -> t) -> t -> t
concatMap (forall m. LinePositioned m -> m
extractLines forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> LinePositioned m
f) m
c)
all :: (Char -> Bool) -> LinePositioned m -> Bool
all Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
all Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. LinePositioned m -> m
extractLines
any :: (Char -> Bool) -> LinePositioned m -> Bool
any Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Bool
any Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. LinePositioned m -> m
extractLines
foldl :: forall a.
(a -> LinePositioned m -> a)
-> (a -> Char -> a) -> a -> LinePositioned m -> a
foldl a -> LinePositioned m -> a
ft a -> Char -> a
fc a
a0 (LinePositioned Int
p0 Int
l0 Int
lp0 m
c0) = forall a b c d. (a, b, c, d) -> a
fstOf4 forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
ft' forall {d} {c}.
(Enum c, Integral d) =>
(a, d, c, d) -> Char -> (a, d, c, d)
fc' (a
a0, Int
p0, Int
l0, Int
lp0) m
c0
where ft' :: (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
ft' (a
a, Int
p, Int
l, Int
lp) m
c = (a -> LinePositioned m -> a
ft a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c), forall a. Enum a => a -> a
succ Int
p, Int
l, Int
lp)
fc' :: (a, d, c, d) -> Char -> (a, d, c, d)
fc' (a
a, d
p, c
l, d
_lp) Char
'\n' = (a -> Char -> a
fc a
a Char
'\n', forall a. Enum a => a -> a
succ d
p, forall a. Enum a => a -> a
succ c
l, d
p)
fc' (a
a, d
p, c
l, d
_lp) Char
'\f' = (a -> Char -> a
fc a
a Char
'\f', forall a. Enum a => a -> a
succ d
p, forall a. Enum a => a -> a
succ c
l, d
p)
fc' (a
a, d
p, c
l, d
_lp) Char
'\r' = (a -> Char -> a
fc a
a Char
'\r', forall a. Enum a => a -> a
succ d
p, c
l, d
p)
fc' (a
a, d
p, c
l, d
lp) Char
'\t' = (a -> Char -> a
fc a
a Char
'\t', forall a. Enum a => a -> a
succ d
p, c
l, d
lp forall a. Num a => a -> a -> a
+ (d
p forall a. Num a => a -> a -> a
- d
lp) forall a. Integral a => a -> a -> a
`mod` d
8 forall a. Num a => a -> a -> a
- d
8)
fc' (a
a, d
p, c
l, d
lp) Char
c
| Char -> Bool
isZeroWidth Char
c = (a -> Char -> a
fc a
a Char
c, d
p, c
l, d
lp)
| Bool
otherwise = (a -> Char -> a
fc a
a Char
c, forall a. Enum a => a -> a
succ d
p, c
l, d
lp)
foldl' :: forall a.
(a -> LinePositioned m -> a)
-> (a -> Char -> a) -> a -> LinePositioned m -> a
foldl' a -> LinePositioned m -> a
ft a -> Char -> a
fc a
a0 (LinePositioned Int
p0 Int
l0 Int
lp0 m
c0) = forall a b c d. (a, b, c, d) -> a
fstOf4 forall a b. (a -> b) -> a -> b
$ forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl' (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
ft' forall {d} {a}.
(Integral d, Enum a) =>
(a, d, a, d) -> Char -> (a, d, a, d)
fc' (a
a0, Int
p0, Int
l0, Int
lp0) m
c0
where ft' :: (a, Int, Int, Int) -> m -> (a, Int, Int, Int)
ft' (a
a, Int
p, Int
l, Int
lp) m
c = let a' :: a
a' = a -> LinePositioned m -> a
ft a
a (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c)
p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
in a
a' seq :: forall a b. a -> b -> b
`seq` Int
p' seq :: forall a b. a -> b -> b
`seq` (a
a', Int
p', Int
l, Int
lp)
fc' :: (a, d, a, d) -> Char -> (a, d, a, d)
fc' (a
a, d
p, a
l, d
lp) Char
c = let a' :: a
a' = a -> Char -> a
fc a
a Char
c
p' :: d
p' = forall a. Enum a => a -> a
succ d
p
l' :: a
l' = forall a. Enum a => a -> a
succ a
l
in a
a' seq :: forall a b. a -> b -> b
`seq` d
p' seq :: forall a b. a -> b -> b
`seq` case Char
c
of Char
'\n' -> a
l' seq :: forall a b. a -> b -> b
`seq` (a
a', d
p', a
l', d
p)
Char
'\f' -> a
l' seq :: forall a b. a -> b -> b
`seq` (a
a', d
p', a
l', d
p)
Char
'\r' -> (a
a', d
p', a
l, d
p)
Char
'\t' -> (a
a', d
p', a
l, d
lp forall a. Num a => a -> a -> a
+ (d
p forall a. Num a => a -> a -> a
- d
lp) forall a. Integral a => a -> a -> a
`mod` d
8 forall a. Num a => a -> a -> a
- d
8)
Char
_ | Char -> Bool
isZeroWidth Char
c -> (a
a', d
p, a
l, d
lp)
Char
_ -> (a
a', d
p', a
l, d
lp)
foldr :: forall a.
(LinePositioned m -> a -> a)
-> (Char -> a -> a) -> a -> LinePositioned m -> a
foldr LinePositioned m -> a -> a
ft Char -> a -> a
fc a
a0 (LinePositioned Int
p0 Int
l0 Int
lp0 m
c0) = forall t a.
TextualMonoid t =>
(t -> a -> a) -> (Char -> a -> a) -> a -> t -> a
Textual.foldr m -> (Int -> Int -> Int -> a) -> Int -> Int -> Int -> a
ft' forall {t} {t}.
(Enum t, Integral t) =>
Char -> (t -> t -> t -> a) -> t -> t -> t -> a
fc' (forall a b c d. a -> b -> c -> d -> a
const3 a
a0) m
c0 Int
p0 Int
l0 Int
lp0
where ft' :: m -> (Int -> Int -> Int -> a) -> Int -> Int -> Int -> a
ft' m
c Int -> Int -> Int -> a
cont Int
p Int
l Int
lp = LinePositioned m -> a -> a
ft (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c) forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ Int
p) Int
l Int
lp
fc' :: Char -> (t -> t -> t -> a) -> t -> t -> t -> a
fc' Char
c t -> t -> t -> a
cont t
p t
l t
lp
| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\n' = Char -> a -> a
fc Char
c forall a b. (a -> b) -> a -> b
$ ((t -> t -> t -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ t
p) forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ t
l) t
p
| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\f' = Char -> a -> a
fc Char
c forall a b. (a -> b) -> a -> b
$ ((t -> t -> t -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ t
p) forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ t
l) t
p
| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\r' = Char -> a -> a
fc Char
c forall a b. (a -> b) -> a -> b
$ (t -> t -> t -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ t
p) t
l t
p
| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\t' = Char -> a -> a
fc Char
c forall a b. (a -> b) -> a -> b
$ (t -> t -> t -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ t
p) t
l (t
lp forall a. Num a => a -> a -> a
+ (t
p forall a. Num a => a -> a -> a
- t
lp) forall a. Integral a => a -> a -> a
`mod` t
8 forall a. Num a => a -> a -> a
- t
8)
| Char -> Bool
isZeroWidth Char
c = Char -> a -> a
fc Char
c forall a b. (a -> b) -> a -> b
$ (t -> t -> t -> a
cont t
p) t
l t
lp
| Bool
otherwise = Char -> a -> a
fc Char
c forall a b. (a -> b) -> a -> b
$ (t -> t -> t -> a
cont forall a b. (a -> b) -> a -> b
$! forall a. Enum a => a -> a
succ t
p) t
l t
lp
spanMaybe :: forall s.
s
-> (s -> LinePositioned m -> Maybe s)
-> (s -> Char -> Maybe s)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, s)
spanMaybe s
s0 s -> LinePositioned m -> Maybe s
ft s -> Char -> Maybe s
fc (LinePositioned Int
p0 Int
l0 Int
lp0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe (s
s0, Int
p0, Int
l0, Int
lp0) (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
ft' forall {d} {c}.
(Integral d, Enum c) =>
(s, d, c, d) -> Char -> Maybe (s, d, c, d)
fc' m
t
where ft' :: (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
ft' (s
s, Int
p, Int
l, Int
lp) m
prime = do s
s' <- s -> LinePositioned m -> Maybe s
ft s
s (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq Int
p' (s
s', Int
p', Int
l, Int
lp)
fc' :: (s, d, c, d) -> Char -> Maybe (s, d, c, d)
fc' (s
s, d
p, c
l, d
lp) Char
c =
s -> Char -> Maybe s
fc s
s Char
c
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \s
s'-> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq d
p' (if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\n' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\f' then seq :: forall a b. a -> b -> b
seq c
l' (s
s', d
p', c
l', d
p)
else if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\r' then (s
s', d
p', c
l, d
p)
else if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\t' then (s
s', d
p', c
l, d
lp forall a. Num a => a -> a -> a
+ (d
p forall a. Num a => a -> a -> a
- d
lp) forall a. Integral a => a -> a -> a
`mod` d
8 forall a. Num a => a -> a -> a
- d
8)
else if Char -> Bool
isZeroWidth Char
c then (s
s', d
p, c
l, d
lp)
else (s
s', d
p', c
l, d
lp))
where p' :: d
p' = forall a. Enum a => a -> a
succ d
p
l' :: c
l' = forall a. Enum a => a -> a
succ c
l
rewrap :: (m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p, Int
l, Int
lp)) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
suffix, c
s)
spanMaybe' :: forall s.
s
-> (s -> LinePositioned m -> Maybe s)
-> (s -> Char -> Maybe s)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, s)
spanMaybe' s
s0 s -> LinePositioned m -> Maybe s
ft s -> Char -> Maybe s
fc (LinePositioned Int
p0 Int
l0 Int
lp0 m
t) = forall {m} {m} {c}.
(m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$! forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe' (s
s0, Int
p0, Int
l0, Int
lp0) (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
ft' forall {d} {c}.
(Integral d, Enum c) =>
(s, d, c, d) -> Char -> Maybe (s, d, c, d)
fc' m
t
where ft' :: (s, Int, Int, Int) -> m -> Maybe (s, Int, Int, Int)
ft' (s
s, Int
p, Int
l, Int
lp) m
prime = do s
s' <- s -> LinePositioned m -> Maybe s
ft s
s (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prime)
let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` Int
p' seq :: forall a b. a -> b -> b
`seq` (s
s', Int
p', Int
l, Int
lp)
fc' :: (s, d, c, d) -> Char -> Maybe (s, d, c, d)
fc' (s
s, d
p, c
l, d
lp) Char
c = do s
s' <- s -> Char -> Maybe s
fc s
s Char
c
let p' :: d
p' = forall a. Enum a => a -> a
succ d
p
l' :: c
l' = forall a. Enum a => a -> a
succ c
l
forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! s
s' seq :: forall a b. a -> b -> b
`seq` d
p'
seq :: forall a b. a -> b -> b
`seq` (if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\n' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\f' then seq :: forall a b. a -> b -> b
seq c
l' (s
s', d
p', c
l', d
p)
else if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\r' then (s
s', d
p', c
l, d
p)
else if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\t' then (s
s', d
p', c
l, d
lp forall a. Num a => a -> a -> a
+ (d
p forall a. Num a => a -> a -> a
- d
lp) forall a. Integral a => a -> a -> a
`mod` d
8 forall a. Num a => a -> a -> a
- d
8)
else if Char -> Bool
isZeroWidth Char
c then (s
s', d
p, c
l, d
lp)
else (s
s', d
p', c
l, d
lp))
rewrap :: (m, m, (c, Int, Int, Int))
-> (LinePositioned m, LinePositioned m, c)
rewrap (m
prefix, m
suffix, (c
s, Int
p, Int
l, Int
lp)) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
suffix, c
s)
span :: (LinePositioned m -> Bool)
-> (Char -> Bool)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m)
span LinePositioned m -> Bool
ft Char -> Bool
fc (LinePositioned Int
p0 Int
l0 Int
lp0 m
t) = forall {m} {m}.
(m, m, (Int, Int, Int)) -> (LinePositioned m, LinePositioned m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s
-> (s -> t -> Maybe s) -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe' (Int
p0, Int
l0, Int
lp0) (Int, Int, Int) -> m -> Maybe (Int, Int, Int)
ft' forall {c} {b}.
(Integral c, Enum b) =>
(c, b, c) -> Char -> Maybe (c, b, c)
fc' m
t
where ft' :: (Int, Int, Int) -> m -> Maybe (Int, Int, Int)
ft' (Int
p, Int
l, Int
lp) m
prime = if LinePositioned m -> Bool
ft (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
prime)
then let p' :: Int
p' = forall a. Enum a => a -> a
succ Int
p
in Int
p' seq :: forall a b. a -> b -> b
`seq` forall a. a -> Maybe a
Just (Int
p', Int
l, Int
lp)
else forall a. Maybe a
Nothing
fc' :: (c, b, c) -> Char -> Maybe (c, b, c)
fc' (c
p, b
l, c
lp) Char
c | Char -> Bool
fc Char
c = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$! seq :: forall a b. a -> b -> b
seq c
p'
forall a b. (a -> b) -> a -> b
$ if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\n' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'\f' then seq :: forall a b. a -> b -> b
seq b
l' (c
p', b
l', c
p)
else if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\r' then (c
p', b
l, c
p)
else if Char
c forall a. Eq a => a -> a -> Bool
== Char
'\t' then (c
p', b
l, c
lp forall a. Num a => a -> a -> a
+ (c
p forall a. Num a => a -> a -> a
- c
lp) forall a. Integral a => a -> a -> a
`mod` c
8 forall a. Num a => a -> a -> a
- c
8)
else if Char -> Bool
isZeroWidth Char
c then (c
p, b
l, c
lp)
else (c
p', b
l, c
lp)
| Bool
otherwise = forall a. Maybe a
Nothing
where p' :: c
p' = forall a. Enum a => a -> a
succ c
p
l' :: b
l' = forall a. Enum a => a -> a
succ b
l
rewrap :: (m, m, (Int, Int, Int)) -> (LinePositioned m, LinePositioned m)
rewrap (m
prefix, m
suffix, (Int
p, Int
l, Int
lp)) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
suffix)
scanl :: (Char -> Char -> Char)
-> Char -> LinePositioned m -> LinePositioned m
scanl Char -> Char -> Char
f Char
ch (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> t -> t
Textual.scanl Char -> Char -> Char
f Char
ch m
c)
scanl1 :: (Char -> Char -> Char) -> LinePositioned m -> LinePositioned m
scanl1 Char -> Char -> Char
f (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall t. TextualMonoid t => (Char -> Char -> Char) -> t -> t
Textual.scanl1 Char -> Char -> Char
f m
c)
scanr :: (Char -> Char -> Char)
-> Char -> LinePositioned m -> LinePositioned m
scanr Char -> Char -> Char
f Char
ch (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall t.
TextualMonoid t =>
(Char -> Char -> Char) -> Char -> t -> t
Textual.scanr Char -> Char -> Char
f Char
ch m
c)
scanr1 :: (Char -> Char -> Char) -> LinePositioned m -> LinePositioned m
scanr1 Char -> Char -> Char
f (LinePositioned Int
p Int
l Int
lp m
c) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall t. TextualMonoid t => (Char -> Char -> Char) -> t -> t
Textual.scanr1 Char -> Char -> Char
f m
c)
mapAccumL :: forall a.
(a -> Char -> (a, Char))
-> a -> LinePositioned m -> (a, LinePositioned m)
mapAccumL a -> Char -> (a, Char)
f a
a0 (LinePositioned Int
p Int
l Int
lp m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp) (forall t a.
TextualMonoid t =>
(a -> Char -> (a, Char)) -> a -> t -> (a, t)
Textual.mapAccumL a -> Char -> (a, Char)
f a
a0 m
c)
mapAccumR :: forall a.
(a -> Char -> (a, Char))
-> a -> LinePositioned m -> (a, LinePositioned m)
mapAccumR a -> Char -> (a, Char)
f a
a0 (LinePositioned Int
p Int
l Int
lp m
c) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp) (forall t a.
TextualMonoid t =>
(a -> Char -> (a, Char)) -> a -> t -> (a, t)
Textual.mapAccumR a -> Char -> (a, Char)
f a
a0 m
c)
split :: (Char -> Bool) -> LinePositioned m -> [LinePositioned m]
split Char -> Bool
f (LinePositioned Int
p0 Int
l0 Int
lp0 m
c0) = forall {m}.
TextualMonoid m =>
Int -> Int -> Int -> [m] -> [LinePositioned m]
rewrap Int
p0 Int
l0 Int
lp0 (forall t. TextualMonoid t => (Char -> Bool) -> t -> [t]
Textual.split Char -> Bool
f m
c0)
where rewrap :: Int -> Int -> Int -> [m] -> [LinePositioned m]
rewrap Int
_ Int
_ Int
_ [] = []
rewrap Int
p Int
l Int
lp (m
c:[m]
rest) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp m
c
forall a. a -> [a] -> [a]
: Int -> Int -> Int -> [m] -> [LinePositioned m]
rewrap Int
p' (Int
l forall a. Num a => a -> a -> a
+ Int
lines) (if Int
lines forall a. Eq a => a -> a -> Bool
== Int
0 then Int
lp else Int
p' forall a. Num a => a -> a -> a
- Int
columns) [m]
rest
where p' :: Int
p' = Int
p forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
c
(Int
lines, Int
columns) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns m
c
find :: (Char -> Bool) -> LinePositioned m -> Maybe Char
find Char -> Bool
p = forall t. TextualMonoid t => (Char -> Bool) -> t -> Maybe Char
find Char -> Bool
p forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall m. LinePositioned m -> m
extractLines
foldl_ :: forall a. (a -> Char -> a) -> a -> LinePositioned m -> a
foldl_ a -> Char -> a
fc a
a0 (LinePositioned Int
_ Int
_ Int
_ m
t) = forall t a. TextualMonoid t => (a -> Char -> a) -> a -> t -> a
Textual.foldl_ a -> Char -> a
fc a
a0 m
t
foldl_' :: forall a. (a -> Char -> a) -> a -> LinePositioned m -> a
foldl_' a -> Char -> a
fc a
a0 (LinePositioned Int
_ Int
_ Int
_ m
t) = forall t a. TextualMonoid t => (a -> Char -> a) -> a -> t -> a
Textual.foldl_' a -> Char -> a
fc a
a0 m
t
foldr_ :: forall a. (Char -> a -> a) -> a -> LinePositioned m -> a
foldr_ Char -> a -> a
fc a
a0 (LinePositioned Int
_ Int
_ Int
_ m
t) = forall t a. TextualMonoid t => (Char -> a -> a) -> a -> t -> a
Textual.foldr_ Char -> a -> a
fc a
a0 m
t
spanMaybe_ :: forall s.
s
-> (s -> Char -> Maybe s)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, s)
spanMaybe_ s
s0 s -> Char -> Maybe s
fc (LinePositioned Int
p0 Int
l0 Int
lp0 m
t) = forall {m} {m} {c}.
TextualMonoid m =>
(m, m, c) -> (LinePositioned m, LinePositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe_ s
s0 s -> Char -> Maybe s
fc m
t
where rewrap :: (m, m, c) -> (LinePositioned m, LinePositioned m, c)
rewrap (m
prefix, m
suffix, c
s) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix,
forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p1 (Int
l0 forall a. Num a => a -> a -> a
+ Int
l) (if Int
l forall a. Eq a => a -> a -> Bool
== Int
0 then Int
lp0 else Int
p1 forall a. Num a => a -> a -> a
- Int
col) m
suffix,
c
s)
where (Int
l, Int
col) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns m
prefix
p1 :: Int
p1 = Int
p0 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
prefix
spanMaybe_' :: forall s.
s
-> (s -> Char -> Maybe s)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m, s)
spanMaybe_' s
s0 s -> Char -> Maybe s
fc (LinePositioned Int
p0 Int
l0 Int
lp0 m
t) = forall {m} {m} {c}.
TextualMonoid m =>
(m, m, c) -> (LinePositioned m, LinePositioned m, c)
rewrap forall a b. (a -> b) -> a -> b
$ forall t s.
TextualMonoid t =>
s -> (s -> Char -> Maybe s) -> t -> (t, t, s)
Textual.spanMaybe_' s
s0 s -> Char -> Maybe s
fc m
t
where rewrap :: (m, m, c) -> (LinePositioned m, LinePositioned m, c)
rewrap (m
prefix, m
suffix, c
s) = Int
p1 seq :: forall a b. a -> b -> b
`seq` Int
l1 seq :: forall a b. a -> b -> b
`seq` Int
lp1 seq :: forall a b. a -> b -> b
`seq`
(forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix, forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p1 Int
l1 Int
lp1 m
suffix, c
s)
where (Int
l, Int
col) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
prefix
p1 :: Int
p1 = Int
p0 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
prefix
l1 :: Int
l1 = Int
l0 forall a. Num a => a -> a -> a
+ Int
l
lp1 :: Int
lp1 = if Int
l forall a. Eq a => a -> a -> Bool
== Int
0 then Int
lp0 else Int
p1 forall a. Num a => a -> a -> a
- Int
col
span_ :: Bool
-> (Char -> Bool)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m)
span_ Bool
bt Char -> Bool
fc (LinePositioned Int
p0 Int
l0 Int
lp0 m
t) = forall {m} {m}.
TextualMonoid m =>
(m, m) -> (LinePositioned m, LinePositioned m)
rewrap forall a b. (a -> b) -> a -> b
$ forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
Textual.span_ Bool
bt Char -> Bool
fc m
t
where rewrap :: (m, m) -> (LinePositioned m, LinePositioned m)
rewrap (m
prefix, m
suffix) = (forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p0 Int
l0 Int
lp0 m
prefix,
forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p1 (Int
l0 forall a. Num a => a -> a -> a
+ Int
l) (if Int
l forall a. Eq a => a -> a -> Bool
== Int
0 then Int
lp0 else Int
p1 forall a. Num a => a -> a -> a
- Int
col) m
suffix)
where (Int
l, Int
col) = forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
prefix
p1 :: Int
p1 = Int
p0 forall a. Num a => a -> a -> a
+ forall m. Factorial m => m -> Int
length m
prefix
break_ :: Bool
-> (Char -> Bool)
-> LinePositioned m
-> (LinePositioned m, LinePositioned m)
break_ Bool
bt Char -> Bool
fc LinePositioned m
t = forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
span_ (Bool -> Bool
not Bool
bt) (Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
fc) LinePositioned m
t
dropWhile_ :: Bool -> (Char -> Bool) -> LinePositioned m -> LinePositioned m
dropWhile_ Bool
bt Char -> Bool
fc LinePositioned m
t = forall a b. (a, b) -> b
snd (forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> (t, t)
span_ Bool
bt Char -> Bool
fc LinePositioned m
t)
takeWhile_ :: Bool -> (Char -> Bool) -> LinePositioned m -> LinePositioned m
takeWhile_ Bool
bt Char -> Bool
fc (LinePositioned Int
p Int
l Int
lp m
t) = forall m. Int -> Int -> Int -> m -> LinePositioned m
LinePositioned Int
p Int
l Int
lp (forall t. TextualMonoid t => Bool -> (Char -> Bool) -> t -> t
takeWhile_ Bool
bt Char -> Bool
fc m
t)
toString :: (LinePositioned m -> String) -> LinePositioned m -> String
toString LinePositioned m -> String
ft LinePositioned m
lpt = forall t. TextualMonoid t => (t -> String) -> t -> String
toString (LinePositioned m -> String
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure) (forall m. LinePositioned m -> m
extractLines LinePositioned m
lpt)
toText :: (LinePositioned m -> Text) -> LinePositioned m -> Text
toText LinePositioned m -> Text
ft LinePositioned m
lpt = forall t. TextualMonoid t => (t -> Text) -> t -> Text
toText (LinePositioned m -> Text
ft forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Applicative f => a -> f a
pure) (forall m. LinePositioned m -> m
extractLines LinePositioned m
lpt)
{-# INLINE characterPrefix #-}
{-# INLINE splitCharacterPrefix #-}
{-# INLINE map #-}
{-# INLINE concatMap #-}
{-# INLINE foldl' #-}
{-# INLINE foldr #-}
{-# INLINE spanMaybe' #-}
{-# INLINE span #-}
{-# INLINE split #-}
{-# INLINE find #-}
{-# INLINE foldl_' #-}
{-# INLINE foldr_ #-}
{-# INLINE any #-}
{-# INLINE all #-}
{-# INLINABLE spanMaybe_ #-}
{-# INLINABLE spanMaybe_' #-}
{-# INLINABLE span_ #-}
{-# INLINE break_ #-}
{-# INLINE dropWhile_ #-}
{-# INLINE takeWhile_ #-}
linesColumns :: TextualMonoid m => m -> (Int, Int)
linesColumns :: forall m. TextualMonoid m => m -> (Int, Int)
linesColumns m
t = forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl (forall a b. a -> b -> a
const 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. Enum a => a -> a
succ) forall {b} {a}. (Integral b, Enum a) => (a, b) -> Char -> (a, b)
fc (Int
0, Int
1) m
t
where fc :: (a, b) -> Char -> (a, b)
fc (a
l, b
_) Char
'\n' = (forall a. Enum a => a -> a
succ a
l, b
1)
fc (a
l, b
_) Char
'\f' = (forall a. Enum a => a -> a
succ a
l, b
1)
fc (a
l, b
_) Char
'\r' = (a
l, b
1)
fc (a
l, b
c) Char
'\t' = (a
l, b
c forall a. Num a => a -> a -> a
+ b
9 forall a. Num a => a -> a -> a
- b
c forall a. Integral a => a -> a -> a
`mod` b
8)
fc (a
l, b
c) Char
ch | Char -> Bool
isZeroWidth Char
ch = (a
l, b
c)
fc (a
l, b
c) Char
_ = (a
l, forall a. Enum a => a -> a
succ b
c)
linesColumns' :: TextualMonoid m => m -> (Int, Int)
linesColumns' :: forall m. TextualMonoid m => m -> (Int, Int)
linesColumns' m
t = forall t a.
TextualMonoid t =>
(a -> t -> a) -> (a -> Char -> a) -> a -> t -> a
Textual.foldl' (forall a b. a -> b -> a
const 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. Enum a => a -> a
succ) forall {b} {a}. (Integral b, Enum a) => (a, b) -> Char -> (a, b)
fc (Int
0, Int
1) m
t
where fc :: (a, a) -> Char -> (a, a)
fc (a
l, a
_) Char
'\n' = let l' :: a
l' = forall a. Enum a => a -> a
succ a
l in seq :: forall a b. a -> b -> b
seq a
l' (a
l', a
1)
fc (a
l, a
_) Char
'\f' = let l' :: a
l' = forall a. Enum a => a -> a
succ a
l in seq :: forall a b. a -> b -> b
seq a
l' (a
l', a
1)
fc (a
l, a
_) Char
'\r' = (a
l, a
1)
fc (a
l, a
c) Char
'\t' = (a
l, a
c forall a. Num a => a -> a -> a
+ a
9 forall a. Num a => a -> a -> a
- a
c forall a. Integral a => a -> a -> a
`mod` a
8)
fc (a
l, a
c) Char
ch | Char -> Bool
isZeroWidth Char
ch = (a
l, a
c)
fc (a
l, a
c) Char
_ = let c' :: a
c' = forall a. Enum a => a -> a
succ a
c in seq :: forall a b. a -> b -> b
seq a
c' (a
l, a
c')
{-# INLINE linesColumns #-}
{-# INLINE linesColumns' #-}
isZeroWidth :: Char -> Bool
isZeroWidth :: Char -> Bool
isZeroWidth Char
'\x200b' = Bool
True
isZeroWidth Char
'\x200c' = Bool
True
isZeroWidth Char
'\x200d' = Bool
True
isZeroWidth Char
'\xfeff' = Bool
True
isZeroWidth Char
_ = Bool
False
const3 :: a -> b -> c -> d -> a
const3 :: forall a b c d. a -> b -> c -> d -> a
const3 a
a b
_p c
_l d
_lp = a
a
{-# INLINE const3 #-}
fstOf4 :: (a, b, c, d) -> a
fstOf4 :: forall a b c d. (a, b, c, d) -> a
fstOf4 (a
a, b
_, c
_, d
_) = a
a
{-# INLINE fstOf4 #-}