2012-06-11 13:11:15 +00:00
|
|
|
|
|
|
|
module ParseModules (moduleDef, imports) where
|
|
|
|
|
|
|
|
import Control.Applicative ((<$>), (<*>))
|
|
|
|
import Data.List (intercalate)
|
|
|
|
import Text.Parsec hiding (newline,spaces)
|
|
|
|
|
|
|
|
import Ast
|
|
|
|
import ParseLib
|
|
|
|
|
2012-06-12 06:28:45 +00:00
|
|
|
moduleDef :: (Monad m) => ParsecT [Char] u m ([String], [String])
|
2012-06-11 13:11:15 +00:00
|
|
|
moduleDef = do
|
2012-06-12 06:28:45 +00:00
|
|
|
try (reserved "module")
|
|
|
|
whitespace <?> "name of module"
|
|
|
|
names <- dotSep1 capVar
|
2012-06-11 13:11:15 +00:00
|
|
|
whitespace
|
|
|
|
exports <- option [] . parens $ commaSep var
|
2012-06-12 06:28:45 +00:00
|
|
|
whitespace <?> "reserved word 'where'"
|
2012-06-11 13:11:15 +00:00
|
|
|
reserved "where"
|
2012-06-12 06:28:45 +00:00
|
|
|
return (names, exports)
|
2012-06-11 13:11:15 +00:00
|
|
|
|
|
|
|
imports :: (Monad m) => ParsecT [Char] u m Imports
|
2012-06-12 06:28:45 +00:00
|
|
|
imports = option [] ((:) <$> import' <*> many (try (freshLine >> import')))
|
2012-06-11 13:11:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
import' :: (Monad m) => ParsecT [Char] u m (String, ImportMethod)
|
|
|
|
import' = do
|
|
|
|
reserved "import"
|
|
|
|
whitespace
|
|
|
|
name <- intercalate "." <$> dotSep1 capVar
|
2012-10-21 11:50:40 +00:00
|
|
|
method <- option (Hiding []) $ try (whitespace >>
|
|
|
|
(as' <|> hiding' <|> importing'))
|
2012-06-11 13:11:15 +00:00
|
|
|
return (name, method)
|
|
|
|
|
|
|
|
|
|
|
|
as' :: (Monad m) => ParsecT [Char] u m ImportMethod
|
2012-06-12 06:28:45 +00:00
|
|
|
as' = reserved "as" >> whitespace >> As <$> capVar <?> "alias for module"
|
2012-06-11 13:11:15 +00:00
|
|
|
|
|
|
|
hiding' :: (Monad m) => ParsecT [Char] u m ImportMethod
|
2012-06-12 06:28:45 +00:00
|
|
|
hiding' = reserved "hiding" >> whitespace >>
|
|
|
|
Hiding <$> parens (commaSep1 var) <?> "listing of hidden values"
|
2012-06-11 13:11:15 +00:00
|
|
|
|
|
|
|
importing' :: (Monad m) => ParsecT [Char] u m ImportMethod
|
2012-06-12 06:28:45 +00:00
|
|
|
importing' = Importing <$> parens (commaSep1 var) <?> "listing of imported values (x,y,z)"
|