distributors-grammar
Copyright(C) 2026 - Eitan Chatav
LicenseBSD-style (see the file LICENSE)
MaintainerEitan Chatav <eitan.chatav@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Control.Lens.Grammar.Prec

Description

Grammars of Haskell types, equivalent to their stock Read & Show instances, by precedence, as ReadPrec reads, & showsPrec shows: PrecGrammars, run by PrecGrammaticals, like tPrecedence, which readsPrecG & showsPrecG run.

Synopsis

PrecGrammar

class PrecGrammar a where Source #

A Haskell type's grammar, by precedence, equivalent to its stock Read & Show instances, readsPrec & showsPrec.

Minimal complete definition

Nothing

Methods

precGrammar :: PrecGrammatical p => p a a Source #

default precGrammar :: (Generic a, GPrecSum (Rep a), PrecGrammatical p) => p a a Source #

precListGrammar :: PrecGrammatical p => p [a] [a] Source #

Lists of the type, as readListPrec & showList, in brackets, by precList, by default, & strings, for Char.

Instances

Instances details
PrecGrammar Int16 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Int32 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Int64 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Int8 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Word16 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Word32 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Word64 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Word8 Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Ordering Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Integer Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Natural Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar () Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precGrammar :: PrecGrammatical p => p () () Source #

precListGrammar :: PrecGrammatical p => p [()] [()] Source #

PrecGrammar Bool Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Char Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Double Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Float Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Int Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar Word Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar a => PrecGrammar (Maybe a) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

PrecGrammar a => PrecGrammar [a] Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precGrammar :: PrecGrammatical p => p [a] [a] Source #

precListGrammar :: PrecGrammatical p => p [[a]] [[a]] Source #

(PrecGrammar a, PrecGrammar b) => PrecGrammar (Either a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

(PrecGrammar a, PrecGrammar b) => PrecGrammar (a, b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precGrammar :: PrecGrammatical p => p (a, b) (a, b) Source #

precListGrammar :: PrecGrammatical p => p [(a, b)] [(a, b)] Source #

(PrecGrammar a, PrecGrammar b, PrecGrammar c) => PrecGrammar (a, b, c) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precGrammar :: PrecGrammatical p => p (a, b, c) (a, b, c) Source #

precListGrammar :: PrecGrammatical p => p [(a, b, c)] [(a, b, c)] Source #

(PrecGrammar a, PrecGrammar b, PrecGrammar c, PrecGrammar d) => PrecGrammar (a, b, c, d) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precGrammar :: PrecGrammatical p => p (a, b, c, d) (a, b, c, d) Source #

precListGrammar :: PrecGrammatical p => p [(a, b, c, d)] [(a, b, c, d)] Source #

(PrecGrammar a, PrecGrammar b, PrecGrammar c, PrecGrammar d, PrecGrammar e) => PrecGrammar (a, b, c, d, e) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precGrammar :: PrecGrammatical p => p (a, b, c, d, e) (a, b, c, d, e) Source #

precListGrammar :: PrecGrammatical p => p [(a, b, c, d, e)] [(a, b, c, d, e)] Source #

class (Grammatical Char p, NotFollowedBy p, forall x y. (x ~ (), y ~ ()) => IsString (p x y)) => PrecGrammatical (p :: Type -> Type -> Type) where Source #

Grammatical interpreters of precedence, as ReadPrec has, where a grammar runs in a precedence context, from 0 to 11, as showsPrec's is.

Methods

precP :: Int -> p a b -> p a b Source #

At a precedence, failing in a context above it, as prec does.

precStep :: p a b -> p a b Source #

In a context one higher, for arguments, as step does.

precReset :: p a b -> p a b Source #

In the context 0, within brackets, as reset does.

precWith :: (Int -> p a b) -> p a b Source #

By the context's precedence.

Instances

Instances details
(Grammatical Char p, NotFollowedBy p) => PrecGrammatical (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precP :: Int -> Precedence p a b -> Precedence p a b Source #

precStep :: Precedence p a b -> Precedence p a b Source #

precReset :: Precedence p a b -> Precedence p a b Source #

precWith :: (Int -> Precedence p a b) -> Precedence p a b Source #

precParens :: PrecGrammatical p => p a b -> p a b Source #

Within any parentheses, after whitespace, as parens reads, & within parentheses where it doesn't print bare, as showParen shows.

precList :: PrecGrammatical p => p a a -> p [a] [a] Source #

A list, in brackets, its items separated by commas, after whitespace, at precedence 0, within any parentheses, as list reads & showList shows.

NotFollowedBy

class NotFollowedBy (p :: Type -> Type -> Type) where Source #

Negative lookahead, as read's lexer munches lexemes maximally.

Methods

notFollowedBy :: RegEx Char -> p () () Source #

Not followed by a string a pattern matches, consuming nothing, & printing nothing; nonterminals match nothing.

Instances

Instances details
NotFollowedBy p => NotFollowedBy (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

notFollowedBy :: RegEx Char -> Precedence p () () Source #

(Alternative f, Cons s s Char Char) => NotFollowedBy (Parsor s f) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

notFollowedBy :: RegEx Char -> Parsor s f () () Source #

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

Defined in Control.Lens.Grammar.Prec

Methods

notFollowedBy :: RegEx Char -> Printor s f () () Source #

eof :: NotFollowedBy p => p () () Source #

At the end of input, not followed by any token.

munch :: (RegGrammatical Char p, NotFollowedBy p) => TokenClass Char -> p String String Source #

Tokens of a class, as many as follow, as munch parses, & printing them.

munch1 :: (RegGrammatical Char p, NotFollowedBy p) => TokenClass Char -> p String String Source #

Tokens of a class, one or more, as many as follow, as munch1 parses, & printing them.

skipSpaces :: (RegGrammatical Char p, NotFollowedBy p) => p () () Source #

Whitespace, by isSpace, as many as follow, as skipSpaces parses, & printing none.

Precedence

newtype Precedence (p :: Type -> Type -> Type) a b Source #

A grammar in a precedence context, a PrecGrammatical interpreter of any Grammatical one, each of whose structures it lifts pointwise.

Constructors

Precedence 

Fields

Instances

Instances details
TerminalSymbol token (p a b) => TerminalSymbol token (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

terminal :: [token] -> Precedence p a b Source #

TokenAlgebra token (p a b) => TokenAlgebra token (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

tokenClass :: TokenClass token -> Precedence p a b Source #

Tokenized token (p a b) => Tokenized token (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

anyToken :: Precedence p a b Source #

token :: token -> Precedence p a b Source #

oneOf :: Foldable f => f token -> Precedence p a b Source #

notOneOf :: Foldable f => f token -> Precedence p a b Source #

asIn :: Categorize token -> Precedence p a b Source #

notAsIn :: Categorize token -> Precedence p a b Source #

Alternator p => Alternator (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

someP :: Precedence p a b -> Precedence p [a] [b] #

optionP :: APrism a b () () -> Precedence p a b -> Precedence p a b #

manyTillP :: Precedence p a b -> Precedence p [a] [b] -> Precedence p [a] [b] #

quantP :: Int -> Maybe Int -> Precedence p a b -> Precedence p [a] [b] #

Distributor p => Distributor (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

optionalP :: Precedence p a b -> Precedence p (Maybe a) (Maybe b) #

manyP :: Precedence p a b -> Precedence p [a] [b] #

CocartesianChoice p => CocartesianChoice (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

alternate :: Either (Precedence p a b) (Precedence p c d) -> Precedence p (Either a c) (Either b d) #

CocartesianMonoidal p => CocartesianMonoidal (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

zeroP :: Precedence p Void Void #

(>+<) :: Precedence p a b -> Precedence p c d -> Precedence p (Either a c) (Either b d) #

NotFollowedBy p => NotFollowedBy (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

notFollowedBy :: RegEx Char -> Precedence p () () Source #

(Grammatical Char p, NotFollowedBy p) => PrecGrammatical (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

precP :: Int -> Precedence p a b -> Precedence p a b Source #

precStep :: Precedence p a b -> Precedence p a b Source #

precReset :: Precedence p a b -> Precedence p a b Source #

precWith :: (Int -> Precedence p a b) -> Precedence p a b Source #

Choice p => Choice (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

left' :: Precedence p a b -> Precedence p (Either a c) (Either b c) #

right' :: Precedence p a b -> Precedence p (Either c a) (Either c b) #

Profunctor p => Profunctor (Precedence p) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

dimap :: (a -> b) -> (c -> d) -> Precedence p b c -> Precedence p a d #

lmap :: (a -> b) -> Precedence p b c -> Precedence p a c #

rmap :: (b -> c) -> Precedence p a b -> Precedence p a c #

(#.) :: forall a b c q. Coercible c b => q b c -> Precedence p a b -> Precedence p a c #

(.#) :: forall a b c q. Coercible b a => Precedence p b c -> q a b -> Precedence p a c #

Alternative (p a) => Alternative (Precedence p a) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

empty :: Precedence p a a0 #

(<|>) :: Precedence p a a0 -> Precedence p a a0 -> Precedence p a a0 #

some :: Precedence p a a0 -> Precedence p a [a0] #

many :: Precedence p a a0 -> Precedence p a [a0] #

Applicative (p a) => Applicative (Precedence p a) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

pure :: a0 -> Precedence p a a0 #

(<*>) :: Precedence p a (a0 -> b) -> Precedence p a a0 -> Precedence p a b #

liftA2 :: (a0 -> b -> c) -> Precedence p a a0 -> Precedence p a b -> Precedence p a c #

(*>) :: Precedence p a a0 -> Precedence p a b -> Precedence p a b #

(<*) :: Precedence p a a0 -> Precedence p a b -> Precedence p a a0 #

Functor (p a) => Functor (Precedence p a) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

fmap :: (a0 -> b) -> Precedence p a a0 -> Precedence p a b #

(<$) :: a0 -> Precedence p a b -> Precedence p a a0 #

DisjunctiveMonoid (p a b) => DisjunctiveMonoid (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

falseP :: Precedence p a b #

(>|<) :: Precedence p a b -> Precedence p a b -> Precedence p a b #

BackusNaurForm (p a b) => BackusNaurForm (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

ruleRec :: String -> (Precedence p a b -> Precedence p a b) -> Precedence p a b Source #

Ruled (p a b) => Ruled (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

rule :: String -> Precedence p a b -> Precedence p a b Source #

Tried (p a b) => Tried (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

try :: Precedence p a b -> Precedence p a b Source #

(a ~ (), b ~ (), TerminalSymbol Char (p () ())) => IsString (Precedence p a b) Source # 
Instance details

Defined in Control.Lens.Grammar.Prec

Methods

fromString :: String -> Precedence p a b #

precG :: (PrecGrammar a, Grammatical Char p, NotFollowedBy p) => Int -> p a a Source #

A type's PrecGrammar at a precedence, at any Grammatical interpreter which parses or prints.

readsPrecG :: PrecGrammar a => Int -> ReadS a Source #

Read at a precedence, as readsPrec does.

showsPrecG :: PrecGrammar a => Int -> a -> Maybe ShowS Source #

Show at a precedence, as showsPrec does, if it shows.