git.haldean.org del / 30e5126 src / Language / Del / Imports.hs
30e5126

Tree @30e5126 (Download .tar.gz)

Imports.hs @30e5126raw · history · blame

module Language.Del.Imports where

import           Language.Del.AST
import           Language.Del.CompileDefs
import qualified Data.Text as T
import qualified Data.Map.Strict as Map

mergeBinds :: T.Text -> Map.Map T.Text Def -> Map.Map T.Text Def -> Artifact (Map.Map T.Text Def)
mergeBinds = undefined

loadImport :: Source -> IO (Artifact AST)
loadImport = undefined

collectImports :: [Source] -> AST -> IO (Artifact AST)
collectImports loaded (AST m ((Import src alias):xs)) =
    if elem src loaded
       then collectImports loaded (AST m xs)
       else do
           iast <- loadImport src
           case iast of
                Success (AST b imps) -> (return $ mergeBinds alias m b) >>=
                    (\merged -> case merged of
                        Success mm -> collectImports (src:loaded) (AST mm (xs ++ imps))
                        Failure e -> return $ Failure e)
                Failure e -> return $ Failure e

-- No imports in the AST, or the previous pattern would have matched; done!
collectImports _ a = return $ Success a