HaskellAnalysisProgram-0.1.0: src/MetaHS/DataModel/Utils/Language/Haskell/Exts/Syntax/Module.hs
{-|
Module : MetaHS.DataModel.Utils.Language.Haskell.Exts.Syntax.Module
Description : Utility functions for Modules objects.
Copyright : Copyright (C) 2017-2019 H.H.R.F. Vos, S. Kamps
License : -- This file is distributed under the terms of the Apache License 2.0.
For more information, see the file "LICENSE", which is included in the distribution.
Stability : experimental
Utility functions for Modules objects.
-}
module MetaHS.DataModel.Utils.Language.Haskell.Exts.Syntax.Module
where
import Prelude hiding (head)
import Data.Maybe (fromMaybe)
import Language.Haskell.Exts.Syntax
import Language.Haskell.Exts.SrcLoc (SrcSpanInfo)
-- | Returns the location information of a Module.
srcSpanInfo :: Module SrcSpanInfo -- ^ The Module to analyze.
-> SrcSpanInfo -- ^ The SrcSpanInfo for this Module.
srcSpanInfo = ann
-- | Returns the ModuleHead of a Module.
head :: Module l -- ^ The Module to analyze.
-> Maybe (ModuleHead l) -- ^ The ModuleHead for this Module.
head (Module _ x _ _ _) = x
head (XmlHybrid _ x _ _ _ _ _ _ _) = x
head _ = Nothing
-- | Returns the name of the module contained in the ModuleHead.
headName :: ModuleHead l -- ^ The ModuleHead to analyze.
-> String -- ^ The name of this ModuleHead.
headName (ModuleHead _ (ModuleName _ x) _ _) = x
-- | Returns the WarningText contained in the ModuleHead
headWarningText :: ModuleHead l -- ^ The ModuleHead to analyze.
-> Maybe (WarningText l) -- ^ The WarningText for this ModuleHead.
headWarningText (ModuleHead _ _ x _) = x
-- | Return the ExportSpecList contained in the ModuleHead.
headExports :: ModuleHead l -- ^ The ModuleHead to analyze.
-> Maybe (ExportSpecList l) -- ^ The ExportSpecList for this ModuleHead.
headExports (ModuleHead _ _ _ x) = x
-- | Returns the name of a Module.
name :: Module l -- ^ The Module to analyze.
-> Maybe String -- ^ The Name of this Module.
name m = headName <$> head m
-- | Returns the WarningText of a Module.
warningText :: Module l -- ^ The Module to analyze.
-> Maybe (WarningText l) -- ^ The WarningText for this Module.
warningText m = f $ headWarningText <$> head m
where
f = fromMaybe Nothing
-- | Returns the ExportSpecList of a Module.
exports :: Module l -- ^ The Module to analyze.
-> Maybe (ExportSpecList l) -- ^ The ExportSpecList for this Module.
exports m = f $ headExports <$> head m
where
f = fromMaybe Nothing
-- | Returns the ExportSpecList as list
getModuleExports :: Module l -- ^ The Module to analyze.
-> [ExportSpec l] -- ^ The ExportSpecList for this Module.
getModuleExports m = case exports m of
(Just (ExportSpecList _ es)) -> es
Nothing -> []
-- | Returns the pragmas of a module.
pragmas :: Module l -- ^ The Module to analyze.
-> [ModulePragma l] -- ^ The list of ModulePragma objects for this Module.
pragmas (Module _ _ x _ _) = x
pragmas (XmlHybrid _ _ x _ _ _ _ _ _) = x
pragmas _ = []
-- | Returns the imports of a module
imports :: Module l -- ^ The Module to analyze.
-> [ImportDecl l] -- ^ The list of ImportDecl objects for this Module.
imports (Module _ _ _ x _) = x
imports (XmlHybrid _ _ _ x _ _ _ _ _) = x
imports _ = []
-- | Returns the Decl of a module
declarations :: Module l -- ^ The Module to analyze.
-> [Decl l] -- ^ The list of Decl objects for this Module.
declarations (Module _ _ _ _ x) = x
declarations (XmlHybrid _ _ _ _ x _ _ _ _) = x
declarations _ = []