@@ -12,7 +12,7 @@ Maintainer : The Idris Community.
12-- FIXME: {-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
12-- FIXME: {-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
13{-# OPTIONS_GHC -fwarn-unused-imports #-}
13{-# OPTIONS_GHC -fwarn-unused-imports #-}
15−module Idris.Parser(IdrisParser(..), ImportInfo(..), addReplSyntax, clearParserWarnings,
15+module Idris.Parser(IdrisParser(..), ImportInfo(..), moduleName, addReplSyntax, clearParserWarnings,
16 decl, fixColour, loadFromIFile, loadModule, name, opChars, parseElabShellStep, parseConst, parseExpr, parseImports, parseTactic,
16 decl, fixColour, loadFromIFile, loadModule, name, opChars, parseElabShellStep, parseConst, parseExpr, parseImports, parseTactic,
17 runparser, ParseError, parseErrorDoc) where
17 runparser, ParseError, parseErrorDoc) where
@@ -81,23 +81,31 @@ import qualified Text.PrettyPrint.ANSI.Leijen as PP
81 ModuleHeader ::= DocComment_t? 'module' Identifier_t ';'?;
81 ModuleHeader ::= DocComment_t? 'module' Identifier_t ';'?;
86+moduleName :: Parsing m => m Name
87+moduleName = mkName [] . map T.pack <$> moduleNamePieces where
89+ mkName :: [T.Text] -> [T.Text] -> Name
90+ mkName ts [x] = NS (UN x) ts
91+ mkName ts (x:xs) = mkName (x : ts) xs
93+moduleNamePieces :: Parsing m => m [String]
94+moduleNamePieces = Spl.splitOn "." <$> identifier
84moduleHeader :: IdrisParser (Maybe (Docstring ()), [String], [(FC, OutputAnnotation)])
96moduleHeader :: IdrisParser (Maybe (Docstring ()), [String], [(FC, OutputAnnotation)])
85moduleHeader = P.try (do docs <- optional docComment
97moduleHeader = P.try (do docs <- optional docComment
86 noArgs docs
98 noArgs docs
87 keyword "module"
99 keyword "module"
88− (i, ifc) <- withExtent identifier
100+ (modName, ifc) <- withExtent moduleNamePieces
89 P.option ';' (lchar ';')
101 P.option ';' (lchar ';')
90− let modName = moduleName i
91 return (fmap fst docs,
102 return (fmap fst docs,
93 [(ifc, AnnNamespace (map T.pack modName) Nothing)]))
104 [(ifc, AnnNamespace (map T.pack modName) Nothing)]))
94 <|> P.try (do lchar '%'; reserved "unqualified"
105 <|> P.try (do lchar '%'; reserved "unqualified"
95 return (Nothing, [], []))
106 return (Nothing, [], []))
96− <|> return (Nothing, moduleName "Main", [])
107+ <|> return (Nothing, ["Main"], [])
97− where moduleName x = case span (/='.') x of
99− (x, '.':y) -> x : moduleName y
100− noArgs (Just (_, args)) | not (null args) = fail "Modules do not take arguments"
108+ where noArgs (Just (_, args)) | not (null args) = fail "Modules do not take arguments"
101 noArgs _ = return ()
109 noArgs _ = return ()
103data ImportInfo = ImportInfo { import_reexport :: Bool
111data ImportInfo = ImportInfo { import_reexport :: Bool
@@ -117,16 +125,15 @@ data ImportInfo = ImportInfo { import_reexport :: Bool
117import_ :: IdrisParser ImportInfo
125import_ :: IdrisParser ImportInfo
118import_ = do fc <- extent $ keyword "import"
126import_ = do fc <- extent $ keyword "import"
119 reexport <- P.option False (True <$ keyword "public")
127 reexport <- P.option False (True <$ keyword "public")
120− (id, idfc) <- withExtent identifier
128+ (ns, idfc) <- withExtent moduleNamePieces
121 newName <- optional (do keyword "as"
129 newName <- optional (do keyword "as"
122 withExtent identifier)
130 withExtent identifier)
123 P.option ';' (lchar ';')
131 P.option ';' (lchar ';')
124− return $ ImportInfo reexport (toPath id)
132+ return $ ImportInfo reexport (toPath ns)
125− (fmap (\(n, fc) -> (toPath n, fc)) newName)
133+ (fmap (\(n, fc) -> (toPath (Spl.splitOn "." n), fc)) newName)
126− (map T.pack $ ns id) fc idfc
134+ (map T.pack ns) fc idfc
127 <?> "import statement"
135 <?> "import statement"
128− where ns = Spl.splitOn "."
129− toPath = foldl1' (</>) . ns
136+ where toPath = foldl1' (</>)
131{-| Parses program source
138{-| Parses program source