{-# LANGUAGE RankNTypes #-}
module Toml.FromValue.Matcher (
Matcher,
Result(..),
MatchMessage(..),
runMatcher,
withScope,
getScope,
warning,
Scope(..),
inKey,
inIndex,
) where
import Control.Applicative (Alternative(..))
import Control.Monad (MonadPlus, ap, liftM)
import Data.Monoid (Endo(..))
newtype Matcher a = Matcher {
forall a.
Matcher a
-> forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
unMatcher ::
forall r.
[Scope] ->
DList MatchMessage ->
(DList MatchMessage -> r) ->
(DList MatchMessage -> a -> r) ->
r
}
instance Functor Matcher where
fmap :: forall a b. (a -> b) -> Matcher a -> Matcher b
fmap = (a -> b) -> Matcher a -> Matcher b
forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM
instance Applicative Matcher where
pure :: forall a. a -> Matcher a
pure a
x = (forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
_env DList MatchMessage
warn DList MatchMessage -> r
_err DList MatchMessage -> a -> r
ok -> DList MatchMessage -> a -> r
ok DList MatchMessage
warn a
x)
<*> :: forall a b. Matcher (a -> b) -> Matcher a -> Matcher b
(<*>) = Matcher (a -> b) -> Matcher a -> Matcher b
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap
instance Monad Matcher where
Matcher a
m >>= :: forall a b. Matcher a -> (a -> Matcher b) -> Matcher b
>>= a -> Matcher b
f = (forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> b -> r)
-> r)
-> Matcher b
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
env DList MatchMessage
warn DList MatchMessage -> r
err DList MatchMessage -> b -> r
ok -> Matcher a
-> forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
forall a.
Matcher a
-> forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
unMatcher Matcher a
m [Scope]
env DList MatchMessage
warn DList MatchMessage -> r
err (\DList MatchMessage
warn' a
x -> Matcher b
-> forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> b -> r)
-> r
forall a.
Matcher a
-> forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
unMatcher (a -> Matcher b
f a
x) [Scope]
env DList MatchMessage
warn' DList MatchMessage -> r
err DList MatchMessage -> b -> r
ok))
{-# INLINE (>>=) #-}
instance Alternative Matcher where
empty :: forall a. Matcher a
empty = (forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
_env DList MatchMessage
_warn DList MatchMessage -> r
err DList MatchMessage -> a -> r
_ok -> DList MatchMessage -> r
err DList MatchMessage
forall a. Monoid a => a
mempty)
Matcher forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
x <|> :: forall a. Matcher a -> Matcher a -> Matcher a
<|> Matcher forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
y = (forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
env DList MatchMessage
warn DList MatchMessage -> r
err DList MatchMessage -> a -> r
ok -> [Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
x [Scope]
env DList MatchMessage
warn (\DList MatchMessage
errs1 -> [Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
y [Scope]
env DList MatchMessage
warn (\DList MatchMessage
errs2 -> DList MatchMessage -> r
err (DList MatchMessage
errs1 DList MatchMessage -> DList MatchMessage -> DList MatchMessage
forall a. Semigroup a => a -> a -> a
<> DList MatchMessage
errs2)) DList MatchMessage -> a -> r
ok) DList MatchMessage -> a -> r
ok)
instance MonadPlus Matcher
data Scope
= ScopeIndex Int
| ScopeKey String
deriving (
ReadPrec [Scope]
ReadPrec Scope
Int -> ReadS Scope
ReadS [Scope]
(Int -> ReadS Scope)
-> ReadS [Scope]
-> ReadPrec Scope
-> ReadPrec [Scope]
-> Read Scope
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Scope
readsPrec :: Int -> ReadS Scope
$creadList :: ReadS [Scope]
readList :: ReadS [Scope]
$creadPrec :: ReadPrec Scope
readPrec :: ReadPrec Scope
$creadListPrec :: ReadPrec [Scope]
readListPrec :: ReadPrec [Scope]
Read ,
Int -> Scope -> ShowS
[Scope] -> ShowS
Scope -> String
(Int -> Scope -> ShowS)
-> (Scope -> String) -> ([Scope] -> ShowS) -> Show Scope
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Scope -> ShowS
showsPrec :: Int -> Scope -> ShowS
$cshow :: Scope -> String
show :: Scope -> String
$cshowList :: [Scope] -> ShowS
showList :: [Scope] -> ShowS
Show ,
Scope -> Scope -> Bool
(Scope -> Scope -> Bool) -> (Scope -> Scope -> Bool) -> Eq Scope
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Scope -> Scope -> Bool
== :: Scope -> Scope -> Bool
$c/= :: Scope -> Scope -> Bool
/= :: Scope -> Scope -> Bool
Eq ,
Eq Scope
Eq Scope =>
(Scope -> Scope -> Ordering)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Bool)
-> (Scope -> Scope -> Scope)
-> (Scope -> Scope -> Scope)
-> Ord Scope
Scope -> Scope -> Bool
Scope -> Scope -> Ordering
Scope -> Scope -> Scope
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Scope -> Scope -> Ordering
compare :: Scope -> Scope -> Ordering
$c< :: Scope -> Scope -> Bool
< :: Scope -> Scope -> Bool
$c<= :: Scope -> Scope -> Bool
<= :: Scope -> Scope -> Bool
$c> :: Scope -> Scope -> Bool
> :: Scope -> Scope -> Bool
$c>= :: Scope -> Scope -> Bool
>= :: Scope -> Scope -> Bool
$cmax :: Scope -> Scope -> Scope
max :: Scope -> Scope -> Scope
$cmin :: Scope -> Scope -> Scope
min :: Scope -> Scope -> Scope
Ord )
data MatchMessage = MatchMessage {
MatchMessage -> [Scope]
matchPath :: [Scope],
MatchMessage -> String
matchMessage :: String
} deriving (
ReadPrec [MatchMessage]
ReadPrec MatchMessage
Int -> ReadS MatchMessage
ReadS [MatchMessage]
(Int -> ReadS MatchMessage)
-> ReadS [MatchMessage]
-> ReadPrec MatchMessage
-> ReadPrec [MatchMessage]
-> Read MatchMessage
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS MatchMessage
readsPrec :: Int -> ReadS MatchMessage
$creadList :: ReadS [MatchMessage]
readList :: ReadS [MatchMessage]
$creadPrec :: ReadPrec MatchMessage
readPrec :: ReadPrec MatchMessage
$creadListPrec :: ReadPrec [MatchMessage]
readListPrec :: ReadPrec [MatchMessage]
Read ,
Int -> MatchMessage -> ShowS
[MatchMessage] -> ShowS
MatchMessage -> String
(Int -> MatchMessage -> ShowS)
-> (MatchMessage -> String)
-> ([MatchMessage] -> ShowS)
-> Show MatchMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> MatchMessage -> ShowS
showsPrec :: Int -> MatchMessage -> ShowS
$cshow :: MatchMessage -> String
show :: MatchMessage -> String
$cshowList :: [MatchMessage] -> ShowS
showList :: [MatchMessage] -> ShowS
Show ,
MatchMessage -> MatchMessage -> Bool
(MatchMessage -> MatchMessage -> Bool)
-> (MatchMessage -> MatchMessage -> Bool) -> Eq MatchMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: MatchMessage -> MatchMessage -> Bool
== :: MatchMessage -> MatchMessage -> Bool
$c/= :: MatchMessage -> MatchMessage -> Bool
/= :: MatchMessage -> MatchMessage -> Bool
Eq ,
Eq MatchMessage
Eq MatchMessage =>
(MatchMessage -> MatchMessage -> Ordering)
-> (MatchMessage -> MatchMessage -> Bool)
-> (MatchMessage -> MatchMessage -> Bool)
-> (MatchMessage -> MatchMessage -> Bool)
-> (MatchMessage -> MatchMessage -> Bool)
-> (MatchMessage -> MatchMessage -> MatchMessage)
-> (MatchMessage -> MatchMessage -> MatchMessage)
-> Ord MatchMessage
MatchMessage -> MatchMessage -> Bool
MatchMessage -> MatchMessage -> Ordering
MatchMessage -> MatchMessage -> MatchMessage
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: MatchMessage -> MatchMessage -> Ordering
compare :: MatchMessage -> MatchMessage -> Ordering
$c< :: MatchMessage -> MatchMessage -> Bool
< :: MatchMessage -> MatchMessage -> Bool
$c<= :: MatchMessage -> MatchMessage -> Bool
<= :: MatchMessage -> MatchMessage -> Bool
$c> :: MatchMessage -> MatchMessage -> Bool
> :: MatchMessage -> MatchMessage -> Bool
$c>= :: MatchMessage -> MatchMessage -> Bool
>= :: MatchMessage -> MatchMessage -> Bool
$cmax :: MatchMessage -> MatchMessage -> MatchMessage
max :: MatchMessage -> MatchMessage -> MatchMessage
$cmin :: MatchMessage -> MatchMessage -> MatchMessage
min :: MatchMessage -> MatchMessage -> MatchMessage
Ord )
newtype DList a = DList (Endo [a])
deriving (NonEmpty (DList a) -> DList a
DList a -> DList a -> DList a
(DList a -> DList a -> DList a)
-> (NonEmpty (DList a) -> DList a)
-> (forall b. Integral b => b -> DList a -> DList a)
-> Semigroup (DList a)
forall b. Integral b => b -> DList a -> DList a
forall a. NonEmpty (DList a) -> DList a
forall a. DList a -> DList a -> DList a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> DList a -> DList a
$c<> :: forall a. DList a -> DList a -> DList a
<> :: DList a -> DList a -> DList a
$csconcat :: forall a. NonEmpty (DList a) -> DList a
sconcat :: NonEmpty (DList a) -> DList a
$cstimes :: forall a b. Integral b => b -> DList a -> DList a
stimes :: forall b. Integral b => b -> DList a -> DList a
Semigroup, Semigroup (DList a)
DList a
Semigroup (DList a) =>
DList a
-> (DList a -> DList a -> DList a)
-> ([DList a] -> DList a)
-> Monoid (DList a)
[DList a] -> DList a
DList a -> DList a -> DList a
forall a. Semigroup (DList a)
forall a. DList a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. [DList a] -> DList a
forall a. DList a -> DList a -> DList a
$cmempty :: forall a. DList a
mempty :: DList a
$cmappend :: forall a. DList a -> DList a -> DList a
mappend :: DList a -> DList a -> DList a
$cmconcat :: forall a. [DList a] -> DList a
mconcat :: [DList a] -> DList a
Monoid)
one :: a -> DList a
one :: forall a. a -> DList a
one a
x = Endo [a] -> DList a
forall a. Endo [a] -> DList a
DList (([a] -> [a]) -> Endo [a]
forall a. (a -> a) -> Endo a
Endo (a
xa -> [a] -> [a]
forall a. a -> [a] -> [a]
:))
runDList :: DList a -> [a]
runDList :: forall a. DList a -> [a]
runDList (DList Endo [a]
x) = Endo [a]
x Endo [a] -> [a] -> [a]
forall a. Endo a -> a -> a
`appEndo` []
data Result e a
= Failure [e]
| Success [e] a
deriving (
ReadPrec [Result e a]
ReadPrec (Result e a)
Int -> ReadS (Result e a)
ReadS [Result e a]
(Int -> ReadS (Result e a))
-> ReadS [Result e a]
-> ReadPrec (Result e a)
-> ReadPrec [Result e a]
-> Read (Result e a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall e a. (Read e, Read a) => ReadPrec [Result e a]
forall e a. (Read e, Read a) => ReadPrec (Result e a)
forall e a. (Read e, Read a) => Int -> ReadS (Result e a)
forall e a. (Read e, Read a) => ReadS [Result e a]
$creadsPrec :: forall e a. (Read e, Read a) => Int -> ReadS (Result e a)
readsPrec :: Int -> ReadS (Result e a)
$creadList :: forall e a. (Read e, Read a) => ReadS [Result e a]
readList :: ReadS [Result e a]
$creadPrec :: forall e a. (Read e, Read a) => ReadPrec (Result e a)
readPrec :: ReadPrec (Result e a)
$creadListPrec :: forall e a. (Read e, Read a) => ReadPrec [Result e a]
readListPrec :: ReadPrec [Result e a]
Read ,
Int -> Result e a -> ShowS
[Result e a] -> ShowS
Result e a -> String
(Int -> Result e a -> ShowS)
-> (Result e a -> String)
-> ([Result e a] -> ShowS)
-> Show (Result e a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall e a. (Show e, Show a) => Int -> Result e a -> ShowS
forall e a. (Show e, Show a) => [Result e a] -> ShowS
forall e a. (Show e, Show a) => Result e a -> String
$cshowsPrec :: forall e a. (Show e, Show a) => Int -> Result e a -> ShowS
showsPrec :: Int -> Result e a -> ShowS
$cshow :: forall e a. (Show e, Show a) => Result e a -> String
show :: Result e a -> String
$cshowList :: forall e a. (Show e, Show a) => [Result e a] -> ShowS
showList :: [Result e a] -> ShowS
Show ,
Result e a -> Result e a -> Bool
(Result e a -> Result e a -> Bool)
-> (Result e a -> Result e a -> Bool) -> Eq (Result e a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall e a. (Eq e, Eq a) => Result e a -> Result e a -> Bool
$c== :: forall e a. (Eq e, Eq a) => Result e a -> Result e a -> Bool
== :: Result e a -> Result e a -> Bool
$c/= :: forall e a. (Eq e, Eq a) => Result e a -> Result e a -> Bool
/= :: Result e a -> Result e a -> Bool
Eq ,
Eq (Result e a)
Eq (Result e a) =>
(Result e a -> Result e a -> Ordering)
-> (Result e a -> Result e a -> Bool)
-> (Result e a -> Result e a -> Bool)
-> (Result e a -> Result e a -> Bool)
-> (Result e a -> Result e a -> Bool)
-> (Result e a -> Result e a -> Result e a)
-> (Result e a -> Result e a -> Result e a)
-> Ord (Result e a)
Result e a -> Result e a -> Bool
Result e a -> Result e a -> Ordering
Result e a -> Result e a -> Result e a
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall e a. (Ord e, Ord a) => Eq (Result e a)
forall e a. (Ord e, Ord a) => Result e a -> Result e a -> Bool
forall e a. (Ord e, Ord a) => Result e a -> Result e a -> Ordering
forall e a.
(Ord e, Ord a) =>
Result e a -> Result e a -> Result e a
$ccompare :: forall e a. (Ord e, Ord a) => Result e a -> Result e a -> Ordering
compare :: Result e a -> Result e a -> Ordering
$c< :: forall e a. (Ord e, Ord a) => Result e a -> Result e a -> Bool
< :: Result e a -> Result e a -> Bool
$c<= :: forall e a. (Ord e, Ord a) => Result e a -> Result e a -> Bool
<= :: Result e a -> Result e a -> Bool
$c> :: forall e a. (Ord e, Ord a) => Result e a -> Result e a -> Bool
> :: Result e a -> Result e a -> Bool
$c>= :: forall e a. (Ord e, Ord a) => Result e a -> Result e a -> Bool
>= :: Result e a -> Result e a -> Bool
$cmax :: forall e a.
(Ord e, Ord a) =>
Result e a -> Result e a -> Result e a
max :: Result e a -> Result e a -> Result e a
$cmin :: forall e a.
(Ord e, Ord a) =>
Result e a -> Result e a -> Result e a
min :: Result e a -> Result e a -> Result e a
Ord )
runMatcher :: Matcher a -> Result MatchMessage a
runMatcher :: forall a. Matcher a -> Result MatchMessage a
runMatcher (Matcher forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
m) = [Scope]
-> DList MatchMessage
-> (DList MatchMessage -> Result MatchMessage a)
-> (DList MatchMessage -> a -> Result MatchMessage a)
-> Result MatchMessage a
forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
m [] DList MatchMessage
forall a. Monoid a => a
mempty ([MatchMessage] -> Result MatchMessage a
forall e a. [e] -> Result e a
Failure ([MatchMessage] -> Result MatchMessage a)
-> (DList MatchMessage -> [MatchMessage])
-> DList MatchMessage
-> Result MatchMessage a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList MatchMessage -> [MatchMessage]
forall a. DList a -> [a]
runDList) ([MatchMessage] -> a -> Result MatchMessage a
forall e a. [e] -> a -> Result e a
Success ([MatchMessage] -> a -> Result MatchMessage a)
-> (DList MatchMessage -> [MatchMessage])
-> DList MatchMessage
-> a
-> Result MatchMessage a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList MatchMessage -> [MatchMessage]
forall a. DList a -> [a]
runDList)
withScope :: Scope -> Matcher a -> Matcher a
withScope :: forall a. Scope -> Matcher a -> Matcher a
withScope Scope
ctx (Matcher forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
m) = (forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
env -> [Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r
m (Scope
ctx Scope -> [Scope] -> [Scope]
forall a. a -> [a] -> [a]
: [Scope]
env))
getScope :: Matcher [Scope]
getScope :: Matcher [Scope]
getScope = (forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> [Scope] -> r)
-> r)
-> Matcher [Scope]
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
env DList MatchMessage
warn DList MatchMessage -> r
_err DList MatchMessage -> [Scope] -> r
ok -> DList MatchMessage -> [Scope] -> r
ok DList MatchMessage
warn ([Scope] -> [Scope]
forall a. [a] -> [a]
reverse [Scope]
env))
warning :: String -> Matcher ()
warning :: String -> Matcher ()
warning String
w =
do [Scope]
loc <- Matcher [Scope]
getScope
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> () -> r)
-> r)
-> Matcher ()
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
_env DList MatchMessage
warn DList MatchMessage -> r
_err DList MatchMessage -> () -> r
ok -> DList MatchMessage -> () -> r
ok (DList MatchMessage
warn DList MatchMessage -> DList MatchMessage -> DList MatchMessage
forall a. Semigroup a => a -> a -> a
<> MatchMessage -> DList MatchMessage
forall a. a -> DList a
one ([Scope] -> String -> MatchMessage
MatchMessage [Scope]
loc String
w)) ())
instance MonadFail Matcher where
fail :: forall a. String -> Matcher a
fail String
e =
do [Scope]
loc <- Matcher [Scope]
getScope
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
forall a.
(forall r.
[Scope]
-> DList MatchMessage
-> (DList MatchMessage -> r)
-> (DList MatchMessage -> a -> r)
-> r)
-> Matcher a
Matcher (\[Scope]
_env DList MatchMessage
_warn DList MatchMessage -> r
err DList MatchMessage -> a -> r
_ok -> DList MatchMessage -> r
err (MatchMessage -> DList MatchMessage
forall a. a -> DList a
one ([Scope] -> String -> MatchMessage
MatchMessage [Scope]
loc String
e)))
inKey :: String -> Matcher a -> Matcher a
inKey :: forall a. String -> Matcher a -> Matcher a
inKey = Scope -> Matcher a -> Matcher a
forall a. Scope -> Matcher a -> Matcher a
withScope (Scope -> Matcher a -> Matcher a)
-> (String -> Scope) -> String -> Matcher a -> Matcher a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Scope
ScopeKey
inIndex :: Int -> Matcher a -> Matcher a
inIndex :: forall a. Int -> Matcher a -> Matcher a
inIndex = Scope -> Matcher a -> Matcher a
forall a. Scope -> Matcher a -> Matcher a
withScope (Scope -> Matcher a -> Matcher a)
-> (Int -> Scope) -> Int -> Matcher a -> Matcher a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Scope
ScopeIndex