| 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.Pretty
Contents
Description
Grammars which lay themselves out, by the layout combinators of
Wadler, A prettier printer,
printing a Doc of the prettyprinter package, which chooses, by the
page's width, between their flat & broken layouts, & parsing every layout
they print, with any indentation.
Synopsis
- class PrettyGrammar a where
- prettyGrammar :: (Grammatical Char p, forall x y. (x ~ (), y ~ ()) => Lined (p x y), forall x y. (x ~ (), y ~ ()) => IsString (p x y), forall x y. LaidOut (p x y)) => p a a
- prettyG :: PrettyGrammar a => a -> Maybe (Doc ann)
- layoutG :: PrettyGrammar a => LayoutStyle -> a -> Maybe String
- data LayoutStyle
- class Lined p where
- hardlineP :: p
- class LaidOut p where
- lineP :: (Lined p, LaidOut p, IsString p) => p
- lineP' :: (Lined p, LaidOut p, IsString p) => p
- softlineP :: (Lined p, LaidOut p, IsString p) => p
- newtype Prettor w (f :: Type -> Type) a b = Prettor {
- runPrettor :: a -> f (b, w)
PrettyGrammar
class PrettyGrammar a where Source #
prettyG :: PrettyGrammar a => a -> Maybe (Doc ann) Source #
A type's PrettyGrammar, printed to a Doc, if it prints.
layoutG :: PrettyGrammar a => LayoutStyle -> a -> Maybe String Source #
A type's PrettyGrammar, printed in a LayoutStyle, if it prints.
data LayoutStyle Source #
A layout style of a Doc, as prettyprinter lays them out.
Constructors
| PrettyLayout LayoutOptions | by |
| SmartLayout LayoutOptions | by |
| CompactLayout | by |
Layout
Grammars with a hard line break.
Instances
| (Ord rule, Lined rule) => Lined (Bnf rule) Source # | |
Defined in Control.Lens.Grammar.Pretty | |
| Lined (RegEx Char) Source # | A newline, then any indentation. |
| Lined (Doc ann) Source # | |
Defined in Control.Lens.Grammar.Pretty | |
| Lined k => Lined (Grammor k a b) Source # | |
Defined in Control.Lens.Grammar.Pretty | |
| (Lined w, Applicative f) => Lined (Prettor w f () ()) Source # | |
Defined in Control.Lens.Grammar.Pretty | |
| (Char ~ Item s, IsList s, Cons s s Char Char, Snoc s s Char Char, Filterable m, Alternative m, Monad m) => Lined (Parsor s m () ()) Source # | A newline, then any indentation, unparsing none. |
Defined in Control.Lens.Grammar.Pretty | |
class LaidOut p where Source #
Grammars laid out by Wadler-Leijen layout combinators, choosing between flat & broken layouts.
prop> nestP 0 = id prop> nestP i . nestP j = nestP (i + j)
Methods
flatAltP :: p -> p -> p Source #
A broken layout, by default, & a flat one, where it's grouped flat.
nestP :: Int -> p -> p Source #
Indented further after its line breaks.
Flat, where it fits.
Indented to the current column after its line breaks.
Instances
| (Ord rule, LaidOut rule) => LaidOut (Bnf rule) Source # | |
| Categorized token => LaidOut (RegEx token) Source # | Either layout, any indentation. |
| LaidOut (Doc ann) Source # | |
| LaidOut k => LaidOut (Grammor k a b) Source # | |
| (LaidOut w, Applicative f) => LaidOut (Prettor w f a b) Source # | Both layouts print a value, the layout of their prints chosen. |
| (Alternative m, Monad m) => LaidOut (Parsor s m a b) Source # | Either layout, any indentation. |
lineP :: (Lined p, LaidOut p, IsString p) => p Source #
A line break, or a space, where it's grouped flat.
lineP' :: (Lined p, LaidOut p, IsString p) => p Source #
A line break, or nothing, where it's grouped flat.
softlineP :: (Lined p, LaidOut p, IsString p) => p Source #
A space, or a line break, where it doesn't fit.
Prettor
newtype Prettor w (f :: Type -> Type) a b Source #
Constructors
| Prettor | |
Fields
| |