@@ -42,6 +42,7 @@ import Control.Concurrent.Lifted as C
43import Data.List (foldl', sort)
43import Data.List (foldl', sort)
44import Data.Maybe (fromMaybe, catMaybes, isJust)
44import Data.Maybe (fromMaybe, catMaybes, isJust)
45+import Data.Either (partitionEithers)
45import Data.Time.Clock
46import Data.Time.Clock
46import Data.String (fromString)
47import Data.String (fromString)
47import Data.Foldable (for_)
48import Data.Foldable (for_)
@@ -417,11 +418,10 @@ checkForeignDecls m path = do
417 js <- either (errorParsingModule . Bundle.UnableToParseModule) pure $ JS.parse jsStr path
418 js <- either (errorParsingModule . Bundle.UnableToParseModule) pure $ JS.parse jsStr path
419 foreignIdentsStrs <- either errorParsingModule pure $ getExps js
420 foreignIdentsStrs <- either errorParsingModule pure $ getExps js
420− let foreignIdents =
421+ foreignIdents <- either
421− either
422+ errorInvalidForeignIdentifiers
422− (internalError . ("checkForeignDecls: unexpected idents: " ++) . show)
423− S.fromList
423+ (pure . S.fromList)
424− (traverse parseIdent foreignIdentsStrs)
424+ (parseIdents foreignIdentsStrs)
425 let importedIdents = S.fromList $ map fst (CF.moduleForeign m)
425 let importedIdents = S.fromList $ map fst (CF.moduleForeign m)
427 let unusedFFI = foreignIdents S.\\ importedIdents
427 let unusedFFI = foreignIdents S.\\ importedIdents
@@ -443,10 +443,24 @@ checkForeignDecls m path = do
443 getExps :: JS.JSAST -> Either Bundle.ErrorMessage [String]
443 getExps :: JS.JSAST -> Either Bundle.ErrorMessage [String]
444 getExps = Bundle.getExportedIdentifiers (runModuleName mname)
444 getExps = Bundle.getExportedIdentifiers (runModuleName mname)
446+ errorInvalidForeignIdentifiers :: [String] -> SupplyT Make a
447+ errorInvalidForeignIdentifiers =
448+ throwError . mconcat . map (errorMessage . InvalidFFIIdentifier mname)
450+ parseIdents :: [String] -> Either [String] [Ident]
452+ case partitionEithers (map parseIdent strs) of
446 -- TODO: Handling for parenthesised operators should be removed after 0.9.
458 -- TODO: Handling for parenthesised operators should be removed after 0.9.
459+ -- We ignore the error message here, just being told it's an invalid
460+ -- identifier should be enough.
447 parseIdent :: String -> Either String Ident
461 parseIdent :: String -> Either String Ident
448 parseIdent str = try str <|> try ("(" ++ str ++ ")")
462 parseIdent str = try str <|> try ("(" ++ str ++ ")")
450− try s = either (Left . show) Right $ do
464+ try s = either (const (Left str)) Right $ do
451 ts <- PSParser.lex "" s
465 ts <- PSParser.lex "" s
452 PSParser.runTokenParser "" (PSParser.parseIdent <* Parsec.eof) ts
466 PSParser.runTokenParser "" (PSParser.parseIdent <* Parsec.eof) ts