@@ -4,7 +4,6 @@
44module Language.PureScript.Parser.Declarations
55 ( parseDeclaration
66 , parseModule
7− , parseModules
87 , parseModulesFromFiles
98 , parseValue
109 , parseGuard
@@ -258,29 +257,31 @@ parseModule = do
258257 exports <- P.optionMaybe $ parens $ commaSep1 parseDeclarationRef
259258 reserved "where"
260259 decls <- mark (P.many (same *> parseDeclaration))
260+ _ <- P.eof
261261 end <- P.getPosition
262262 let ss = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos end)
263263 return $ Module ss comments name decls exports
264264
265265-- | Parse a collection of modules in parallel
266−parseModulesFromFiles :: forall m k. (MonadError MultipleErrors m) =>
267− (k -> FilePath) -> [(k, String)] -> m [(k, Module)]
268−parseModulesFromFiles toFilePath input = do
269− modules <- flip parU id $ map wrapError $ inParallel $ flip map input $ \(k, content) -> do
266+parseModulesFromFiles
267+ :: forall m k
268+ . MonadError MultipleErrors m
269+ => (k -> FilePath)
270+ -> [(k, String)]
271+ -> m [(k, Module)]
272+parseModulesFromFiles toFilePath input =
273+ flip parU wrapError . inParallel . flip map input $ \(k, content) -> do
270274 let filename = toFilePath k
271275 ts <- lex filename content
272− ms <- runTokenParser filename parseModules ts
273− return (k, ms)
274− return $ collect modules
276+ m <- runTokenParser filename parseModule ts
277+ return (k, m)
275278 where
276− collect :: [(k, [v])] -> [(k, v)]
277− collect vss = [ (k, v) | (k, vs) <- vss, v <- vs ]
278279 wrapError :: Either P.ParseError a -> m a
279280 wrapError = either (throwError . MultipleErrors . pure . toPositionedError) return
280281 -- It is enough to force each parse result to WHNF, since success or failure can't be
281282 -- determined until the end of the file, so this effectively distributes parsing of each file
282283 -- to a different spark.
283− inParallel :: [Either P.ParseError (k, [Module])] -> [Either P.ParseError (k, [Module])]
284+ inParallel :: [Either P.ParseError (k, a)] -> [Either P.ParseError (k, a)]
284285 inParallel = withStrategy (parList rseq)
285286
286287
@@ -291,12 +292,6 @@ toPositionedError perr = ErrorMessage [ PositionedError (SourceSpan name start e
291292 start = (C.toSourcePos . P.errorPos) perr
292293 end = start
293294
294−-- |
295−-- Parse a collection of modules
296−--
297−parseModules :: TokenParser [Module]
298−parseModules = mark (P.many (same *> parseModule)) <* P.eof
299−
300295booleanLiteral :: TokenParser Bool
301296booleanLiteral = (reserved "true" >> return True) P.<|> (reserved "false" >> return False)
302297