trifecta-2.1.4: A modern parser combinator library with convenient diagnostics

Copyright | (C) 2011-2019 Edward Kmett
License | BSD-style (see the file LICENSE)
Maintainer | Edward Kmett <ekmett@gmail.com>
Stability | experimental
Portability | non-portable
Safe Haskell | None
Language | Haskell2010

Text.Trifecta.Rendering

Contents

- Carets
- Spans
- Fixits
- Drawing primitives

Description

The type for Lines will very likely change over time, to enable drawing lit up multi-character versions of control characters for `^Z`, `^[`, `0xff`, etc. This will make for much nicer diagnostics when working with protocols.

Synopsis

- data Rendering = Rendering !Delta !Int64 !Int64 (Lines -> Lines) (Delta -> Lines -> Lines)
- class HasRendering c where
  - rendering :: Lens' c Rendering
  - renderingDelta :: Lens' c Delta
  - renderingLine :: Lens' c (Lines -> Lines)
  - renderingLineBytes :: Lens' c Int64
  - renderingLineLen :: Lens' c Int64
  - renderingOverlays :: Lens' c (Delta -> Lines -> Lines)
- nullRendering :: Rendering -> Bool
- emptyRendering :: Rendering
- prettyRendering :: Rendering -> Doc AnsiStyle
- class Source t where
  - source :: t -> (Int64, Int64, Lines -> Lines)
- rendered :: Source s => Delta -> s -> Rendering
- class Renderable t where
  - render :: t -> Rendering
- data Rendered a = a :@ Rendering
- gutterEffects :: [SGR]
- data Caret = Caret !Delta !ByteString
- class HasCaret t where
  - caret :: Lens' t Caret
- data Careted a = a :^ Caret
- drawCaret :: Delta -> Delta -> Lines -> Lines
- addCaret :: Delta -> Rendering -> Rendering
- caretEffects :: [SGR]
- renderingCaret :: Delta -> ByteString -> Rendering
- data Span = Span !Delta !Delta !ByteString
- class HasSpan t where
  - span :: Lens' t Span
- data Spanned a = a :~ Span
- spanEffects :: [SGR]
- drawSpan :: Delta -> Delta -> Delta -> Lines -> Lines
- addSpan :: Delta -> Delta -> Rendering -> Rendering
- data Fixit = Fixit {
  - _fixitSpan :: !Span
  - _fixitReplacement :: !ByteString
  }
- class HasFixit c where
  - fixit :: Lens' c Fixit
  - fixitReplacement :: Lens' c ByteString
  - fixitSpan :: Lens' c Span
- drawFixit :: Delta -> Delta -> String -> Delta -> Lines -> Lines
- addFixit :: Delta -> Delta -> String -> Rendering -> Rendering
- type Lines = Array (Int, Int64) ([SGR], Char)
- draw :: [SGR] -> Int -> Int64 -> String -> Lines -> Lines
- ifNear :: Delta -> (Lines -> Lines) -> Delta -> Lines -> Lines
- (.#) :: (Delta -> Lines -> Lines) -> Rendering -> Rendering

# Documentation

data Rendering Source #

A `Rendering` is a canvas of text that output can be written to.

Constructors

Rendering !Delta !Int64 !Int64 (Lines -> Lines) (Delta -> Lines -> Lines) |

#### Instances

Instances details

Monoid Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods mempty :: Rendering Source # mappend :: Rendering -> Rendering -> Rendering Source # mconcat :: [Rendering] -> Rendering Source #
Semigroup Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (<>) :: Rendering -> Rendering -> Rendering Source # sconcat :: NonEmpty Rendering -> Rendering Source # stimes :: Integral b => b -> Rendering -> Rendering Source #
Show Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods showsPrec :: Int -> Rendering -> ShowS Source # show :: Rendering -> String Source # showList :: [Rendering] -> ShowS Source #
HasDelta Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Rendering -> Delta Source #
HasRendering Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods rendering :: Lens' Rendering Rendering Source # renderingDelta :: Lens' Rendering Delta Source # renderingLine :: Lens' Rendering (Lines -> Lines) Source # renderingLineBytes :: Lens' Rendering Int64 Source # renderingLineLen :: Lens' Rendering Int64 Source # renderingOverlays :: Lens' Rendering (Delta -> Lines -> Lines) Source #
Renderable Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Rendering -> Rendering Source #
Reducer Caret Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Caret -> Rendering Source # snoc :: Rendering -> Caret -> Rendering Source # cons :: Caret -> Rendering -> Rendering Source #
Reducer Fixit Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Fixit -> Rendering Source # snoc :: Rendering -> Fixit -> Rendering Source # cons :: Fixit -> Rendering -> Rendering Source #
Reducer Span Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Span -> Rendering Source # snoc :: Rendering -> Span -> Rendering Source # cons :: Span -> Rendering -> Rendering Source #
Reducer (Careted a) Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Careted a -> Rendering Source # snoc :: Rendering -> Careted a -> Rendering Source # cons :: Careted a -> Rendering -> Rendering Source #
Reducer (Spanned a) Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Spanned a -> Rendering Source # snoc :: Rendering -> Spanned a -> Rendering Source # cons :: Spanned a -> Rendering -> Rendering Source #

class HasRendering c where Source #

Minimal complete definition

rendering

Methods

rendering :: Lens' c Rendering Source #

renderingDelta :: Lens' c Delta Source #

renderingLine :: Lens' c (Lines -> Lines) Source #

renderingLineBytes :: Lens' c Int64 Source #

renderingLineLen :: Lens' c Int64 Source #

renderingOverlays :: Lens' c (Delta -> Lines -> Lines) Source #

#### Instances

Instances details

HasRendering Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods rendering :: Lens' Rendering Rendering Source # renderingDelta :: Lens' Rendering Delta Source # renderingLine :: Lens' Rendering (Lines -> Lines) Source # renderingLineBytes :: Lens' Rendering Int64 Source # renderingLineLen :: Lens' Rendering Int64 Source # renderingOverlays :: Lens' Rendering (Delta -> Lines -> Lines) Source #

nullRendering :: Rendering -> Bool Source #

Is the `Rendering` empty?

    >>> nullRendering emptyRendering
    True

    >>> nullRendering exampleRendering
    False

emptyRendering :: Rendering Source #

The empty `Rendering`, which contains nothing at all.

    >>> show (prettyRendering emptyRendering)
    ""

prettyRendering :: Rendering -> Doc AnsiStyle Source #

class Source t where Source #

Methods

source :: t -> (Int64, Int64, Lines -> Lines) Source #

    ( Number of (padded) columns
    , number of bytes
    , line )

#### Instances

Instances details

Source ByteString Source # |
Instance details Defined in Text.Trifecta.Rendering Methods source :: ByteString -> (Int64, Int64, Lines -> Lines) Source #
Source String Source # |
Instance details Defined in Text.Trifecta.Rendering Methods source :: String -> (Int64, Int64, Lines -> Lines) Source #

rendered :: Source s => Delta -> s -> Rendering Source #

create a drawing surface

class Renderable t where Source #

Methods

render :: t -> Rendering Source #

#### Instances

Instances details

Renderable Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Caret -> Rendering Source #
Renderable Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Fixit -> Rendering Source #
Renderable Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Rendering -> Rendering Source #
Renderable Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Span -> Rendering Source #
Renderable (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Careted a -> Rendering Source #
Renderable (Rendered a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Rendered a -> Rendering Source #
Renderable (Spanned a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Spanned a -> Rendering Source #

data Rendered a Source #

Constructors

a :@ Rendering |

#### Instances

Instances details

Comonad Rendered Source # |
Instance details Defined in Text.Trifecta.Rendering Methods extract :: Rendered a -> a Source # duplicate :: Rendered a -> Rendered (Rendered a) Source # extend :: (Rendered a -> b) -> Rendered a -> Rendered b Source #
ComonadApply Rendered Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (<@>) :: Rendered (a -> b) -> Rendered a -> Rendered b Source # (@>) :: Rendered a -> Rendered b -> Rendered b Source # (<@) :: Rendered a -> Rendered b -> Rendered a Source #
Functor Rendered Source # |
Instance details Defined in Text.Trifecta.Rendering Methods fmap :: (a -> b) -> Rendered a -> Rendered b Source # (<$) :: a -> Rendered b -> Rendered a Source #
Foldable Rendered Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

fold :: Monoid m => Rendered m -> m Source #

foldMap :: Monoid m => (a -> m) -> Rendered a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Rendered a -> m Source #

foldr :: (a -> b -> b) -> b -> Rendered a -> b Source #

foldr' :: (a -> b -> b) -> b -> Rendered a -> b Source #

foldl :: (b -> a -> b) -> b -> Rendered a -> b Source #

foldl' :: (b -> a -> b) -> b -> Rendered a -> b Source #

foldr1 :: (a -> a -> a) -> Rendered a -> a Source #

foldl1 :: (a -> a -> a) -> Rendered a -> a Source #

toList :: Rendered a -> [a] Source #

null :: Rendered a -> Bool Source #

length :: Rendered a -> Int Source #

elem :: Eq a => a -> Rendered a -> Bool Source #

maximum :: Ord a => Rendered a -> a Source #

minimum :: Ord a => Rendered a -> a Source #

sum :: Num a => Rendered a -> a Source #

product :: Num a => Rendered a -> a Source #

Traversable Rendered Source # |
Instance details Defined in Text.Trifecta.Rendering Methods traverse :: Applicative f => (a -> f b) -> Rendered a -> f (Rendered b) Source # sequenceA :: Applicative f => Rendered (f a) -> f (Rendered a) Source # mapM :: Monad m => (a -> m b) -> Rendered a -> m (Rendered b) Source # sequence :: Monad m => Rendered (m a) -> m (Rendered a) Source #
Show a => Show (Rendered a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods showsPrec :: Int -> Rendered a -> ShowS Source # show :: Rendered a -> String Source # showList :: [Rendered a] -> ShowS Source #
HasBytes (Rendered a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods bytes :: Rendered a -> Int64 Source #
HasDelta (Rendered a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Rendered a -> Delta Source #
Renderable (Rendered a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Rendered a -> Rendering Source #

gutterEffects :: [SGR] Source #

ANSI terminal style for rendering the gutter.

# Carets

data Caret Source #

A `Caret` marks a point in the input with a simple `^` character.

    >>> unAnnotate (prettyRendering (addCaret (Columns 35 35) exampleRendering))
    1 | int main(int argc, char ** argv) { int; }<EOF>
      |                                    ^

Constructors

Caret !Delta !ByteString |

#### Instances

Instances details

Semigroup Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (<>) :: Caret -> Caret -> Caret Source # sconcat :: NonEmpty Caret -> Caret Source # stimes :: Integral b => b -> Caret -> Caret Source #
Data Caret Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Caret -> c Caret Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Caret Source #

toConstr :: Caret -> Constr Source #

dataTypeOf :: Caret -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Caret) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Caret) Source #

gmapT :: (forall b. Data b => b -> b) -> Caret -> Caret Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Caret -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Caret -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Caret -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Caret -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Caret -> m Caret Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Caret -> m Caret Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Caret -> m Caret Source #

Generic Caret Source # |

Instance details

Defined in Text.Trifecta.Rendering

Associated Types

type Rep Caret |

Instance details

Defined in Text.Trifecta.Rendering

type Rep Caret = D1 ('MetaData "Caret" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Caret" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Methods

from :: Caret -> Rep Caret x Source #

to :: Rep Caret x -> Caret Source #

Show Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods showsPrec :: Int -> Caret -> ShowS Source # show :: Caret -> String Source # showList :: [Caret] -> ShowS Source #
Eq Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (==) :: Caret -> Caret -> Bool Source # (/=) :: Caret -> Caret -> Bool Source #
Ord Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods compare :: Caret -> Caret -> Ordering Source # (<) :: Caret -> Caret -> Bool Source # (<=) :: Caret -> Caret -> Bool Source # (>) :: Caret -> Caret -> Bool Source # (>=) :: Caret -> Caret -> Bool Source # max :: Caret -> Caret -> Caret Source # min :: Caret -> Caret -> Caret Source #
Hashable Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods hashWithSalt :: Int -> Caret -> Int Source # hash :: Caret -> Int Source #
HasBytes Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods bytes :: Caret -> Int64 Source #
HasDelta Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Caret -> Delta Source #
HasCaret Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods caret :: Lens' Caret Caret Source #
Renderable Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Caret -> Rendering Source #
Reducer Caret Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Caret -> Rendering Source # snoc :: Rendering -> Caret -> Rendering Source # cons :: Caret -> Rendering -> Rendering Source #
type Rep Caret Source # |

Instance details

Defined in Text.Trifecta.Rendering

type Rep Caret = D1 ('MetaData "Caret" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Caret" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

class HasCaret t where Source #

Methods

caret :: Lens' t Caret Source #

#### Instances

Instances details

HasCaret Caret Source # |
Instance details Defined in Text.Trifecta.Rendering Methods caret :: Lens' Caret Caret Source #
HasCaret (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods caret :: Lens' (Careted a) Caret Source #

data Careted a Source #

Constructors

a :^ Caret |

#### Instances

Instances details

Comonad Careted Source # |
Instance details Defined in Text.Trifecta.Rendering Methods extract :: Careted a -> a Source # duplicate :: Careted a -> Careted (Careted a) Source # extend :: (Careted a -> b) -> Careted a -> Careted b Source #
ComonadApply Careted Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (<@>) :: Careted (a -> b) -> Careted a -> Careted b Source # (@>) :: Careted a -> Careted b -> Careted b Source # (<@) :: Careted a -> Careted b -> Careted a Source #
Functor Careted Source # |
Instance details Defined in Text.Trifecta.Rendering Methods fmap :: (a -> b) -> Careted a -> Careted b Source # (<$) :: a -> Careted b -> Careted a Source #
Foldable Careted Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

fold :: Monoid m => Careted m -> m Source #

foldMap :: Monoid m => (a -> m) -> Careted a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Careted a -> m Source #

foldr :: (a -> b -> b) -> b -> Careted a -> b Source #

foldr' :: (a -> b -> b) -> b -> Careted a -> b Source #

foldl :: (b -> a -> b) -> b -> Careted a -> b Source #

foldl' :: (b -> a -> b) -> b -> Careted a -> b Source #

foldr1 :: (a -> a -> a) -> Careted a -> a Source #

foldl1 :: (a -> a -> a) -> Careted a -> a Source #

toList :: Careted a -> [a] Source #

null :: Careted a -> Bool Source #

length :: Careted a -> Int Source #

elem :: Eq a => a -> Careted a -> Bool Source #

maximum :: Ord a => Careted a -> a Source #

minimum :: Ord a => Careted a -> a Source #

sum :: Num a => Careted a -> a Source #

product :: Num a => Careted a -> a Source #

Traversable Careted Source # |
Instance details Defined in Text.Trifecta.Rendering Methods traverse :: Applicative f => (a -> f b) -> Careted a -> f (Careted b) Source # sequenceA :: Applicative f => Careted (f a) -> f (Careted a) Source # mapM :: Monad m => (a -> m b) -> Careted a -> m (Careted b) Source # sequence :: Monad m => Careted (m a) -> m (Careted a) Source #
Data a => Data (Careted a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Careted a -> c (Careted a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Careted a) Source #

toConstr :: Careted a -> Constr Source #

dataTypeOf :: Careted a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Careted a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Careted a)) Source #

gmapT :: (forall b. Data b => b -> b) -> Careted a -> Careted a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Careted a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Careted a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Careted a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Careted a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Careted a -> m (Careted a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Careted a -> m (Careted a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Careted a -> m (Careted a) Source #

Generic (Careted a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

Associated Types

type Rep (Careted a) |

Instance details

Defined in Text.Trifecta.Rendering

type Rep (Careted a) = D1 ('MetaData "Careted" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons ":^" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Caret)))

Methods

from :: Careted a -> Rep (Careted a) x Source #

to :: Rep (Careted a) x -> Careted a Source #

Show a => Show (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods showsPrec :: Int -> Careted a -> ShowS Source # show :: Careted a -> String Source # showList :: [Careted a] -> ShowS Source #
Eq a => Eq (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (==) :: Careted a -> Careted a -> Bool Source # (/=) :: Careted a -> Careted a -> Bool Source #
Ord a => Ord (Careted a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

compare :: Careted a -> Careted a -> Ordering Source #

(<) :: Careted a -> Careted a -> Bool Source #

(<=) :: Careted a -> Careted a -> Bool Source #

(>) :: Careted a -> Careted a -> Bool Source #

(>=) :: Careted a -> Careted a -> Bool Source #

max :: Careted a -> Careted a -> Careted a Source #

min :: Careted a -> Careted a -> Careted a Source #

Hashable a => Hashable (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods hashWithSalt :: Int -> Careted a -> Int Source # hash :: Careted a -> Int Source #
HasBytes (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods bytes :: Careted a -> Int64 Source #
HasDelta (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods delta :: Careted a -> Delta Source #
HasCaret (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods caret :: Lens' (Careted a) Caret Source #
Renderable (Careted a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Careted a -> Rendering Source #
Reducer (Careted a) Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Careted a -> Rendering Source # snoc :: Rendering -> Careted a -> Rendering Source # cons :: Careted a -> Rendering -> Rendering Source #
type Rep (Careted a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

type Rep (Careted a) = D1 ('MetaData "Careted" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons ":^" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Caret)))

drawCaret :: Delta -> Delta -> Lines -> Lines Source #

addCaret :: Delta -> Rendering -> Rendering Source #

Render a caret at a certain position in a `Rendering`.

caretEffects :: [SGR] Source #

ANSI terminal style for rendering the caret.

renderingCaret :: Delta -> ByteString -> Rendering Source #

# Spans

data Span Source #

A `Span` marks a range of input characters. If `Caret` is a point, then `Span` is a line.

    >>> unAnnotate (prettyRendering (addSpan (Columns 35 35) (Columns 38 38) exampleRendering))
    1 | int main(int argc, char ** argv) { int; }<EOF>
      |                                    ~~~

Constructors

Span !Delta !Delta !ByteString |

#### Instances

Instances details

Semigroup Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (<>) :: Span -> Span -> Span Source # sconcat :: NonEmpty Span -> Span Source # stimes :: Integral b => b -> Span -> Span Source #
Data Span Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Span -> c Span Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Span Source #

toConstr :: Span -> Constr Source #

dataTypeOf :: Span -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Span) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Span) Source #

gmapT :: (forall b. Data b => b -> b) -> Span -> Span Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Span -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Span -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Span -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Span -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Span -> m Span Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Span -> m Span Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Span -> m Span Source #

Generic Span Source # |

Instance details

Defined in Text.Trifecta.Rendering

Associated Types

type Rep Span |

Instance details

Defined in Text.Trifecta.Rendering

type Rep Span = D1 ('MetaData "Span" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Span" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ByteString))))

Methods

from :: Span -> Rep Span x Source #

to :: Rep Span x -> Span Source #

Show Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods showsPrec :: Int -> Span -> ShowS Source # show :: Span -> String Source # showList :: [Span] -> ShowS Source #
Eq Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (==) :: Span -> Span -> Bool Source # (/=) :: Span -> Span -> Bool Source #
Ord Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods compare :: Span -> Span -> Ordering Source # (<) :: Span -> Span -> Bool Source # (<=) :: Span -> Span -> Bool Source # (>) :: Span -> Span -> Bool Source # (>=) :: Span -> Span -> Bool Source # max :: Span -> Span -> Span Source # min :: Span -> Span -> Span Source #
Hashable Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods hashWithSalt :: Int -> Span -> Int Source # hash :: Span -> Int Source #
HasSpan Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods span :: Lens' Span Span Source #
Renderable Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Span -> Rendering Source #
Reducer Span Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Span -> Rendering Source # snoc :: Rendering -> Span -> Rendering Source # cons :: Span -> Rendering -> Rendering Source #
type Rep Span Source # |

Instance details

Defined in Text.Trifecta.Rendering

type Rep Span = D1 ('MetaData "Span" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Span" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta) :*: (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Delta) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 ByteString))))

class HasSpan t where Source #

Methods

span :: Lens' t Span Source #

#### Instances

Instances details

HasSpan Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods span :: Lens' Fixit Span Source #
HasSpan Span Source # |
Instance details Defined in Text.Trifecta.Rendering Methods span :: Lens' Span Span Source #
HasSpan (Spanned a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods span :: Lens' (Spanned a) Span Source #

data Spanned a Source #

Annotate an arbitrary piece of data with a `Span`, typically its corresponding input location.

Constructors

a :~ Span |

#### Instances

Instances details

Comonad Spanned Source # |
Instance details Defined in Text.Trifecta.Rendering Methods extract :: Spanned a -> a Source # duplicate :: Spanned a -> Spanned (Spanned a) Source # extend :: (Spanned a -> b) -> Spanned a -> Spanned b Source #
ComonadApply Spanned Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (<@>) :: Spanned (a -> b) -> Spanned a -> Spanned b Source # (@>) :: Spanned a -> Spanned b -> Spanned b Source # (<@) :: Spanned a -> Spanned b -> Spanned a Source #
Functor Spanned Source # |
Instance details Defined in Text.Trifecta.Rendering Methods fmap :: (a -> b) -> Spanned a -> Spanned b Source # (<$) :: a -> Spanned b -> Spanned a Source #
Foldable Spanned Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

fold :: Monoid m => Spanned m -> m Source #

foldMap :: Monoid m => (a -> m) -> Spanned a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Spanned a -> m Source #

foldr :: (a -> b -> b) -> b -> Spanned a -> b Source #

foldr' :: (a -> b -> b) -> b -> Spanned a -> b Source #

foldl :: (b -> a -> b) -> b -> Spanned a -> b Source #

foldl' :: (b -> a -> b) -> b -> Spanned a -> b Source #

foldr1 :: (a -> a -> a) -> Spanned a -> a Source #

foldl1 :: (a -> a -> a) -> Spanned a -> a Source #

toList :: Spanned a -> [a] Source #

null :: Spanned a -> Bool Source #

length :: Spanned a -> Int Source #

elem :: Eq a => a -> Spanned a -> Bool Source #

maximum :: Ord a => Spanned a -> a Source #

minimum :: Ord a => Spanned a -> a Source #

sum :: Num a => Spanned a -> a Source #

product :: Num a => Spanned a -> a Source #

Traversable Spanned Source # |
Instance details Defined in Text.Trifecta.Rendering Methods traverse :: Applicative f => (a -> f b) -> Spanned a -> f (Spanned b) Source # sequenceA :: Applicative f => Spanned (f a) -> f (Spanned a) Source # mapM :: Monad m => (a -> m b) -> Spanned a -> m (Spanned b) Source # sequence :: Monad m => Spanned (m a) -> m (Spanned a) Source #
Data a => Data (Spanned a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Spanned a -> c (Spanned a) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Spanned a) Source #

toConstr :: Spanned a -> Constr Source #

dataTypeOf :: Spanned a -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Spanned a)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Spanned a)) Source #

gmapT :: (forall b. Data b => b -> b) -> Spanned a -> Spanned a Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Spanned a -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Spanned a -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Spanned a -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Spanned a -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Spanned a -> m (Spanned a) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Spanned a -> m (Spanned a) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Spanned a -> m (Spanned a) Source #

Generic (Spanned a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

Associated Types

type Rep (Spanned a) |

Instance details

Defined in Text.Trifecta.Rendering

type Rep (Spanned a) = D1 ('MetaData "Spanned" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons ":~" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Span)))

Methods

from :: Spanned a -> Rep (Spanned a) x Source #

to :: Rep (Spanned a) x -> Spanned a Source #

Show a => Show (Spanned a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods showsPrec :: Int -> Spanned a -> ShowS Source # show :: Spanned a -> String Source # showList :: [Spanned a] -> ShowS Source #
Eq a => Eq (Spanned a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (==) :: Spanned a -> Spanned a -> Bool Source # (/=) :: Spanned a -> Spanned a -> Bool Source #
Ord a => Ord (Spanned a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

compare :: Spanned a -> Spanned a -> Ordering Source #

(<) :: Spanned a -> Spanned a -> Bool Source #

(<=) :: Spanned a -> Spanned a -> Bool Source #

(>) :: Spanned a -> Spanned a -> Bool Source #

(>=) :: Spanned a -> Spanned a -> Bool Source #

max :: Spanned a -> Spanned a -> Spanned a Source #

min :: Spanned a -> Spanned a -> Spanned a Source #

Hashable a => Hashable (Spanned a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods hashWithSalt :: Int -> Spanned a -> Int Source # hash :: Spanned a -> Int Source #
HasSpan (Spanned a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods span :: Lens' (Spanned a) Span Source #
Renderable (Spanned a) Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Spanned a -> Rendering Source #
Reducer (Spanned a) Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Spanned a -> Rendering Source # snoc :: Rendering -> Spanned a -> Rendering Source # cons :: Spanned a -> Rendering -> Rendering Source #
type Rep (Spanned a) Source # |

Instance details

Defined in Text.Trifecta.Rendering

type Rep (Spanned a) = D1 ('MetaData "Spanned" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons ":~" ('InfixI 'LeftAssociative 9) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Span)))

spanEffects :: [SGR] Source #

ANSI terminal style to render spans with.

drawSpan Source #

Arguments

:: Delta | Start of the region of interest
-> Delta | End of the region of interest
-> Delta | Currrent location
-> Lines | `Lines` to add the rendering to
-> Lines |

addSpan :: Delta -> Delta -> Rendering -> Rendering Source #

# Fixits

data Fixit Source #

A `Fixit` is a `Span` with a suggestion.

    >>> unAnnotate (prettyRendering (addFixit (Columns 35 35) (Columns 38 38) "Fix this!" exampleRendering))
    1 | int main(int argc, char ** argv) { int; }<EOF>
      |                                    ~~~
      |                                    Fix this!

Constructors

Fixit |

Fields

- _fixitSpan :: !Span

  `Span` where the error occurred

- _fixitReplacement :: !ByteString

  Replacement suggestion

#### Instances

Instances details

Data Fixit Source # |

Instance details

Defined in Text.Trifecta.Rendering

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Fixit -> c Fixit Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Fixit Source #

toConstr :: Fixit -> Constr Source #

dataTypeOf :: Fixit -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Fixit) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Fixit) Source #

gmapT :: (forall b. Data b => b -> b) -> Fixit -> Fixit Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Fixit -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Fixit -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Fixit -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Fixit -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Fixit -> m Fixit Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Fixit -> m Fixit Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Fixit -> m Fixit Source #

Generic Fixit Source # |

Instance details

Defined in Text.Trifecta.Rendering

Associated Types

type Rep Fixit |

Instance details

Defined in Text.Trifecta.Rendering

type Rep Fixit = D1 ('MetaData "Fixit" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Fixit" 'PrefixI 'True) (S1 ('MetaSel ('Just "_fixitSpan") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Span) :*: S1 ('MetaSel ('Just "_fixitReplacement") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

Methods

from :: Fixit -> Rep Fixit x Source #

to :: Rep Fixit x -> Fixit Source #

Show Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods showsPrec :: Int -> Fixit -> ShowS Source # show :: Fixit -> String Source # showList :: [Fixit] -> ShowS Source #
Eq Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods (==) :: Fixit -> Fixit -> Bool Source # (/=) :: Fixit -> Fixit -> Bool Source #
Ord Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods compare :: Fixit -> Fixit -> Ordering Source # (<) :: Fixit -> Fixit -> Bool Source # (<=) :: Fixit -> Fixit -> Bool Source # (>) :: Fixit -> Fixit -> Bool Source # (>=) :: Fixit -> Fixit -> Bool Source # max :: Fixit -> Fixit -> Fixit Source # min :: Fixit -> Fixit -> Fixit Source #
Hashable Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods hashWithSalt :: Int -> Fixit -> Int Source # hash :: Fixit -> Int Source #
HasFixit Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods fixit :: Lens' Fixit Fixit Source # fixitReplacement :: Lens' Fixit ByteString Source # fixitSpan :: Lens' Fixit Span Source #
HasSpan Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods span :: Lens' Fixit Span Source #
Renderable Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods render :: Fixit -> Rendering Source #
Reducer Fixit Rendering Source # |
Instance details Defined in Text.Trifecta.Rendering Methods unit :: Fixit -> Rendering Source # snoc :: Rendering -> Fixit -> Rendering Source # cons :: Fixit -> Rendering -> Rendering Source #
type Rep Fixit Source # |

Instance details

Defined in Text.Trifecta.Rendering

type Rep Fixit = D1 ('MetaData "Fixit" "Text.Trifecta.Rendering" "trifecta-2.1.4-2SYQdBIWV6KTgQcAl4jnc" 'False) (C1 ('MetaCons "Fixit" 'PrefixI 'True) (S1 ('MetaSel ('Just "_fixitSpan") 'SourceUnpack 'SourceStrict 'DecidedStrict) (Rec0 Span) :*: S1 ('MetaSel ('Just "_fixitReplacement") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 ByteString)))

class HasFixit c where Source #

Minimal complete definition

fixit

Methods

fixit :: Lens' c Fixit Source #

fixitReplacement :: Lens' c ByteString Source #

fixitSpan :: Lens' c Span Source #

#### Instances

Instances details

HasFixit Fixit Source # |
Instance details Defined in Text.Trifecta.Rendering Methods fixit :: Lens' Fixit Fixit Source # fixitReplacement :: Lens' Fixit ByteString Source # fixitSpan :: Lens' Fixit Span Source #

drawFixit :: Delta -> Delta -> String -> Delta -> Lines -> Lines Source #

addFixit :: Delta -> Delta -> String -> Rendering -> Rendering Source #

# Drawing primitives

type Lines = Array (Int, Int64) ([SGR], Char) Source #

A raw canvas to paint ANSI-styled characters on.

draw Source #

Arguments

:: [SGR] | ANSI style to use
-> Int | Line; 0 is at the top
-> Int64 | Column; 0 is on the left
-> String | Data to be written
-> Lines | Canvas to draw on
-> Lines |

ifNear Source #

Arguments

:: Delta | Position 1
-> (Lines -> Lines) | Modify the fallback result if the positions are `near` each other
-> Delta | Position 2
-> Lines | Fallback result if the positions are not `near` each other
-> Lines |

(.#) :: (Delta -> Lines -> Lines) -> Rendering -> Rendering Source #