| Copyright | (C) 2026 - Eitan Chatav |
|---|---|
| License | BSD-style (see the file LICENSE) |
| Maintainer | Eitan Chatav <eitan.chatav@gmail.com> |
| Stability | provisional |
| Portability | non-portable |
| Safe Haskell | None |
| Language | Haskell2010 |
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
- class PrecGrammar a where
- precGrammar :: PrecGrammatical p => p a a
- precListGrammar :: PrecGrammatical p => p [a] [a]
- class (Grammatical Char p, NotFollowedBy p, forall x y. (x ~ (), y ~ ()) => IsString (p x y)) => PrecGrammatical (p :: Type -> Type -> Type) where
- precParens :: PrecGrammatical p => p a b -> p a b
- precList :: PrecGrammatical p => p a a -> p [a] [a]
- class NotFollowedBy (p :: Type -> Type -> Type) where
- notFollowedBy :: RegEx Char -> p () ()
- eof :: NotFollowedBy p => p () ()
- munch :: (RegGrammatical Char p, NotFollowedBy p) => TokenClass Char -> p String String
- munch1 :: (RegGrammatical Char p, NotFollowedBy p) => TokenClass Char -> p String String
- skipSpaces :: (RegGrammatical Char p, NotFollowedBy p) => p () ()
- newtype Precedence (p :: Type -> Type -> Type) a b = Precedence {
- runPrecedence :: Int -> p a b
- precG :: (PrecGrammar a, Grammatical Char p, NotFollowedBy p) => Int -> p a a
- readsPrecG :: PrecGrammar a => Int -> ReadS a
- showsPrecG :: PrecGrammar a => Int -> a -> Maybe ShowS
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 #
Instances
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
| (Grammatical Char p, NotFollowedBy p) => PrecGrammatical (Precedence p) Source # | |
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 #
precList :: PrecGrammatical p => p a a -> p [a] [a] Source #
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
| NotFollowedBy p => NotFollowedBy (Precedence p) Source # | |
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 # | |
Defined in Control.Lens.Grammar.Prec | |
| Applicative f => NotFollowedBy (Printor s f) Source # | |
Defined in Control.Lens.Grammar.Prec | |
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
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.