on master help sign in
Rename functions and modules
commit640f98e7d56dcd31308eba665c704e1b566f0e3f authorEvan Czaplicki <info@elm-lang.org> dateTue 16 Jul 2013, 21:38 (13 years ago) parent1ffaad1
2 files changed+15−8
Elm.cabal+3−2 compiler/Parse/Parse.hs+12−6
Elm.cabal+3−2
@@ -59,7 +59,7 @@ Library
5959 Parse.Helpers,
6060 Parse.Literal,
6161 Parse.Module,
62− Parse.Parser,
62+ Parse.Parse,
6363 Parse.Pattern,
6464 Parse.Type,
6565 Type.Constrain.Declaration,
@@ -126,7 +126,7 @@ Executable elm
126126 Parse.Helpers,
127127 Parse.Literal,
128128 Parse.Module,
129− Parse.Parser,
129+ Parse.Parse,
130130 Parse.Pattern,
131131 Parse.Type,
132132 Type.Constrain.Declaration,
@@ -184,6 +184,7 @@ Executable elm-doc
184184 pretty,
185185 cmdargs,
186186 filepath,
187+ union-find,
187188 indents
188189
189190Test-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
22
3−import SourceSyntax.Module
43import Control.Applicative ((<$>), (<*>))
54import Control.Monad
65import Data.Char (isSymbol, isDigit)
@@ -8,6 +7,7 @@ import Data.List (foldl',intercalate)
87import Text.Parsec hiding (newline,spaces)
98import qualified Text.PrettyPrint as P
109
10+import qualified SourceSyntax.Module as S
1111import Parse.Helpers
1212import Parse.Binop (infixStmt, OpTable)
1313import Parse.Expression
@@ -22,17 +22,23 @@ freshDef = commitIf (freshLine >> (letter <|> char '_')) $ do
2222decls = do d <- Decl.declaration <?> "at least one datatype or variable definition"
2323 (d:) <$> many freshDef
2424
25−program = do
25+program :: String -> Either [P.Doc] (S.Module t v)
26+program = setupParser $ do
2627 optional freshLine
2728 (names,exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine)
2829 is <- (do try (lookAhead $ reserved "import")
2930 imports `followedBy` freshLine) <|> return []
3031 declarations <- decls
3132 optional freshLine ; optional spaces ; eof
32− return $ Module names exports is declarations
33+ return $ S.Module names exports is declarations
3334
34−parseProgram :: String -> Either [P.Doc] (Module t v)
35−parseProgram = setupParser program
35+dependencies :: String -> Either [P.Doc] (String, [String])
36+dependencies =
37+ let getName = intercalate "." . fst in
38+ setupParser $ do
39+ optional freshLine
40+ (,) <$> option "Main" (getName <$> moduleDef `followedBy` freshLine)
41+ <*> option [] (map fst <$> imports `followedBy` freshLine)
3642
3743setupParser :: IParser a -> String -> Either [P.Doc] a
3844setupParser p source =