{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE EmptyDataDeriving #-}
-- | promoted regular expression functions

module Predicate.Data.Regex (
    Re
  , Re'
  , Rescan
  , Rescan'
  , RescanRanges
  , RescanRanges'
  , Resplit
  , Resplit'
  , ReplaceAll
  , ReplaceAll'
  , ReplaceOne
  , ReplaceOne'
  , ReplaceAllString
  , ReplaceAllString'
  , ReplaceOneString
  , ReplaceOneString'
  , ReplaceFn
  , ReplaceFn1
  , ReplaceFn2
  , ReplaceFn3
 ) where
import Predicate.Core
import Predicate.Misc
import Predicate.Util
import Data.Proxy (Proxy(Proxy))
import qualified Text.Regex.PCRE.Heavy as RH
import Data.Bool (bool)
-- $setup

-- >>> :set -XDataKinds

-- >>> :set -XTypeApplications

-- >>> :set -XTypeOperators

-- >>> :set -XOverloadedStrings

-- >>> import Safe (readNote)

-- >>> import Predicate.Prelude

-- >>> import Data.Time


-- | runs a regular expression with given regex options and returns a boolean: see 'RH.=~'

--

-- >>> pl @(Re' '[ 'Caseless, 'Dotall ] "ab" Id) "aB"

-- True (Re' ['Caseless, 'Dotall] (ab) | aB)

-- Val True

--

-- >>> pl @(Re' '[ 'Caseless, 'Dotall ] "ab." Id) "aB\n"

-- True (Re' ['Caseless, 'Dotall] (ab.) | aB

-- )

-- Val True

--

-- >>> pl @(Re' '[ 'Caseless ] "ab." Id) "aB\n"

-- False (Re' ['Caseless] (ab.) | aB

-- )

-- Val False

--

data Re' (rs :: [ROpt]) p q deriving Int -> Re' rs p q -> ShowS
[Re' rs p q] -> ShowS
Re' rs p q -> String
(Int -> Re' rs p q -> ShowS)
-> (Re' rs p q -> String)
-> ([Re' rs p q] -> ShowS)
-> Show (Re' rs p q)
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> Re' rs p q -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k). [Re' rs p q] -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k). Re' rs p q -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Re' rs p q] -> ShowS
$cshowList :: forall (rs :: [ROpt]) k (p :: k) k (q :: k). [Re' rs p q] -> ShowS
show :: Re' rs p q -> String
$cshow :: forall (rs :: [ROpt]) k (p :: k) k (q :: k). Re' rs p q -> String
showsPrec :: Int -> Re' rs p q -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> Re' rs p q -> ShowS
Show

instance ( GetROpts rs
         , PP p x ~ String
         , PP q x ~ String
         , P p x
         , P q x
         ) => P (Re' rs p q) x where
  type PP (Re' rs p q) x = Bool
  eval :: proxy (Re' rs p q) -> POpts -> x -> m (TT (PP (Re' rs p q) x))
eval proxy (Re' rs p q)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"Re" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [PCREOption] -> ShowS
forall (t :: Type -> Type) m a.
(Foldable t, Monoid m) =>
t a -> m -> m
unlessNull [PCREOption]
rs (String
"' " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
displayROpts [String]
fs)
        ([String]
fs,[PCREOption]
rs) = GetROpts rs => ([String], [PCREOption])
forall (os :: [ROpt]). GetROpts os => ([String], [PCREOption])
getROpts @rs
    Either (TT Bool) (String, String, TT String, TT String)
lr <- Inline
-> String
-> Proxy p
-> Proxy q
-> POpts
-> x
-> [Tree PE]
-> m (Either (TT Bool) (PP p x, PP q x, TT (PP p x), TT (PP q x)))
forall k1 k2 (p :: k1) a (q :: k2) (m :: Type -> Type)
       (proxy1 :: k1 -> Type) (proxy2 :: k2 -> Type) x.
(P p a, P q a, MonadEval m) =>
Inline
-> String
-> proxy1 p
-> proxy2 q
-> POpts
-> a
-> [Tree PE]
-> m (Either (TT x) (PP p a, PP q a, TT (PP p a), TT (PP q a)))
runPQ Inline
NoInline String
msg0 (Proxy p
forall k (t :: k). Proxy t
Proxy @p) (Proxy q
forall k (t :: k). Proxy t
Proxy @q) POpts
opts x
x []
    TT Bool -> m (TT Bool)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT Bool -> m (TT Bool)) -> TT Bool -> m (TT Bool)
forall a b. (a -> b) -> a -> b
$ case Either (TT Bool) (String, String, TT String, TT String)
lr of
      Left TT Bool
e -> TT Bool
e
      Right (String
p,String
q,TT String
pp,TT String
qq) ->
        let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
p String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
            hhs :: [Tree PE]
hhs = [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp, TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
qq]
        in case String -> String -> Either (String, String) Regex
forall (rs :: [ROpt]).
GetROpts rs =>
String -> String -> Either (String, String) Regex
compileRegex @rs String
msg1 String
p of
            Left (String
e,String
e1) -> POpts -> Val Bool -> String -> [Tree PE] -> TT Bool
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val Bool
forall a. String -> Val a
Fail String
e) String
e1 [Tree PE]
hhs
            Right Regex
regex ->
               let b :: Bool
b = String
q String -> Regex -> Bool
forall a.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS) =>
a -> Regex -> Bool
RH.=~ Regex
regex
               in POpts -> Bool -> String -> [Tree PE] -> TT Bool
mkNodeB POpts
opts Bool
b (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
litVerbose POpts
opts String
" | " String
q) [Tree PE]
hhs


-- | runs a regular expression and returns a boolean: see 'RH.=~'

--

-- >>> pz @(Re "^\\d{2}:\\d{2}:\\d{2}$") "13:05:25"

-- Val True

--

-- >>> pl @(Re "\\d{4}-\\d{3}") "1234-123"

-- True (Re (\d{4}-\d{3}) | 1234-123)

-- Val True

--

-- >>> pl @(Re "\\d{4}-\\d{3}") "1234-1x3"

-- False (Re (\d{4}-\d{3}) | 1234-1x3)

-- Val False

--

-- >>> pl @(Re "(?i)ab") "aB" -- runtime [use 'Caseless instead]

-- True (Re ((?i)ab) | aB)

-- Val True

--

-- >>> pl @(Re "ab") "aB"

-- False (Re (ab) | aB)

-- Val False

--

-- >>> pl @(Re "^\\d{1,3}(?:\\.\\d{1,3}){3}$") "123.1.1.21"

-- True (Re (^\d{1,3}(?:\.\d{1,3}){3}$) | 123.1.1.21)

-- Val True

--

-- >>> pl @(Guard "regex failed" (Re "^\\d+(?:\\.\\d+)?$") >> ReadP Double Id) "13.345"

-- Present 13.345 ((>>) 13.345 | {ReadP Double 13.345})

-- Val 13.345

--

-- >>> pl @(Guard "regex failed" (Re "^\\d+(?:\\.\\d+)?$") >> ReadP Double Id) "13"

-- Present 13.0 ((>>) 13.0 | {ReadP Double 13.0})

-- Val 13.0

--

-- >>> pl @(ExitWhen "regex failed" (Not (Re "^\\d+(?:\\.\\d+)?$")) >> ReadP Double Id) "-13.4"

-- Error regex failed (Guard | "-13.4")

-- Fail "regex failed"

--

-- >>> pl @(Re "\\d{4}\\") "ayx"

-- Error Regex failed to compile (Re (\d{4}\) ([],[]):\ at end of pattern)

-- Fail "Regex failed to compile"

--

-- >>> pl @(Re "^\\d+$") "123\nx"

-- False (Re (^\d+$) | 123

-- x)

-- Val False

--

-- >>> pl @(Re "(?m)^\\d+$") "123\nx" -- (?m) anchors match beginning/end of line instead of whole string

-- True (Re ((?m)^\d+$) | 123

-- x)

-- Val True

--

-- >>> pl @(Catch (Re "\\d+(") 'False) "123"

-- False (Catch caught exception[Regex failed to compile])

-- Val False

--

-- >>> pl @(Catch (Re "\\d+") 'False) "123"

-- True (Catch did not fire)

-- Val True

--

data Re p deriving Int -> Re p -> ShowS
[Re p] -> ShowS
Re p -> String
(Int -> Re p -> ShowS)
-> (Re p -> String) -> ([Re p] -> ShowS) -> Show (Re p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k). Int -> Re p -> ShowS
forall k (p :: k). [Re p] -> ShowS
forall k (p :: k). Re p -> String
showList :: [Re p] -> ShowS
$cshowList :: forall k (p :: k). [Re p] -> ShowS
show :: Re p -> String
$cshow :: forall k (p :: k). Re p -> String
showsPrec :: Int -> Re p -> ShowS
$cshowsPrec :: forall k (p :: k). Int -> Re p -> ShowS
Show
type ReT p = Re' '[] p Id

instance P (ReT p) x => P (Re p) x where
  type PP (Re p) x = PP (ReT p) x
  eval :: proxy (Re p) -> POpts -> x -> m (TT (PP (Re p) x))
eval proxy (Re p)
_ = Proxy (ReT p) -> POpts -> x -> m (TT (PP (ReT p) x))
forall k (m :: Type -> Type) (p :: k) a (proxy :: k -> Type).
(MonadEval m, P p a, PP p a ~ Bool) =>
proxy p -> POpts -> a -> m (TT (PP p a))
evalBool (Proxy (ReT p)
forall k (t :: k). Proxy t
Proxy @(ReT p))

-- | runs a regex matcher returning the original values and optionally any groups: see 'RH.scan'

--

-- >>> pl @(Rescan' '[ 'Anchored ] "([[:xdigit:]]{2})" Id) "wfeb12az"

-- Error Regex no results (Rescan' ['Anchored] (([[:xdigit:]]{2})) | "wfeb12az")

-- Fail "Regex no results"

--

-- >>> pz @(Rescan' '[] Snd "13:05:25") ('a',"^(\\d{2}):(\\d{2}):(\\d{2})$")

-- Val [("13:05:25",["13","05","25"])]

--

-- >>> pz @('(Id,Intercalate '["\\."] (Repeat 4 "([01]?\\d?\\d|2[0-4]\\d|25[0-5])") >> Concat) >> Rescan' '[] ("^" <> Snd <> "$") Fst) "1.2.3.255" -- have to use Rescan' here: Lift helps not!

-- Val [("1.2.3.255",["1","2","3","255"])]

--

-- >>> pz @('(Id,Intercalate '["\\."] (Repeat 4 "([01]?\\d?\\d|2[0-4]\\d|25[0-5])") >> Concat) >> Rescan' '[] ("^" <> Snd <> "$") Fst >> FMap (Second (FMap (ReadP Int Id)))) "1.2.3.255"

-- Val [("1.2.3.255",[1,2,3,255])]

--

data Rescan' (rs :: [ROpt]) p q deriving Int -> Rescan' rs p q -> ShowS
[Rescan' rs p q] -> ShowS
Rescan' rs p q -> String
(Int -> Rescan' rs p q -> ShowS)
-> (Rescan' rs p q -> String)
-> ([Rescan' rs p q] -> ShowS)
-> Show (Rescan' rs p q)
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> Rescan' rs p q -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
[Rescan' rs p q] -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Rescan' rs p q -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Rescan' rs p q] -> ShowS
$cshowList :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
[Rescan' rs p q] -> ShowS
show :: Rescan' rs p q -> String
$cshow :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Rescan' rs p q -> String
showsPrec :: Int -> Rescan' rs p q -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> Rescan' rs p q -> ShowS
Show

instance ( GetROpts rs
         , PP p x ~ String
         , PP q x ~ String
         , P p x
         , P q x
         ) => P (Rescan' rs p q) x where
  type PP (Rescan' rs p q) x = [(String, [String])]
  eval :: proxy (Rescan' rs p q)
-> POpts -> x -> m (TT (PP (Rescan' rs p q) x))
eval proxy (Rescan' rs p q)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"Rescan" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [PCREOption] -> ShowS
forall (t :: Type -> Type) m a.
(Foldable t, Monoid m) =>
t a -> m -> m
unlessNull [PCREOption]
rs (String
"' " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
displayROpts [String]
fs)
        ([String]
fs,[PCREOption]
rs) = GetROpts rs => ([String], [PCREOption])
forall (os :: [ROpt]). GetROpts os => ([String], [PCREOption])
getROpts @rs
    Either
  (TT [(String, [String])]) (String, String, TT String, TT String)
lr <- Inline
-> String
-> Proxy p
-> Proxy q
-> POpts
-> x
-> [Tree PE]
-> m (Either
        (TT [(String, [String])])
        (PP p x, PP q x, TT (PP p x), TT (PP q x)))
forall k1 k2 (p :: k1) a (q :: k2) (m :: Type -> Type)
       (proxy1 :: k1 -> Type) (proxy2 :: k2 -> Type) x.
(P p a, P q a, MonadEval m) =>
Inline
-> String
-> proxy1 p
-> proxy2 q
-> POpts
-> a
-> [Tree PE]
-> m (Either (TT x) (PP p a, PP q a, TT (PP p a), TT (PP q a)))
runPQ Inline
NoInline String
msg0 (Proxy p
forall k (t :: k). Proxy t
Proxy @p) (Proxy q
forall k (t :: k). Proxy t
Proxy @q) POpts
opts x
x []
    TT [(String, [String])] -> m (TT [(String, [String])])
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT [(String, [String])] -> m (TT [(String, [String])]))
-> TT [(String, [String])] -> m (TT [(String, [String])])
forall a b. (a -> b) -> a -> b
$ case Either
  (TT [(String, [String])]) (String, String, TT String, TT String)
lr of
      Left TT [(String, [String])]
e -> TT [(String, [String])]
e
      Right (String
p,String
q,TT String
pp,TT String
qq) ->
        let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
p String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
            hhs :: [Tree PE]
hhs = [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp, TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
qq]
        in case String -> String -> Either (String, String) Regex
forall (rs :: [ROpt]).
GetROpts rs =>
String -> String -> Either (String, String) Regex
compileRegex @rs String
msg1 String
p of
             Left (String
e,String
e1) -> POpts
-> Val [(String, [String])]
-> String
-> [Tree PE]
-> TT [(String, [String])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [(String, [String])]
forall a. String -> Val a
Fail String
e) String
e1 [Tree PE]
hhs
             Right Regex
regex ->
               let r :: Int
r = POpts -> Int
getMaxRecursionValue POpts
opts
               in case Int
-> [(String, [String])]
-> ([(String, [String])], [(String, [String])])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
r ([(String, [String])]
 -> ([(String, [String])], [(String, [String])]))
-> [(String, [String])]
-> ([(String, [String])], [(String, [String])])
forall a b. (a -> b) -> a -> b
$ Regex -> String -> [(String, [String])]
forall a.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS) =>
Regex -> a -> [(a, [a])]
RH.scan Regex
regex String
q of
                    ([(String, [String])]
b, (String, [String])
_:[(String, [String])]
_) -> POpts
-> Val [(String, [String])]
-> String
-> [Tree PE]
-> TT [(String, [String])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [(String, [String])]
forall a. String -> Val a
Fail (String
"Regex looping(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
r String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")")) (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [(String, [String])] -> String
forall a. Show a => a -> String
show (Int -> [(String, [String])] -> [(String, [String])]
forall a. Int -> [a] -> [a]
take Int
10 [(String, [String])]
b) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"..." String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " String
q) [Tree PE]
hhs
                    ([], [(String, [String])]
_) -> -- this is a failure because an empty string is returned: so reuse p?

                                POpts
-> Val [(String, [String])]
-> String
-> [Tree PE]
-> TT [(String, [String])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [(String, [String])]
forall a. String -> Val a
Fail String
"Regex no results") (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " String
q) [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp, TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
qq]
                    ([(String, [String])]
b, [(String, [String])]
_) -> POpts
-> Val [(String, [String])]
-> String
-> [Tree PE]
-> TT [(String, [String])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts ([(String, [String])] -> Val [(String, [String])]
forall a. a -> Val a
Val [(String, [String])]
b) (POpts -> String -> [(String, [String])] -> String -> ShowS
forall a1. Show a1 => POpts -> String -> a1 -> String -> ShowS
lit3 POpts
opts String
msg1 [(String, [String])]
b String
"" String
q) [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp, TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
qq]

-- | see 'RH.scan'

--

-- >>> pz @(Rescan "^(\\d{2}):(\\d{2}):(\\d{2})$") "13:05:25"

-- Val [("13:05:25",["13","05","25"])]

--

-- >>> pz @(Rescan "^(\\d{2}):(\\d{2}):(\\d{2})$" >> L2 Head >> Map (ReadP Int Id)) "13:05:25"

-- Val [13,5,25]

--

-- >>> pl @(Rescan "(\\d+)\\D?" >> Map (Second (ReadP Int (OneP)))) "123-444-987"

-- Present [("123-",123),("444-",444),("987",987)] ((>>) [("123-",123),("444-",444),("987",987)] | {Map [("123-",123),("444-",444),("987",987)] | [("123-",["123"]),("444-",["444"]),("987",["987"])]})

-- Val [("123-",123),("444-",444),("987",987)]

--

-- >>> pl @(Rescan ".(.)") "aBcd"

-- Present [("aB",["B"]),("cd",["d"])] (Rescan (.(.)) [("aB",["B"]),("cd",["d"])] | aBcd)

-- Val [("aB",["B"]),("cd",["d"])]

--

-- >>> pl @(Rescan "\\d{1,3}(\\.)?") "123.8.99.21"

-- Present [("123.",["."]),("8.",["."]),("99.",["."]),("21",[])] (Rescan (\d{1,3}(\.)?) [("123.",["."]),("8.",["."]),("99.",["."]),("21",[])] | 123.8.99.21)

-- Val [("123.",["."]),("8.",["."]),("99.",["."]),("21",[])]

--

-- >>> pl @(Map' Fst (Rescan "." << ShowP Id) >> Filter (Same "2") Id) 12324

-- Present ["2","2"] ((>>) ["2","2"] | {Fst ["2","2"] | (["2","2"],["1","3","4"])})

-- Val ["2","2"]

--

-- >>> pl @(Rescan "(\\d)+?") "1234"

-- Present [("1",["1"]),("2",["2"]),("3",["3"]),("4",["4"])] (Rescan ((\d)+?) [("1",["1"]),("2",["2"]),("3",["3"]),("4",["4"])] | 1234)

-- Val [("1",["1"]),("2",["2"]),("3",["3"]),("4",["4"])]

--

-- >>> pl @(Rescan "(\\d)+") "1234"

-- Present [("1234",["4"])] (Rescan ((\d)+) [("1234",["4"])] | 1234)

-- Val [("1234",["4"])]

--

-- >>> pl @(Rescan "(\\d{1,3})(\\.(\\d{1,3}))+?") "1.2.3.4" -- overcapturing

-- Present [("1.2",["1",".2","2"]),("3.4",["3",".4","4"])] (Rescan ((\d{1,3})(\.(\d{1,3}))+?) [("1.2",["1",".2","2"]),("3.4",["3",".4","4"])] | 1.2.3.4)

-- Val [("1.2",["1",".2","2"]),("3.4",["3",".4","4"])]

--

-- >>> pl @(Rescan "^(\\d)+?$") "1234"

-- Present [("1234",["4"])] (Rescan (^(\d)+?$) [("1234",["4"])] | 1234)

-- Val [("1234",["4"])]

--

-- >>> pl @(Rescan "(\\d{1,3})(\\.(\\d{1,3}))+?") "1.2.3.4"

-- Present [("1.2",["1",".2","2"]),("3.4",["3",".4","4"])] (Rescan ((\d{1,3})(\.(\d{1,3}))+?) [("1.2",["1",".2","2"]),("3.4",["3",".4","4"])] | 1.2.3.4)

-- Val [("1.2",["1",".2","2"]),("3.4",["3",".4","4"])]

--

-- >>> pl @(Rescan "(\\d{1,3})(?:\\.(\\d{1,3}))+?") "1.2.3.4" -- bizzare!

-- Present [("1.2",["1","2"]),("3.4",["3","4"])] (Rescan ((\d{1,3})(?:\.(\d{1,3}))+?) [("1.2",["1","2"]),("3.4",["3","4"])] | 1.2.3.4)

-- Val [("1.2",["1","2"]),("3.4",["3","4"])]

--

-- >>> pl @(Rescan "^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$") "1.2.3.4"

-- Present [("1.2.3.4",["1","2","3","4"])] (Rescan (^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$) [("1.2.3.4",["1","2","3","4"])] | 1.2.3.4)

-- Val [("1.2.3.4",["1","2","3","4"])]

--

-- >>> pl @(Rescan "([[:xdigit:]]{2})") "wfeb12az"

-- Present [("fe",["fe"]),("b1",["b1"]),("2a",["2a"])] (Rescan (([[:xdigit:]]{2})) [("fe",["fe"]),("b1",["b1"]),("2a",["2a"])] | wfeb12az)

-- Val [("fe",["fe"]),("b1",["b1"]),("2a",["2a"])]

--

-- >>> pz @(Rescan "^Date\\((\\d+)(\\d{3}[+-]\\d{4})\\)" >> Head >> Snd >> (Id !! 0 <> "." <> Id !! 1)  >> ParseTimeP ZonedTime "%s%Q%z") "Date(1593460089052+0800)"

-- Val 2020-06-30 03:48:09.052 +0800

--

data Rescan p deriving Int -> Rescan p -> ShowS
[Rescan p] -> ShowS
Rescan p -> String
(Int -> Rescan p -> ShowS)
-> (Rescan p -> String) -> ([Rescan p] -> ShowS) -> Show (Rescan p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k). Int -> Rescan p -> ShowS
forall k (p :: k). [Rescan p] -> ShowS
forall k (p :: k). Rescan p -> String
showList :: [Rescan p] -> ShowS
$cshowList :: forall k (p :: k). [Rescan p] -> ShowS
show :: Rescan p -> String
$cshow :: forall k (p :: k). Rescan p -> String
showsPrec :: Int -> Rescan p -> ShowS
$cshowsPrec :: forall k (p :: k). Int -> Rescan p -> ShowS
Show
type RescanT p = Rescan' '[] p Id

instance P (RescanT p) x => P (Rescan p) x where
  type PP (Rescan p) x = PP (RescanT p) x
  eval :: proxy (Rescan p) -> POpts -> x -> m (TT (PP (Rescan p) x))
eval proxy (Rescan p)
_ = Proxy (RescanT p) -> POpts -> x -> m (TT (PP (RescanT p) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (RescanT p)
forall k (t :: k). Proxy t
Proxy @(RescanT p))

-- | similar to 'RescanRanges' but also allows the regex options @rs@ to be specified

data RescanRanges' (rs :: [ROpt]) p q deriving Int -> RescanRanges' rs p q -> ShowS
[RescanRanges' rs p q] -> ShowS
RescanRanges' rs p q -> String
(Int -> RescanRanges' rs p q -> ShowS)
-> (RescanRanges' rs p q -> String)
-> ([RescanRanges' rs p q] -> ShowS)
-> Show (RescanRanges' rs p q)
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> RescanRanges' rs p q -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
[RescanRanges' rs p q] -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
RescanRanges' rs p q -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RescanRanges' rs p q] -> ShowS
$cshowList :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
[RescanRanges' rs p q] -> ShowS
show :: RescanRanges' rs p q -> String
$cshow :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
RescanRanges' rs p q -> String
showsPrec :: Int -> RescanRanges' rs p q -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> RescanRanges' rs p q -> ShowS
Show

instance ( GetROpts rs
         , PP p x ~ String
         , PP q x ~ String
         , P p x
         , P q x
         ) => P (RescanRanges' rs p q) x where
  type PP (RescanRanges' rs p q) x = [((Int,Int), [(Int,Int)])]
  eval :: proxy (RescanRanges' rs p q)
-> POpts -> x -> m (TT (PP (RescanRanges' rs p q) x))
eval proxy (RescanRanges' rs p q)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"RescanRanges" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [PCREOption] -> ShowS
forall (t :: Type -> Type) m a.
(Foldable t, Monoid m) =>
t a -> m -> m
unlessNull [PCREOption]
rs (String
"' " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
displayROpts [String]
fs)
        ([String]
fs,[PCREOption]
rs) = GetROpts rs => ([String], [PCREOption])
forall (os :: [ROpt]). GetROpts os => ([String], [PCREOption])
getROpts @rs
    Either
  (TT [((Int, Int), [(Int, Int)])])
  (String, String, TT String, TT String)
lr <- Inline
-> String
-> Proxy p
-> Proxy q
-> POpts
-> x
-> [Tree PE]
-> m (Either
        (TT [((Int, Int), [(Int, Int)])])
        (PP p x, PP q x, TT (PP p x), TT (PP q x)))
forall k1 k2 (p :: k1) a (q :: k2) (m :: Type -> Type)
       (proxy1 :: k1 -> Type) (proxy2 :: k2 -> Type) x.
(P p a, P q a, MonadEval m) =>
Inline
-> String
-> proxy1 p
-> proxy2 q
-> POpts
-> a
-> [Tree PE]
-> m (Either (TT x) (PP p a, PP q a, TT (PP p a), TT (PP q a)))
runPQ Inline
NoInline String
msg0 (Proxy p
forall k (t :: k). Proxy t
Proxy @p) (Proxy q
forall k (t :: k). Proxy t
Proxy @q) POpts
opts x
x []
    TT [((Int, Int), [(Int, Int)])]
-> m (TT [((Int, Int), [(Int, Int)])])
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT [((Int, Int), [(Int, Int)])]
 -> m (TT [((Int, Int), [(Int, Int)])]))
-> TT [((Int, Int), [(Int, Int)])]
-> m (TT [((Int, Int), [(Int, Int)])])
forall a b. (a -> b) -> a -> b
$ case Either
  (TT [((Int, Int), [(Int, Int)])])
  (String, String, TT String, TT String)
lr of
      Left TT [((Int, Int), [(Int, Int)])]
e -> TT [((Int, Int), [(Int, Int)])]
e
      Right (String
p,String
q,TT String
pp,TT String
qq) ->
        let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
p String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
            hhs :: [Tree PE]
hhs = [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp, TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
qq]
        in case String -> String -> Either (String, String) Regex
forall (rs :: [ROpt]).
GetROpts rs =>
String -> String -> Either (String, String) Regex
compileRegex @rs String
msg1 String
p of
          Left (String
e,String
e1) -> POpts
-> Val [((Int, Int), [(Int, Int)])]
-> String
-> [Tree PE]
-> TT [((Int, Int), [(Int, Int)])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [((Int, Int), [(Int, Int)])]
forall a. String -> Val a
Fail String
e) String
e1 [Tree PE]
hhs
          Right Regex
regex ->
            let r :: Int
r = POpts -> Int
getMaxRecursionValue POpts
opts
            in case Int
-> [((Int, Int), [(Int, Int)])]
-> ([((Int, Int), [(Int, Int)])], [((Int, Int), [(Int, Int)])])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
r ([((Int, Int), [(Int, Int)])]
 -> ([((Int, Int), [(Int, Int)])], [((Int, Int), [(Int, Int)])]))
-> [((Int, Int), [(Int, Int)])]
-> ([((Int, Int), [(Int, Int)])], [((Int, Int), [(Int, Int)])])
forall a b. (a -> b) -> a -> b
$ Regex -> String -> [((Int, Int), [(Int, Int)])]
forall a.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS) =>
Regex -> a -> [((Int, Int), [(Int, Int)])]
RH.scanRanges Regex
regex String
q of
                 ([((Int, Int), [(Int, Int)])]
b, ((Int, Int), [(Int, Int)])
_:[((Int, Int), [(Int, Int)])]
_) -> POpts
-> Val [((Int, Int), [(Int, Int)])]
-> String
-> [Tree PE]
-> TT [((Int, Int), [(Int, Int)])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [((Int, Int), [(Int, Int)])]
forall a. String -> Val a
Fail (String
"Regex looping(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
r String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")")) (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [((Int, Int), [(Int, Int)])] -> String
forall a. Show a => a -> String
show (Int -> [((Int, Int), [(Int, Int)])] -> [((Int, Int), [(Int, Int)])]
forall a. Int -> [a] -> [a]
take Int
10 [((Int, Int), [(Int, Int)])]
b) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"..." String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " String
q) [Tree PE]
hhs
                 ([], [((Int, Int), [(Int, Int)])]
_) -> -- this is a failure because an empty string is returned: so reuse p?

                            POpts
-> Val [((Int, Int), [(Int, Int)])]
-> String
-> [Tree PE]
-> TT [((Int, Int), [(Int, Int)])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [((Int, Int), [(Int, Int)])]
forall a. String -> Val a
Fail String
"Regex no results") (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " String
q) [Tree PE]
hhs
                 ([((Int, Int), [(Int, Int)])]
b, [((Int, Int), [(Int, Int)])]
_) -> POpts
-> Val [((Int, Int), [(Int, Int)])]
-> String
-> [Tree PE]
-> TT [((Int, Int), [(Int, Int)])]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts ([((Int, Int), [(Int, Int)])] -> Val [((Int, Int), [(Int, Int)])]
forall a. a -> Val a
Val [((Int, Int), [(Int, Int)])]
b) (POpts -> String -> [((Int, Int), [(Int, Int)])] -> String -> ShowS
forall a1. Show a1 => POpts -> String -> a1 -> String -> ShowS
lit3 POpts
opts String
msg1 [((Int, Int), [(Int, Int)])]
b String
"" String
q) [Tree PE]
hhs

-- | see 'RH.scanRanges'

--

-- >>> pz @(RescanRanges "^(\\d{2}):(\\d{2}):(\\d{2})$" Id) "13:05:25"

-- Val [((0,8),[(0,2),(3,5),(6,8)])]

--

data RescanRanges p q deriving Int -> RescanRanges p q -> ShowS
[RescanRanges p q] -> ShowS
RescanRanges p q -> String
(Int -> RescanRanges p q -> ShowS)
-> (RescanRanges p q -> String)
-> ([RescanRanges p q] -> ShowS)
-> Show (RescanRanges p q)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k). Int -> RescanRanges p q -> ShowS
forall k (p :: k) k (q :: k). [RescanRanges p q] -> ShowS
forall k (p :: k) k (q :: k). RescanRanges p q -> String
showList :: [RescanRanges p q] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k). [RescanRanges p q] -> ShowS
show :: RescanRanges p q -> String
$cshow :: forall k (p :: k) k (q :: k). RescanRanges p q -> String
showsPrec :: Int -> RescanRanges p q -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k). Int -> RescanRanges p q -> ShowS
Show
type RescanRangesT p q = RescanRanges' '[] p q

instance P (RescanRangesT p q) x => P (RescanRanges p q) x where
  type PP (RescanRanges p q) x = PP (RescanRangesT p q) x
  eval :: proxy (RescanRanges p q)
-> POpts -> x -> m (TT (PP (RescanRanges p q) x))
eval proxy (RescanRanges p q)
_ = Proxy (RescanRangesT p q)
-> POpts -> x -> m (TT (PP (RescanRangesT p q) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (RescanRangesT p q)
forall k (t :: k). Proxy t
Proxy @(RescanRangesT p q))

-- | splits a string on a regex delimiter: see 'RH.split'

--

-- >>> pl @(Resplit' '[ 'Caseless ] "aBc" Id) "123AbC456abc"

-- Present ["123","456",""] (Resplit' ['Caseless] (aBc) ["123","456",""] | 123AbC456abc)

-- Val ["123","456",""]

--

-- >>> pz @(Resplit' '[] (Singleton Fst) Snd) (':', "12:13:1")

-- Val ["12","13","1"]

--

data Resplit' (rs :: [ROpt]) p q deriving Int -> Resplit' rs p q -> ShowS
[Resplit' rs p q] -> ShowS
Resplit' rs p q -> String
(Int -> Resplit' rs p q -> ShowS)
-> (Resplit' rs p q -> String)
-> ([Resplit' rs p q] -> ShowS)
-> Show (Resplit' rs p q)
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> Resplit' rs p q -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
[Resplit' rs p q] -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Resplit' rs p q -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Resplit' rs p q] -> ShowS
$cshowList :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
[Resplit' rs p q] -> ShowS
show :: Resplit' rs p q -> String
$cshow :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Resplit' rs p q -> String
showsPrec :: Int -> Resplit' rs p q -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) k (p :: k) k (q :: k).
Int -> Resplit' rs p q -> ShowS
Show

instance ( GetROpts rs
         , PP p x ~ String
         , PP q x ~ String
         , P p x
         , P q x
         ) => P (Resplit' rs p q) x where
  type PP (Resplit' rs p q) x = [String]
  eval :: proxy (Resplit' rs p q)
-> POpts -> x -> m (TT (PP (Resplit' rs p q) x))
eval proxy (Resplit' rs p q)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"Resplit" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [PCREOption] -> ShowS
forall (t :: Type -> Type) m a.
(Foldable t, Monoid m) =>
t a -> m -> m
unlessNull [PCREOption]
rs (String
"' " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
displayROpts [String]
fs)
        ([String]
fs,[PCREOption]
rs) = GetROpts rs => ([String], [PCREOption])
forall (os :: [ROpt]). GetROpts os => ([String], [PCREOption])
getROpts @rs
    Either (TT [String]) (String, String, TT String, TT String)
lr <- Inline
-> String
-> Proxy p
-> Proxy q
-> POpts
-> x
-> [Tree PE]
-> m (Either
        (TT [String]) (PP p x, PP q x, TT (PP p x), TT (PP q x)))
forall k1 k2 (p :: k1) a (q :: k2) (m :: Type -> Type)
       (proxy1 :: k1 -> Type) (proxy2 :: k2 -> Type) x.
(P p a, P q a, MonadEval m) =>
Inline
-> String
-> proxy1 p
-> proxy2 q
-> POpts
-> a
-> [Tree PE]
-> m (Either (TT x) (PP p a, PP q a, TT (PP p a), TT (PP q a)))
runPQ Inline
NoInline String
msg0 (Proxy p
forall k (t :: k). Proxy t
Proxy @p) (Proxy q
forall k (t :: k). Proxy t
Proxy @q) POpts
opts x
x []
    TT [String] -> m (TT [String])
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT [String] -> m (TT [String])) -> TT [String] -> m (TT [String])
forall a b. (a -> b) -> a -> b
$ case Either (TT [String]) (String, String, TT String, TT String)
lr of
      Left TT [String]
e -> TT [String]
e
      Right (String
p,String
q,TT String
pp,TT String
qq) ->
        let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
p String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
            hhs :: [Tree PE]
hhs = [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp, TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
qq]
        in case String -> String -> Either (String, String) Regex
forall (rs :: [ROpt]).
GetROpts rs =>
String -> String -> Either (String, String) Regex
compileRegex @rs String
msg1 String
p of
          Left (String
e,String
e1) -> POpts -> Val [String] -> String -> [Tree PE] -> TT [String]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [String]
forall a. String -> Val a
Fail String
e) String
e1 [Tree PE]
hhs
          Right Regex
regex ->
            let r :: Int
r = POpts -> Int
getMaxRecursionValue POpts
opts
            in case Int -> [String] -> ([String], [String])
forall a. Int -> [a] -> ([a], [a])
splitAt Int
r ([String] -> ([String], [String]))
-> [String] -> ([String], [String])
forall a b. (a -> b) -> a -> b
$ Regex -> String -> [String]
forall a.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS) =>
Regex -> a -> [a]
RH.split Regex
regex String
q of
                 ([String]
b, String
_:[String]
_) -> POpts -> Val [String] -> String -> [Tree PE] -> TT [String]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [String]
forall a. String -> Val a
Fail (String
"Regex looping(" String -> ShowS
forall a. [a] -> [a] -> [a]
++ Int -> String
forall a. Show a => a -> String
show Int
r String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
")")) (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
forall a. Show a => a -> String
show (Int -> [String] -> [String]
forall a. Int -> [a] -> [a]
take Int
10 [String]
b) String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
"..." String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " String
q) [Tree PE]
hhs
                 ([], [String]
_) -> -- this is a failure because an empty string is returned: so reuse p?

                            POpts -> Val [String] -> String -> [Tree PE] -> TT [String]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val [String]
forall a. String -> Val a
Fail String
"Regex no results") (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " String
q) [Tree PE]
hhs
                 ([String]
b, [String]
_) -> POpts -> Val [String] -> String -> [Tree PE] -> TT [String]
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts ([String] -> Val [String]
forall a. a -> Val a
Val [String]
b) (POpts -> String -> [String] -> String -> ShowS
forall a1. Show a1 => POpts -> String -> a1 -> String -> ShowS
lit3 POpts
opts String
msg1 [String]
b String
"" String
q) [Tree PE]
hhs

-- | splits a string on a regex delimiter: see 'RH.split'

--

-- >>> pz @(Resplit "\\.") "141.201.1.22"

-- Val ["141","201","1","22"]

--

-- >>> pl @(Resplit "\\.") "123.2.3.5.6"

-- Present ["123","2","3","5","6"] (Resplit (\.) ["123","2","3","5","6"] | 123.2.3.5.6)

-- Val ["123","2","3","5","6"]

--

-- >>> pl @(Map' (ReadP Int Id) (Resplit "\\.") >> '(Id, '(Len == 4, All (0 <..> 0xff)))) "141.214.125.1.2.3333"

-- Present ([141,214,125,1,2,3333],(False,False)) ((>>) ([141,214,125,1,2,3333],(False,False)) | {'([141,214,125,1,2,3333],(False,False))})

-- Val ([141,214,125,1,2,3333],(False,False))

--

-- >>> pl @(Map' (ReadP Int Id) (Resplit "\\.") >> Id &&& ((Len == 4) &&& All (0 <..> 0xff))) "141.214.125.1.2.6"

-- Present ([141,214,125,1,2,6],(False,True)) ((>>) ([141,214,125,1,2,6],(False,True)) | {'([141,214,125,1,2,6],(False,True))})

-- Val ([141,214,125,1,2,6],(False,True))

--

-- >>> pl @(Resplit "\\." >> Map (ReadP Int Id) >> Id &&& ((Len == 4) &&& All (0 <..> 0xff))) "141.214.125."

-- Error ReadP Int () (Map(i=3, a="") excnt=1)

-- Fail "ReadP Int ()"

--

data Resplit p deriving Int -> Resplit p -> ShowS
[Resplit p] -> ShowS
Resplit p -> String
(Int -> Resplit p -> ShowS)
-> (Resplit p -> String)
-> ([Resplit p] -> ShowS)
-> Show (Resplit p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k). Int -> Resplit p -> ShowS
forall k (p :: k). [Resplit p] -> ShowS
forall k (p :: k). Resplit p -> String
showList :: [Resplit p] -> ShowS
$cshowList :: forall k (p :: k). [Resplit p] -> ShowS
show :: Resplit p -> String
$cshow :: forall k (p :: k). Resplit p -> String
showsPrec :: Int -> Resplit p -> ShowS
$cshowsPrec :: forall k (p :: k). Int -> Resplit p -> ShowS
Show
type ResplitT p = Resplit' '[] p Id

instance P (ResplitT p) x => P (Resplit p) x where
  type PP (Resplit p) x = PP (ResplitT p) x
  eval :: proxy (Resplit p) -> POpts -> x -> m (TT (PP (Resplit p) x))
eval proxy (Resplit p)
_ = Proxy (ResplitT p) -> POpts -> x -> m (TT (PP (ResplitT p) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ResplitT p)
forall k (t :: k). Proxy t
Proxy @(ResplitT p))

data ReplaceImpl (alle :: Bool) (rs :: [ROpt]) p q r deriving Int -> ReplaceImpl alle rs p q r -> ShowS
[ReplaceImpl alle rs p q r] -> ShowS
ReplaceImpl alle rs p q r -> String
(Int -> ReplaceImpl alle rs p q r -> ShowS)
-> (ReplaceImpl alle rs p q r -> String)
-> ([ReplaceImpl alle rs p q r] -> ShowS)
-> Show (ReplaceImpl alle rs p q r)
forall (alle :: Bool) (rs :: [ROpt]) k (p :: k) k (q :: k) k
       (r :: k).
Int -> ReplaceImpl alle rs p q r -> ShowS
forall (alle :: Bool) (rs :: [ROpt]) k (p :: k) k (q :: k) k
       (r :: k).
[ReplaceImpl alle rs p q r] -> ShowS
forall (alle :: Bool) (rs :: [ROpt]) k (p :: k) k (q :: k) k
       (r :: k).
ReplaceImpl alle rs p q r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplaceImpl alle rs p q r] -> ShowS
$cshowList :: forall (alle :: Bool) (rs :: [ROpt]) k (p :: k) k (q :: k) k
       (r :: k).
[ReplaceImpl alle rs p q r] -> ShowS
show :: ReplaceImpl alle rs p q r -> String
$cshow :: forall (alle :: Bool) (rs :: [ROpt]) k (p :: k) k (q :: k) k
       (r :: k).
ReplaceImpl alle rs p q r -> String
showsPrec :: Int -> ReplaceImpl alle rs p q r -> ShowS
$cshowsPrec :: forall (alle :: Bool) (rs :: [ROpt]) k (p :: k) k (q :: k) k
       (r :: k).
Int -> ReplaceImpl alle rs p q r -> ShowS
Show

instance ( GetBool alle
         , GetROpts rs
         , PP p x ~ String
         , PP q x ~ RReplace
         , PP r x ~ String
         , P p x
         , P q x
         , P r x
         ) => P (ReplaceImpl alle rs p q r) x where
  type PP (ReplaceImpl alle rs p q r) x = String
  eval :: proxy (ReplaceImpl alle rs p q r)
-> POpts -> x -> m (TT (PP (ReplaceImpl alle rs p q r) x))
eval proxy (ReplaceImpl alle rs p q r)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"Replace" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String -> String -> Bool -> String
forall a. a -> a -> Bool -> a
bool String
"One" String
"All" Bool
alle String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [PCREOption] -> ShowS
forall (t :: Type -> Type) m a.
(Foldable t, Monoid m) =>
t a -> m -> m
unlessNull [PCREOption]
rs (String
"' " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> [String] -> String
displayROpts [String]
fs)
        ([String]
fs,[PCREOption]
rs) = GetROpts rs => ([String], [PCREOption])
forall (os :: [ROpt]). GetROpts os => ([String], [PCREOption])
getROpts @rs
        alle :: Bool
alle = GetBool alle => Bool
forall (a :: Bool). GetBool a => Bool
getBool @alle
    Either (TT String) (String, RReplace, TT String, TT RReplace)
lr <- Inline
-> String
-> Proxy p
-> Proxy q
-> POpts
-> x
-> [Tree PE]
-> m (Either
        (TT String) (PP p x, PP q x, TT (PP p x), TT (PP q x)))
forall k1 k2 (p :: k1) a (q :: k2) (m :: Type -> Type)
       (proxy1 :: k1 -> Type) (proxy2 :: k2 -> Type) x.
(P p a, P q a, MonadEval m) =>
Inline
-> String
-> proxy1 p
-> proxy2 q
-> POpts
-> a
-> [Tree PE]
-> m (Either (TT x) (PP p a, PP q a, TT (PP p a), TT (PP q a)))
runPQ Inline
NoInline String
msg0 (Proxy p
forall k (t :: k). Proxy t
Proxy @p) (Proxy q
forall k (t :: k). Proxy t
Proxy @q) POpts
opts x
x []
    case Either (TT String) (String, RReplace, TT String, TT RReplace)
lr of
      Left TT String
e -> TT String -> m (TT String)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure TT String
e
      Right (String
p,RReplace
q,TT String
pp,TT RReplace
qq) ->
        let msg1 :: String
msg1 = String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" (" String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
p String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
")"
            hhs :: [Tree PE]
hhs = [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp, TT RReplace -> Tree PE
forall a. TT a -> Tree PE
hh TT RReplace
qq]
        in case String -> String -> Either (String, String) Regex
forall (rs :: [ROpt]).
GetROpts rs =>
String -> String -> Either (String, String) Regex
compileRegex @rs String
msg1 String
p of
          Left (String
e,String
e1) -> TT String -> m (TT String)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT String -> m (TT String)) -> TT String -> m (TT String)
forall a b. (a -> b) -> a -> b
$ POpts -> Val String -> String -> [Tree PE] -> TT String
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val String
forall a. String -> Val a
Fail String
e) String
e1 [Tree PE]
hhs
          Right Regex
regex -> do
            TT String
rr <- Proxy r -> POpts -> x -> m (TT (PP r x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy r
forall k (t :: k). Proxy t
Proxy @r) POpts
opts x
x
            TT String -> m (TT String)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT String -> m (TT String)) -> TT String -> m (TT String)
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT String
-> [Tree PE]
-> Either (TT String) String
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts String
msg0 TT String
rr [Tree PE]
hhs of
              Left TT String
e -> TT String
e
              Right String
r ->
               let ret :: String
                   ret :: String
ret = case RReplace
q of
                           RReplace ReplaceFnSub
o String
s ->
                             let g :: ShowS -> String
g ShowS
fn = (Regex -> ShowS -> ShowS)
-> (Regex -> ShowS -> ShowS) -> Bool -> Regex -> ShowS -> ShowS
forall a. a -> a -> Bool -> a
bool Regex -> ShowS -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.sub Regex -> ShowS -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.gsub Bool
alle Regex
regex ShowS
fn String
r
                             in ShowS -> String
g (case ReplaceFnSub
o of
                                  ReplaceFnSub
RPrepend -> (String
s String -> ShowS
forall a. Semigroup a => a -> a -> a
<>)
                                  ReplaceFnSub
ROverWrite -> String -> ShowS
forall a b. a -> b -> a
const String
s
                                  ReplaceFnSub
RAppend -> (String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
s))
                           RReplace1 String -> [String] -> String
s -> (Regex -> (String -> [String] -> String) -> ShowS)
-> (Regex -> (String -> [String] -> String) -> ShowS)
-> Bool
-> Regex
-> (String -> [String] -> String)
-> ShowS
forall a. a -> a -> Bool -> a
bool Regex -> (String -> [String] -> String) -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.sub Regex -> (String -> [String] -> String) -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.gsub Bool
alle Regex
regex String -> [String] -> String
s String
r
                           RReplace2 ShowS
s -> (Regex -> ShowS -> ShowS)
-> (Regex -> ShowS -> ShowS) -> Bool -> Regex -> ShowS -> ShowS
forall a. a -> a -> Bool -> a
bool Regex -> ShowS -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.sub Regex -> ShowS -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.gsub Bool
alle Regex
regex ShowS
s String
r
                           RReplace3 [String] -> String
s -> (Regex -> ([String] -> String) -> ShowS)
-> (Regex -> ([String] -> String) -> ShowS)
-> Bool
-> Regex
-> ([String] -> String)
-> ShowS
forall a. a -> a -> Bool -> a
bool Regex -> ([String] -> String) -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.sub Regex -> ([String] -> String) -> ShowS
forall a r.
(ConvertibleStrings SBS a, ConvertibleStrings a SBS,
 RegexReplacement r) =>
Regex -> r -> a -> a
RH.gsub Bool
alle Regex
regex [String] -> String
s String
r
               in POpts -> Val String -> String -> [Tree PE] -> TT String
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (String -> Val String
forall a. a -> Val a
Val String
ret) (String
msg1 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> String
" " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> ShowS
litL POpts
opts String
r String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
litVerbose POpts
opts String
" | " String
ret) ([Tree PE]
hhs [Tree PE] -> [Tree PE] -> [Tree PE]
forall a. Semigroup a => a -> a -> a
<> [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
rr])

-- | replaces all values using regex @p@ with a replacement function @q@ inside the value @r@ using regex options @rs@

data ReplaceAll' (rs :: [ROpt]) p q r deriving Int -> ReplaceAll' rs p q r -> ShowS
[ReplaceAll' rs p q r] -> ShowS
ReplaceAll' rs p q r -> String
(Int -> ReplaceAll' rs p q r -> ShowS)
-> (ReplaceAll' rs p q r -> String)
-> ([ReplaceAll' rs p q r] -> ShowS)
-> Show (ReplaceAll' rs p q r)
forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceAll' rs p q r -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
[ReplaceAll' rs p q r] -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
ReplaceAll' rs p q r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplaceAll' rs p q r] -> ShowS
$cshowList :: forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
[ReplaceAll' rs p q r] -> ShowS
show :: ReplaceAll' rs p q r -> String
$cshow :: forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
ReplaceAll' rs p q r -> String
showsPrec :: Int -> ReplaceAll' rs p q r -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceAll' rs p q r -> ShowS
Show
type ReplaceAllT' (rs :: [ROpt]) p q r = ReplaceImpl 'True rs p q r

instance P (ReplaceAllT' rs p q r) x => P (ReplaceAll' rs p q r) x where
  type PP (ReplaceAll' rs p q r) x = PP (ReplaceAllT' rs p q r) x
  eval :: proxy (ReplaceAll' rs p q r)
-> POpts -> x -> m (TT (PP (ReplaceAll' rs p q r) x))
eval proxy (ReplaceAll' rs p q r)
_ = Proxy (ReplaceAllT' rs p q r)
-> POpts -> x -> m (TT (PP (ReplaceAllT' rs p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceAllT' rs p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceAllT' rs p q r))

-- | replaces all values using regex @p@ with a replacement function @q@ inside the value @r@

data ReplaceAll p q r deriving Int -> ReplaceAll p q r -> ShowS
[ReplaceAll p q r] -> ShowS
ReplaceAll p q r -> String
(Int -> ReplaceAll p q r -> ShowS)
-> (ReplaceAll p q r -> String)
-> ([ReplaceAll p q r] -> ShowS)
-> Show (ReplaceAll p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceAll p q r -> ShowS
forall k (p :: k) k (q :: k) k (r :: k).
[ReplaceAll p q r] -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). ReplaceAll p q r -> String
showList :: [ReplaceAll p q r] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k) k (r :: k).
[ReplaceAll p q r] -> ShowS
show :: ReplaceAll p q r -> String
$cshow :: forall k (p :: k) k (q :: k) k (r :: k). ReplaceAll p q r -> String
showsPrec :: Int -> ReplaceAll p q r -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceAll p q r -> ShowS
Show
type ReplaceAllT p q r = ReplaceAll' '[] p q r

instance P (ReplaceAllT p q r) x => P (ReplaceAll p q r) x where
  type PP (ReplaceAll p q r) x = PP (ReplaceAllT p q r) x
  eval :: proxy (ReplaceAll p q r)
-> POpts -> x -> m (TT (PP (ReplaceAll p q r) x))
eval proxy (ReplaceAll p q r)
_ = Proxy (ReplaceAllT p q r)
-> POpts -> x -> m (TT (PP (ReplaceAllT p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceAllT p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceAllT p q r))

-- | replaces the first value using regex @p@ with a replacement function @q@ inside the value @r@ using regex options @rs@

data ReplaceOne' (rs :: [ROpt]) p q r deriving Int -> ReplaceOne' rs p q r -> ShowS
[ReplaceOne' rs p q r] -> ShowS
ReplaceOne' rs p q r -> String
(Int -> ReplaceOne' rs p q r -> ShowS)
-> (ReplaceOne' rs p q r -> String)
-> ([ReplaceOne' rs p q r] -> ShowS)
-> Show (ReplaceOne' rs p q r)
forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceOne' rs p q r -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
[ReplaceOne' rs p q r] -> ShowS
forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
ReplaceOne' rs p q r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplaceOne' rs p q r] -> ShowS
$cshowList :: forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
[ReplaceOne' rs p q r] -> ShowS
show :: ReplaceOne' rs p q r -> String
$cshow :: forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
ReplaceOne' rs p q r -> String
showsPrec :: Int -> ReplaceOne' rs p q r -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceOne' rs p q r -> ShowS
Show
type ReplaceOneT' (rs :: [ROpt]) p q r = ReplaceImpl 'False rs p q r

instance P (ReplaceOneT' rs p q r) x => P (ReplaceOne' rs p q r) x where
  type PP (ReplaceOne' rs p q r) x = PP (ReplaceOneT' rs p q r) x
  eval :: proxy (ReplaceOne' rs p q r)
-> POpts -> x -> m (TT (PP (ReplaceOne' rs p q r) x))
eval proxy (ReplaceOne' rs p q r)
_ = Proxy (ReplaceOneT' rs p q r)
-> POpts -> x -> m (TT (PP (ReplaceOneT' rs p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceOneT' rs p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceOneT' rs p q r))

-- | replaces first value using regex @p@ with a replacement function @q@ inside the value @r@

data ReplaceOne p q r deriving Int -> ReplaceOne p q r -> ShowS
[ReplaceOne p q r] -> ShowS
ReplaceOne p q r -> String
(Int -> ReplaceOne p q r -> ShowS)
-> (ReplaceOne p q r -> String)
-> ([ReplaceOne p q r] -> ShowS)
-> Show (ReplaceOne p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceOne p q r -> ShowS
forall k (p :: k) k (q :: k) k (r :: k).
[ReplaceOne p q r] -> ShowS
forall k (p :: k) k (q :: k) k (r :: k). ReplaceOne p q r -> String
showList :: [ReplaceOne p q r] -> ShowS
$cshowList :: forall k (p :: k) k (q :: k) k (r :: k).
[ReplaceOne p q r] -> ShowS
show :: ReplaceOne p q r -> String
$cshow :: forall k (p :: k) k (q :: k) k (r :: k). ReplaceOne p q r -> String
showsPrec :: Int -> ReplaceOne p q r -> ShowS
$cshowsPrec :: forall k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceOne p q r -> ShowS
Show
type ReplaceOneT p q r = ReplaceOne' '[] p q r

instance P (ReplaceOneT p q r) x => P (ReplaceOne p q r) x where
  type PP (ReplaceOne p q r) x = PP (ReplaceOneT p q r) x
  eval :: proxy (ReplaceOne p q r)
-> POpts -> x -> m (TT (PP (ReplaceOne p q r) x))
eval proxy (ReplaceOne p q r)
_ = Proxy (ReplaceOneT p q r)
-> POpts -> x -> m (TT (PP (ReplaceOneT p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceOneT p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceOneT p q r))

-- | replace all occurrences of string @p@ with @q@ in @r@ using regex options @rs@

data ReplaceAllString' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r deriving Int -> ReplaceAllString' rs o p q r -> ShowS
[ReplaceAllString' rs o p q r] -> ShowS
ReplaceAllString' rs o p q r -> String
(Int -> ReplaceAllString' rs o p q r -> ShowS)
-> (ReplaceAllString' rs o p q r -> String)
-> ([ReplaceAllString' rs o p q r] -> ShowS)
-> Show (ReplaceAllString' rs o p q r)
forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
Int -> ReplaceAllString' rs o p q r -> ShowS
forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
[ReplaceAllString' rs o p q r] -> ShowS
forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
ReplaceAllString' rs o p q r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplaceAllString' rs o p q r] -> ShowS
$cshowList :: forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
[ReplaceAllString' rs o p q r] -> ShowS
show :: ReplaceAllString' rs o p q r -> String
$cshow :: forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
ReplaceAllString' rs o p q r -> String
showsPrec :: Int -> ReplaceAllString' rs o p q r -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
Int -> ReplaceAllString' rs o p q r -> ShowS
Show
type ReplaceAllStringT' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r = ReplaceAll' rs p (ReplaceFn o q) r

instance P (ReplaceAllStringT' rs o p q r) x => P (ReplaceAllString' rs o p q r) x where
  type PP (ReplaceAllString' rs o p q r) x = PP (ReplaceAllStringT' rs o p q r) x
  eval :: proxy (ReplaceAllString' rs o p q r)
-> POpts -> x -> m (TT (PP (ReplaceAllString' rs o p q r) x))
eval proxy (ReplaceAllString' rs o p q r)
_ = Proxy (ReplaceAllStringT' rs o p q r)
-> POpts -> x -> m (TT (PP (ReplaceAllStringT' rs o p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceAllStringT' rs o p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceAllStringT' rs o p q r))

-- | replace all occurrences of string @p@ with @q@ in @r@

--

-- >>> pl @(ReplaceAllString 'ROverWrite "abc" "def" Id) "123abc456abc"

-- Present "123def456def" (ReplaceAll (abc) 123abc456abc | 123def456def)

-- Val "123def456def"

--

-- >>> pl @(ReplaceAllString' '[] 'ROverWrite "abc" "def" Id) "123AbC456abc"

-- Present "123AbC456def" (ReplaceAll (abc) 123AbC456abc | 123AbC456def)

-- Val "123AbC456def"

--

-- >>> pl @(ReplaceAllString' '[ 'Caseless ] 'ROverWrite "abc" "def" Id) "123AbC456abc"

-- Present "123def456def" (ReplaceAll' ['Caseless] (abc) 123AbC456abc | 123def456def)

-- Val "123def456def"

--

-- >>> pl @(ReplaceAllString 'RPrepend "abc" "def" Id) "123AbC456abc"

-- Present "123AbC456defabc" (ReplaceAll (abc) 123AbC456abc | 123AbC456defabc)

-- Val "123AbC456defabc"

--

-- >>> pl @(ReplaceAllString 'ROverWrite "abc" "def" Id) "123AbC456abc"

-- Present "123AbC456def" (ReplaceAll (abc) 123AbC456abc | 123AbC456def)

-- Val "123AbC456def"

--

-- >>> pl @(ReplaceAllString 'RAppend "abc" "def" Id) "123AbC456abc"

-- Present "123AbC456abcdef" (ReplaceAll (abc) 123AbC456abc | 123AbC456abcdef)

-- Val "123AbC456abcdef"

--

-- >>> pz @(ReplaceAllString 'ROverWrite "\\." ":" Id) "141.201.1.22"

-- Val "141:201:1:22"

--

data ReplaceAllString o p q r deriving Int -> ReplaceAllString o p q r -> ShowS
[ReplaceAllString o p q r] -> ShowS
ReplaceAllString o p q r -> String
(Int -> ReplaceAllString o p q r -> ShowS)
-> (ReplaceAllString o p q r -> String)
-> ([ReplaceAllString o p q r] -> ShowS)
-> Show (ReplaceAllString o p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (o :: k) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceAllString o p q r -> ShowS
forall k (o :: k) k (p :: k) k (q :: k) k (r :: k).
[ReplaceAllString o p q r] -> ShowS
forall k (o :: k) k (p :: k) k (q :: k) k (r :: k).
ReplaceAllString o p q r -> String
showList :: [ReplaceAllString o p q r] -> ShowS
$cshowList :: forall k (o :: k) k (p :: k) k (q :: k) k (r :: k).
[ReplaceAllString o p q r] -> ShowS
show :: ReplaceAllString o p q r -> String
$cshow :: forall k (o :: k) k (p :: k) k (q :: k) k (r :: k).
ReplaceAllString o p q r -> String
showsPrec :: Int -> ReplaceAllString o p q r -> ShowS
$cshowsPrec :: forall k (o :: k) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceAllString o p q r -> ShowS
Show
type ReplaceAllStringT o p q r = ReplaceAllString' '[] o p q r

instance P (ReplaceAllStringT o p q r) x => P (ReplaceAllString o p q r) x where
  type PP (ReplaceAllString o p q r) x = PP (ReplaceAllStringT o p q r) x
  eval :: proxy (ReplaceAllString o p q r)
-> POpts -> x -> m (TT (PP (ReplaceAllString o p q r) x))
eval proxy (ReplaceAllString o p q r)
_ = Proxy (ReplaceAllStringT o p q r)
-> POpts -> x -> m (TT (PP (ReplaceAllStringT o p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceAllStringT o p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceAllStringT o p q r))

-- | same as 'ReplaceOneString' but allow setting regex options with @rs@

data ReplaceOneString' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r deriving Int -> ReplaceOneString' rs o p q r -> ShowS
[ReplaceOneString' rs o p q r] -> ShowS
ReplaceOneString' rs o p q r -> String
(Int -> ReplaceOneString' rs o p q r -> ShowS)
-> (ReplaceOneString' rs o p q r -> String)
-> ([ReplaceOneString' rs o p q r] -> ShowS)
-> Show (ReplaceOneString' rs o p q r)
forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
Int -> ReplaceOneString' rs o p q r -> ShowS
forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
[ReplaceOneString' rs o p q r] -> ShowS
forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
ReplaceOneString' rs o p q r -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplaceOneString' rs o p q r] -> ShowS
$cshowList :: forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
[ReplaceOneString' rs o p q r] -> ShowS
show :: ReplaceOneString' rs o p q r -> String
$cshow :: forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
ReplaceOneString' rs o p q r -> String
showsPrec :: Int -> ReplaceOneString' rs o p q r -> ShowS
$cshowsPrec :: forall (rs :: [ROpt]) (o :: ReplaceFnSub) k (p :: k) k (q :: k) k
       (r :: k).
Int -> ReplaceOneString' rs o p q r -> ShowS
Show
type ReplaceOneStringT' (rs :: [ROpt]) (o :: ReplaceFnSub) p q r = ReplaceOne' rs p (ReplaceFn o q) r

instance P (ReplaceOneStringT' rs o p q r) x => P (ReplaceOneString' rs o p q r) x where
  type PP (ReplaceOneString' rs o p q r) x = PP (ReplaceOneStringT' rs o p q r) x
  eval :: proxy (ReplaceOneString' rs o p q r)
-> POpts -> x -> m (TT (PP (ReplaceOneString' rs o p q r) x))
eval proxy (ReplaceOneString' rs o p q r)
_ = Proxy (ReplaceOneStringT' rs o p q r)
-> POpts -> x -> m (TT (PP (ReplaceOneStringT' rs o p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceOneStringT' rs o p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceOneStringT' rs o p q r))

-- | replace first occurrence of string @p@ with @q@ in @r@

--

-- >>> pl @(ReplaceOneString 'ROverWrite "abc" "def" Id) "123abc456abc"

-- Present "123def456abc" (ReplaceOne (abc) 123abc456abc | 123def456abc)

-- Val "123def456abc"

--

-- >>> pz @(Rescan "^Date\\((\\d+[+-]\\d{4})\\)" >> Head >> Snd >> Id !! 0 >> ReplaceOneString 'RPrepend "\\d{3}[+-]" "." Id >> ParseTimeP ZonedTime "%s%Q%z") "Date(1530144000123+0530)"

-- Val 2018-06-28 05:30:00.123 +0530

--

-- >>> pz @(Rescan "^Date\\((\\d+[+-]\\d{4})\\)" >> Head >> Snd >> Id !! 0 >> ReplaceOneString 'RPrepend "\\d{3}[+-]" "." Id >> ParseTimeP ZonedTime "%s%Q%z") "Date(1593460089052+0800)"

-- Val 2020-06-30 03:48:09.052 +0800

--

data ReplaceOneString (o :: ReplaceFnSub) p q r deriving Int -> ReplaceOneString o p q r -> ShowS
[ReplaceOneString o p q r] -> ShowS
ReplaceOneString o p q r -> String
(Int -> ReplaceOneString o p q r -> ShowS)
-> (ReplaceOneString o p q r -> String)
-> ([ReplaceOneString o p q r] -> ShowS)
-> Show (ReplaceOneString o p q r)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (o :: ReplaceFnSub) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceOneString o p q r -> ShowS
forall (o :: ReplaceFnSub) k (p :: k) k (q :: k) k (r :: k).
[ReplaceOneString o p q r] -> ShowS
forall (o :: ReplaceFnSub) k (p :: k) k (q :: k) k (r :: k).
ReplaceOneString o p q r -> String
showList :: [ReplaceOneString o p q r] -> ShowS
$cshowList :: forall (o :: ReplaceFnSub) k (p :: k) k (q :: k) k (r :: k).
[ReplaceOneString o p q r] -> ShowS
show :: ReplaceOneString o p q r -> String
$cshow :: forall (o :: ReplaceFnSub) k (p :: k) k (q :: k) k (r :: k).
ReplaceOneString o p q r -> String
showsPrec :: Int -> ReplaceOneString o p q r -> ShowS
$cshowsPrec :: forall (o :: ReplaceFnSub) k (p :: k) k (q :: k) k (r :: k).
Int -> ReplaceOneString o p q r -> ShowS
Show
type ReplaceOneStringT (o :: ReplaceFnSub) p q r = ReplaceOneString' '[] o p q r

instance P (ReplaceOneStringT o p q r) x => P (ReplaceOneString o p q r) x where
  type PP (ReplaceOneString o p q r) x = PP (ReplaceOneStringT o p q r) x
  eval :: proxy (ReplaceOneString o p q r)
-> POpts -> x -> m (TT (PP (ReplaceOneString o p q r) x))
eval proxy (ReplaceOneString o p q r)
_ = Proxy (ReplaceOneStringT o p q r)
-> POpts -> x -> m (TT (PP (ReplaceOneStringT o p q r) x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy (ReplaceOneStringT o p q r)
forall k (t :: k). Proxy t
Proxy @(ReplaceOneStringT o p q r))

-- | Simple replacement string: see 'ReplaceAllString' and 'ReplaceOneString'

--

data ReplaceFn (o :: ReplaceFnSub) p deriving Int -> ReplaceFn o p -> ShowS
[ReplaceFn o p] -> ShowS
ReplaceFn o p -> String
(Int -> ReplaceFn o p -> ShowS)
-> (ReplaceFn o p -> String)
-> ([ReplaceFn o p] -> ShowS)
-> Show (ReplaceFn o p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (o :: ReplaceFnSub) k (p :: k).
Int -> ReplaceFn o p -> ShowS
forall (o :: ReplaceFnSub) k (p :: k). [ReplaceFn o p] -> ShowS
forall (o :: ReplaceFnSub) k (p :: k). ReplaceFn o p -> String
showList :: [ReplaceFn o p] -> ShowS
$cshowList :: forall (o :: ReplaceFnSub) k (p :: k). [ReplaceFn o p] -> ShowS
show :: ReplaceFn o p -> String
$cshow :: forall (o :: ReplaceFnSub) k (p :: k). ReplaceFn o p -> String
showsPrec :: Int -> ReplaceFn o p -> ShowS
$cshowsPrec :: forall (o :: ReplaceFnSub) k (p :: k).
Int -> ReplaceFn o p -> ShowS
Show

instance ( GetReplaceFnSub r
         , PP p x ~ String
         , P p x
         ) => P (ReplaceFn r p) x where
  type PP (ReplaceFn r p) x = RReplace
  eval :: proxy (ReplaceFn r p)
-> POpts -> x -> m (TT (PP (ReplaceFn r p) x))
eval proxy (ReplaceFn r p)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"ReplaceFn"
    TT String
pp <- Proxy p -> POpts -> x -> m (TT (PP p x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy p
forall k (t :: k). Proxy t
Proxy @p) POpts
opts x
x
    TT RReplace -> m (TT RReplace)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT RReplace -> m (TT RReplace)) -> TT RReplace -> m (TT RReplace)
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT String
-> [Tree PE]
-> Either (TT RReplace) String
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts String
msg0 TT String
pp [] of
      Left TT RReplace
e -> TT RReplace
e
      Right String
p ->
        let ret :: RReplace
ret = ReplaceFnSub -> String -> RReplace
RReplace (GetReplaceFnSub r => ReplaceFnSub
forall (k :: ReplaceFnSub). GetReplaceFnSub k => ReplaceFnSub
getReplaceFnSub @r) String
p
        in POpts -> Val RReplace -> String -> [Tree PE] -> TT RReplace
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (RReplace -> Val RReplace
forall a. a -> Val a
Val RReplace
ret) (String
msg0 String -> ShowS
forall a. Semigroup a => a -> a -> a
<> POpts -> String -> ShowS
forall a. Show a => POpts -> String -> a -> String
showVerbose POpts
opts String
" | " String
p) [TT String -> Tree PE
forall a. TT a -> Tree PE
hh TT String
pp]

-- | A replacement function @(String -> [String] -> String)@ which returns the whole match and the groups

-- Used by 'RH.sub' and 'RH.gsub'

--

-- Requires "Text.Show.Functions"

--

data ReplaceFn1 p deriving Int -> ReplaceFn1 p -> ShowS
[ReplaceFn1 p] -> ShowS
ReplaceFn1 p -> String
(Int -> ReplaceFn1 p -> ShowS)
-> (ReplaceFn1 p -> String)
-> ([ReplaceFn1 p] -> ShowS)
-> Show (ReplaceFn1 p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k). Int -> ReplaceFn1 p -> ShowS
forall k (p :: k). [ReplaceFn1 p] -> ShowS
forall k (p :: k). ReplaceFn1 p -> String
showList :: [ReplaceFn1 p] -> ShowS
$cshowList :: forall k (p :: k). [ReplaceFn1 p] -> ShowS
show :: ReplaceFn1 p -> String
$cshow :: forall k (p :: k). ReplaceFn1 p -> String
showsPrec :: Int -> ReplaceFn1 p -> ShowS
$cshowsPrec :: forall k (p :: k). Int -> ReplaceFn1 p -> ShowS
Show

instance ( PP p x ~ (String -> [String] -> String)
         , P p x
         ) => P (ReplaceFn1 p) x where
  type PP (ReplaceFn1 p) x = RReplace
  eval :: proxy (ReplaceFn1 p) -> POpts -> x -> m (TT (PP (ReplaceFn1 p) x))
eval proxy (ReplaceFn1 p)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"ReplaceFn1 (String -> [String] -> String)"
    TT (String -> [String] -> String)
pp <- Proxy p -> POpts -> x -> m (TT (PP p x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy p
forall k (t :: k). Proxy t
Proxy @p) POpts
opts x
x
    TT RReplace -> m (TT RReplace)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT RReplace -> m (TT RReplace)) -> TT RReplace -> m (TT RReplace)
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT (String -> [String] -> String)
-> [Tree PE]
-> Either (TT RReplace) (String -> [String] -> String)
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts String
msg0 TT (String -> [String] -> String)
pp [] of
      Left TT RReplace
e -> TT RReplace
e
      Right String -> [String] -> String
f -> POpts -> Val RReplace -> String -> [Tree PE] -> TT RReplace
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (RReplace -> Val RReplace
forall a. a -> Val a
Val ((String -> [String] -> String) -> RReplace
RReplace1 String -> [String] -> String
f)) String
msg0 [TT (String -> [String] -> String) -> Tree PE
forall a. TT a -> Tree PE
hh TT (String -> [String] -> String)
pp]

-- | A replacement function @(String -> String)@ that yields the whole match

-- Used by 'RH.sub' and 'RH.gsub'

--

-- Requires "Text.Show.Functions"

--

-- >>> :m + Text.Show.Functions

-- >>> pz @(ReplaceAll "\\." (ReplaceFn2 Fst) Snd) (\x -> x <> ":" <> x, "141.201.1.22")

-- Val "141.:.201.:.1.:.22"

--

data ReplaceFn2 p deriving Int -> ReplaceFn2 p -> ShowS
[ReplaceFn2 p] -> ShowS
ReplaceFn2 p -> String
(Int -> ReplaceFn2 p -> ShowS)
-> (ReplaceFn2 p -> String)
-> ([ReplaceFn2 p] -> ShowS)
-> Show (ReplaceFn2 p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k). Int -> ReplaceFn2 p -> ShowS
forall k (p :: k). [ReplaceFn2 p] -> ShowS
forall k (p :: k). ReplaceFn2 p -> String
showList :: [ReplaceFn2 p] -> ShowS
$cshowList :: forall k (p :: k). [ReplaceFn2 p] -> ShowS
show :: ReplaceFn2 p -> String
$cshow :: forall k (p :: k). ReplaceFn2 p -> String
showsPrec :: Int -> ReplaceFn2 p -> ShowS
$cshowsPrec :: forall k (p :: k). Int -> ReplaceFn2 p -> ShowS
Show

instance ( PP p x ~ (String -> String)
         , P p x
         ) => P (ReplaceFn2 p) x where
  type PP (ReplaceFn2 p) x = RReplace
  eval :: proxy (ReplaceFn2 p) -> POpts -> x -> m (TT (PP (ReplaceFn2 p) x))
eval proxy (ReplaceFn2 p)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"ReplaceFn2 (String -> String)"
    TT ShowS
pp <- Proxy p -> POpts -> x -> m (TT (PP p x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy p
forall k (t :: k). Proxy t
Proxy @p) POpts
opts x
x
    TT RReplace -> m (TT RReplace)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT RReplace -> m (TT RReplace)) -> TT RReplace -> m (TT RReplace)
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT ShowS
-> [Tree PE]
-> Either (TT RReplace) ShowS
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts String
msg0 TT ShowS
pp [] of
      Left TT RReplace
e -> TT RReplace
e
      Right ShowS
f -> POpts -> Val RReplace -> String -> [Tree PE] -> TT RReplace
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (RReplace -> Val RReplace
forall a. a -> Val a
Val (ShowS -> RReplace
RReplace2 ShowS
f)) String
msg0 [TT ShowS -> Tree PE
forall a. TT a -> Tree PE
hh TT ShowS
pp]

-- | A replacement function @([String] -> String)@ which yields the groups

-- Used by 'RH.sub' and 'RH.gsub'

--

-- Requires "Text.Show.Functions"

--

-- >>> :m + Text.Show.Functions

-- >>> import Data.List (intercalate)

-- >>> pz @(ReplaceAll "^(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)$" (ReplaceFn3 Fst) Snd) (\ys -> intercalate  " | " $ map (show . succ . readNote @Int "invalid int") ys, "141.201.1.22")

-- Val "142 | 202 | 2 | 23"

--

data ReplaceFn3 p deriving Int -> ReplaceFn3 p -> ShowS
[ReplaceFn3 p] -> ShowS
ReplaceFn3 p -> String
(Int -> ReplaceFn3 p -> ShowS)
-> (ReplaceFn3 p -> String)
-> ([ReplaceFn3 p] -> ShowS)
-> Show (ReplaceFn3 p)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall k (p :: k). Int -> ReplaceFn3 p -> ShowS
forall k (p :: k). [ReplaceFn3 p] -> ShowS
forall k (p :: k). ReplaceFn3 p -> String
showList :: [ReplaceFn3 p] -> ShowS
$cshowList :: forall k (p :: k). [ReplaceFn3 p] -> ShowS
show :: ReplaceFn3 p -> String
$cshow :: forall k (p :: k). ReplaceFn3 p -> String
showsPrec :: Int -> ReplaceFn3 p -> ShowS
$cshowsPrec :: forall k (p :: k). Int -> ReplaceFn3 p -> ShowS
Show

instance ( PP p x ~ ([String] -> String)
         , P p x
         ) => P (ReplaceFn3 p) x where
  type PP (ReplaceFn3 p) x = RReplace
  eval :: proxy (ReplaceFn3 p) -> POpts -> x -> m (TT (PP (ReplaceFn3 p) x))
eval proxy (ReplaceFn3 p)
_ POpts
opts x
x = do
    let msg0 :: String
msg0 = String
"ReplaceFn3 ([String] -> String)"
    TT ([String] -> String)
pp <- Proxy p -> POpts -> x -> m (TT (PP p x))
forall k (p :: k) a (m :: Type -> Type) (proxy :: k -> Type).
(P p a, MonadEval m) =>
proxy p -> POpts -> a -> m (TT (PP p a))
eval (Proxy p
forall k (t :: k). Proxy t
Proxy @p) POpts
opts x
x
    TT RReplace -> m (TT RReplace)
forall (f :: Type -> Type) a. Applicative f => a -> f a
pure (TT RReplace -> m (TT RReplace)) -> TT RReplace -> m (TT RReplace)
forall a b. (a -> b) -> a -> b
$ case Inline
-> POpts
-> String
-> TT ([String] -> String)
-> [Tree PE]
-> Either (TT RReplace) ([String] -> String)
forall a x.
Inline -> POpts -> String -> TT a -> [Tree PE] -> Either (TT x) a
getValueLR Inline
NoInline POpts
opts String
msg0 TT ([String] -> String)
pp [] of
      Left TT RReplace
e -> TT RReplace
e
      Right [String] -> String
f -> POpts -> Val RReplace -> String -> [Tree PE] -> TT RReplace
forall a. POpts -> Val a -> String -> [Tree PE] -> TT a
mkNode POpts
opts (RReplace -> Val RReplace
forall a. a -> Val a
Val (([String] -> String) -> RReplace
RReplace3 [String] -> String
f)) String
msg0 [TT ([String] -> String) -> Tree PE
forall a. TT a -> Tree PE
hh TT ([String] -> String)
pp]