@@ -4,7 +4,6 @@
4module Language.PureScript.Parser.Declarations
4module Language.PureScript.Parser.Declarations
5 ( parseDeclaration
5 ( parseDeclaration
6 , parseModule
6 , parseModule
8 , parseModulesFromFiles
7 , parseModulesFromFiles
9 , parseValue
8 , parseValue
10 , parseGuard
9 , parseGuard
@@ -258,29 +257,31 @@ parseModule = do
258 exports <- P.optionMaybe $ parens $ commaSep1 parseDeclarationRef
257 exports <- P.optionMaybe $ parens $ commaSep1 parseDeclarationRef
259 reserved "where"
258 reserved "where"
260 decls <- mark (P.many (same *> parseDeclaration))
259 decls <- mark (P.many (same *> parseDeclaration))
261 end <- P.getPosition
261 end <- P.getPosition
262 let ss = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos end)
262 let ss = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos end)
263 return $ Module ss comments name decls exports
263 return $ Module ss comments name decls exports
265-- | Parse a collection of modules in parallel
265-- | Parse a collection of modules in parallel
266+parseModulesFromFiles
266−parseModulesFromFiles :: forall m k. (MonadError MultipleErrors m) =>
268+ . MonadError MultipleErrors m
267− (k -> FilePath) -> [(k, String)] -> m [(k, Module)]
269+ => (k -> FilePath)
268−parseModulesFromFiles toFilePath input = do
272+parseModulesFromFiles toFilePath input =
269− modules <- flip parU id $ map wrapError $ inParallel $ flip map input $ \(k, content) -> do
273+ flip parU wrapError . inParallel . flip map input $ \(k, content) -> do
270 let filename = toFilePath k
274 let filename = toFilePath k
271 ts <- lex filename content
275 ts <- lex filename content
272− ms <- runTokenParser filename parseModules ts
276+ m <- runTokenParser filename parseModule ts
273− return (k, ms)
277+ return (k, m)
274− return $ collect modules
276− collect :: [(k, [v])] -> [(k, v)]
277− collect vss = [ (k, v) | (k, vs) <- vss, v <- vs ]
278 wrapError :: Either P.ParseError a -> m a
279 wrapError :: Either P.ParseError a -> m a
279 wrapError = either (throwError . MultipleErrors . pure . toPositionedError) return
280 wrapError = either (throwError . MultipleErrors . pure . toPositionedError) return
280 -- It is enough to force each parse result to WHNF, since success or failure can't be
281 -- It is enough to force each parse result to WHNF, since success or failure can't be
281 -- determined until the end of the file, so this effectively distributes parsing of each file
282 -- determined until the end of the file, so this effectively distributes parsing of each file
282 -- to a different spark.
283 -- 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)]
284 inParallel = withStrategy (parList rseq)
285 inParallel = withStrategy (parList rseq)
@@ -291,12 +292,6 @@ toPositionedError perr = ErrorMessage [ PositionedError (SourceSpan name start e
291 start = (C.toSourcePos . P.errorPos) perr
292 start = (C.toSourcePos . P.errorPos) perr
292 end = start
293 end = start
295−-- Parse a collection of modules
297−parseModules :: TokenParser [Module]
298−parseModules = mark (P.many (same *> parseModule)) <* P.eof
300booleanLiteral :: TokenParser Bool
295booleanLiteral :: TokenParser Bool
301booleanLiteral = (reserved "true" >> return True) P.<|> (reserved "false" >> return False)
296booleanLiteral = (reserved "true" >> return True) P.<|> (reserved "false" >> return False)