fixplate-0.1.8: Uniplate-style generic traversals for optionally annotated fixed-point types.

Safe HaskellSafe
LanguageHaskell2010

Data.Generics.Fixplate.Pretty

Description

Generic pretty-printing of expression trees.

TODO:

  • make the style configurable (so that we can print the same expression in different formats) (in Haskell98, we have to use the record instead of class trick for this?)
  • corresponding parser?
Synopsis

Documentation

data Assoc Source #

Associativity

Constructors

NoAssoc 
LeftAssoc 
RightAssoc 
Instances
Eq Assoc Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

Methods

(==) :: Assoc -> Assoc -> Bool #

(/=) :: Assoc -> Assoc -> Bool #

Show Assoc Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

Methods

showsPrec :: Int -> Assoc -> ShowS #

show :: Assoc -> String #

showList :: [Assoc] -> ShowS #

data Bracket Source #

A pair of matching brackets, eg. Bracket "(" ")" or Bracket "[|" "|]".

Constructors

Bracket !String !String 
Instances
Eq Bracket Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

Methods

(==) :: Bracket -> Bracket -> Bool #

(/=) :: Bracket -> Bracket -> Bool #

Show Bracket Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

type Separator = String Source #

A separator, eg. "," or " | ".

data AppStyle Source #

Application style

Constructors

Haskell

eg. (Node arg1 arg2 arg3); precedence will be app_prec == 10

Algol !Bracket !Separator

eg. node[arg1,arg2,arg3]; precedence will be 11, but child environment precedence will be 0

Instances
Eq AppStyle Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

Show AppStyle Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

data MixWord Source #

Mixfix style. Example:

[ Keyword "if" , Placeholder , keyword "then" , Placeholder , keyword "else" , Placeholder ]

Constructors

Keyword String 
Placeholder 
Instances
Eq MixWord Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

Methods

(==) :: MixWord -> MixWord -> Bool #

(/=) :: MixWord -> MixWord -> Bool #

Show MixWord Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

data Fixity Source #

Fixities. TODO: separate non-fixity stuff like style and words

Constructors

Atom

eg. variable; precedence will be 666

Application !AppStyle

eg. (Node arg1 arg2 arg3) or node[arg1,arg2,arg3].

Prefix !Int

eg. ~arg; the Int is the precendence

Infix !Assoc !Int

eg. x+y

Postfix !Int

eg. arg++

Mixfix [MixWord]

eg. if ... then ... else ... or let ... in .... With precedence 0?

Custom !Int

for your custom rendering

Instances
Eq Fixity Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

Methods

(==) :: Fixity -> Fixity -> Bool #

(/=) :: Fixity -> Fixity -> Bool #

Show Fixity Source # 
Instance details

Defined in Data.Generics.Fixplate.Pretty

class (Functor f, Foldable f) => Pretty f where Source #

A class encoding fixity and rendering of nodes if the tree.

Minimum complete definition: fixity, and showNode or showsPrecNode. Unless you want some type of rendering not directly supported, you shouldn't specify showsPrecNode.

Minimal complete definition

fixity, showNode

Methods

fixity :: f a -> Fixity Source #

fixity of the node

showNode :: f a -> String Source #

a string representing the node without the children

showsPrecNode :: (Int -> a -> ShowS) -> Int -> f a -> ShowS Source #

full rendering of the node. You can redefine this for custom renderings.

pretty :: Pretty f => Mu f -> String Source #

Render the expression

prettyS :: Pretty f => Mu f -> ShowS Source #

prettyPrec :: Pretty f => Int -> Mu f -> ShowS Source #