Community
Modules 28

Prettyprinter.Render.Util.SimpleDocTree

Conversion of the linked-list-like SimpleDocStream to a tree-like SimpleDocTree.

4 generation diagnostics
  • unattached documentation comment at 150:5
  • unattached documentation comment at 153:5
  • unattached documentation comment at 156:5
  • unattached documentation comment at 159:5

Type and conversion

data SimpleDocTree ann

A SimpleDocStream is a linked list of different annotated cons cells (SText and then some further SimpleDocStream, SLine and then some further SimpleDocStream, …). This format is very suitable as a target for a layout engine, but not very useful for rendering to a structured format such as HTML, where we don’t want to do a lookahead until the end of some markup. These formats benefit from a tree-like structure that explicitly marks its contents as annotated. SimpleDocTree is that format.

STChar :: Char -> SimpleDocTree ann

STText :: Int -> Text -> SimpleDocTree ann

STLine :: Int -> SimpleDocTree ann

STAnn :: ann -> (SimpleDocTree ann) -> SimpleDocTree ann

STConcat :: [SimpleDocTree ann] -> SimpleDocTree ann

treeForm :: SimpleDocStream ann -> SimpleDocTree ann

Convert a SimpleDocStream to its SimpleDocTree representation.

Manipulating annotations

unAnnotateST :: SimpleDocTree ann -> SimpleDocTree xxx

Remove all annotations. unAnnotate for SimpleDocTree.

reAnnotateST :: (ann -> ann') -> SimpleDocTree ann -> SimpleDocTree ann'

Change the annotation of a document. reAnnotate for SimpleDocTree.

alterAnnotationsST :: (ann -> [ann']) -> SimpleDocTree ann -> SimpleDocTree ann'

Change the annotation of a document to a different annotation, or none at all. alterAnnotations for SimpleDocTree.

Note that this is as powerful as alterAnnotations, allowing one annotation to become multiple ones, contrary to alterAnnotationsS, which cannot do this.

Common use case shortcut definitions

renderSimplyDecorated :: Monoid out => (Text -> out) -> (ann -> out -> out) -> SimpleDocTree ann -> out

Simplest possible tree-based renderer.

For example, here is a document annotated with (), and the behaviour is to surround annotated regions with »>>>« and »<<<«:

>>> let doc = "hello" <+> annotate () "world" <> "!"
>>> let stdoc = treeForm (layoutPretty defaultLayoutOptions doc)
>>> T.putStrLn (renderSimplyDecorated id (\() x -> ">>>" <> x <> "<<<") stdoc)
hello >>>world<<<!
(Text -> out)

Render plain Text

(ann -> out -> out)

How to modify an element with an annotation

renderSimplyDecoratedA :: (Applicative f, Monoid out) => (Text -> f out) -> (ann -> f out -> f out) -> SimpleDocTree ann -> f out

Version of renderSimplyDecoratedA that allows for Applicative effects.

(Text -> f out)

Render plain Text

(ann -> f out -> f out)

How to modify an element with an annotation

Instances

15
  • instance Functor (UniqueParser s)
  • instance Applicative (UniqueParser s)
  • instance Monad (UniqueParser s)
  • instance Fail.MonadFail (UniqueParser s)
  • instance Alternative (UniqueParser s)
  • instance Eq ann => Eq (SimpleDocTok ann)
  • instance Ord ann => Ord (SimpleDocTok ann)
  • instance Show ann => Show (SimpleDocTok ann)
  • instance Eq ann => Eq (SimpleDocTree ann)
  • instance Ord ann => Ord (SimpleDocTree ann)
  • instance Show ann => Show (SimpleDocTree ann)
  • instance Generic ann => Generic (SimpleDocTree ann)
  • instance Functor SimpleDocTree

    Alter the document’s annotations.

    This instance makes SimpleDocTree more flexible (because it can be used in Functor-polymorphic values), but fmap is much less readable compared to using reAnnotateST in code that only works for SimpleDocTree anyway. Consider using the latter when the type does not matter.

  • instance Foldable SimpleDocTree

    Collect all annotations from a document.

  • instance Traversable SimpleDocTree

    Transform a document based on its annotations, possibly leveraging Applicative effects.

Build record and source files

Community contribution. The service has not verified this documentation. The generator reported 21 diagnostics.

Target: Linux on x86-64. Some inferred types and resolved links are not available.

Generator: aihc-haddock-858b1951-web-1

Metadata snapshot: 19f659e0fd2a9606431ae6a3ec65f9ace725052e19ca6a9f9e9f2759e30fd129

Open the dependency plan · Download the documentation model

Import a package

Enter a package name and an exact version from Hackage. The site contains imported versions only.