@@ -52,6 +52,7 @@ import qualified Data.List.Split as Spl
52import Data.List
52import Data.List
53import Data.Monoid
53import Data.Monoid
54import Data.Char
54import Data.Char
55+import qualified Data.Map as M
55import qualified Data.HashSet as HS
56import qualified Data.HashSet as HS
56import qualified Data.Text as T
57import qualified Data.Text as T
57import qualified Data.ByteString.UTF8 as UTF8
58import qualified Data.ByteString.UTF8 as UTF8
@@ -91,13 +92,14 @@ moduleHeader = try (do reserved "module"
91{- | Parses an import statement
92{- | Parses an import statement
92 Import ::= 'import' Identifier_t ';'?;
93 Import ::= 'import' Identifier_t ';'?;
94−import_ :: IdrisParser String
95+import_ :: IdrisParser (String, Maybe String)
95import_ = do reserved "import"
96import_ = do reserved "import"
96 id <- identifier
97 id <- identifier
98+ newName <- optional (reserved "as" *> identifier)
97 option ';' (lchar ';')
99 option ';' (lchar ';')
98− return (toPath id)
100+ return (toPath id, toPath <$> newName)
99 <?> "import statement"
101 <?> "import statement"
100− where toPath f = foldl1' (</>) (Spl.splitOn "." f)
102+ where toPath = foldl1' (</>) . Spl.splitOn "."
102{- | Parses program source
104{- | Parses program source
103 Prog ::= Decl* EOF;
105 Prog ::= Decl* EOF;
@@ -934,7 +936,7 @@ parseTactic :: IState -> String -> Result PTactic
934parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
936parseTactic st = runparser (fullTactic defaultSyntax) st "(input)"
936-- | Parse module header and imports
938-- | Parse module header and imports
937−parseImports :: FilePath -> String -> Idris ([String], [String], Maybe Delta)
939+parseImports :: FilePath -> String -> Idris ([String], [(String, Maybe String)], Maybe Delta)
938parseImports fname input
940parseImports fname input
939 = do i <- getIState
941 = do i <- getIState
940 case parseString (runInnerParser (evalStateT imports i)) (Directed (UTF8.fromString fname) 0 0 0 0) input of
942 case parseString (runInnerParser (evalStateT imports i)) (Directed (UTF8.fromString fname) 0 0 0 0) input of
@@ -942,7 +944,7 @@ parseImports fname input
942 Success (x, i) -> do -- Discard state updates (there should be
944 Success (x, i) -> do -- Discard state updates (there should be
943 -- none anyway)
945 -- none anyway)
945− where imports :: IdrisParser (([String], [String], Maybe Delta), IState)
947+ where imports :: IdrisParser (([String], [(String, Maybe String)], Maybe Delta), IState)
946 imports = do whiteSpace
948 imports = do whiteSpace
947 mname <- moduleHeader
949 mname <- moduleHeader
948 ps <- many import_
950 ps <- many import_
@@ -1053,13 +1055,17 @@ loadSource h lidr f
1053 let def_total = default_total i
1055 let def_total = default_total i
1054 file_in <- runIO $ readFile f
1056 file_in <- runIO $ readFile f
1055 file <- if lidr then tclift $ unlit f file_in else return file_in
1057 file <- if lidr then tclift $ unlit f file_in else return file_in
1056− (mname, modules, pos) <- parseImports f file
1058+ (mname, imports, pos) <- parseImports f file
1059+ let modules = map fst imports
1060+ modAliases = M.fromList
1061+ [(prep alias, prep realName)| (realName, Just alias) <- imports]
1062+ prep = map T.pack . Spl.splitOn "/"
1057 i <- getIState
1063 i <- getIState
1058 putIState (i { default_access = Hidden })
1064 putIState (i { default_access = Hidden })
1059 clearIBC -- start a new .ibc file
1065 clearIBC -- start a new .ibc file
1060 mapM_ (addIBC . IBCImport) modules
1066 mapM_ (addIBC . IBCImport) modules
1061− ds' <- parseProg (defaultSyntax {syn_namespace = reverse mname })
1067+ let syntax = defaultSyntax{ syn_namespace = reverse mname }
1062− f file pos
1068+ ds' <- parseProg syntax f file pos
1063 unless (null ds') $ do
1069 unless (null ds') $ do
1064 let ds = namespaces mname ds'
1070 let ds = namespaces mname ds'
1065 logLvl 3 (showDecls True ds)
1071 logLvl 3 (showDecls True ds)