packages feed

haskell-tools-ast (empty) → 0.1.2.0

raw patch · 29 files changed

+2549/−0 lines, 29 filesdep +basedep +ghcdep +referencessetup-changed

Dependencies added: base, ghc, references, structural-traversal, uniplate

Files

+ LICENSE view
@@ -0,0 +1,29 @@+Haskell-Tools is Copyright (c) Boldizsár Németh, 2016, all rights reserved,
+and is distributed as free software under the following license.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions, and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions, and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+- The names of the copyright holders may not be used to endorse or
+promote products derived from this software without specific prior
+written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY
+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Language/Haskell/Tools/AST.hs view
@@ -0,0 +1,38 @@+-- | A custom AST representation for Haskell tools.
+-- Different layers of the AST are recursive, to separate them into modules
+-- we introduced source imports.
+module Language.Haskell.Tools.AST 
+  ( module Language.Haskell.Tools.AST.Modules
+  , module Language.Haskell.Tools.AST.TH
+  , module Language.Haskell.Tools.AST.Decls
+  , module Language.Haskell.Tools.AST.Binds
+  , module Language.Haskell.Tools.AST.Exprs
+  , module Language.Haskell.Tools.AST.Stmts
+  , module Language.Haskell.Tools.AST.Patterns
+  , module Language.Haskell.Tools.AST.Types
+  , module Language.Haskell.Tools.AST.Kinds
+  , module Language.Haskell.Tools.AST.Literals
+  , module Language.Haskell.Tools.AST.Base
+  , module Language.Haskell.Tools.AST.Ann
+  , module Language.Haskell.Tools.AST.References
+  , module Language.Haskell.Tools.AST.Helpers
+  , module Language.Haskell.Tools.AST.Utils.OrdSrcSpan
+  ) where
+
+import Language.Haskell.Tools.AST.Instances
+import Language.Haskell.Tools.AST.References
+import Language.Haskell.Tools.AST.Helpers
+
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.TH
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Stmts
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Utils.OrdSrcSpan
+ Language/Haskell/Tools/AST/Ann.hs view
@@ -0,0 +1,153 @@+{-# LANGUAGE FlexibleInstances
+           , FlexibleContexts
+           , TemplateHaskell
+           , DeriveDataTypeable
+           , StandaloneDeriving
+           #-}
+-- | Parts of AST representation for keeping extra data
+module Language.Haskell.Tools.AST.Ann where
+
+import Data.Data
+import Control.Reference
+import SrcLoc
+import Name
+import RdrName
+import Module
+import Id
+import Outputable
+import Language.Haskell.Tools.AST.Utils.GHCInstances
+
+-- | An element of the AST keeping extra information.
+data Ann elem annot
+-- The type parameters are organized this way because we want the annotation type to
+-- be more flexible, but the annotation is the first parameter because it eases 
+-- pattern matching.
+  = Ann { _annotation :: annot -- ^ The extra information for the AST part
+        , _element    :: elem annot -- ^ The original AST part
+        }
+        
+makeReferences ''Ann
+        
+-- | Semantic and source code related information for an AST node.
+data NodeInfo sema src 
+  = NodeInfo { _semanticInfo :: sema
+             , _sourceInfo :: src
+             }
+  deriving (Eq, Show, Data)
+             
+makeReferences ''NodeInfo
+
+-- | Location info for different types of nodes
+data SpanInfo 
+  = NodeSpan { _nodeSpan :: SrcSpan }
+  | ListPos { _listBefore :: String
+            , _listAfter :: String
+            , _listDefaultSep :: String
+            , _listIndented :: Bool
+            , _listPos :: SrcLoc 
+            }
+  | OptionalPos { _optionalBefore :: String
+                , _optionalAfter :: String 
+                , _optionalPos :: SrcLoc 
+                }
+  deriving (Eq, Show, Data)
+
+makeReferences ''SpanInfo
+
+-- | Extracts the concrete range corresponding to a given span.
+-- In case of lists and optional elements, it may not contain the elements inside.
+spanRange :: SpanInfo -> SrcSpan
+spanRange (NodeSpan sp)                   = sp
+spanRange ListPos{_listPos = pos}         = srcLocSpan pos
+spanRange OptionalPos{_optionalPos = pos} = srcLocSpan pos
+  
+class HasRange annot where
+  getRange :: annot -> SrcSpan
+  
+instance HasRange (NodeInfo sema SpanInfo) where 
+  getRange = spanRange . (^. sourceInfo)
+  
+type RangeInfo = NodeInfo (SemanticInfo RdrName) SpanInfo
+type RangeWithName = NodeInfo (SemanticInfo Name) SpanInfo
+type RangeWithType = NodeInfo (SemanticInfo Id) SpanInfo
+
+-- | Semantic information for an AST node. Semantic information is
+-- currently heterogeneous.
+data SemanticInfo n
+  = NoSemanticInfo -- ^ Semantic info type for any node not 
+                   -- carrying additional semantic information
+  | ScopeInfo { _scopedLocals :: [[Name]] 
+              }
+  | NameInfo { _scopedLocals :: [[Name]]
+             , _isDefined :: Bool
+             , _nameInfo :: n
+             } -- ^ Info corresponding to a name
+  | ModuleInfo { _defModuleName :: Module 
+               , _importedNames :: [n] -- ^ Implicitely imported names
+               } -- ^ Info for the module element
+  | ImportInfo { _importedModule :: Module -- ^ The name and package of the imported module
+               , _availableNames :: [n] -- ^ Names available from the imported module
+               , _importedNames :: [n] -- ^ Names actually imported from the module.
+               } -- ^ Info corresponding to an import declaration
+  | AmbiguousNameInfo { _scopedLocals :: [[Name]]
+                      , _isDefined :: Bool
+                      , _ambiguousName :: RdrName
+                      , _ambiguousLocation :: SrcSpan
+                      }
+  -- | ImplicitImports [ImportDecl]
+  -- | ImplicitFieldUpdates [ImportDecl]
+  deriving (Eq, Data)
+
+instance Outputable n => Show (SemanticInfo n) where
+  show NoSemanticInfo = "NoSemanticInfo"
+  show (ScopeInfo locals) = "(ScopeInfo " ++ showSDocUnsafe (ppr locals) ++ ")"
+  show (NameInfo locals defined nameInfo) = "(NameInfo " ++ showSDocUnsafe (ppr locals) ++ " " ++ show defined ++ " " ++ showSDocUnsafe (ppr nameInfo) ++ ")"
+  show (ModuleInfo mod imp) = "(ModuleInfo " ++ showSDocUnsafe (ppr mod) ++ " " ++ showSDocUnsafe (ppr imp) ++ ")"
+  show (ImportInfo mod avail imported) = "(ImportInfo " ++ showSDocUnsafe (ppr mod) ++ " " ++ showSDocUnsafe (ppr avail) ++ " " ++ showSDocUnsafe (ppr imported) ++ ")"
+
+makeReferences ''SemanticInfo
+
+-- | A list of AST elements
+data AnnList e a = AnnList { _annListAnnot :: a 
+                           , _annListElems :: [Ann e a]
+                           }
+                           
+makeReferences ''AnnList
+        
+annList :: Traversal (AnnList e a) (AnnList e' a) (Ann e a) (Ann e' a)                          
+annList = annListElems & traversal
+
+-- | An optional AST element
+data AnnMaybe e a = AnnMaybe { _annMaybeAnnot :: a 
+                             , _annMaybe :: Maybe (Ann e a)
+                             }
+                             
+makeReferences ''AnnMaybe
+                          
+annJust :: Partial (AnnMaybe e a) (AnnMaybe e' a) (Ann e a) (Ann e' a)                          
+annJust = annMaybe & just
+
+-- | An empty list of AST elements
+annNil :: a -> AnnList e a
+annNil a = AnnList a []
+
+isAnnNothing :: AnnMaybe e a -> Bool
+isAnnNothing (AnnMaybe _ Nothing) = True
+isAnnNothing (AnnMaybe _ _) = False
+
+-- | A non-existing AST part
+annNothing :: a -> AnnMaybe e a
+annNothing a = AnnMaybe a Nothing
+
+  
+class HasAnnot node where
+  getAnnot :: node a -> a
+
+instance HasAnnot (Ann e) where
+  getAnnot = (^. annotation)
+  
+instance HasAnnot (AnnList e) where
+  getAnnot = (^. annListAnnot)
+  
+instance HasAnnot (AnnMaybe e) where
+  getAnnot = (^. annMaybeAnnot)
+ Language/Haskell/Tools/AST/Base.hs view
@@ -0,0 +1,117 @@+
+{-# LANGUAGE TypeFamilies
+           , MultiParamTypeClasses
+           , FlexibleInstances
+           #-}
+
+-- | Simple AST elements of Haskell
+module Language.Haskell.Tools.AST.Base where
+  
+import Language.Haskell.Tools.AST.Ann
+
+data Operator a
+  = BacktickOp { _operatorName :: Ann SimpleName a } -- ^ Backtick operator name: @ a `mod` b @
+  | NormalOp { _operatorName :: Ann SimpleName a }
+
+data Name a
+  = ParenName { _simpleName :: Ann SimpleName a } -- ^ Parenthesized name: @ foldl (+) 0 @
+  | NormalName { _simpleName :: Ann SimpleName a }
+
+-- | Possible qualified names. Contains also implicit names.
+-- Linear implicit parameter: @%x@. Non-linear implicit parameter: @?x@.
+data SimpleName a 
+  = SimpleName { _qualifiers      :: AnnList UnqualName a
+               , _unqualifiedName :: Ann UnqualName a 
+               }
+
+nameFromList :: AnnList UnqualName a -> SimpleName a
+nameFromList (AnnList a xs) | not (null xs) 
+  = SimpleName (AnnList a (init xs)) (last xs) 
+nameFromList _ = error "nameFromList: empty list"
+         
+-- | Parts of a qualified name.         
+data UnqualName a 
+  = UnqualName { _simpleNameStr :: String } 
+               
+-- | Program elements formatted as string literals (import packages, pragma texts)
+data StringNode a
+  = StringNode { _stringNodeStr :: String }
+                   
+-- | The @data@ or the @newtype@ keyword to define ADTs.
+data DataOrNewtypeKeyword a
+  = DataKeyword
+  | NewtypeKeyword
+    
+-- | Keywords @do@ or @mdo@ to start a do-block
+data DoKind a
+  = DoKeyword
+  | MDoKeyword
+  
+-- | The @type@ keyword used to qualify that the type and not the constructor of the same name is referred
+data TypeKeyword a = TypeKeyword
+  
+-- | Recognised overlaps for overlap pragmas. Can be applied to class declarations and class instance declarations.    
+data OverlapPragma a
+  = EnableOverlap     -- ^ @OVERLAP@ pragma
+  | DisableOverlap    -- ^ @NO_OVERLAP@ pragma
+  | Overlappable      -- ^ @OVERLAPPABLE@ pragma
+  | Overlapping       -- ^ @OVERLAPPING@ pragma
+  | Overlaps          -- ^ @OVERLAPS@ pragma
+  | IncoherentOverlap -- ^ @INCOHERENT@ pragma
+  
+-- | Call conventions of foreign functions
+data CallConv a
+  = StdCall
+  | CCall
+  | CPlusPlus
+  | DotNet
+  | Jvm
+  | Js
+  | JavaScript
+  | CApi
+  
+data ArrowAppl a
+  = LeftAppl -- ^ Left arrow application: @-<@
+  | RightAppl -- ^ Right arrow application: @>-@
+  | LeftHighApp -- ^ Left arrow high application: @-<<@
+  | RightHighApp -- ^ Right arrow high application: @>>-@
+  
+-- | Safety annotations for foreign calls
+data Safety a
+  = Safe
+  | ThreadSafe
+  | Unsafe
+  | Interruptible
+
+-- | Associativity of an operator.
+data Assoc a
+  = AssocNone  -- ^ non-associative operator (declared with @infix@)
+  | AssocLeft  -- ^ left-associative operator (declared with @infixl@)
+  | AssocRight -- ^ right-associative operator (declared with @infixr@)
+
+data Role a
+  = Nominal
+  | Representational
+  | Phantom
+  
+data ConlikeAnnot a = ConlikeAnnot
+
+-- | Numeric precedence of an operator
+data Precedence a
+  = Precedence { _precedenceValue :: Int } 
+
+data LineNumber a
+  = LineNumber { _lineNumber :: Int } 
+     
+-- | Controls the activation of a rewrite rule (@ [1] @)
+data PhaseControl a
+  = PhaseControl { _phaseUntil :: AnnMaybe PhaseInvert a
+                 , _phaseNumber :: Ann PhaseNumber a
+                 } 
+
+-- | Phase number for rewrite rules
+data PhaseNumber a 
+  = PhaseNumber { _phaseNum :: Integer }
+
+-- | A tilde that marks the inversion of the phase number
+data PhaseInvert a = PhaseInvert
+ Language/Haskell/Tools/AST/Binds.hs view
@@ -0,0 +1,151 @@+-- | Representation of Haskell AST value and function bindings (both local and top-level)
+module Language.Haskell.Tools.AST.Binds where
+
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Literals
+import {-# SOURCE #-} Language.Haskell.Tools.AST.TH
+
+-- | Value binding for top-level and local bindings
+data ValueBind a
+  = SimpleBind { _valBindPat :: Ann Pattern a
+               , _valBindRhs :: Ann Rhs a  
+               , _valBindLocals :: AnnMaybe LocalBinds a
+               } -- ^ Non-function binding (@ v = "12" @)  
+  -- TODO: use one name for a function instead of names in each match
+  | FunBind    { _funBindMatches :: AnnList Match a 
+               } -- ^ Function binding (@ f 0 = 1; f x = x @). All matches must have the same name.
+
+-- | Clause of function (or value) binding   
+data Match a
+  = Match { _matchLhs :: Ann MatchLhs a
+          , _matchRhs :: Ann Rhs a
+          , _matchBinds :: AnnMaybe LocalBinds a
+          } 
+
+-- | Something on the left side of the match
+data MatchLhs a 
+  = NormalLhs { _matchLhsName :: Ann Name a
+              , _matchLhsArgs :: AnnList Pattern a
+              }
+  | InfixLhs { _matchLhsLhs :: Ann Pattern a
+             , _matchLhsOperator :: Ann Operator a
+             , _matchLhsRhs :: Ann Pattern a
+             , _matchLhsArgs :: AnnList Pattern a
+             }
+    
+-- | Local bindings attached to a declaration (@ where x = 42 @)             
+data LocalBinds a
+  = LocalBinds { _localBinds :: AnnList LocalBind a 
+               }
+  
+-- | Bindings that are enabled in local blocks (where or let).
+data LocalBind a 
+  = LocalValBind   { _localVal :: Ann ValueBind a 
+                   }
+  -- TODO: check that no other signature can be inside a local binding
+  | LocalSignature { _localSig :: Ann TypeSignature a 
+                   }
+  | LocalFixity    { _localFixity :: Ann FixitySignature a
+                   }
+                   
+-- | A type signature (@ _f :: Int -> Int @)
+data TypeSignature a 
+  = TypeSignature { _tsName :: AnnList Name a
+                  , _tsType :: Ann Type a
+                  }     
+                   
+-- | A fixity signature (@ infixl 5 +, - @).
+data FixitySignature a 
+  = FixitySignature { _fixityAssoc :: Ann Assoc a
+                    , _fixityPrecedence :: Ann Precedence a
+                    , _fixityOperators :: AnnList Operator a
+                    }
+   
+-- | Right hand side of a value binding (possible with guards): (@ = 3 @ or @ | x == 1 = 3; | otherwise = 4 @)
+data Rhs a
+  = UnguardedRhs { _rhsExpr :: Ann Expr a
+                 }
+  | GuardedRhss  { _rhsGuards :: AnnList GuardedRhs a
+                 }
+      
+-- | A guarded right-hand side of a value binding (@ | x > 3 = 2 @)      
+data GuardedRhs a
+  = GuardedRhs { _guardStmts :: AnnList RhsGuard a -- ^ Cannot be empty.
+               , _guardExpr :: Ann Expr a
+               } 
+
+-- | Guards for value bindings and pattern matches (@ Just v <- x, v > 1 @)
+data RhsGuard a
+  = GuardBind  { _guardPat :: Ann Pattern a
+               , _guardRhs :: Ann Expr a
+               }
+  | GuardLet   { _guardBinds :: AnnList LocalBind a 
+               }
+  | GuardCheck { _guardCheck :: Ann Expr a 
+               }
+
+-- * Pragmas
+
+-- | Top level pragmas
+data TopLevelPragma a
+  = RulePragma       { _pragmaRule :: AnnList Rule a 
+                     }
+  | DeprPragma       { _pragmaObjects :: AnnList Name a
+                     , _pragmaMessage :: Ann StringNode a
+                     }
+  | WarningPragma    { _pragmaObjects :: AnnList Name a
+                     , _pragmaMessage :: Ann StringNode a
+                     }
+  | AnnPragma        { _annotationSubject :: Ann AnnotationSubject a 
+                     , _annotateExpr :: Ann Expr a
+                     }
+  | InlinePragma     { _pragmaConlike :: AnnMaybe ConlikeAnnot a
+                     , _pragmaPhase :: AnnMaybe PhaseControl a
+                     , _inlineDef :: Ann Name a 
+                     }
+  | NoInlinePragma   { _pragmaConlike :: AnnMaybe ConlikeAnnot a
+                     , _pragmaPhase :: AnnMaybe PhaseControl a
+                     , _noInlineDef :: Ann Name a 
+                     }
+  | InlinablePragma  { _pragmaPhase :: AnnMaybe PhaseControl a
+                     , _inlinableDef :: Ann Name a 
+                     }
+  | LinePragma       { _pragmaLineNum :: Ann LineNumber a
+                     , _pragmaFileName :: AnnMaybe StringNode a 
+                     }
+  | SpecializePragma { _pragmaPhase :: AnnMaybe PhaseControl a
+                     , _specializeDef :: Ann Name a 
+                     , _specializeType :: AnnList Type a 
+                     }
+
+-- | A rewrite rule (@ "map/map" forall f g xs. map f (map g xs) = map (f.g) xs @)
+data Rule a
+  = Rule { _ruleName :: Ann StringNode a -- ^ User name of the rule
+         , _rulePhase :: AnnMaybe PhaseControl a -- ^ The compilation phases in which the rule can be applied
+         , _ruleBounded :: AnnList TyVar a -- ^ Variables bound in the rule
+         , _ruleLhs :: Ann Expr a -- ^ The transformed expression
+         , _ruleRhs :: Ann Expr a -- ^ The resulting expression
+         }
+ 
+-- | Annotation allows you to connect an expression to any declaration. 
+data AnnotationSubject a
+  = NameAnnotation { _annotateName :: Ann Name a
+                   } -- ^ The definition with the given name is annotated
+  | TypeAnnotation { _annotateName :: Ann Name a 
+                   } -- ^ A type with the given name is annotated
+  | ModuleAnnotation -- ^ The whole module is annotated
+
+-- | Formulas of minimal annotations declaring which functions should be defined.
+data MinimalFormula a
+  = MinimalName  { _minimalName :: Ann Name a 
+                 }
+  | MinimalParen { _minimalInner :: Ann MinimalFormula a 
+                 }
+  | MinimalOr    { _minimalOrs :: AnnList MinimalFormula a
+                 } -- ^ One of the minimal formulas are needed (@ min1 | min2 @)
+  | MinimalAnd   { _minimalAnds :: AnnList MinimalFormula a
+                 } -- ^ Both of the minimal formulas are needed (@ min1 , min2 @)
+ Language/Haskell/Tools/AST/Binds.hs-boot view
@@ -0,0 +1,11 @@+{-# LANGUAGE RoleAnnotations #-}
+module Language.Haskell.Tools.AST.Binds where
+
+type role LocalBind nominal
+data LocalBind a
+
+type role LocalBinds nominal
+data LocalBinds a
+
+type role RhsGuard nominal
+data RhsGuard a
+ Language/Haskell/Tools/AST/Decls.hs view
@@ -0,0 +1,302 @@+-- | Representation of Haskell AST definitions
+module Language.Haskell.Tools.AST.Decls where
+
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Ann
+import {-# SOURCE #-} Language.Haskell.Tools.AST.TH
+
+
+-- | Haskell declaration
+data Decl a
+  = TypeDecl             { _declHead :: Ann DeclHead a
+                         , _declType :: Ann Type a
+                         } -- ^ A type synonym ( @type String = [Char]@ )
+  | TypeFamilyDecl       { _declTypeFamily :: Ann TypeFamily a 
+                         }
+  | ClosedTypeFamilyDecl { _declHead :: Ann DeclHead a
+                         , _declKind :: AnnMaybe KindConstraint a
+                         , _declDecl :: AnnList TypeEqn a -- ^ cannot be empty
+                         } -- ^ A closed type family declaration
+  | DataDecl             { _declNewtype :: Ann DataOrNewtypeKeyword a
+                         , _declCtx  :: AnnMaybe Context a
+                         , _declHead :: Ann DeclHead a
+                         , _declCons :: AnnList ConDecl a
+                         , _declDeriving :: AnnMaybe Deriving a
+                         } -- ^ A data or newtype declaration. Empty data type declarations without 
+                           -- where keyword are always belong to DataDecl.
+  | GDataDecl            { _declNewtype :: Ann DataOrNewtypeKeyword a
+                         , _declCtx  :: AnnMaybe Context a
+                         , _declHead :: Ann DeclHead a
+                         , _declKind :: AnnMaybe KindConstraint a
+                         , _declGadt :: AnnList GadtConDecl a
+                         , _declDeriving :: AnnMaybe Deriving a
+                         } -- ^ A data or newtype declaration.
+  | TypeInstDecl         { _declInstance :: Ann InstanceRule a
+                         , _declAssignedType :: Ann Type a
+                         } -- ^ Type instance declaration (@ type instance Fam T = AssignedT @)
+  | DataInstDecl         { _declNewtype :: Ann DataOrNewtypeKeyword a
+                         , _declInstance :: Ann InstanceRule a
+                         , _declCons :: AnnList ConDecl a
+                         , _declDeriving :: AnnMaybe Deriving a
+                         } -- ^ Data instance declaration (@ data instance Fam T = Con1 | Con2 @)
+  | GDataInstDecl        { _declNewtype :: Ann DataOrNewtypeKeyword a
+                         , _declInstance :: Ann InstanceRule a
+                         , _declKind :: AnnMaybe KindConstraint a
+                         , _declGadt :: AnnList GadtConDecl a
+                         } -- ^ Gadt style data instance declaration (@ data instance Fam T where ... @)
+  | ClassDecl            { _declCtx :: AnnMaybe Context a
+                         , _declHead :: Ann DeclHead a
+                         , _declFunDeps :: AnnMaybe FunDeps a
+                         , _declBody :: AnnMaybe ClassBody a
+                         } -- ^ Type class declaration (@ class X a [where f = ...] @)
+  | InstDecl             { _declOverlap :: AnnMaybe OverlapPragma a
+                         , _declInstRule :: Ann InstanceRule a
+                         , _declInstDecl :: AnnMaybe InstBody a
+                         } -- ^ Instance declaration (@ instance X T [where f = ...] @)
+  | PatternSynonymDecl   { _declPatSyn :: Ann PatternSynonym a
+                         } -- ^ Pattern synonyms (@ pattern Arrow t1 t2 = App "->" [t1, t2] @)
+  | DerivDecl            { _declOverlap :: AnnMaybe OverlapPragma a
+                         , _declInstRule :: Ann InstanceRule a
+                         } -- ^ Standalone deriving declaration (@ deriving instance X T @)
+  | FixityDecl           { _declFixity :: Ann FixitySignature a 
+                         } -- ^ Fixity declaration (@ infixl 5 +, - @)
+  | DefaultDecl          { _declTypes :: AnnList Type a
+                         } -- ^ Default types (@ default (T1, T2) @)
+  | TypeSigDecl          { _declTypeSig :: Ann TypeSignature a 
+                         } -- ^ Type signature declaration (@ _f :: Int -> Int @)
+  | PatTypeSigDecl       { _declPatTypeSig :: Ann PatternTypeSignature a 
+                         } -- ^ Type signature declaration (@ _f :: Int -> Int @)
+  | ValueBinding         { _declValBind :: Ann ValueBind a
+                         } -- ^ Function binding (@ f x = 12 @)
+  | ForeignImport        { _declCallConv :: Ann CallConv a
+                         , _declSafety :: AnnMaybe Safety a
+                         , _declName :: Ann Name a
+                         , _declType :: Ann Type a
+                         } -- ^ Foreign import (@ foreign import _foo :: Int -> IO Int @)
+  | ForeignExport        { _declCallConv :: Ann CallConv a
+                         , _declName :: Ann Name a
+                         , _declType :: Ann Type a
+                         } -- ^ foreign export (@ foreign export ccall _foo :: Int -> IO Int @)
+  | PragmaDecl           { _declPragma :: Ann TopLevelPragma a 
+                         } -- ^ top level pragmas
+  | RoleDecl             { _declRoleType :: Ann SimpleName a 
+                         , _declRoles :: AnnList Role a
+                         } -- ^ role annotations (@ type role Ptr representational @)
+  | SpliceDecl           { _declSplice :: Ann Splice a 
+                         } -- ^ A Template Haskell splice declaration (@ $(generateDecls) @)
+    
+-- | Open type and data families
+data TypeFamily a
+  = TypeFamily { _tfHead :: Ann DeclHead a
+               , _tfSpec :: AnnMaybe TypeFamilySpec a
+               } -- ^ A type family declaration (@ type family A _a :: * -> * @)    
+  | DataFamily { _tfHead :: Ann DeclHead a
+               , _tfKind :: AnnMaybe KindConstraint a
+               } -- ^ Data family declaration
+                  
+data TypeFamilySpec a 
+  = TypeFamilyKind { _tfSpecKind :: Ann KindConstraint a 
+                   }
+  | TypeFamilyInjectivity { _tfInjectivity :: Ann InjectivityAnn a
+                          }
+
+data InjectivityAnn a
+  = InjectivityAnn { _injAnnRes :: Ann Name a
+                   , _injAnnDeps :: AnnList Name a
+                   }
+
+-- | The list of declarations that can appear in a typeclass
+data ClassBody a
+  = ClassBody { _cbElements :: AnnList ClassElement a 
+              }
+                 
+-- | Members of a class declaration       
+data ClassElement a
+  = ClsSig     { _ceTypeSig :: Ann TypeSignature a 
+               } -- ^ Signature: @ _f :: A -> B @
+  | ClsDef     { _ceBind :: Ann ValueBind a
+               } -- ^ Default binding: @ f x = "aaa" @
+  | ClsTypeFam { _ceTypeFam :: Ann TypeFamily a
+               } -- ^ Declaration of an associated type synonym: @ type T _x :: * @ 
+  | ClsTypeDef { _ceHead :: Ann DeclHead a
+               , _ceKind :: Ann Type a
+               } -- ^ Default choice for type synonym: @ type T x = TE @ or @ type instance T x = TE @ 
+  | ClsDefSig  { _ceName :: Ann Name a
+               , _ceType :: Ann Type a
+               } -- ^ Default signature (by using @DefaultSignatures@): @ default _enum :: (Generic a, GEnum (Rep a)) => [a] @
+  | ClsMinimal { _pragmaFormula :: Ann MinimalFormula a 
+               } -- ^ Minimal pragma: @ {-# MINIMAL (==) | (/=) #-} @
+
+   -- not supported yet (GHC 7.10.3)
+  | ClsPatSig  { _cePatSig :: Ann PatternTypeSignature a 
+               } -- ^ Pattern signature in a class declaration (by using @PatternSynonyms@)
+       
+-- The declared (possibly parameterized) type (@ A x :+: B y @).
+data DeclHead a
+  = DeclHead { _dhName :: Ann Name a 
+             } -- ^ Type or class name
+  | DHParen  { _dhBody :: Ann DeclHead a 
+             } -- ^ Parenthesized type
+  | DHApp    { _dhAppFun :: Ann DeclHead a
+             , _dhAppOperand :: Ann TyVar a
+             } -- ^ Type application
+  | DHInfix  { _dhLeft :: Ann TyVar a
+             , _dhOperator :: Ann Operator a 
+             , _dhRight :: Ann TyVar a
+             } -- ^ Infix application of the type/class name to the left operand
+       
+-- | Instance body is the implementation of the class functions (@ where a x = 1; b x = 2 @)
+data InstBody a
+  = InstBody { _instBodyDecls :: AnnList InstBodyDecl a 
+             }
+
+-- | Declarations inside an instance declaration.
+data InstBodyDecl a
+  = InstBodyNormalDecl   { _instBodyDeclFunbind :: Ann ValueBind a 
+                         } -- ^ A normal declaration (@ f x = 12 @)
+  | InstBodyTypeSig      { _instBodyTypeSig :: Ann TypeSignature a 
+                         } -- ^ Type signature in instance definition with @InstanceSigs@
+  | InstBodyTypeDecl     { _instBodyTypeEqn :: Ann TypeEqn a 
+                         } -- ^ An associated type definition (@ type A X = B @)
+  | InstBodyDataDecl     { _instBodyDataNew :: Ann DataOrNewtypeKeyword a
+                         , _instBodyLhsType :: Ann InstanceRule a
+                         , _instBodyDataCons :: AnnList ConDecl a
+                         , _instBodyDerivings :: AnnMaybe Deriving a
+                         } -- ^ An associated data type implementation (@ data A X = C1 | C2 @)
+  | InstBodyGadtDataDecl { _instBodyDataNew :: Ann DataOrNewtypeKeyword a
+                         , _instBodyLhsType :: Ann InstanceRule a
+                         , _instBodyDataKind :: AnnMaybe Kind a
+                         , _instBodyGadtCons :: AnnList GadtConDecl a
+                         , _instBodyDerivings :: AnnMaybe Deriving a
+                         } -- ^ An associated data type implemented using GADT style
+  | SpecializeInstance   { _specializeInstanceType :: Ann Type a 
+                         } -- ^ Specialize instance pragma (no phase selection is allowed)
+  -- not supported yet
+  | InstBodyPatSyn       { _instBodyPatSyn :: Ann PatternSynonym a 
+                         } -- ^ A pattern synonym in a class instance
+
+-- | GADT constructor declaration (@ _D1 :: { _val :: Int } -> T String @)
+data GadtConDecl a
+  = GadtConDecl { _gadtConNames :: AnnList Name a
+                , _gadtConType :: Ann GadtConType a
+                }
+             
+-- | Type of GADT constructors (can be record types: @{ _val :: Int }@)
+data GadtConType a
+  = GadtNormalType { _gadtConNormalType :: Ann Type a 
+                   }
+  | GadtRecordType { _gadtConRecordFields :: AnnList FieldDecl a
+                   , _gadtConResultType :: Ann Type a
+                   }
+
+data GadtField a
+  = GadtNormalField { _gadtFieldType :: Ann Type a 
+                    } -- ^ Normal GADT field type (@ Int @)
+  | GadtNamedField  { _gadtFieldName :: Ann Name a
+                    , _gadtFieldType :: Ann Type a
+                    } -- ^ Named GADT field (@ { _val :: Int } @)
+         
+-- | A list of functional dependencies: @ | a -> b, c -> d @ separated by commas  
+data FunDeps a
+  = FunDeps { _funDeps :: AnnList FunDep a 
+            } 
+         
+-- | A functional dependency, given on the form @l1 ... ln -> r1 ... rn@         
+data FunDep a
+  = FunDep { _funDepLhs :: AnnList Name a
+           , _funDepRhs :: AnnList Name a
+           }
+  
+data ConDecl a
+  = ConDecl      { _conDeclName :: Ann Name a
+                 , _conDeclArgs :: AnnList Type a
+                 } -- ^ ordinary data constructor (@ C t1 t2 @)
+  | RecordDecl   { _conDeclName :: Ann Name a
+                 , _conDeclFields :: AnnList FieldDecl a
+                 } -- ^ record data constructor (@ C { _n1 :: t1, _n2 :: t2 } @)
+  | InfixConDecl { _conDeclLhs :: Ann Type a
+                 , _conDeclOp :: Ann Operator a
+                 , _conDeclRhs :: Ann Type a
+                 } -- ^ infix data constructor (@ t1 :+: t2 @)
+  
+-- | Field declaration (@ _fld :: Int @)
+data FieldDecl a
+  = FieldDecl { _fieldNames :: AnnList Name a
+              , _fieldType :: Ann Type a
+              }
+  
+-- | A deriving clause following a data type declaration. (@ deriving Show @ or @ deriving (Show, Eq) @)
+data Deriving a
+  = DerivingOne { _oneDerived :: Ann InstanceHead a }
+  | Derivings { _allDerived :: AnnList InstanceHead a }
+  
+-- | The instance declaration rule, which is, roughly, the part of the instance declaration before the where keyword.
+data InstanceRule a
+  = InstanceRule  { _irVars :: AnnMaybe (AnnList TyVar) a
+                  , _irCtx :: AnnMaybe Context a
+                  , _irHead :: Ann InstanceHead a
+                  }
+  | InstanceParen { _irRule :: Ann InstanceRule a 
+                  }
+
+-- | The specification of the class instance declaration
+data InstanceHead a
+  = InstanceHeadCon   { _ihConName :: Ann Name a 
+                      } -- ^ Type or class name
+  | InstanceHeadInfix { _ihLeftOp :: Ann Type a
+                      , _ihOperator :: Ann Name a
+                      } -- ^ Infix application of the type/class name to the left operand
+  | InstanceHeadParen { _ihHead :: Ann InstanceHead a 
+                      } -- ^ Parenthesized instance head
+  | InstanceHeadApp   { _ihFun :: Ann InstanceHead a
+                      , _ihType :: Ann Type a
+                      } -- ^ Application to one more type
+        
+-- | Type equations as found in closed type families (@ T A = S @)
+data TypeEqn a
+  = TypeEqn { _teLhs :: Ann Type a
+            , _teRhs :: Ann Type a
+            }
+
+-- | A pattern type signature (@ pattern p :: Int -> T @)
+data PatternTypeSignature a 
+  = PatternTypeSignature { _patSigName :: Ann Name a
+                         , _patSigType :: Ann Type a
+                         }   
+
+-- | Pattern synonyms: @ pattern Arrow t1 t2 = App "->" [t1, t2] @
+data PatternSynonym a 
+  = PatternSynonym { _patLhs :: Ann PatSynLhs a
+                   , _patRhs :: Ann PatSynRhs a
+                   }
+
+-- | Left hand side of a pattern synonym
+data PatSynLhs a
+  = NormalPatSyn { _patName :: Ann Name a
+                 , _patArgs :: AnnList Name a
+                 }
+  | InfixPatSyn { _patSynLhs :: Ann Name a 
+                , _patSynOp :: Ann Operator a
+                , _patSynRhs :: Ann Name a
+                }
+  | RecordPatSyn { _patName :: Ann Name a
+                 , _patArgs :: AnnList Name a
+                 }
+
+-- | Right-hand side of pattern synonym
+data PatSynRhs a
+  = BidirectionalPatSyn { _patRhsPat :: Ann Pattern a
+                        , _patRhsOpposite :: AnnMaybe PatSynWhere a
+                        } -- ^ @ pattern Int = App "Int" [] @ or @ pattern Int <- App "Int" [] where Int = App "Int" [] @
+  | OneDirectionalPatSyn { _patRhsPat :: Ann Pattern a
+                         } -- ^ @ pattern Int <- App "Int" [] @
+
+-- | Where clause of pattern synonym (explicit expression direction)
+data PatSynWhere a
+  = PatSynWhere { _patOpposite :: AnnList Match a }
+ Language/Haskell/Tools/AST/Exprs.hs view
@@ -0,0 +1,216 @@+-- | Representation of Haskell expressions
+module Language.Haskell.Tools.AST.Exprs where
+
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Stmts
+import {-# SOURCE #-} Language.Haskell.Tools.AST.TH
+import {-# SOURCE #-} Language.Haskell.Tools.AST.Binds (LocalBind, LocalBinds, RhsGuard)
+
+-- | Haskell expressions
+data Expr a
+  = Var            { _exprName :: Ann Name a 
+                   } -- ^ A variable or a data constructor (@ a @)
+  | Lit            { _exprLit :: Ann Literal a
+                   } -- ^ Primitive literal
+  | InfixApp       { _exprLhs :: Ann Expr a
+                   , _exprOperator :: Ann Operator a
+                   , _exprRhs :: Ann Expr a
+                   } -- ^ Infix operator application (@ a + b @)
+  | PrefixApp      { _exprOperator :: Ann Operator a
+                   , _exprRhs :: Ann Expr a
+                   } -- ^ Prefix operator application (@ -x @)
+  | App            { _exprFun :: Ann Expr a
+                   , _exprArg :: Ann Expr a
+                   } -- ^ Function application (@ f 4 @)
+                   -- unary minus omitted
+  | Lambda         { _exprBindings :: AnnList Pattern a -- ^ at least one
+                   , _exprInner :: Ann Expr a
+                   } -- ^ Lambda expression (@ \a b -> a + b @)
+  | Let            { _exprFunBind :: AnnList LocalBind a -- ^ nonempty
+                   , _exprInner :: Ann Expr a
+                   } -- ^ Local binding (@ let x = 2; y = 3 in e x y @)
+  | If             { _exprCond :: Ann Expr a
+                   , _exprThen :: Ann Expr a
+                   , _exprElse :: Ann Expr a
+                   } -- ^ If expression (@ if a then b else c @)
+  | MultiIf        { _exprIfAlts :: AnnList GuardedCaseRhs a 
+                   } -- ^ Multi way if expressions with @MultiWayIf@ extension (@ if | guard1 -> expr1; guard2 -> expr2 @)
+  | Case           { _exprCase :: Ann Expr a
+                   , _exprAlts :: AnnList Alt a
+                   } -- ^ Pattern matching expression (@ case expr of pat1 -> expr1; pat2 -> expr2 @)
+  | Do             { _doKind :: Ann DoKind a
+                   , _exprStmts :: AnnList Stmt a
+                   } -- ^ Do-notation expressions (@ do x <- act1; act2 @)
+  | Tuple          { _tupleElems :: AnnList Expr a
+                   } -- ^ Tuple expression (@ (e1, e2, e3) @)
+  | UnboxedTuple   { _tupleElems :: AnnList Expr a 
+                   } -- ^ Unboxed tuple expression (@ (# e1, e2, e3 #) @)
+  | TupleSection   { _tupleSectionElems :: AnnList TupSecElem a
+                   } -- ^ Tuple section, enabled with @TupleSections@ (@ (a,,b) @). One of the elements must be missing.
+  | UnboxedTupSec  { _tupleSectionElems :: AnnList TupSecElem a 
+                   }
+  | List           { _listElems :: AnnList Expr a 
+                   } -- ^ List expression: @[1,2,3]@
+  | ParArray       { _listElems :: AnnList Expr a 
+                   } -- ^ Parallel array expression: @[: 1,2,3 :]@
+  | Paren          { _exprInner :: Ann Expr a 
+                   }
+  | LeftSection    { _exprLhs :: Ann Expr a
+                   , _exprOperator :: Ann Operator a
+                   } -- ^ Left operator section: @(1+)@
+  | RightSection   { _exprOperator :: Ann Operator a
+                   , _exprRhs :: Ann Expr a
+                   } -- ^ Right operator section: @(+1)@
+  | RecCon         { _exprRecName :: Ann Name a
+                   , _exprRecFields :: AnnList FieldUpdate a
+                   } -- ^ Record value construction: @Point { x = 3, y = -2 }@
+  | RecUpdate      { _exprInner :: Ann Expr a
+                   , _exprRecFields :: AnnList FieldUpdate a
+                   } -- ^ Record value  update: @p1 { x = 3, y = -2 }@
+  | Enum           { _enumFrom :: Ann Expr a
+                   , _enumThen :: AnnMaybe Expr a
+                   , _enumTo :: AnnMaybe Expr a
+                   } -- ^ Enumeration expression (@ [1,3..10] @)
+  | ParArrayEnum   { _enumFrom :: Ann Expr a
+                   , _enumThen :: AnnMaybe Expr a
+                   , _enumToFix :: Ann Expr a
+                   } -- ^ Parallel array enumeration (@ [: 1,3 .. 10 :] @)
+  | ListComp       { _compExpr :: Ann Expr a
+                   , _compBody :: AnnList ListCompBody a -- ^ Can only have 1 element without @ParallelListComp@
+                   } -- ^ List comprehension (@ [ (x, y) | x <- xs | y <- ys ] @)
+  | ParArrayComp   { _compExpr :: Ann Expr a
+                   , _compBody :: AnnList ListCompBody a
+                   } -- ^ Parallel array comprehensions @ [: (x, y) | x <- xs , y <- ys :] @ enabled by @ParallelArrays@
+  | TypeSig        { _exprInner :: Ann Expr a
+                   , _exprSig :: Ann Type a
+                   } -- ^ Explicit type signature (@ _x :: Int @)
+  | ExplTypeApp    { _exprInner :: Ann Expr a
+                   , _exprType :: Ann Type a
+                   } -- ^ Explicit type application (@ show \@Integer (read "5") @)
+  | VarQuote       { _quotedName :: Ann Name a 
+                   } -- ^ @'x@ for template haskell reifying of expressions
+  | TypeQuote      { _quotedName :: Ann Name a 
+                   } -- ^ @''T@ for template haskell reifying of types
+  | BracketExpr    { _bracket :: Ann Bracket a 
+                   } -- ^ Template haskell bracket expression
+  | Splice         { _innerExpr :: Ann Splice a 
+                   } -- ^ Template haskell splice expression, for example: @$(gen a)@ or @$x@
+  | QuasiQuoteExpr { _exprQQ :: Ann QuasiQuote a 
+                   } -- ^ Template haskell quasi-quotation: @[$quoter|str]@
+  | ExprPragma     { _exprPragma :: Ann ExprPragma a
+                   }
+  -- Arrows
+  | Proc           { _procPattern :: Ann Pattern a
+                   , _procExpr :: Ann Cmd a
+                   } -- ^ Arrow definition: @proc a -> f -< a+1@
+  | ArrowApp       { _exprLhs :: Ann Expr a
+                   , _arrowAppl :: Ann ArrowAppl a
+                   , _exprRhs :: Ann Expr a
+                   } -- ^ Arrow application: @f -< a+1@
+  | LamCase        { _exprAlts :: AnnList Alt a
+                   } -- ^ Lambda case ( @\case 0 -> 1; 1 -> 2@ )
+  | StaticPtr      { _exprInner :: Ann Expr a
+                   } -- ^ Static pointer expression (@ static e @). The inner expression must be closed (cannot have variables bound outside)
+  -- XML expressions omitted
+                   
+-- | Field update expressions
+data FieldUpdate a 
+  = NormalFieldUpdate { _fieldName :: Ann Name a
+                      , _fieldValue :: Ann Expr a
+                      } -- ^ Update of a field (@ x = 1 @)
+  | FieldPun          { _fieldUpdateName :: Ann Name a 
+                      } -- ^ Update the field to the value of the same name (@ x @)
+  | FieldWildcard     -- ^ Update the fields of the bounded names to their values (@ .. @). Must be the last update. Cannot be used in a record update expression.
+      
+-- | An element of a tuple section that can be an expression or missing (indicating a value from a parameter)
+data TupSecElem a
+  = Present { _tupSecExpr :: Ann Expr a 
+            } -- ^ An existing element in a tuple section
+  | Missing -- ^ A missing element in a tuple section
+  
+-- | Clause of case expression          
+data Alt' expr a
+  = Alt { _altPattern :: Ann Pattern a
+        , _altRhs :: Ann (CaseRhs' expr) a
+        , _altBinds :: AnnMaybe LocalBinds a
+        }
+type Alt = Alt' Expr
+type CmdAlt = Alt' Cmd
+
+  
+-- | Right hand side of a match (possible with guards): (@ = 3 @ or @ | x == 1 = 3; | otherwise = 4 @)
+data CaseRhs' expr a
+  = UnguardedCaseRhs { _rhsCaseExpr :: Ann expr a 
+                     }
+  | GuardedCaseRhss  { _rhsCaseGuards :: AnnList (GuardedCaseRhs' expr) a 
+                     }
+type CaseRhs = CaseRhs' Expr
+type CmdCaseRhs = CaseRhs' Cmd
+                     
+-- | A guarded right-hand side of pattern matches binding (@ | x > 3 -> 2 @)      
+data GuardedCaseRhs' expr a
+  = GuardedCaseRhs { _caseGuardStmts :: AnnList RhsGuard a -- ^ Cannot be empty.
+                   , _caseGuardExpr :: Ann expr a
+                   } 
+type GuardedCaseRhs = GuardedCaseRhs' Expr
+type CmdGuardedCaseRhs = GuardedCaseRhs' Cmd
+               
+-- | Pragmas that can be applied to expressions
+data ExprPragma a
+  = CorePragma      { _pragmaStr :: Ann StringNode a 
+                    }
+  | SccPragma       { _pragmaStr :: Ann StringNode a 
+                    }
+  | GeneratedPragma { _pragmaSrcRange :: Ann SourceRange a 
+                    }
+
+-- | In-AST source ranges (for generated pragmas)
+data SourceRange a
+  = SourceRange { _srFileName :: Ann StringNode a
+                , _srFromLine :: Ann Number a
+                , _srFromCol :: Ann Number a
+                , _srToLine :: Ann Number a
+                , _srToCol :: Ann Number a
+                }  
+                
+data Number a 
+  = Number { _numberInteger :: Integer 
+           }
+        
+data Cmd a
+  = ArrowAppCmd   { _cmdLhs :: Ann Expr a
+                  , _cmdArrowOp :: Ann ArrowAppl a
+                  , _cmdRhs :: Ann Expr a
+                  }
+  | ArrowFormCmd  { _cmdExpr :: Ann Expr a
+                  , _cmdInnerCmds :: AnnList Cmd a
+                  }
+  | AppCmd        { _cmdInnerCmd :: Ann Cmd a
+                  , _cmdApplied :: Ann Expr a
+                  }
+  | InfixCmd      { _cmdLeftCmd :: Ann Cmd a
+                  , _cmdOperator :: Ann Name a
+                  , _cmdRightCmd :: Ann Cmd a
+                  }
+  | LambdaCmd     { _cmdBindings :: AnnList Pattern a -- ^ at least one
+                  , _cmdInner :: Ann Cmd a
+                  }
+  | ParenCmd      { _cmdInner :: Ann Cmd a
+                  }
+  | CaseCmd       { _cmdExpr :: Ann Expr a 
+                  , _cmdAlts :: AnnList CmdAlt a
+                  }
+  | IfCmd         { _cmdExpr :: Ann Expr a 
+                  , _cmdThen :: Ann Cmd a
+                  , _cmdElse :: Ann Cmd a
+                  }
+  | LetCmd        { _cmdBinds :: AnnList LocalBind a -- ^ nonempty
+                  , _cmdInner :: Ann Cmd a
+                  }
+  | DoCmd         { _cmdStmts :: AnnList (Stmt' Cmd) a
+                  }
+ 
+ Language/Haskell/Tools/AST/Exprs.hs-boot view
@@ -0,0 +1,8 @@+{-# LANGUAGE RoleAnnotations #-}
+module Language.Haskell.Tools.AST.Exprs where
+
+type role Expr nominal
+data Expr a
+
+type role Cmd nominal
+data Cmd a
+ Language/Haskell/Tools/AST/Helpers.hs view
@@ -0,0 +1,172 @@+{-# LANGUAGE FlexibleContexts 
+           , LambdaCase 
+           , RankNTypes 
+           , ScopedTypeVariables 
+           #-}
+
+-- | Helper functions for using the AST.
+module Language.Haskell.Tools.AST.Helpers where
+
+import SrcLoc
+import qualified Name as GHC
+
+import Control.Reference hiding (element)
+import Control.Monad
+import Data.List
+import Data.Maybe
+import Data.Function hiding ((&))
+import Data.Generics.Uniplate.Operations
+
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.References
+
+import Debug.Trace
+
+ordByOccurrence :: SimpleName a -> SimpleName a -> Ordering
+ordByOccurrence = compare `on` nameElements
+
+-- | The occurrence of the name.
+nameString :: SimpleName a -> String
+nameString = intercalate "." . nameElements
+
+-- | The qualifiers and the unqualified name
+nameElements :: SimpleName a -> [String]
+nameElements n = (n ^? qualifiers&annList&element&simpleNameStr) 
+                    ++ [n ^. unqualifiedName&element&simpleNameStr]
+
+-- | The qualifier of the name
+nameQualifier :: SimpleName a -> [String]
+nameQualifier n = n ^? qualifiers&annList&element&simpleNameStr
+         
+-- | Does the import declaration import only the explicitly listed elements?
+importIsExact :: ImportDecl a -> Bool
+importIsExact = isJust . (^? importSpec&annJust&element&importSpecList)  
+  
+-- | Does the import declaration has a 'hiding' clause?
+importIsHiding :: ImportDecl a -> Bool
+importIsHiding = isJust . (^? importSpec&annJust&element&importSpecHiding)
+       
+-- | All elements that are explicitly listed to be imported in the import declaration
+importExacts :: Simple Traversal (ImportDecl a) (IESpec a)
+importExacts = importSpec&annJust&element&importSpecList&annList&element
+
+-- | All elements that are hidden in an import
+importHidings :: Simple Traversal (ImportDecl a) (IESpec a)
+importHidings = importSpec&annJust&element&importSpecList&annList&element
+         
+-- | Possible qualifiers to use imported definitions         
+importQualifiers :: ImportDecl a -> [[String]]
+importQualifiers imp 
+  = (if isAnnNothing (imp ^. importQualified) then [[]] else [])
+      ++ maybe [] (\n -> [nameElements n]) 
+               (imp ^? importAs&annJust&element&importRename&element)
+        
+bindingSemantics :: Simple Traversal (Ann ValueBind (NodeInfo (SemanticInfo n) s)) (SemanticInfo n)
+bindingSemantics = element&(valBindPat&element&patternName&element&simpleName 
+                             &+& funBindMatches&annList&element&matchLhs&element
+                                   &(matchLhsName&element&simpleName &+& matchLhsOperator&element&operatorName))
+                          &semantics
+
+bindingName :: Simple Traversal (Ann ValueBind (NodeInfo (SemanticInfo n) s)) n
+bindingName = bindingSemantics&nameInfo
+                     
+declHeadNames :: Simple Traversal (Ann DeclHead a) (Ann SimpleName a)
+declHeadNames = element & (dhName&element&simpleName &+& dhBody&declHeadNames &+& dhAppFun&declHeadNames &+& dhOperator&element&operatorName)
+
+               
+typeParams :: Simple Traversal (Ann Type a) (Ann Type a)
+typeParams = fromTraversal typeParamsTrav
+  where typeParamsTrav f (Ann a (TyFun p r)) = Ann a <$> (TyFun <$> f p <*> typeParamsTrav f r)
+        typeParamsTrav f (Ann a (TyForall vs t)) = Ann a <$> (TyForall vs <$> typeParamsTrav f t)
+        typeParamsTrav f (Ann a (TyCtx ctx t)) = Ann a <$> (TyCtx ctx <$> typeParamsTrav f t)
+        typeParamsTrav f (Ann a (TyParen t)) = Ann a <$> (TyParen <$> typeParamsTrav f t)
+        typeParamsTrav f t = f t
+        
+
+-- | Access the semantic information of an AST node.
+semantics :: Simple Lens (Ann a (NodeInfo sema src)) sema
+semantics = annotation&semanticInfo
+
+dhNames :: Simple Traversal (Ann DeclHead (NodeInfo (SemanticInfo n) src)) n
+dhNames = declHeadNames & semantics & nameInfo
+
+-- | A type class for transformations that work on both top-level and local definitions
+class BindingElem d where
+  sigBind :: Simple Partial (d a) (Ann TypeSignature a)
+  valBind :: Simple Partial (d a) (Ann ValueBind a)
+  createTypeSig :: Ann TypeSignature a -> d a
+  createBinding :: Ann ValueBind a -> d a
+  isTypeSig :: d a -> Bool
+  isBinding :: d a -> Bool
+  
+instance BindingElem Decl where
+  sigBind = declTypeSig
+  valBind = declValBind
+  createTypeSig = TypeSigDecl
+  createBinding = ValueBinding
+  isTypeSig (TypeSigDecl _) = True
+  isTypeSig _ = False
+  isBinding (ValueBinding _) = True
+  isBinding _ = False
+
+instance BindingElem LocalBind where
+  sigBind = localSig
+  valBind = localVal
+  createTypeSig = LocalSignature
+  createBinding = LocalValBind
+  isTypeSig (LocalSignature _) = True
+  isTypeSig _ = False
+  isBinding (LocalValBind _) = True
+  isBinding _ = False
+
+bindName :: BindingElem d => Simple Traversal (d (NodeInfo (SemanticInfo n) src)) n
+bindName = valBind&bindingName &+& sigBind&element&tsName&annList&element&simpleName&semantics&nameInfo
+
+valBindsInList :: BindingElem d => Simple Traversal (AnnList d a) (Ann ValueBind a)
+valBindsInList = annList & element & valBind
+     
+getValBindInList :: (BindingElem d, HasRange a) => RealSrcSpan -> AnnList d a -> Maybe (Ann ValueBind a)
+getValBindInList sp ls = case ls ^? valBindsInList & filtered (isInside sp) of
+  [] -> Nothing
+  [n] -> Just n
+  _ -> error "getValBindInList: Multiple nodes"
+
+nodesContaining :: forall node inner a . (Biplate (node a) (inner a), HasAnnot node, HasAnnot inner, HasRange a) 
+                => RealSrcSpan -> Simple Traversal (node a) (inner a)
+nodesContaining rng = biplateRef & filtered (isInside rng) 
+              
+isInside :: (HasAnnot node, HasRange a) => RealSrcSpan -> node a -> Bool
+isInside rng nd = case getRange (getAnnot nd) of RealSrcSpan sp -> sp `containsSpan` rng
+                                                 _ -> False
+             
+nodesWithRange :: forall node inner a . (Biplate (node a) (inner a), HasAnnot node, HasAnnot inner, HasRange a) 
+               => RealSrcSpan -> Simple Traversal (node a) (inner a)
+nodesWithRange rng = biplateRef & filtered (hasRange rng) 
+                                         
+hasRange :: (HasAnnot node, HasRange a) => RealSrcSpan -> node a -> Bool
+hasRange rng node = case getRange (getAnnot node) of RealSrcSpan sp -> sp == rng
+                                                     _ -> False
+
+getNodeContaining :: (Biplate (node a) (Ann inner a), HasAnnot node, HasRange a) 
+                  => RealSrcSpan -> node a -> Maybe (Ann inner a)
+getNodeContaining sp node = case node ^? nodesContaining sp of
+  [] -> Nothing
+  results -> Just $ minimumBy (compareRangeLength `on` (getRange . (^. annotation))) results
+
+compareRangeLength :: SrcSpan -> SrcSpan -> Ordering
+compareRangeLength (RealSrcSpan sp1) (RealSrcSpan sp2)
+  = (lineDiff sp1 `compare` lineDiff sp2) `mappend` (colDiff sp1 `compare` colDiff sp2)
+  where lineDiff sp = srcLocLine (realSrcSpanStart sp) - srcLocLine (realSrcSpanEnd sp)
+        colDiff sp = srcLocCol (realSrcSpanStart sp) - srcLocCol (realSrcSpanEnd sp)
+
+getNode :: (Biplate (node a) (inner a), HasAnnot node, HasAnnot inner, HasRange a) 
+        => RealSrcSpan -> node a -> inner a
+getNode sp node = case node ^? nodesWithRange sp of
+  [] -> error "getNode: The node cannot be found"
+  [n] -> n
+  _ -> error "getNode: Multiple nodes"
+ Language/Haskell/Tools/AST/Instances.hs view
@@ -0,0 +1,8 @@+-- | All derived instances for AST elements
+module Language.Haskell.Tools.AST.Instances where
+
+import Language.Haskell.Tools.AST.Instances.Data
+import Language.Haskell.Tools.AST.Instances.Eq
+import Language.Haskell.Tools.AST.Instances.Show
+import Language.Haskell.Tools.AST.Instances.Generic
+import Language.Haskell.Tools.AST.Instances.StructuralTraversal
+ Language/Haskell/Tools/AST/Instances/Data.hs view
@@ -0,0 +1,133 @@+-- | Data instances for Haskell AST (used for generics)
+{-# LANGUAGE FlexibleContexts, StandaloneDeriving, DeriveDataTypeable #-}
+module Language.Haskell.Tools.AST.Instances.Data where
+
+import Data.Data
+
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.TH
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Stmts
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+
+-- Annotations
+deriving instance (Typeable a, Data a, Typeable e, Data (e a)) => Data (Ann e a)
+deriving instance (Typeable a, Data a, Typeable e, Data (e a)) => Data (AnnMaybe e a)
+deriving instance (Typeable a, Data a, Typeable e, Data (e a)) => Data (AnnList e a)
+
+-- Modules
+deriving instance Data a => Data (Module a)
+deriving instance Data a => Data (ModuleHead a)
+deriving instance Data a => Data (ExportSpecList a)
+deriving instance Data a => Data (ExportSpec a)
+deriving instance Data a => Data (IESpec a)
+deriving instance Data a => Data (SubSpec a)
+deriving instance Data a => Data (ModulePragma a)
+deriving instance Data a => Data (FilePragma a)
+deriving instance Data a => Data (ImportDecl a)
+deriving instance Data a => Data (ImportSpec a)
+deriving instance Data a => Data (ImportQualified a)
+deriving instance Data a => Data (ImportSource a)
+deriving instance Data a => Data (ImportSafe a)
+deriving instance Data a => Data (TypeNamespace a)
+deriving instance Data a => Data (ImportRenaming a)
+
+-- Declarations
+deriving instance Data a => Data (Decl a)
+deriving instance Data a => Data (ClassBody a)
+deriving instance Data a => Data (ClassElement a)
+deriving instance Data a => Data (DeclHead a)
+deriving instance Data a => Data (InstBody a)
+deriving instance Data a => Data (InstBodyDecl a)
+deriving instance Data a => Data (GadtConDecl a)
+deriving instance Data a => Data (GadtConType a)
+deriving instance Data a => Data (GadtField a)
+deriving instance Data a => Data (FunDeps a)
+deriving instance Data a => Data (FunDep a)
+deriving instance Data a => Data (ConDecl a)
+deriving instance Data a => Data (FieldDecl a)
+deriving instance Data a => Data (Deriving a)
+deriving instance Data a => Data (InstanceRule a)
+deriving instance Data a => Data (InstanceHead a)
+deriving instance Data a => Data (TypeEqn a)
+deriving instance Data a => Data (KindConstraint a)
+deriving instance Data a => Data (TyVar a)
+deriving instance Data a => Data (Type a)
+deriving instance Data a => Data (Kind a)
+deriving instance Data a => Data (Context a)
+deriving instance Data a => Data (Assertion a)
+deriving instance Data a => Data (Expr a)
+deriving instance (Data a, Typeable expr, Data (expr a)) => Data (Stmt' expr a)
+deriving instance Data a => Data (CompStmt a)
+deriving instance Data a => Data (ValueBind a)
+deriving instance Data a => Data (Pattern a)
+deriving instance Data a => Data (PatternField a)
+deriving instance Data a => Data (Splice a)
+deriving instance Data a => Data (QQString a)
+deriving instance Data a => Data (Match a)
+deriving instance (Data a, Typeable expr, Data (expr a)) => Data (Alt' expr a)
+deriving instance Data a => Data (Rhs a)
+deriving instance Data a => Data (GuardedRhs a)
+deriving instance Data a => Data (FieldUpdate a)
+deriving instance Data a => Data (Bracket a)
+deriving instance Data a => Data (TopLevelPragma a)
+deriving instance Data a => Data (Rule a)
+deriving instance Data a => Data (AnnotationSubject a)
+deriving instance Data a => Data (MinimalFormula a)
+deriving instance Data a => Data (ExprPragma a)
+deriving instance Data a => Data (SourceRange a)
+deriving instance Data a => Data (Number a)
+deriving instance Data a => Data (QuasiQuote a)
+deriving instance Data a => Data (RhsGuard a)
+deriving instance Data a => Data (LocalBind a)
+deriving instance Data a => Data (LocalBinds a)
+deriving instance Data a => Data (FixitySignature a)
+deriving instance Data a => Data (TypeSignature a)
+deriving instance Data a => Data (ListCompBody a)
+deriving instance Data a => Data (TupSecElem a)
+deriving instance Data a => Data (TypeFamily a)
+deriving instance Data a => Data (TypeFamilySpec a)
+deriving instance Data a => Data (InjectivityAnn a)
+deriving instance (Data a, Typeable expr, Data (expr a)) => Data (CaseRhs' expr a)
+deriving instance (Data a, Typeable expr, Data (expr a))=> Data (GuardedCaseRhs' expr a)
+deriving instance Data a => Data (PatternSynonym a)
+deriving instance Data a => Data (PatSynRhs a)
+deriving instance Data a => Data (PatSynLhs a)
+deriving instance Data a => Data (PatSynWhere a)
+deriving instance Data a => Data (PatternTypeSignature a)
+deriving instance Data a => Data (Role a)
+deriving instance Data a => Data (Cmd a)
+deriving instance Data a => Data (LanguageExtension a)
+deriving instance Data a => Data (MatchLhs a)
+
+-- Literal
+deriving instance Data a => Data (Literal a)
+deriving instance (Data a, Typeable k, Data (k a)) => Data (Promoted k a)
+
+-- Base
+deriving instance Data a => Data (Operator a)
+deriving instance Data a => Data (Name a)
+deriving instance Data a => Data (SimpleName a)
+deriving instance Data a => Data (UnqualName a)
+deriving instance Data a => Data (StringNode a)
+deriving instance Data a => Data (DataOrNewtypeKeyword a)
+deriving instance Data a => Data (DoKind a)
+deriving instance Data a => Data (TypeKeyword a)
+deriving instance Data a => Data (OverlapPragma a)
+deriving instance Data a => Data (CallConv a)
+deriving instance Data a => Data (ArrowAppl a)
+deriving instance Data a => Data (Safety a)
+deriving instance Data a => Data (ConlikeAnnot a)
+deriving instance Data a => Data (Assoc a)
+deriving instance Data a => Data (Precedence a)
+deriving instance Data a => Data (LineNumber a)
+deriving instance Data a => Data (PhaseControl a)
+deriving instance Data a => Data (PhaseNumber a)
+deriving instance Data a => Data (PhaseInvert a)
+ Language/Haskell/Tools/AST/Instances/Eq.hs view
@@ -0,0 +1,136 @@+-- | Equality check of AST nodes that ignore the source and semantic information.
+{-# LANGUAGE FlexibleContexts, StandaloneDeriving #-}
+module Language.Haskell.Tools.AST.Instances.Eq where
+
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.TH
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Stmts
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+
+-- Annotations
+instance (Eq (e a)) => Eq (Ann e a) where
+  Ann _ e1 == Ann _ e2 = e1 == e2
+
+instance (Eq (e a)) => Eq (AnnMaybe e a) where
+  AnnMaybe _ e1 == AnnMaybe _ e2 = e1 == e2
+
+instance (Eq (e a)) => Eq (AnnList e a) where
+  AnnList _ e1 == AnnList _ e2 = e1 == e2
+
+-- Modules
+deriving instance Eq (Module a)
+deriving instance Eq (ModuleHead a)
+deriving instance Eq (ExportSpecList a)
+deriving instance Eq (ExportSpec a)
+deriving instance Eq (IESpec a)
+deriving instance Eq (SubSpec a)
+deriving instance Eq (ModulePragma a)
+deriving instance Eq (FilePragma a)
+deriving instance Eq (ImportDecl a)
+deriving instance Eq (ImportSpec a)
+deriving instance Eq (ImportQualified a)
+deriving instance Eq (ImportSource a)
+deriving instance Eq (ImportSafe a)
+deriving instance Eq (TypeNamespace a)
+deriving instance Eq (ImportRenaming a)
+
+-- Declarations
+deriving instance Eq (Decl a)
+deriving instance Eq (ClassBody a)
+deriving instance Eq (ClassElement a)
+deriving instance Eq (DeclHead a)
+deriving instance Eq (InstBody a)
+deriving instance Eq (InstBodyDecl a)
+deriving instance Eq (GadtConDecl a)
+deriving instance Eq (GadtConType a)
+deriving instance Eq (GadtField a)
+deriving instance Eq (FunDeps a)
+deriving instance Eq (FunDep a)
+deriving instance Eq (ConDecl a)
+deriving instance Eq (FieldDecl a)
+deriving instance Eq (Deriving a)
+deriving instance Eq (InstanceRule a)
+deriving instance Eq (InstanceHead a)
+deriving instance Eq (TypeEqn a)
+deriving instance Eq (KindConstraint a)
+deriving instance Eq (TyVar a)
+deriving instance Eq (Type a)
+deriving instance Eq (Kind a)
+deriving instance Eq (Context a)
+deriving instance Eq (Assertion a)
+deriving instance Eq (Expr a)
+deriving instance Eq (expr a) => Eq (Stmt' expr a)
+deriving instance Eq (CompStmt a)
+deriving instance Eq (ValueBind a)
+deriving instance Eq (Pattern a)
+deriving instance Eq (PatternField a)
+deriving instance Eq (Splice a)
+deriving instance Eq (QQString a)
+deriving instance Eq (Match a)
+deriving instance Eq (expr a) => Eq (Alt' expr a)
+deriving instance Eq (Rhs a)
+deriving instance Eq (GuardedRhs a)
+deriving instance Eq (FieldUpdate a)
+deriving instance Eq (Bracket a)
+deriving instance Eq (TopLevelPragma a)
+deriving instance Eq (Rule a)
+deriving instance Eq (AnnotationSubject a)
+deriving instance Eq (MinimalFormula a)
+deriving instance Eq (ExprPragma a)
+deriving instance Eq (SourceRange a)
+deriving instance Eq (Number a)
+deriving instance Eq (QuasiQuote a)
+deriving instance Eq (RhsGuard a)
+deriving instance Eq (LocalBind a)
+deriving instance Eq (LocalBinds a)
+deriving instance Eq (FixitySignature a)
+deriving instance Eq (TypeSignature a)
+deriving instance Eq (ListCompBody a)
+deriving instance Eq (TupSecElem a)
+deriving instance Eq (TypeFamily a)
+deriving instance Eq (TypeFamilySpec a)
+deriving instance Eq (InjectivityAnn a)
+deriving instance Eq (expr a) => Eq (CaseRhs' expr a)
+deriving instance Eq (expr a) => Eq (GuardedCaseRhs' expr a)
+deriving instance Eq (PatternSynonym a)
+deriving instance Eq (PatSynRhs a)
+deriving instance Eq (PatSynLhs a)
+deriving instance Eq (PatSynWhere a)
+deriving instance Eq (PatternTypeSignature a)
+deriving instance Eq (Role a)
+deriving instance Eq (Cmd a)
+deriving instance Eq (LanguageExtension a)
+deriving instance Eq (MatchLhs a)
+
+-- Literal
+deriving instance Eq (Literal a)
+deriving instance Eq (k a) => Eq (Promoted k a)
+
+-- Base
+deriving instance Eq (Operator a)
+deriving instance Eq (Name a)
+deriving instance Eq (SimpleName a)
+deriving instance Eq (UnqualName a)
+deriving instance Eq (StringNode a)
+deriving instance Eq (DataOrNewtypeKeyword a)
+deriving instance Eq (DoKind a)
+deriving instance Eq (TypeKeyword a)
+deriving instance Eq (OverlapPragma a)
+deriving instance Eq (CallConv a)
+deriving instance Eq (ArrowAppl a)
+deriving instance Eq (Safety a)
+deriving instance Eq (ConlikeAnnot a)
+deriving instance Eq (Assoc a)
+deriving instance Eq (Precedence a)
+deriving instance Eq (LineNumber a)
+deriving instance Eq (PhaseControl a)
+deriving instance Eq (PhaseNumber a)
+deriving instance Eq (PhaseInvert a)
+ Language/Haskell/Tools/AST/Instances/Generic.hs view
@@ -0,0 +1,134 @@+-- | Generic instance for Haskell AST representation
+{-# LANGUAGE FlexibleContexts, StandaloneDeriving, DeriveGeneric #-}
+module Language.Haskell.Tools.AST.Instances.Generic where
+
+import GHC.Generics
+
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.TH
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Stmts
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+
+-- Annotations
+deriving instance (Generic a, Generic (e a)) => Generic (Ann e a)
+deriving instance (Generic a, Generic (e a)) => Generic (AnnMaybe e a)
+deriving instance (Generic a, Generic (e a)) => Generic (AnnList e a)
+
+-- Modules
+deriving instance Generic a => Generic (Module a)
+deriving instance Generic a => Generic (ModuleHead a)
+deriving instance Generic a => Generic (ExportSpecList a)
+deriving instance Generic a => Generic (ExportSpec a)
+deriving instance Generic a => Generic (IESpec a)
+deriving instance Generic a => Generic (SubSpec a)
+deriving instance Generic a => Generic (ModulePragma a)
+deriving instance Generic a => Generic (FilePragma a)
+deriving instance Generic a => Generic (ImportDecl a)
+deriving instance Generic a => Generic (ImportSpec a)
+deriving instance Generic a => Generic (ImportQualified a)
+deriving instance Generic a => Generic (ImportSource a)
+deriving instance Generic a => Generic (ImportSafe a)
+deriving instance Generic a => Generic (TypeNamespace a)
+deriving instance Generic a => Generic (ImportRenaming a)
+
+-- Declarations
+deriving instance Generic a => Generic (Decl a)
+deriving instance Generic a => Generic (ClassBody a)
+deriving instance Generic a => Generic (ClassElement a)
+deriving instance Generic a => Generic (DeclHead a)
+deriving instance Generic a => Generic (InstBody a)
+deriving instance Generic a => Generic (InstBodyDecl a)
+deriving instance Generic a => Generic (GadtConDecl a)
+deriving instance Generic a => Generic (GadtConType a)
+deriving instance Generic a => Generic (GadtField a)
+deriving instance Generic a => Generic (FunDeps a)
+deriving instance Generic a => Generic (FunDep a)
+deriving instance Generic a => Generic (ConDecl a)
+deriving instance Generic a => Generic (FieldDecl a)
+deriving instance Generic a => Generic (Deriving a)
+deriving instance Generic a => Generic (InstanceRule a)
+deriving instance Generic a => Generic (InstanceHead a)
+deriving instance Generic a => Generic (TypeEqn a)
+deriving instance Generic a => Generic (KindConstraint a)
+deriving instance Generic a => Generic (TyVar a)
+deriving instance Generic a => Generic (Type a)
+deriving instance Generic a => Generic (Kind a)
+deriving instance Generic a => Generic (Context a)
+deriving instance Generic a => Generic (Assertion a)
+deriving instance Generic a => Generic (Expr a)
+deriving instance (Generic a, Generic (expr a)) => Generic (Stmt' expr a)
+deriving instance Generic a => Generic (CompStmt a)
+deriving instance Generic a => Generic (ValueBind a)
+deriving instance Generic a => Generic (Pattern a)
+deriving instance Generic a => Generic (PatternField a)
+deriving instance Generic a => Generic (Splice a)
+deriving instance Generic a => Generic (QQString a)
+deriving instance Generic a => Generic (Match a)
+deriving instance (Generic a, Generic (expr a)) => Generic (Alt' expr a)
+deriving instance Generic a => Generic (Rhs a)
+deriving instance Generic a => Generic (GuardedRhs a)
+deriving instance Generic a => Generic (FieldUpdate a)
+deriving instance Generic a => Generic (Bracket a)
+deriving instance Generic a => Generic (TopLevelPragma a)
+deriving instance Generic a => Generic (Rule a)
+deriving instance Generic a => Generic (AnnotationSubject a)
+deriving instance Generic a => Generic (MinimalFormula a)
+deriving instance Generic a => Generic (ExprPragma a)
+deriving instance Generic a => Generic (SourceRange a)
+deriving instance Generic a => Generic (Number a)
+deriving instance Generic a => Generic (QuasiQuote a)
+deriving instance Generic a => Generic (RhsGuard a)
+deriving instance Generic a => Generic (LocalBind a)
+deriving instance Generic a => Generic (LocalBinds a)
+deriving instance Generic a => Generic (FixitySignature a)
+deriving instance Generic a => Generic (TypeSignature a)
+deriving instance Generic a => Generic (ListCompBody a)
+deriving instance Generic a => Generic (TupSecElem a)
+deriving instance Generic a => Generic (TypeFamily a)
+deriving instance Generic a => Generic (TypeFamilySpec a)
+deriving instance Generic a => Generic (InjectivityAnn a)
+deriving instance (Generic a, Generic (expr a)) => Generic (CaseRhs' expr a)
+deriving instance (Generic a, Generic (expr a)) => Generic (GuardedCaseRhs' expr a)
+deriving instance Generic a => Generic (PatternSynonym a)
+deriving instance Generic a => Generic (PatSynRhs a)
+deriving instance Generic a => Generic (PatSynLhs a)
+deriving instance Generic a => Generic (PatSynWhere a)
+deriving instance Generic a => Generic (PatternTypeSignature a)
+deriving instance Generic a => Generic (Role a)
+deriving instance Generic a => Generic (Cmd a)
+deriving instance Generic a => Generic (LanguageExtension a)
+deriving instance Generic a => Generic (MatchLhs a)
+
+
+-- Literal
+deriving instance Generic a => Generic (Literal a)
+deriving instance (Generic a, Generic (k a)) => Generic (Promoted k a)
+
+-- Base
+deriving instance Generic a => Generic (Operator a)
+deriving instance Generic a => Generic (Name a)
+deriving instance Generic a => Generic (SimpleName a)
+deriving instance Generic a => Generic (UnqualName a)
+deriving instance Generic a => Generic (StringNode a)
+deriving instance Generic a => Generic (DataOrNewtypeKeyword a)
+deriving instance Generic a => Generic (DoKind a)
+deriving instance Generic a => Generic (TypeKeyword a)
+deriving instance Generic a => Generic (OverlapPragma a)
+deriving instance Generic a => Generic (CallConv a)
+deriving instance Generic a => Generic (ArrowAppl a)
+deriving instance Generic a => Generic (Safety a)
+deriving instance Generic a => Generic (ConlikeAnnot a)
+deriving instance Generic a => Generic (Assoc a)
+deriving instance Generic a => Generic (Precedence a)
+deriving instance Generic a => Generic (LineNumber a)
+deriving instance Generic a => Generic (PhaseControl a)
+deriving instance Generic a => Generic (PhaseNumber a)
+deriving instance Generic a => Generic (PhaseInvert a)
+ Language/Haskell/Tools/AST/Instances/Show.hs view
@@ -0,0 +1,137 @@+-- | Show instance for Haskell AST representation ignoring source and semantic information
+{-# LANGUAGE FlexibleContexts, StandaloneDeriving #-}
+module Language.Haskell.Tools.AST.Instances.Show where
+
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.TH
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Stmts
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+
+-- Annotations
+instance (Show (e a)) => Show (Ann e a) where
+  show (Ann _ e) = show e
+
+instance (Show (e a)) => Show (AnnMaybe e a) where
+  show (AnnMaybe _ e) = show e
+  
+instance (Show (e a)) => Show (AnnList e a) where
+  show (AnnList _ e) = show e
+
+-- Modules
+deriving instance Show (Module a)
+deriving instance Show (ModuleHead a)
+deriving instance Show (ExportSpecList a)
+deriving instance Show (ExportSpec a)
+deriving instance Show (IESpec a)
+deriving instance Show (SubSpec a)
+deriving instance Show (ModulePragma a)
+deriving instance Show (FilePragma a)
+deriving instance Show (ImportDecl a)
+deriving instance Show (ImportSpec a)
+deriving instance Show (ImportQualified a)
+deriving instance Show (ImportSource a)
+deriving instance Show (ImportSafe a)
+deriving instance Show (TypeNamespace a)
+deriving instance Show (ImportRenaming a)
+
+-- Declarations
+deriving instance Show (Decl a)
+deriving instance Show (ClassBody a)
+deriving instance Show (ClassElement a)
+deriving instance Show (DeclHead a)
+deriving instance Show (InstBody a)
+deriving instance Show (InstBodyDecl a)
+deriving instance Show (GadtConDecl a)
+deriving instance Show (GadtConType a)
+deriving instance Show (GadtField a)
+deriving instance Show (FunDeps a)
+deriving instance Show (FunDep a)
+deriving instance Show (ConDecl a)
+deriving instance Show (FieldDecl a)
+deriving instance Show (Deriving a)
+deriving instance Show (InstanceRule a)
+deriving instance Show (InstanceHead a)
+deriving instance Show (TypeEqn a)
+deriving instance Show (KindConstraint a)
+deriving instance Show (TyVar a)
+deriving instance Show (Type a)
+deriving instance Show (Kind a)
+deriving instance Show (Context a)
+deriving instance Show (Assertion a)
+deriving instance Show (Expr a)
+deriving instance Show (expr a) => Show (Stmt' expr a)
+deriving instance Show (CompStmt a)
+deriving instance Show (ValueBind a)
+deriving instance Show (Pattern a)
+deriving instance Show (PatternField a)
+deriving instance Show (Splice a)
+deriving instance Show (QQString a)
+deriving instance Show (Match a)
+deriving instance Show (expr a) => Show (Alt' expr a)
+deriving instance Show (Rhs a)
+deriving instance Show (GuardedRhs a)
+deriving instance Show (FieldUpdate a)
+deriving instance Show (Bracket a)
+deriving instance Show (TopLevelPragma a)
+deriving instance Show (Rule a)
+deriving instance Show (AnnotationSubject a)
+deriving instance Show (MinimalFormula a)
+deriving instance Show (ExprPragma a)
+deriving instance Show (SourceRange a)
+deriving instance Show (Number a)
+deriving instance Show (QuasiQuote a)
+deriving instance Show (RhsGuard a)
+deriving instance Show (LocalBind a)
+deriving instance Show (LocalBinds a)
+deriving instance Show (FixitySignature a)
+deriving instance Show (TypeSignature a)
+deriving instance Show (ListCompBody a)
+deriving instance Show (TupSecElem a)
+deriving instance Show (TypeFamily a)
+deriving instance Show (TypeFamilySpec a)
+deriving instance Show (InjectivityAnn a)
+deriving instance Show (expr a) => Show (CaseRhs' expr a)
+deriving instance Show (expr a) => Show (GuardedCaseRhs' expr a)
+deriving instance Show (PatternSynonym a)
+deriving instance Show (PatSynRhs a)
+deriving instance Show (PatSynLhs a)
+deriving instance Show (PatSynWhere a)
+deriving instance Show (PatternTypeSignature a)
+deriving instance Show (Role a)
+deriving instance Show (Cmd a)
+deriving instance Show (LanguageExtension a)
+deriving instance Show (MatchLhs a)
+
+
+-- Literal
+deriving instance Show (Literal a)
+deriving instance Show (k a) => Show (Promoted k a)
+
+-- Base
+deriving instance Show (Operator a)
+deriving instance Show (Name a)
+deriving instance Show (SimpleName a)
+deriving instance Show (UnqualName a)
+deriving instance Show (StringNode a)
+deriving instance Show (DataOrNewtypeKeyword a)
+deriving instance Show (DoKind a)
+deriving instance Show (TypeKeyword a)
+deriving instance Show (OverlapPragma a)
+deriving instance Show (CallConv a)
+deriving instance Show (ArrowAppl a)
+deriving instance Show (Safety a)
+deriving instance Show (ConlikeAnnot a)
+deriving instance Show (Assoc a)
+deriving instance Show (Precedence a)
+deriving instance Show (LineNumber a)
+deriving instance Show (PhaseControl a)
+deriving instance Show (PhaseNumber a)
+deriving instance Show (PhaseInvert a)
+ Language/Haskell/Tools/AST/Instances/StructuralTraversal.hs view
@@ -0,0 +1,183 @@+-- | Generating StructuralTraversal instances for Haskell Representation
+{-# LANGUAGE FlexibleContexts, TemplateHaskell #-}
+module Language.Haskell.Tools.AST.Instances.StructuralTraversal where
+
+import Control.Applicative
+import Data.StructuralTraversal
+
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.TH
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Stmts
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+
+-- Annotations
+instance StructuralTraversable elem => StructuralTraversable (Ann elem) where
+  traverseUp desc asc f (Ann ann e) = flip Ann <$> (desc *> traverseUp desc asc f e <* asc) <*> f ann
+  traverseDown desc asc f (Ann ann e) = Ann <$> f ann <*> (desc *> traverseDown desc asc f e <* asc)
+  
+instance StructuralTraversable elem => StructuralTraversable (AnnMaybe elem) where
+  traverseUp desc asc f (AnnMaybe a (Just annotated)) 
+    = flip AnnMaybe <$> (Just <$> (desc *> traverseUp desc asc f annotated <* asc)) <*> f a
+  traverseUp desc asc f (AnnMaybe a Nothing) = AnnMaybe <$> f a <*> pure Nothing
+  
+  traverseDown desc asc f (AnnMaybe a (Just annotated)) 
+    = AnnMaybe <$> f a <*> (Just <$> (desc *> traverseDown desc asc f annotated <* asc))
+  traverseDown desc asc f (AnnMaybe a Nothing) = AnnMaybe <$> f a <*> pure Nothing
+
+instance StructuralTraversable elem => StructuralTraversable (AnnList elem) where
+  traverseUp desc asc f (AnnList a ls) 
+    = flip AnnList <$> sequenceA (map (\e -> desc *> traverseUp desc asc f e <* asc) ls) <*> f a
+  traverseDown desc asc f (AnnList a ls) 
+    = AnnList <$> f a <*> sequenceA (map (\e -> desc *> traverseDown desc asc f e <* asc) ls)
+
+-- Modules
+deriveStructTrav ''Module
+deriveStructTrav ''ModuleHead
+deriveStructTrav ''ExportSpecList
+deriveStructTrav ''ExportSpec
+deriveStructTrav ''IESpec
+deriveStructTrav ''SubSpec
+deriveStructTrav ''ModulePragma
+deriveStructTrav ''FilePragma
+deriveStructTrav ''ImportDecl
+deriveStructTrav ''ImportSpec
+deriveStructTrav ''ImportQualified
+deriveStructTrav ''ImportSource
+deriveStructTrav ''ImportSafe
+deriveStructTrav ''TypeNamespace
+deriveStructTrav ''ImportRenaming
+
+-- Declarations
+deriveStructTrav ''Decl
+deriveStructTrav ''ClassBody
+deriveStructTrav ''ClassElement
+deriveStructTrav ''DeclHead
+deriveStructTrav ''InstBody
+deriveStructTrav ''InstBodyDecl
+deriveStructTrav ''GadtConDecl
+deriveStructTrav ''GadtConType
+deriveStructTrav ''GadtField
+deriveStructTrav ''FunDeps
+deriveStructTrav ''FunDep
+deriveStructTrav ''ConDecl
+deriveStructTrav ''FieldDecl
+deriveStructTrav ''Deriving
+deriveStructTrav ''InstanceRule
+deriveStructTrav ''InstanceHead
+deriveStructTrav ''TypeEqn
+deriveStructTrav ''KindConstraint
+deriveStructTrav ''TyVar
+deriveStructTrav ''Type
+deriveStructTrav ''Kind
+deriveStructTrav ''Context
+deriveStructTrav ''Assertion
+deriveStructTrav ''Expr
+deriveStructTrav ''CompStmt
+deriveStructTrav ''ValueBind
+deriveStructTrav ''Pattern
+deriveStructTrav ''PatternField
+deriveStructTrav ''Splice
+deriveStructTrav ''QQString
+deriveStructTrav ''Match
+deriveStructTrav ''Rhs
+deriveStructTrav ''GuardedRhs
+deriveStructTrav ''FieldUpdate
+deriveStructTrav ''Bracket
+deriveStructTrav ''TopLevelPragma
+deriveStructTrav ''Rule
+deriveStructTrav ''AnnotationSubject
+deriveStructTrav ''MinimalFormula
+deriveStructTrav ''ExprPragma
+deriveStructTrav ''SourceRange
+deriveStructTrav ''Number
+deriveStructTrav ''QuasiQuote
+deriveStructTrav ''RhsGuard
+deriveStructTrav ''LocalBind
+deriveStructTrav ''LocalBinds
+deriveStructTrav ''FixitySignature
+deriveStructTrav ''TypeSignature
+deriveStructTrav ''ListCompBody
+deriveStructTrav ''TupSecElem
+deriveStructTrav ''TypeFamily
+deriveStructTrav ''TypeFamilySpec
+deriveStructTrav ''InjectivityAnn
+deriveStructTrav ''PatternSynonym
+deriveStructTrav ''PatSynRhs
+deriveStructTrav ''PatSynLhs
+deriveStructTrav ''PatSynWhere
+deriveStructTrav ''PatternTypeSignature
+deriveStructTrav ''Role
+deriveStructTrav ''Cmd
+deriveStructTrav ''LanguageExtension
+deriveStructTrav ''MatchLhs
+
+
+-- FIXME: structural traversal deriving does not respect the instance requirements for type like Ann expr a
+instance StructuralTraversable expr => StructuralTraversable (Stmt' expr) where
+  traverseUp desc asc f (BindStmt p e) = BindStmt <$> traverseUp desc asc f p <*> traverseUp desc asc f e
+  traverseUp desc asc f (ExprStmt e) = ExprStmt <$> traverseUp desc asc f e
+  traverseUp desc asc f (LetStmt bs) = LetStmt <$> traverseUp desc asc f bs
+  traverseUp desc asc f (RecStmt stmts) = RecStmt <$> traverseUp desc asc f stmts
+  traverseDown desc asc f (BindStmt p e) = BindStmt <$> traverseDown desc asc f p <*> traverseDown desc asc f e
+  traverseDown desc asc f (ExprStmt e) = ExprStmt <$> traverseDown desc asc f e
+  traverseDown desc asc f (LetStmt bs) = LetStmt <$> traverseDown desc asc f bs
+  traverseDown desc asc f (RecStmt stmts) = RecStmt <$> traverseDown desc asc f stmts
+
+instance StructuralTraversable expr => StructuralTraversable (Alt' expr) where
+  traverseUp desc asc f (Alt p r b) = Alt <$> traverseUp desc asc f p <*> traverseUp desc asc f r <*> traverseUp desc asc f b
+  traverseDown desc asc f (Alt p r b) = Alt <$> traverseDown desc asc f p <*> traverseDown desc asc f r <*> traverseDown desc asc f b
+
+-- FIXME: structural traversal deriving does not respect the instance requirements for type like Ann expr a
+instance StructuralTraversable expr => StructuralTraversable (CaseRhs' expr) where
+  traverseUp desc asc f (UnguardedCaseRhs e) = UnguardedCaseRhs <$> traverseUp desc asc f e
+  traverseUp desc asc f (GuardedCaseRhss g) = GuardedCaseRhss <$> traverseUp desc asc f g
+  traverseDown desc asc f (UnguardedCaseRhs e) = UnguardedCaseRhs <$> traverseDown desc asc f e
+  traverseDown desc asc f (GuardedCaseRhss g) = GuardedCaseRhss <$> traverseDown desc asc f g
+
+instance StructuralTraversable expr => StructuralTraversable (GuardedCaseRhs' expr) where
+  traverseUp desc asc f (GuardedCaseRhs g e) = GuardedCaseRhs <$> traverseUp desc asc f g <*> traverseUp desc asc f e
+  traverseDown desc asc f (GuardedCaseRhs g e) = GuardedCaseRhs <$> traverseDown desc asc f g <*> traverseDown desc asc f e
+
+-- Literal
+deriveStructTrav ''Literal
+
+instance StructuralTraversable k => StructuralTraversable (Promoted k) where
+  traverseUp desc asc f (PromotedInt i) = pure $ PromotedInt i
+  traverseUp desc asc f (PromotedString str) = pure $ PromotedString str
+  traverseUp desc asc f (PromotedCon name) = PromotedCon <$> traverseUp desc asc f name
+  traverseUp desc asc f (PromotedList elems) = PromotedList <$> traverseUp desc asc f elems
+  traverseUp desc asc f (PromotedTuple elems) = PromotedTuple <$> traverseUp desc asc f elems
+  traverseDown desc asc f (PromotedInt i) = pure $ PromotedInt i
+  traverseDown desc asc f (PromotedString str) = pure $ PromotedString str
+  traverseDown desc asc f (PromotedCon name) = PromotedCon <$> traverseDown desc asc f name
+  traverseDown desc asc f (PromotedList elems) = PromotedList <$> traverseDown desc asc f elems
+  traverseDown desc asc f (PromotedTuple elems) = PromotedTuple <$> traverseDown desc asc f elems
+
+-- Base
+deriveStructTrav ''Operator
+deriveStructTrav ''Name
+deriveStructTrav ''SimpleName
+deriveStructTrav ''UnqualName
+deriveStructTrav ''StringNode
+deriveStructTrav ''DataOrNewtypeKeyword
+deriveStructTrav ''DoKind
+deriveStructTrav ''TypeKeyword
+deriveStructTrav ''OverlapPragma
+deriveStructTrav ''CallConv
+deriveStructTrav ''ArrowAppl
+deriveStructTrav ''Safety
+deriveStructTrav ''ConlikeAnnot
+deriveStructTrav ''Assoc
+deriveStructTrav ''Precedence
+deriveStructTrav ''LineNumber
+deriveStructTrav ''PhaseControl
+deriveStructTrav ''PhaseNumber
+deriveStructTrav ''PhaseInvert
+ Language/Haskell/Tools/AST/Kinds.hs view
@@ -0,0 +1,38 @@+-- | Representation of Haskell Kinds
+module Language.Haskell.Tools.AST.Kinds where
+
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Base
+
+-- | Kind constraint (@ :: * -> * @)
+data KindConstraint a 
+  = KindConstraint { _kindConstr :: Ann Kind a 
+                   }
+                 
+-- | Haskell kinds
+data Kind a
+  = KindStar  -- ^ @*@, the kind of types
+  | KindUnbox -- ^ @#@, the kind of unboxed types
+  | KindFn       { _kindLeft :: Ann Kind a
+                 , _kindRight :: Ann Kind a
+                 } -- ^ @->@, the kind of type constructor
+  | KindParen    { _kindParen :: Ann Kind a
+                 } -- ^ A parenthesised kind
+  | KindVar      { _kindVar :: Ann Name a
+                 } -- ^ kind variable (using @PolyKinds@ extension)
+  | KindApp      { _kindAppFun :: Ann Kind a
+                 , _kindAppArg :: Ann Kind a 
+                 } -- ^ Kind application (@ k1 k2 @)
+  | KindList     { _kindElem :: Ann Kind a
+                 } -- ^ A list kind (@ [k] @)
+  | KindPromoted { _kindPromoted :: Ann (Promoted Kind) a
+                 } -- ^ A promoted kind (@ '(k1,k2,k3) @)
+
+data Promoted t a
+  = PromotedInt    { _promotedIntValue :: Integer }
+  | PromotedString { _promotedStringValue :: String }
+  | PromotedCon    { _promotedConName :: Ann Name a }
+  | PromotedList   { _promotedElements :: AnnList t a }
+  | PromotedTuple  { _promotedElements :: AnnList t a }
+  | PromotedUnit
+ Language/Haskell/Tools/AST/Literals.hs view
@@ -0,0 +1,28 @@+-- | Representation of Haskell literals
+module Language.Haskell.Tools.AST.Literals where
+
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Base
+
+-- | Haskell literals
+data Literal a
+  = CharLit { _charLitValue :: Char 
+            } -- ^ Character literal: @'c'@
+  | StringLit { _stringLitValue :: String 
+              } -- ^ String literal: @"abc"@
+  | IntLit { _intLitValue :: Integer 
+           } -- ^ Integer literal: @12@
+  | FracLit { _fracLitValue :: Rational 
+            } -- ^ Fractional literal: @3.14@
+  | PrimIntLit { _intLitValue :: Integer 
+               } -- ^ Primitive integer literal (of type @Int#@): @32#@
+  | PrimWordLit { _intLitValue :: Integer 
+                } -- ^ Primitive word literal (of type @Word#@): @32##@
+  | PrimFloatLit { _floatLitValue :: Rational 
+                 } -- ^ Primitive float literal (of type @Float#@): @3.14#@
+  | PrimDoubleLit { _floatLitValue :: Rational 
+                  } -- ^ Primitive double literal (of type @Double#@): @3.14##@
+  | PrimCharLit { _charLitValue :: Char 
+                } -- ^ Primitive character literal (of type @Char#@): @'c'#@
+  | PrimStringLit { _stringLitValue :: String }
+               
+ Language/Haskell/Tools/AST/Modules.hs view
@@ -0,0 +1,94 @@+-- | Representation of Haskell modules with imports and exports
+module Language.Haskell.Tools.AST.Modules where
+
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Decls
+
+data Module a 
+  = Module { _filePragmas :: AnnList FilePragma a
+           , _modHead :: AnnMaybe ModuleHead a
+           , _modImports :: AnnList ImportDecl a
+           , _modDecl :: AnnList Decl a
+           }
+
+-- | Module declaration with name and (optional) exports
+data ModuleHead a
+  = ModuleHead { _mhName :: Ann SimpleName a
+               , _mhExports :: AnnMaybe ExportSpecList a
+               , _mhPragma :: AnnMaybe ModulePragma a
+               }
+
+-- | A list of export specifications surrounded by parentheses
+data ExportSpecList a
+  = ExportSpecList { _espExports :: AnnList ExportSpec a }
+  
+-- | Export specifier
+data ExportSpec a
+  = DeclExport { _exportDecl :: Ann IESpec a 
+               } -- ^ Export a name and related names
+  | ModuleExport { _exportModuleName :: Ann SimpleName a 
+                 } -- ^ The export of an imported module (@ module A @)
+  
+-- | Marks a name to be imported or exported with related names (subspecifier)
+data IESpec a
+  = IESpec { _ieName :: Ann Name a
+           , _ieSubspec :: AnnMaybe SubSpec a
+           }
+  
+-- | Marks how related names will be imported or exported with a given name
+data SubSpec a
+  = SubSpecAll -- @(..)@: a class exported with all of its methods, or a datatype exported with all of its constructors.
+  | SubSpecList { _essList :: AnnList Name a } -- @(a,b,c)@: a class exported with some of its methods, or a datatype exported with some of its constructors.
+           
+-- | Pragmas that must be used before defining the module         
+data FilePragma a
+  = LanguagePragma { _lpPragmas :: AnnList LanguageExtension a 
+                   }  -- ^ LANGUAGE pragma
+  | OptionsPragma {  _opStr :: Ann StringNode a
+                  } -- ^ OPTIONS pragma, possibly qualified with a tool, e.g. OPTIONS_GHC
+                        
+-- | Pragmas that must be used after the module head  
+data ModulePragma a
+  = ModuleWarningPragma { _modWarningStr :: AnnList StringNode a 
+                        }  -- ^ a warning pragma attached to the module
+  | ModuleDeprecatedPragma {  _modDeprecatedPragma :: AnnList StringNode a
+                           } -- ^ a deprecated pragma attached to the module
+             
+data LanguageExtension a = LanguageExtension { _langExt :: String }
+
+-- | An import declaration: @import Module.Name@         
+data ImportDecl a
+  = ImportDecl { _importSource :: AnnMaybe ImportSource a
+               , _importQualified :: AnnMaybe ImportQualified a
+               , _importSafe :: AnnMaybe ImportSafe a
+               , _importPkg :: AnnMaybe StringNode a
+               , _importModule :: Ann SimpleName a
+               , _importAs :: AnnMaybe ImportRenaming a
+               , _importSpec :: AnnMaybe ImportSpec a
+               }
+
+-- | Restriction on the imported names
+data ImportSpec a
+  = ImportSpecList { _importSpecList :: AnnList IESpec a 
+                   } -- ^ Restrict the import definition to ONLY import the listed names
+  | ImportSpecHiding { _importSpecHiding :: AnnList IESpec a 
+                     } -- ^ Restrict the import definition to DONT import the listed names
+               
+-- | Marks the import as qualified: @qualified@
+data ImportQualified a = ImportQualified
+
+-- | Marks the import as source: @{-# SOURCE #-}@
+data ImportSource a = ImportSource
+
+-- | Marks the import as safe: @safe@
+data ImportSafe a = ImportSafe
+
+-- | Marks an imported name to belong to the type namespace: @type@
+data TypeNamespace a = TypeNamespace
+
+-- | Renaming imports (@ as A @)
+data ImportRenaming a = ImportRenaming { _importRename :: Ann SimpleName a }
+               
+ Language/Haskell/Tools/AST/Patterns.hs view
@@ -0,0 +1,69 @@+-- | Representation of Haskell patterns
+module Language.Haskell.Tools.AST.Patterns where
+          
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Base  
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Types
+import {-# SOURCE #-} Language.Haskell.Tools.AST.Exprs (Expr)
+import {-# SOURCE #-} Language.Haskell.Tools.AST.TH
+
+        
+-- | Representation of patterns for pattern bindings
+data Pattern a
+  = VarPat        { _patternName :: Ann Name a 
+                  } -- ^ Pattern name binding
+  | LitPat        { _patternLiteral :: Ann Literal a 
+                  } -- ^ Literal pattern
+  | InfixPat      { _patternLhs :: Ann Pattern a
+                  , _patternOperator :: Ann Operator a
+                  , _patternRhs :: Ann Pattern a
+                  } -- ^ Infix constructor application pattern (@ a :+: b @)
+  | AppPat        { _patternName :: Ann Name a
+                  , _patternArgs :: AnnList Pattern a
+                  } -- ^ Constructor application pattern (@ Point x y @)
+  | TuplePat      { _patternElems :: AnnList Pattern a
+                  } -- ^ Tuple pattern (@ (x,y) @)
+  | UnboxTuplePat { _patternElems :: AnnList Pattern a
+                  } -- ^ Unboxed tuple pattern (@ (# x, y #) @)
+  | ListPat       { _patternElems :: AnnList Pattern a 
+                  } -- ^ List pattern (@ [1,2,a,x] @)
+  | ParArrPat     { _patternElems :: AnnList Pattern a 
+                  } -- ^ Parallel array pattern (@ [:1,2,a,x:] @)
+  | ParenPat      { _patternInner :: Ann Pattern a 
+                  } -- ^ Parenthesised patterns
+  | RecPat        { _patternName :: Ann Name a
+                  , _patternFields :: AnnList PatternField a
+                  } -- ^ Record pattern (@ Point { x = 3, y } @)
+  | AsPat         { _patternName :: Ann Name a
+                  , _patternInner :: Ann Pattern a
+                  } -- ^ As-pattern (explicit name binding) (@ ls\@(hd:_) @)
+  | WildPat       -- ^ Wildcard pattern: (@ _ @)
+  | IrrPat        { _patternInner :: Ann Pattern a 
+                  } -- ^ Irrefutable pattern (@ ~(x:_) @)
+  | BangPat       { _patternInner :: Ann Pattern a 
+                  } -- ^ Bang pattern (@ !x @)
+  | TypeSigPat    { _patternInner :: Ann Pattern a
+                  , _patternType :: Ann Type a
+                  } -- ^ Pattern with explicit type signature (@ __ :: Int @)
+  | ViewPat       { _patternExpr :: Ann Expr a
+                  , _patternInner :: Ann Pattern a
+                  } -- ^ View pattern (@ f -> Just 1 @)
+  -- regular list pattern omitted
+  -- xml patterns omitted
+  | SplicePat     { _patternSplice :: Ann Splice a 
+                  } -- ^ Splice patterns: @$(generateX inp)@
+  | QuasiQuotePat { _patQQ :: Ann QuasiQuote a 
+                  } -- ^ Quasi-quoted patterns: @[| 1 + 2 |]@
+  | NPlusKPat     { _patternName :: Ann Name a
+                  , _patternLit :: Ann Literal a
+                  }
+                  
+-- Field specification of a record pattern
+data PatternField a 
+  = NormalFieldPattern   { _fieldPatternName :: Ann Name a
+                         , _fieldPattern :: Ann Pattern a
+                         } -- ^ Named field pattern (@ p = Point 3 2 @)
+  | FieldPunPattern      { _fieldPatternName :: Ann Name a 
+                         } -- ^ Named field pun (@ p @)
+  | FieldWildcardPattern -- ^ Wildcard field pattern (@ .. @)
+ Language/Haskell/Tools/AST/References.hs view
@@ -0,0 +1,124 @@+{-# LANGUAGE FlexibleContexts, TemplateHaskell #-}
+-- Generated references for handling the custom AST
+module Language.Haskell.Tools.AST.References where
+
+import Control.Reference
+
+import Language.Haskell.Tools.AST.Modules
+import Language.Haskell.Tools.AST.TH
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Stmts
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Kinds
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+
+-- Modules
+makeReferences ''Module
+makeReferences ''ModuleHead
+makeReferences ''ExportSpecList
+makeReferences ''ExportSpec
+makeReferences ''IESpec
+makeReferences ''SubSpec
+makeReferences ''ModulePragma
+makeReferences ''ImportDecl
+makeReferences ''ImportSpec
+makeReferences ''ImportQualified
+makeReferences ''ImportSource
+makeReferences ''ImportSafe
+makeReferences ''TypeNamespace
+makeReferences ''ImportRenaming
+
+-- Declarations
+makeReferences ''Decl
+makeReferences ''ClassBody
+makeReferences ''ClassElement
+makeReferences ''DeclHead
+makeReferences ''InstBody
+makeReferences ''InstBodyDecl
+makeReferences ''GadtConDecl
+makeReferences ''GadtConType
+makeReferences ''GadtField
+makeReferences ''FunDeps
+makeReferences ''FunDep
+makeReferences ''ConDecl
+makeReferences ''FieldDecl
+makeReferences ''Deriving
+makeReferences ''InstanceRule
+makeReferences ''InstanceHead
+makeReferences ''TypeEqn
+makeReferences ''KindConstraint
+makeReferences ''TyVar
+makeReferences ''Type
+makeReferences ''Kind
+makeReferences ''Context
+makeReferences ''Assertion
+makeReferences ''Expr
+makeReferences ''Stmt'
+makeReferences ''CompStmt
+makeReferences ''ValueBind
+makeReferences ''Pattern
+makeReferences ''PatternField
+makeReferences ''Splice
+makeReferences ''QQString
+makeReferences ''Match
+makeReferences ''Alt'
+makeReferences ''Rhs
+makeReferences ''GuardedRhs
+makeReferences ''FieldUpdate
+makeReferences ''Bracket
+makeReferences ''TopLevelPragma
+makeReferences ''Rule
+makeReferences ''AnnotationSubject
+makeReferences ''MinimalFormula
+makeReferences ''ExprPragma
+makeReferences ''SourceRange
+makeReferences ''Number
+makeReferences ''QuasiQuote
+makeReferences ''RhsGuard
+makeReferences ''LocalBind
+makeReferences ''LocalBinds
+makeReferences ''FixitySignature
+makeReferences ''TypeSignature
+makeReferences ''ListCompBody
+makeReferences ''TupSecElem
+makeReferences ''TypeFamily
+makeReferences ''TypeFamilySpec
+makeReferences ''InjectivityAnn
+makeReferences ''CaseRhs'
+makeReferences ''GuardedCaseRhs'
+makeReferences ''PatternSynonym
+makeReferences ''PatSynRhs
+makeReferences ''PatSynLhs
+makeReferences ''PatSynWhere
+makeReferences ''PatternTypeSignature
+makeReferences ''Role
+makeReferences ''LanguageExtension
+makeReferences ''MatchLhs
+
+-- Literal
+makeReferences ''Literal
+makeReferences ''Promoted
+
+-- Base
+makeReferences ''Operator
+makeReferences ''Name
+makeReferences ''SimpleName
+makeReferences ''UnqualName
+makeReferences ''StringNode
+makeReferences ''DataOrNewtypeKeyword
+makeReferences ''DoKind
+makeReferences ''TypeKeyword
+makeReferences ''OverlapPragma
+makeReferences ''CallConv
+makeReferences ''ArrowAppl
+makeReferences ''Safety
+makeReferences ''Assoc
+makeReferences ''Precedence
+makeReferences ''PhaseControl
+makeReferences ''PhaseNumber
+makeReferences ''PhaseInvert
+ Language/Haskell/Tools/AST/Stmts.hs view
@@ -0,0 +1,38 @@+-- | Representation of Haskell statements (both do-notation and comprehensions)
+module Language.Haskell.Tools.AST.Stmts where
+
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Patterns
+import {-# SOURCE #-} Language.Haskell.Tools.AST.Exprs (Expr, Cmd)
+import {-# SOURCE #-} Language.Haskell.Tools.AST.Binds (LocalBind)
+
+-- | Normal monadic statements
+data Stmt' expr a
+  = BindStmt { _stmtPattern :: Ann Pattern a
+             , _stmtExpr :: Ann expr a
+             } -- ^ Binding statement (@ x <- action @)
+  | ExprStmt { _stmtExpr :: Ann expr a 
+             } -- ^ Non-binding statement (@ action @)
+  | LetStmt  { _stmtBinds :: AnnList LocalBind a 
+             } -- ^ Let statement (@ let x = 3; y = 4 @)
+  | RecStmt  { _cmdStmtBinds :: AnnList (Stmt' expr) a 
+             } -- ^ A recursive binding statement with (@ rec b <- f a c; c <- f b a @)
+type Stmt = Stmt' Expr
+
+-- | Body of a list comprehension: (@ | x <- [1..10] @)
+data ListCompBody a
+  = ListCompBody { _compStmts :: AnnList CompStmt a 
+                 } 
+         
+-- | List comprehension statement
+data CompStmt a
+  = CompStmt   { _compStmt :: Ann Stmt a 
+               } -- ^ Normal monadic statement of a list comprehension
+  | ThenStmt   { _thenExpr :: Ann Expr a 
+               , _byExpr :: AnnMaybe Expr a
+               } -- ^ Then statements by @TransformListComp@ (@ then sortWith by (x + y) @)
+  | GroupStmt  { _byExpr :: AnnMaybe Expr a
+               , _usingExpr :: AnnMaybe Expr a
+               } -- ^ Grouping statements by @TransformListComp@ (@ then group by (x + y) using groupWith @) 
+                 -- Note: either byExpr or usingExpr must have a value
+ Language/Haskell/Tools/AST/TH.hs view
@@ -0,0 +1,41 @@+-- | Representation of Template Haskell AST elements
+module Language.Haskell.Tools.AST.TH where
+              
+import Language.Haskell.Tools.AST.Decls
+import Language.Haskell.Tools.AST.Binds
+import Language.Haskell.Tools.AST.Exprs
+import Language.Haskell.Tools.AST.Patterns
+import Language.Haskell.Tools.AST.Types
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Ann
+              
+-- | A template haskell splice          
+data Splice a
+  = IdSplice    { _spliceId :: Ann Name a 
+                } -- ^ A simple name splice: @$generateX@
+  | ParenSplice { _spliceExpr :: Ann Expr a
+                } -- ^ A splice with parentheses: @$(generate input)@
+  
+-- | Template haskell quasi-quotation: @[quoter|str]@  
+data QuasiQuote a 
+  = QuasiQuote { _qqExprName :: Ann Name a
+               , _qqExprBody :: Ann QQString a
+               } 
+        
+-- | Template Haskell Quasi-quotation content
+data QQString a
+  = QQString { _qqString :: String 
+             } 
+
+          
+-- | Template Haskell bracket expressions
+data Bracket a
+  = ExprBracket    { _bracketExpr :: Ann Expr a 
+                   } -- ^ Expression bracket (@ [| x + y |] @)
+  | PatternBracket { _bracketPattern :: Ann Pattern a 
+                   } -- ^ Pattern bracket (@ [| Point x y |] @)
+  | TypeBracket    { _bracketType :: Ann Type a 
+                   } -- ^ Pattern bracket (@ [| (Int,Int) |] @)
+  | DeclsBracket   { _bracketDecl :: AnnList Decl a 
+                   } -- ^ Declaration bracket (@ [| _f :: Int -> Int; f x = x*x |] @)
+            
+ Language/Haskell/Tools/AST/TH.hs-boot view
@@ -0,0 +1,8 @@+{-# LANGUAGE RoleAnnotations #-}
+module Language.Haskell.Tools.AST.TH where
+type role Splice nominal
+data Splice a
+type role QuasiQuote nominal
+data QuasiQuote a
+type role Bracket nominal
+data Bracket a
+ Language/Haskell/Tools/AST/Types.hs view
@@ -0,0 +1,84 @@+-- | Representation of Haskell types
+module Language.Haskell.Tools.AST.Types where
+
+import Language.Haskell.Tools.AST.Ann
+import Language.Haskell.Tools.AST.Literals
+import Language.Haskell.Tools.AST.Base
+import Language.Haskell.Tools.AST.Kinds
+import {-# SOURCE #-} Language.Haskell.Tools.AST.TH
+
+-- | Type variable declaration
+data TyVar a 
+  = TyVarDecl { _tyVarName :: Ann Name a
+              , _tyVarKind :: AnnMaybe KindConstraint a
+              }
+
+-- | Haskell types
+data Type a
+  = TyForall     { _typeBounded :: AnnList TyVar a
+                 , _typeType :: Ann Type a
+                 } -- ^ Forall types (@ forall x y . type @)
+  | TyCtx        { _typeCtx :: Ann Context a
+                 , _typeType :: Ann Type a
+                 } -- ^ Type with a context (@ forall x y . type @)
+  | TyFun        { _typeParam :: Ann Type a
+                 , _typeResult :: Ann Type a
+                 } -- ^ Function types (@ a -> b @)
+  | TyTuple      { _typeElements :: AnnList Type a
+                 } -- ^ Tuple types (@ (a,b) @)
+  | TyUnbTuple   { _typeElements :: AnnList Type a 
+                 } -- ^ Unboxed tuple types (@ (#a,b#) @)
+  | TyList       { _typeElement :: Ann Type a 
+                 } -- ^ List type with special syntax (@ [a] @)
+  | TyParArray   { _typeElement :: Ann Type a
+                 } -- ^ Parallel array type (@ [:a:] @)
+  | TyApp        { _typeCon :: Ann Type a
+                 , _typeArg :: Ann Type a
+                 } -- ^ Type application (@ F a @)
+  | TyVar        { _typeName :: Ann Name a
+                 } -- ^ type variable or constructor (@ a @)
+  | TyParen      { _typeInner :: Ann Type a
+                 } -- ^ type surrounded by parentheses (@ (T a) @)
+  | TyInfix      { _typeLeft :: Ann Type a 
+                 , _typeOperator :: Ann Operator a
+                 , _typeRight :: Ann Type a
+                 } -- ^ Infix type constructor (@ (a <: b) @)
+  | TyKinded     { _typeInner :: Ann Type a
+                 , _typeKind :: Ann Kind a
+                 } -- ^ Type with explicit kind signature (@ _a :: * @)
+  | TyPromoted   { _tpPromoted :: Ann (Promoted Type) a
+                 } -- A promoted data type with @-XDataKinds@ (@ 3 @, @ Left @, @ 'Left @).
+  | TySplice     { _tsSplice :: Splice a
+                 } -- ^ a Template Haskell splice type (@ $(genType) @).
+  | TyQuasiQuote { _typeQQ :: QuasiQuote a
+                 } -- ^ a Template Haskell quasi-quote type (@ [quoter| ... ] @).
+  | TyBang       { _typeInner :: Ann Type a
+                 } -- ^ Strict type marked with @!@.
+  | TyLazy       { _typeInner :: Ann Type a
+                 } -- ^ Lazy type marked with @~@. (Should only be used if @Strict@ or @StrictData@ language extension is used)
+  | TyUnpack     { _typeInner :: Ann Type a
+                 } -- ^ Strict type marked with UNPACK pragma. (Usually contains the bang mark.)
+  | TyNoUnpack   { _typeInner :: Ann Type a
+                 } -- ^ Strict type marked with NOUNPACK pragma. (Usually contains the bang mark.)
+  | TyWildcard   -- ^ A wildcard type (@ _ @) with @-XPartialTypeSignatures@
+  | TyNamedWildc { _typeWildcardName :: Ann Name a
+                 } -- ^ A named wildcard type (@ _t @) with @-XPartialTypeSignatures@
+
+-- One or more assertions
+data Context a
+  = ContextOne   { _contextAssertion :: Ann Assertion a
+                 } -- ^ One assertion (@ C a => ... @)
+  | ContextMulti { _contextAssertions :: AnnList Assertion a 
+                 } -- ^ A set of assertions (@ (C1 a, C2 b) => ... @, but can be one: @ (C a) => ... @)
+
+-- | A single assertion in the context
+data Assertion a
+  = ClassAssert { _assertClsName :: Ann Name a
+                , _assertTypes :: AnnList Type a
+                } -- ^ Class assertion (@Cls x@)
+  | InfixAssert { _assertLhs :: Ann Type a
+                , _assertOp :: Ann Operator a
+                , _assertRhs :: Ann Type a
+                } -- ^ Infix class assertion, also contains type equations (@ a ~ X y @)
+                 
+                 
+ Language/Haskell/Tools/AST/Utils/GHCInstances.hs view
@@ -0,0 +1,19 @@+{-# LANGUAGE StandaloneDeriving, DeriveDataTypeable #-}
+module Language.Haskell.Tools.AST.Utils.GHCInstances where
+
+import Data.Data
+import SrcLoc
+
+deriving instance Data SrcLoc
+  
+instance Data RealSrcLoc where
+    gfoldl k z rsl = z mkRealSrcLoc `k` srcLocFile rsl `k` srcLocLine rsl `k` srcLocCol rsl
+
+    gunfold k z c = case constrIndex c of
+                        1 -> k (k (k (z mkRealSrcLoc)))
+
+    toConstr _ = con_RSL
+    dataTypeOf _ = ty_RSL
+
+con_RSL = mkConstr ty_RSL "RSL" [] Prefix
+ty_RSL   = mkDataType "SrcLoc.RealSrcLoc" [con_RSL]
+ Language/Haskell/Tools/AST/Utils/OrdSrcSpan.hs view
@@ -0,0 +1,30 @@+-- | A wrapper for SrcSpans that is ordered.
+module Language.Haskell.Tools.AST.Utils.OrdSrcSpan where
+
+import SrcLoc
+import FastString
+
+-- | Wraps the SrcSpan into an ordered source span
+ordSrcSpan :: SrcSpan -> OrdSrcSpan
+ordSrcSpan (RealSrcSpan sp) = OrdSrcSpan sp
+ordSrcSpan (UnhelpfulSpan fs) = NoOrdSrcSpan fs
+
+-- | Unwrap the ordered source span
+fromOrdSrcSpan :: OrdSrcSpan -> SrcSpan 
+fromOrdSrcSpan (OrdSrcSpan sp) = RealSrcSpan sp
+fromOrdSrcSpan (NoOrdSrcSpan fs) = UnhelpfulSpan fs
+
+-- | A wrapper for SrcSpans that is ordered.
+data OrdSrcSpan 
+  = OrdSrcSpan RealSrcSpan
+  | NoOrdSrcSpan FastString
+  deriving (Show, Eq)
+
+instance Ord OrdSrcSpan where
+  compare (NoOrdSrcSpan _) (NoOrdSrcSpan _) = EQ
+  compare (OrdSrcSpan _) (NoOrdSrcSpan _) = GT
+  compare (NoOrdSrcSpan _) (OrdSrcSpan _) = LT
+  compare (OrdSrcSpan rsp1)  (OrdSrcSpan rsp2) 
+    = compare (realSrcSpanStart rsp1) (realSrcSpanStart rsp2)
+        `mappend` compare (realSrcSpanEnd rsp1) (realSrcSpanEnd rsp2)
+        
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ haskell-tools-ast.cabal view
@@ -0,0 +1,46 @@+name:                haskell-tools-ast
+version:             0.1.2.0
+synopsis:            Haskell AST for efficient tooling
+description:         A representation of a Haskell Syntax tree that contain source-related and semantic annotations. These annotations help developer tools to work with the defined program. The source information enables refactoring and program transformation tools to change the source code without losing the original format (layout, comments) of the source. Semantic information helps analyzing the program. The representation is different from the GHC's syntax tree. It contains information from all representations in GHC (different version of syntax trees, lexical and module-level information).
+
+homepage:            https://github.com/nboldi/haskell-tools
+license:             BSD3
+license-file:        LICENSE
+author:              Boldizsar Nemeth
+maintainer:          nboldi@elte.hu
+category:            Language
+build-type:          Simple
+cabal-version:       >=1.10
+
+library
+  exposed-modules:     Language.Haskell.Tools.AST    
+  other-modules:       Language.Haskell.Tools.AST.Modules
+                     , Language.Haskell.Tools.AST.TH
+                     , Language.Haskell.Tools.AST.Decls
+                     , Language.Haskell.Tools.AST.Binds
+                     , Language.Haskell.Tools.AST.Exprs
+                     , Language.Haskell.Tools.AST.Stmts
+                     , Language.Haskell.Tools.AST.Patterns
+                     , Language.Haskell.Tools.AST.Types
+                     , Language.Haskell.Tools.AST.Kinds
+                     , Language.Haskell.Tools.AST.Literals
+                     , Language.Haskell.Tools.AST.Base
+                     , Language.Haskell.Tools.AST.Ann
+                   
+                     , Language.Haskell.Tools.AST.Instances
+                     , Language.Haskell.Tools.AST.Instances.Eq
+                     , Language.Haskell.Tools.AST.Instances.Show
+                     , Language.Haskell.Tools.AST.Instances.Data
+                     , Language.Haskell.Tools.AST.Instances.Generic
+                     , Language.Haskell.Tools.AST.Instances.StructuralTraversal
+                     , Language.Haskell.Tools.AST.References
+                     , Language.Haskell.Tools.AST.Helpers
+                     , Language.Haskell.Tools.AST.Utils.OrdSrcSpan
+                     , Language.Haskell.Tools.AST.Utils.GHCInstances
+                     
+  build-depends:       base                 >=4.9   && <5.0
+                     , ghc                  >=8.0   && <8.1
+                     , references           >=0.3.2 && <1.0
+                     , uniplate             >=1.6   && <2.0
+                     , structural-traversal >=0.1   && <0.2
+  default-language:    Haskell2010