module Web.Willow.Common.Parser.Util
( range
, choice
, findNext
) where
import qualified Control.Applicative as A
import Control.Applicative ( (<|>) )
import Web.Willow.Common.Parser
range
:: Ord a
=> a
-> a
-> a
-> Bool
range :: a -> a -> a -> Bool
range a
low a
high a
test = a
test a -> a -> Bool
forall a. Ord a => a -> a -> Bool
>= a
low Bool -> Bool -> Bool
&& a
test a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
high
choice :: A.Alternative m => [m a] -> m a
choice :: [m a] -> m a
choice = (m a -> m a -> m a) -> m a -> [m a] -> m a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
(<|>) m a
forall (f :: * -> *) a. Alternative f => f a
A.empty
findNext :: MonadParser parser stream token => parser out -> parser out
findNext :: parser out -> parser out
findNext parser out
target = [parser out] -> parser out
forall (m :: * -> *) a. Alternative m => [m a] -> m a
choice
[ parser out
target
, parser token
forall (m :: * -> *) stream token.
MonadParser m stream token =>
m token
next parser token -> parser out -> parser out
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> parser out -> parser out
forall (parser :: * -> *) stream token out.
MonadParser parser stream token =>
parser out -> parser out
findNext parser out
target
]