diff --git a/Elm.cabal b/Elm.cabal index c48b2f9..9d33f4b 100644 --- a/Elm.cabal +++ b/Elm.cabal @@ -59,7 +59,7 @@ Library Parse.Helpers, Parse.Literal, Parse.Module, - Parse.Parser, + Parse.Parse, Parse.Pattern, Parse.Type, Type.Constrain.Declaration, @@ -126,7 +126,7 @@ Executable elm Parse.Helpers, Parse.Literal, Parse.Module, - Parse.Parser, + Parse.Parse, Parse.Pattern, Parse.Type, Type.Constrain.Declaration, @@ -184,6 +184,7 @@ Executable elm-doc pretty, cmdargs, filepath, + union-find, indents Test-Suite test-elm diff --git a/compiler/Parse/Parse.hs b/compiler/Parse/Parse.hs index 693b074..94f2f9f 100644 --- a/compiler/Parse/Parse.hs +++ b/compiler/Parse/Parse.hs @@ -1,6 +1,5 @@ -module Parse.Parser (parseProgram) where +module Parse.Parse (program, dependencies) where -import SourceSyntax.Module import Control.Applicative ((<$>), (<*>)) import Control.Monad import Data.Char (isSymbol, isDigit) @@ -8,6 +7,7 @@ import Data.List (foldl',intercalate) import Text.Parsec hiding (newline,spaces) import qualified Text.PrettyPrint as P +import qualified SourceSyntax.Module as S import Parse.Helpers import Parse.Binop (infixStmt, OpTable) import Parse.Expression @@ -22,17 +22,23 @@ freshDef = commitIf (freshLine >> (letter <|> char '_')) $ do decls = do d <- Decl.declaration "at least one datatype or variable definition" (d:) <$> many freshDef -program = do +program :: String -> Either [P.Doc] (S.Module t v) +program = setupParser $ do optional freshLine (names,exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine) is <- (do try (lookAhead $ reserved "import") imports `followedBy` freshLine) <|> return [] declarations <- decls optional freshLine ; optional spaces ; eof - return $ Module names exports is declarations + return $ S.Module names exports is declarations -parseProgram :: String -> Either [P.Doc] (Module t v) -parseProgram = setupParser program +dependencies :: String -> Either [P.Doc] (String, [String]) +dependencies = + let getName = intercalate "." . fst in + setupParser $ do + optional freshLine + (,) <$> option "Main" (getName <$> moduleDef `followedBy` freshLine) + <*> option [] (map fst <$> imports `followedBy` freshLine) setupParser :: IParser a -> String -> Either [P.Doc] a setupParser p source =