on master help sign in
Make "combineAnnotations" a part of parsing a program
commit98f7be328b7911b2a0023859372569b56a7f4089 authorEvan Czaplicki <info@elm-lang.org> dateThu 2 Jan 2014, 23:42 (13 years ago) parent49fc0b6
1 file changed+18−10
compiler/Parse/Parse.hs+18−10
compiler/Parse/Parse.hs+18−10
@@ -8,8 +8,9 @@ import qualified Data.Map as Map
88import Text.Parsec hiding (newline,spaces)
99import qualified Text.PrettyPrint as P
1010
11−import qualified SourceSyntax.Module as S
11+import qualified SourceSyntax.Expression as E
1212import qualified SourceSyntax.Declaration as D
13+import qualified SourceSyntax.Module as M
1314import Parse.Helpers
1415import Parse.Binop (OpTable)
1516import Parse.Expression
@@ -17,6 +18,7 @@ import Parse.Declaration (infixDecl)
1718import Parse.Type
1819import Parse.Module
1920import qualified Parse.Declaration as Decl
21+import Transform.Declaration (combineAnnotations)
2022
2123freshDef = commitIf (freshLine >> (letter <|> char '_')) $ do
2224 freshLine
@@ -25,15 +27,21 @@ freshDef = commitIf (freshLine >> (letter <|> char '_')) $ do
2527decls = do d <- Decl.declaration <?> "at least one datatype or variable definition"
2628 (d:) <$> many freshDef
2729
28−program :: OpTable -> String -> Either [P.Doc] (S.Module t v)
29−program table = setupParserWithTable table $ do
30− optional freshLine
31− (names,exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine)
32− is <- (do try (lookAhead $ reserved "import")
33− imports `followedBy` freshLine) <|> return []
34− declarations <- decls
35− optional freshLine ; optional spaces ; eof
36− return $ S.Module names exports is declarations
30+program :: OpTable -> String -> Either [P.Doc] (M.Module D.Declaration)
31+program table src =
32+ do (M.Module names exs ims parseDecls) <- setupParserWithTable table programParser src
33+ decls <- either (\err -> Left [P.text err]) Right (combineAnnotations parseDecls)
34+ return $ M.Module names exs ims decls
35+
36+programParser :: IParser (M.Module D.ParseDeclaration)
37+programParser =
38+ do optional freshLine
39+ (names,exports) <- option (["Main"],[]) (moduleDef `followedBy` freshLine)
40+ is <- (do try (lookAhead $ reserved "import")
41+ imports `followedBy` freshLine) <|> return []
42+ declarations <- decls
43+ optional freshLine ; optional spaces ; eof
44+ return $ M.Module names exports is declarations
3745
3846dependencies :: String -> Either [P.Doc] (String, [String])
3947dependencies =