git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Errors for multiple module FFI implementations
2b71c78Gary Burgess
src/Language/PureScript/Errors.hs+4−6
@@ -55,7 +55,7 @@ data SimpleErrorMessage
55 | ErrorParsingPrelude P.ParseError
55 | ErrorParsingPrelude P.ParseError
56 | ErrorParsingModule P.ParseError
56 | ErrorParsingModule P.ParseError
57 | MissingFFIModule ModuleName
57 | MissingFFIModule ModuleName
58− | MultipleFFIModules ModuleName FilePath FilePath
58+ | MultipleFFIModules ModuleName [FilePath]
59 | UnnecessaryFFIModule ModuleName FilePath
59 | UnnecessaryFFIModule ModuleName FilePath
60 | InvalidExternsFile FilePath
60 | InvalidExternsFile FilePath
61 | CannotGetFileInfo FilePath
61 | CannotGetFileInfo FilePath
@@ -390,11 +390,9 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
390 paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ show mn ++ ": "
390 paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ show mn ++ ": "
391 , indent . line $ path
391 , indent . line $ path
392 ]
392 ]
393− goSimple (MultipleFFIModules mn path1 path2) =
393+ goSimple (MultipleFFIModules mn paths) =
394− paras [ line $ "Multiple FFI implementations have been provided for module " ++ show mn ++ ": "
394+ paras $ [ line $ "Multiple FFI implementations have been provided for module " ++ show mn ++ ": " ]
395− , indent . line $ path1
395+ ++ map (indent . line) paths
396− , indent . line $ path2
397− ]
398 goSimple (ErrorParsingPrelude err) =
396 goSimple (ErrorParsingPrelude err) =
399 paras [ line "Error parsing prelude: "
397 paras [ line "Error parsing prelude: "
400 , indent . line . show $ err
398 , indent . line . show $ err
src/Language/PureScript/Parser/JS.hs+13−3
@@ -20,8 +20,11 @@ module Language.PureScript.Parser.JS
20 ) where
20 ) where
21
21
22import Control.Applicative ((*>), (<*))
22import Control.Applicative ((*>), (<*))
23−import Control.Monad (msum)
23+import Control.Monad (forM_, when, msum)
24import Control.Monad.Error.Class (MonadError(..))
24import Control.Monad.Error.Class (MonadError(..))
25+import Control.Monad.Writer.Class (MonadWriter(..))
26+import Data.Function (on)
27+import Data.List (sortBy, groupBy)
25import Language.PureScript.Errors
28import Language.PureScript.Errors
26import Language.PureScript.Names
29import Language.PureScript.Names
27import Language.PureScript.Parser.Common
30import Language.PureScript.Parser.Common
@@ -32,13 +35,20 @@ import qualified Text.Parsec as PS
32
35
33type ForeignJS = String
36type ForeignJS = String
34
37
35−parseForeignModulesFromFiles :: (MonadError MultipleErrors m, Functor m) => [(FilePath, ForeignJS)] -> m (M.Map ModuleName (FilePath, ForeignJS))
38+parseForeignModulesFromFiles :: (Functor m, MonadError MultipleErrors m, MonadWriter MultipleErrors m)
39+ => [(FilePath, ForeignJS)]
40+ -> m (M.Map ModuleName (FilePath, ForeignJS))
36parseForeignModulesFromFiles files = do
41parseForeignModulesFromFiles files = do
37− -- TODO: emit MultipleFFIModules error when duplicates are found
38 foreigns <- parU files $ \(path, file) ->
42 foreigns <- parU files $ \(path, file) ->
39 case findModuleName (lines file) of
43 case findModuleName (lines file) of
40 Just name -> return (name, (path, file))
44 Just name -> return (name, (path, file))
41 Nothing -> throwError (errorMessage $ ErrorParsingFFIModule path)
45 Nothing -> throwError (errorMessage $ ErrorParsingFFIModule path)
46+ let grouped = groupBy ((==) `on` fst) $ sortBy (compare `on` fst) foreigns
47+ forM_ grouped $ \grp ->
48+ when (length grp > 1) $ do
49+ let mn = fst (head grp)
50+ paths = map (fst . snd) grp
51+ tell $ errorMessage $ MultipleFFIModules mn paths
42 return $ M.fromList foreigns
52 return $ M.fromList foreigns
43
53
44findModuleName :: [String] -> Maybe ModuleName
54findModuleName :: [String] -> Maybe ModuleName