module Text.Regex.Do.Pcre.Ascii.Replace
(Replace(..),
Replace'(),
Repl_) where
import Text.Regex.Base.RegexLike as R
import Prelude as P
import Text.Regex.Do.Type.Do
import Text.Regex.Do.Type.Reexport as R
import Text.Regex.Do.Pcre.Matchf
import qualified Text.Regex.Do.ReplaceOpen as O
import Text.Regex.Do.Type.Regex as T
import Text.Regex.Do.Type.Extract
import Text.Regex.Do.Type.MatchHint
import Text.Regex.Do.Pcre.Option as O
class Replace pat repl body out where
replace::pat -> repl -> body -> out
instance (T.Regex a, Hint all, Replace' all a repl b) =>
Replace (all (Pattern a)) (repl b) (Body b) b where
replace = replace'
instance (T.Regex a, Hint all, Replace' all a repl b, Functor all) =>
Replace (all a) (repl b) b b where
replace p0 r0 b0 = replace' (Pattern <$> p0) r0 $ Body b0
instance (T.Regex a, Hint all, Replace' all a repl b) =>
Replace a (all(repl b)) b b where
replace p0 r0 b0 = replace' p1 (unhint r0) $ Body b0
where p1 = swap r0 $ Pattern p0
instance (T.Regex a, Replace' Once a repl b) =>
Replace a (repl b) (Once b) b where
replace p0 r0 b0 = replace' p1 r0 $ Body $ unhint b0
where p1 = swap b0 $ Pattern p0
instance (T.Regex a, Replace' All a repl b) =>
Replace a (repl b) (All b) b where
replace p0 r0 b0 = replace' p1 r0 $ Body $ unhint b0
where p1 = swap b0 $ Pattern p0
class Replace' all a repl b where
replace'::all (Pattern a) -> repl b -> Body b -> b
type Repl_ f rx r a = (T.Regex rx,
R.RegexLike R.Regex a,
Extract' a,
O.ReplaceOpen f r)
replace_ fn0 p0 r0 b0 =
let ma1 = fn0 p1 b0
p1 = T.makeRegex' <$> p0
in O.replace ma1 r0 b0
instance Repl_ Maybe a repl b => Replace' Once a repl b where
replace' = replace_ marray_
instance Repl_ [] a repl b => Replace' All a repl b where
replace' = replace_ marray_
dum_::Comp
dum_ = Blank