distributors-0.3.0.0: Unifying Parsers, Printers & Grammars
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Profunctor.Grammar

Description

 
Synopsis

Parsor

newtype Parsor s f a b Source #

Parsor is a simple invertible parser Profunctor.

Constructors

Parsor 

Fields

Instances

Instances details
(Alternative m, Monad m) => Category (Parsor s m :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

id :: forall (a :: k). Parsor s m a a #

(.) :: forall (b :: k) (c :: k) (a :: k). Parsor s m b c -> Parsor s m a b -> Parsor s m a c #

AsEmpty s => Matching s (Parsor s List a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(=~) :: s -> Parsor s List a b -> Bool Source #

(Categorized a, a ~ Item s, IsList s, Cons s s a a, Snoc s s a a, Filterable m, Alternative m, Monad m) => TokenAlgebra a (Parsor s m a a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

tokenClass :: TokenTest a -> Parsor s m a a Source #

(Categorized a, a ~ Item s, IsList s, Cons s s a a, Snoc s s a a, Filterable m, Alternative m, Monad m) => TerminalSymbol a (Parsor s m () ()) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

terminal :: [a] -> Parsor s m () () Source #

(Categorized a, a ~ Item s, IsList s, Cons s s a a, Snoc s s a a, Filterable m, Alternative m, Monad m) => Tokenized a (Parsor s m a a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

anyToken :: Parsor s m a a Source #

token :: a -> Parsor s m a a Source #

oneOf :: Foldable f => f a -> Parsor s m a a Source #

notOneOf :: Foldable f => f a -> Parsor s m a a Source #

asIn :: Categorize a -> Parsor s m a a Source #

notAsIn :: Categorize a -> Parsor s m a a Source #

(Alternative m, Monad m) => Arrow (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

arr :: (b -> c) -> Parsor s m b c #

first :: Parsor s m b c -> Parsor s m (b, d) (c, d) #

second :: Parsor s m b c -> Parsor s m (d, b) (d, c) #

(***) :: Parsor s m b c -> Parsor s m b' c' -> Parsor s m (b, b') (c, c') #

(&&&) :: Parsor s m b c -> Parsor s m b c' -> Parsor s m b (c, c') #

(Alternative m, Monad m) => ArrowChoice (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

left :: Parsor s m b c -> Parsor s m (Either b d) (Either c d) #

right :: Parsor s m b c -> Parsor s m (Either d b) (Either d c) #

(+++) :: Parsor s m b c -> Parsor s m b' c' -> Parsor s m (Either b b') (Either c c') #

(|||) :: Parsor s m b d -> Parsor s m c d -> Parsor s m (Either b c) d #

(Alternative m, Monad m) => ArrowPlus (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(<+>) :: Parsor s m b c -> Parsor s m b c -> Parsor s m b c #

(Alternative m, Monad m) => ArrowZero (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

zeroArrow :: Parsor s m b c #

(Alternative m, Monad m) => Alternator (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

alternate :: Either (Parsor s m a b) (Parsor s m c d) -> Parsor s m (Either a c) (Either b d) Source #

someP :: Parsor s m a b -> Parsor s m [a] [b] Source #

(Alternative m, Monad m) => Distributor (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

zeroP :: Parsor s m Void Void Source #

(>+<) :: Parsor s m a b -> Parsor s m c d -> Parsor s m (Either a c) (Either b d) Source #

optionalP :: Parsor s m a b -> Parsor s m (Maybe a) (Maybe b) Source #

manyP :: Parsor s m a b -> Parsor s m [a] [b] Source #

Filterable f => Filtrator (Parsor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

filtrate :: Parsor s f (Either a c) (Either b d) -> (Parsor s f a b, Parsor s f c d) Source #

(Alternative m, Monad m) => Choice (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

left' :: Parsor s m a b -> Parsor s m (Either a c) (Either b c) #

right' :: Parsor s m a b -> Parsor s m (Either c a) (Either c b) #

Filterable f => Cochoice (Parsor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

unleft :: Parsor s f (Either a d) (Either b d) -> Parsor s f a b #

unright :: Parsor s f (Either d a) (Either d b) -> Parsor s f a b #

(Alternative m, Monad m) => Strong (Parsor s m) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

first' :: Parsor s m a b -> Parsor s m (a, c) (b, c) #

second' :: Parsor s m a b -> Parsor s m (c, a) (c, b) #

Functor f => Profunctor (Parsor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

dimap :: (a -> b) -> (c -> d) -> Parsor s f b c -> Parsor s f a d #

lmap :: (a -> b) -> Parsor s f b c -> Parsor s f a c #

rmap :: (b -> c) -> Parsor s f a b -> Parsor s f a c #

(#.) :: forall a b c q. Coercible c b => q b c -> Parsor s f a b -> Parsor s f a c #

(.#) :: forall a b c q. Coercible b a => Parsor s f b c -> q a b -> Parsor s f a c #

(Alternative m, Monad m) => MonadFail (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fail :: String -> Parsor s m a a0 #

(Alternative m, Monad m) => Alternative (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

empty :: Parsor s m a a0 #

(<|>) :: Parsor s m a a0 -> Parsor s m a a0 -> Parsor s m a a0 #

some :: Parsor s m a a0 -> Parsor s m a [a0] #

many :: Parsor s m a a0 -> Parsor s m a [a0] #

Monad m => Applicative (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

pure :: a0 -> Parsor s m a a0 #

(<*>) :: Parsor s m a (a0 -> b) -> Parsor s m a a0 -> Parsor s m a b #

liftA2 :: (a0 -> b -> c) -> Parsor s m a a0 -> Parsor s m a b -> Parsor s m a c #

(*>) :: Parsor s m a a0 -> Parsor s m a b -> Parsor s m a b #

(<*) :: Parsor s m a a0 -> Parsor s m a b -> Parsor s m a a0 #

Functor f => Functor (Parsor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fmap :: (a0 -> b) -> Parsor s f a a0 -> Parsor s f a b #

(<$) :: a0 -> Parsor s f a b -> Parsor s f a a0 #

Monad m => Monad (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(>>=) :: Parsor s m a a0 -> (a0 -> Parsor s m a b) -> Parsor s m a b #

(>>) :: Parsor s m a a0 -> Parsor s m a b -> Parsor s m a b #

return :: a0 -> Parsor s m a a0 #

(Alternative m, Monad m) => MonadPlus (Parsor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

mzero :: Parsor s m a a0 #

mplus :: Parsor s m a a0 -> Parsor s m a a0 -> Parsor s m a a0 #

Filterable f => Filterable (Parsor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

mapMaybe :: (a0 -> Maybe b) -> Parsor s f a a0 -> Parsor s f a b #

catMaybes :: Parsor s f a (Maybe a0) -> Parsor s f a a0 #

filter :: (a0 -> Bool) -> Parsor s f a a0 -> Parsor s f a a0 #

drain :: Parsor s f a a0 -> Parsor s f a b #

(Char ~ Item s, IsList s, Cons s s Char Char, Snoc s s Char Char, Filterable m, Alternative m, Monad m) => IsString (Parsor s m () ()) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fromString :: String -> Parsor s m () () #

(Char ~ Item s, IsList s, Cons s s Char Char, Snoc s s Char Char, AsEmpty s, Filterable m, Alternative m, Monad m) => IsString (Parsor s m s s) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fromString :: String -> Parsor s m s s #

BackusNaurForm (Parsor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

rule :: String -> Parsor s m a b -> Parsor s m a b Source #

ruleRec :: String -> (Parsor s m a b -> Parsor s m a b) -> Parsor s m a b Source #

unparseP :: Functor f => Parsor s f a b -> a -> s -> f s Source #

Run the parser in reverse on a value and an input string; snocing tokens at the end of the string, from left to right, and returning the new string.

parseP :: Parsor s f a b -> s -> f (b, s) Source #

Run the parser on an input string, unconsing tokens from the beginning of the string, from left to right, returning a value and the remaining string.

Printor

newtype Printor s f a b Source #

Printor is a simple printer Profunctor.

Constructors

Printor 

Fields

Instances

Instances details
Monad f => Category (Printor s f :: Type -> Type -> Type) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

id :: forall (a :: k). Printor s f a a #

(.) :: forall (b :: k) (c :: k) (a :: k). Printor s f b c -> Printor s f a b -> Printor s f a c #

(Categorized a, a ~ Item s, IsList s, Cons s s a a, Filterable m, Alternative m, Monad m) => TokenAlgebra a (Printor s m a a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

tokenClass :: TokenTest a -> Printor s m a a Source #

(Categorized a, a ~ Item s, IsList s, Cons s s a a, Filterable m, Alternative m, Monad m) => TerminalSymbol a (Printor s m () ()) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

terminal :: [a] -> Printor s m () () Source #

(Categorized a, a ~ Item s, IsList s, Cons s s a a, Filterable m, Alternative m, Monad m) => Tokenized a (Printor s m a a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

anyToken :: Printor s m a a Source #

token :: a -> Printor s m a a Source #

oneOf :: Foldable f => f a -> Printor s m a a Source #

notOneOf :: Foldable f => f a -> Printor s m a a Source #

asIn :: Categorize a -> Printor s m a a Source #

notAsIn :: Categorize a -> Printor s m a a Source #

Monad f => Arrow (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

arr :: (b -> c) -> Printor s f b c #

first :: Printor s f b c -> Printor s f (b, d) (c, d) #

second :: Printor s f b c -> Printor s f (d, b) (d, c) #

(***) :: Printor s f b c -> Printor s f b' c' -> Printor s f (b, b') (c, c') #

(&&&) :: Printor s f b c -> Printor s f b c' -> Printor s f b (c, c') #

(Alternative f, Monad f) => ArrowChoice (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

left :: Printor s f b c -> Printor s f (Either b d) (Either c d) #

right :: Printor s f b c -> Printor s f (Either d b) (Either d c) #

(+++) :: Printor s f b c -> Printor s f b' c' -> Printor s f (Either b b') (Either c c') #

(|||) :: Printor s f b d -> Printor s f c d -> Printor s f (Either b c) d #

(Alternative f, Monad f) => ArrowPlus (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(<+>) :: Printor s f b c -> Printor s f b c -> Printor s f b c #

(Alternative f, Monad f) => ArrowZero (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

zeroArrow :: Printor s f b c #

Alternative f => Alternator (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

alternate :: Either (Printor s f a b) (Printor s f c d) -> Printor s f (Either a c) (Either b d) Source #

someP :: Printor s f a b -> Printor s f [a] [b] Source #

Applicative f => Distributor (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

zeroP :: Printor s f Void Void Source #

(>+<) :: Printor s f a b -> Printor s f c d -> Printor s f (Either a c) (Either b d) Source #

optionalP :: Printor s f a b -> Printor s f (Maybe a) (Maybe b) Source #

manyP :: Printor s f a b -> Printor s f [a] [b] Source #

Filterable f => Filtrator (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

filtrate :: Printor s f (Either a c) (Either b d) -> (Printor s f a b, Printor s f c d) Source #

Alternative f => Choice (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

left' :: Printor s f a b -> Printor s f (Either a c) (Either b c) #

right' :: Printor s f a b -> Printor s f (Either c a) (Either c b) #

Filterable f => Cochoice (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

unleft :: Printor s f (Either a d) (Either b d) -> Printor s f a b #

unright :: Printor s f (Either d a) (Either d b) -> Printor s f a b #

Functor f => Strong (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

first' :: Printor s f a b -> Printor s f (a, c) (b, c) #

second' :: Printor s f a b -> Printor s f (c, a) (c, b) #

Functor f => Profunctor (Printor s f) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

dimap :: (a -> b) -> (c -> d) -> Printor s f b c -> Printor s f a d #

lmap :: (a -> b) -> Printor s f b c -> Printor s f a c #

rmap :: (b -> c) -> Printor s f a b -> Printor s f a c #

(#.) :: forall a b c q. Coercible c b => q b c -> Printor s f a b -> Printor s f a c #

(.#) :: forall a b c q. Coercible b a => Printor s f b c -> q a b -> Printor s f a c #

(Alternative m, Monad m) => MonadFail (Printor s m a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fail :: String -> Printor s m a a0 #

Alternative f => Alternative (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

empty :: Printor s f a a0 #

(<|>) :: Printor s f a a0 -> Printor s f a a0 -> Printor s f a a0 #

some :: Printor s f a a0 -> Printor s f a [a0] #

many :: Printor s f a a0 -> Printor s f a [a0] #

Applicative f => Applicative (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

pure :: a0 -> Printor s f a a0 #

(<*>) :: Printor s f a (a0 -> b) -> Printor s f a a0 -> Printor s f a b #

liftA2 :: (a0 -> b -> c) -> Printor s f a a0 -> Printor s f a b -> Printor s f a c #

(*>) :: Printor s f a a0 -> Printor s f a b -> Printor s f a b #

(<*) :: Printor s f a a0 -> Printor s f a b -> Printor s f a a0 #

Functor f => Functor (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fmap :: (a0 -> b) -> Printor s f a a0 -> Printor s f a b #

(<$) :: a0 -> Printor s f a b -> Printor s f a a0 #

Monad f => Monad (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(>>=) :: Printor s f a a0 -> (a0 -> Printor s f a b) -> Printor s f a b #

(>>) :: Printor s f a a0 -> Printor s f a b -> Printor s f a b #

return :: a0 -> Printor s f a a0 #

(Alternative f, Monad f) => MonadPlus (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

mzero :: Printor s f a a0 #

mplus :: Printor s f a a0 -> Printor s f a a0 -> Printor s f a a0 #

Filterable f => Filterable (Printor s f a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

mapMaybe :: (a0 -> Maybe b) -> Printor s f a a0 -> Printor s f a b #

catMaybes :: Printor s f a (Maybe a0) -> Printor s f a a0 #

filter :: (a0 -> Bool) -> Printor s f a a0 -> Printor s f a a0 #

drain :: Printor s f a a0 -> Printor s f a b #

(Char ~ Item s, IsList s, Cons s s Char Char, Filterable m, Alternative m, Monad m) => IsString (Printor s m () ()) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fromString :: String -> Printor s m () () #

(Char ~ Item s, IsList s, Cons s s Char Char, AsEmpty s, Filterable m, Alternative m, Monad m) => IsString (Printor s m s s) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fromString :: String -> Printor s m s s #

BackusNaurForm (Printor s m a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

rule :: String -> Printor s m a b -> Printor s m a b Source #

ruleRec :: String -> (Printor s m a b -> Printor s m a b) -> Printor s m a b Source #

printP :: Functor f => Printor s f a b -> a -> f (s -> s) Source #

Run the printer on a value, returning a function that conses tokens at the beginning of an input string, from right to left.

Grammor

newtype Grammor k a b Source #

Grammor is a constant Profunctor.

Constructors

Grammor 

Fields

Instances

Instances details
Matching s k => Matching s (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

(=~) :: s -> Grammor k a b -> Bool Source #

TokenAlgebra a k => TokenAlgebra a (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

tokenClass :: TokenTest a -> Grammor k a b Source #

TerminalSymbol token k => TerminalSymbol token (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

terminal :: [token] -> Grammor k a b Source #

Tokenized token k => Tokenized token (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

anyToken :: Grammor k a b Source #

token :: token -> Grammor k a b Source #

oneOf :: Foldable f => f token -> Grammor k a b Source #

notOneOf :: Foldable f => f token -> Grammor k a b Source #

asIn :: Categorize token -> Grammor k a b Source #

notAsIn :: Categorize token -> Grammor k a b Source #

Bifunctor (Grammor k) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

bimap :: (a -> b) -> (c -> d) -> Grammor k a c -> Grammor k b d #

first :: (a -> b) -> Grammor k a c -> Grammor k b c #

second :: (b -> c) -> Grammor k a b -> Grammor k a c #

KleeneStarAlgebra k => Alternator (Grammor k) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

alternate :: Either (Grammor k a b) (Grammor k c d) -> Grammor k (Either a c) (Either b d) Source #

someP :: Grammor k a b -> Grammor k [a] [b] Source #

KleeneStarAlgebra k => Distributor (Grammor k) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

zeroP :: Grammor k Void Void Source #

(>+<) :: Grammor k a b -> Grammor k c d -> Grammor k (Either a c) (Either b d) Source #

optionalP :: Grammor k a b -> Grammor k (Maybe a) (Maybe b) Source #

manyP :: Grammor k a b -> Grammor k [a] [b] Source #

Choice (Grammor k) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

left' :: Grammor k a b -> Grammor k (Either a c) (Either b c) #

right' :: Grammor k a b -> Grammor k (Either c a) (Either c b) #

Profunctor (Grammor k) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

dimap :: (a -> b) -> (c -> d) -> Grammor k b c -> Grammor k a d #

lmap :: (a -> b) -> Grammor k b c -> Grammor k a c #

rmap :: (b -> c) -> Grammor k a b -> Grammor k a c #

(#.) :: forall a b c q. Coercible c b => q b c -> Grammor k a b -> Grammor k a c #

(.#) :: forall a b c q. Coercible b a => Grammor k b c -> q a b -> Grammor k a c #

Contravariant (Grammor k a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

contramap :: (a' -> a0) -> Grammor k a a0 -> Grammor k a a' #

(>$) :: b -> Grammor k a b -> Grammor k a a0 #

KleeneStarAlgebra k => Alternative (Grammor k a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

empty :: Grammor k a a0 #

(<|>) :: Grammor k a a0 -> Grammor k a a0 -> Grammor k a a0 #

some :: Grammor k a a0 -> Grammor k a [a0] #

many :: Grammor k a a0 -> Grammor k a [a0] #

Monoid k => Applicative (Grammor k a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

pure :: a0 -> Grammor k a a0 #

(<*>) :: Grammor k a (a0 -> b) -> Grammor k a a0 -> Grammor k a b #

liftA2 :: (a0 -> b -> c) -> Grammor k a a0 -> Grammor k a b -> Grammor k a c #

(*>) :: Grammor k a a0 -> Grammor k a b -> Grammor k a b #

(<*) :: Grammor k a a0 -> Grammor k a b -> Grammor k a a0 #

Functor (Grammor k a) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

fmap :: (a0 -> b) -> Grammor k a a0 -> Grammor k a b #

(<$) :: a0 -> Grammor k a b -> Grammor k a a0 #

BackusNaurForm k => BackusNaurForm (Grammor k a b) Source # 
Instance details

Defined in Data.Profunctor.Grammar

Methods

rule :: String -> Grammor k a b -> Grammor k a b Source #

ruleRec :: String -> (Grammor k a b -> Grammor k a b) -> Grammor k a b Source #