module Fay.Types.ModulePath
( ModulePath (..)
, mkModulePath
, mkModulePaths
, mkModulePathFromQName
) where
import Fay.Compiler.QName
import qualified Fay.Exts as F
import Data.List
import Data.List.Split
import Language.Haskell.Exts
newtype ModulePath = ModulePath { unModulePath :: [String] }
deriving (Eq, Ord, Show)
mkModulePath :: ModuleName a -> ModulePath
mkModulePath (ModuleName _ m) = ModulePath . splitOn "." $ m
mkModulePaths :: ModuleName a -> [ModulePath]
mkModulePaths (ModuleName _ m) = map ModulePath . tail . inits . splitOn "." $ m
mkModulePathFromQName :: QName a -> ModulePath
mkModulePathFromQName (Qual _ (ModuleName _ m) n) = mkModulePath $ ModuleName F.noI $ m ++ "." ++ unname n
mkModulePathFromQName _ = error "mkModulePathFromQName: Not a qualified name"