haskell-src-exts-util-0.2.5: Helper functions for working with haskell-src-exts trees

Safe Haskell | None
Language | Haskell2010

Language.Haskell.Exts.Util

Contents

- Free variables of ASTs
- Rebracketing of ASTs
- Orphan instances

Synopsis

- class FreeVars a where
  - freeVars :: a -> Set (Name ())
- data Vars = Vars {
  - bound :: Set (Name ())
  - free :: Set (Name ())
  }
- class AllVars a where
  - allVars :: a -> Vars
- class Brackets a where
  - remParen :: a -> Maybe a
  - addParen :: a -> a
  - isAtom :: a -> Bool
  - needBracket :: Int -> a -> a -> Bool
- paren :: (Data l, Default l) => Exp l -> Exp l
- transformBracket :: (Data l, Default l) => (Exp l -> Maybe (Exp l)) -> Exp l -> Exp l
- rebracket1 :: (Data l, Default l) => Exp l -> Exp l
- appsBracket :: (Data l, Default l) => [Exp l] -> Exp l

# Free variables of ASTs

class FreeVars a where Source #

Methods

freeVars :: a -> Set (Name ()) Source #

Return the variables, erring on the side of more free variables

#### Instances

Instances details

(Data s, Ord s) => FreeVars (Set (Name s)) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: Set (Name s) -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars (Alt s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: Alt s -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars (Exp s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: Exp s -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars (FieldUpdate s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: FieldUpdate s -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars (GuardedRhs s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: GuardedRhs s -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars (IPBind s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: IPBind s -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars (Rhs s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: Rhs s -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars [Alt s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: [Alt s] -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars [Exp s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: [Exp s] -> Set (Name ()) Source #
(Data s, Ord s) => FreeVars [IPBind s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods freeVars :: [IPBind s] -> Set (Name ()) Source #

data Vars Source #

Constructors

Vars |

Fields

- bound :: Set (Name ())
- free :: Set (Name ())

#### Instances

Instances details

Monoid Vars Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods mempty :: Vars Source # mappend :: Vars -> Vars -> Vars Source # mconcat :: [Vars] -> Vars Source #
Semigroup Vars Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods (<>) :: Vars -> Vars -> Vars Source # sconcat :: NonEmpty Vars -> Vars Source # stimes :: Integral b => b -> Vars -> Vars Source #
AllVars Vars Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Vars -> Vars Source #

class AllVars a where Source #

Methods

allVars :: a -> Vars Source #

Return the variables, erring on the side of more free variables

#### Instances

Instances details

AllVars Vars Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Vars -> Vars Source #
(Data s, Ord s) => AllVars (Binds s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Binds s -> Vars Source #
(Data s, Ord s) => AllVars (Decl s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Decl s -> Vars Source #
(Data s, Ord s) => AllVars (Match s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Match s -> Vars Source #
(Data s, Ord s) => AllVars (Pat s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Pat s -> Vars Source #
(Data s, Ord s) => AllVars (PatField s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: PatField s -> Vars Source #
(Data s, Ord s) => AllVars (QualStmt s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: QualStmt s -> Vars Source #
(Data s, Ord s) => AllVars (Stmt s) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Stmt s -> Vars Source #
(Data s, Ord s) => AllVars (Maybe (Binds s)) Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: Maybe (Binds s) -> Vars Source #
(Data s, Ord s) => AllVars [Decl s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: [Decl s] -> Vars Source #
(Data s, Ord s) => AllVars [Match s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: [Match s] -> Vars Source #
(Data s, Ord s) => AllVars [Pat s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: [Pat s] -> Vars Source #
(Data s, Ord s) => AllVars [PatField s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: [PatField s] -> Vars Source #
(Data s, Ord s) => AllVars [QualStmt s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: [QualStmt s] -> Vars Source #
(Data s, Ord s) => AllVars [Stmt s] Source # |
Instance details Defined in Language.Haskell.Exts.FreeVars Methods allVars :: [Stmt s] -> Vars Source #

# Rebracketing of ASTs

class Brackets a where Source #

Methods

remParen :: a -> Maybe a Source #

addParen :: a -> a Source #

isAtom :: a -> Bool Source #

Is this item lexically requiring no bracketing ever i.e. is totally atomic

needBracket :: Int -> a -> a -> Bool Source #

Is the child safe free from brackets in the parent position. Err on the side of caution, True = don't know

#### Instances

Instances details

(Data l, Default l) => Brackets (Exp l) Source # |
Instance details Defined in Language.Haskell.Exts.Bracket Methods remParen :: Exp l -> Maybe (Exp l) Source # addParen :: Exp l -> Exp l Source # isAtom :: Exp l -> Bool Source # needBracket :: Int -> Exp l -> Exp l -> Bool Source #
Default l => Brackets (Pat l) Source # |
Instance details Defined in Language.Haskell.Exts.Bracket Methods remParen :: Pat l -> Maybe (Pat l) Source # addParen :: Pat l -> Pat l Source # isAtom :: Pat l -> Bool Source # needBracket :: Int -> Pat l -> Pat l -> Bool Source #
Default l => Brackets (Type l) Source # |
Instance details Defined in Language.Haskell.Exts.Bracket Methods remParen :: Type l -> Maybe (Type l) Source # addParen :: Type l -> Type l Source # isAtom :: Type l -> Bool Source # needBracket :: Int -> Type l -> Type l -> Bool Source #

paren :: (Data l, Default l) => Exp l -> Exp l Source #

Add a Paren around something if it is not atomic

transformBracket :: (Data l, Default l) => (Exp l -> Maybe (Exp l)) -> Exp l -> Exp l Source #

rebracket1 :: (Data l, Default l) => Exp l -> Exp l Source #

Add/remove brackets as suggested needBracket at 1-level of depth

appsBracket :: (Data l, Default l) => [Exp l] -> Exp l Source #

# Orphan instances

Default SrcLoc Source # |
Instance details Methods def :: SrcLoc Source #
Default SrcSpan Source # |
Instance details Methods def :: SrcSpan Source #
Default SrcSpanInfo Source # |
Instance details Methods def :: SrcSpanInfo Source #