on master help sign in
Rename functions and modules
640f98eEvan Czaplicki
Elm.cabal+3−2
@@ -59,7 +59,7 @@ Library
59 Parse.Helpers,
59 Parse.Helpers,
60 Parse.Literal,
60 Parse.Literal,
61 Parse.Module,
61 Parse.Module,
62− Parse.Parser,
62+ Parse.Parse,
63 Parse.Pattern,
63 Parse.Pattern,
64 Parse.Type,
64 Parse.Type,
65 Type.Constrain.Declaration,
65 Type.Constrain.Declaration,
@@ -126,7 +126,7 @@ Executable elm
126 Parse.Helpers,
126 Parse.Helpers,
127 Parse.Literal,
127 Parse.Literal,
128 Parse.Module,
128 Parse.Module,
129− Parse.Parser,
129+ Parse.Parse,
130 Parse.Pattern,
130 Parse.Pattern,
131 Parse.Type,
131 Parse.Type,
132 Type.Constrain.Declaration,
132 Type.Constrain.Declaration,
@@ -184,6 +184,7 @@ Executable elm-doc
184 pretty,
184 pretty,
185 cmdargs,
185 cmdargs,
186 filepath,
186 filepath,
187+ union-find,
187 indents
188 indents
188
189
189Test-Suite test-elm
190Test-Suite test-elm
compiler/Parse/Parse.hs+12−6
@@ -1,6 +1,5 @@
1−module Parse.Parser (parseProgram) where
1+module Parse.Parse (program, dependencies) where
2
2
3−import SourceSyntax.Module
4import Control.Applicative ((<$>), (<*>))
3import Control.Applicative ((<$>), (<*>))
5import Control.Monad
4import Control.Monad
6import Data.Char (isSymbol, isDigit)
5import Data.Char (isSymbol, isDigit)
@@ -8,6 +7,7 @@ import Data.List (foldl',intercalate)
8import Text.Parsec hiding (newline,spaces)
7import Text.Parsec hiding (newline,spaces)
9import qualified Text.PrettyPrint as P
8import qualified Text.PrettyPrint as P
10
9
10+import qualified SourceSyntax.Module as S
11import Parse.Helpers
11import Parse.Helpers
12import Parse.Binop (infixStmt, OpTable)
12import Parse.Binop (infixStmt, OpTable)
13import Parse.Expression
13import Parse.Expression
@@ -22,17 +22,23 @@ freshDef = commitIf (freshLine >> (letter <|> char '_')) $ do
22decls = do d <- Decl.declaration <?> "at least one datatype or variable definition"
22decls = do d <- Decl.declaration <?> "at least one datatype or variable definition"
23 (d:) <$> many freshDef
23 (d:) <$> many freshDef
24
24
25−program = do
25+program :: String -> Either [P.Doc] (S.Module t v)
26+program = setupParser $ do
26 optional freshLine
27 optional freshLine
27 (names,exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine)
28 (names,exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine)
28 is <- (do try (lookAhead $ reserved "import")
29 is <- (do try (lookAhead $ reserved "import")
29 imports `followedBy` freshLine) <|> return []
30 imports `followedBy` freshLine) <|> return []
30 declarations <- decls
31 declarations <- decls
31 optional freshLine ; optional spaces ; eof
32 optional freshLine ; optional spaces ; eof
32− return $ Module names exports is declarations
33+ return $ S.Module names exports is declarations
33
34
34−parseProgram :: String -> Either [P.Doc] (Module t v)
35+dependencies :: String -> Either [P.Doc] (String, [String])
36+dependencies =
37+ let getName = intercalate "." . fst in
35−parseProgram = setupParser program
38+ setupParser $ do
39+ optional freshLine
40+ (,) <$> option "Main" (getName <$> moduleDef `followedBy` freshLine)
41+ <*> option [] (map fst <$> imports `followedBy` freshLine)
36
42
37setupParser :: IParser a -> String -> Either [P.Doc] a
43setupParser :: IParser a -> String -> Either [P.Doc] a
38setupParser p source =
44setupParser p source =