git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Errors for multiple module FFI implementations
commit2b71c7822b73461635d535320056021a18ea4b57 authorGary Burgess <gary.burgess@gmail.com> dateThu 14 May 2015, 11:03 (11 years ago) parent911af32
2 files changed+17−9
src/Language/PureScript/Errors.hs+4−6 src/Language/PureScript/Parser/JS.hs+13−3
src/Language/PureScript/Errors.hs+4−6
@@ -55,7 +55,7 @@ data SimpleErrorMessage
5555 | ErrorParsingPrelude P.ParseError
5656 | ErrorParsingModule P.ParseError
5757 | MissingFFIModule ModuleName
58− | MultipleFFIModules ModuleName FilePath FilePath
58+ | MultipleFFIModules ModuleName [FilePath]
5959 | UnnecessaryFFIModule ModuleName FilePath
6060 | InvalidExternsFile FilePath
6161 | CannotGetFileInfo FilePath
@@ -390,11 +390,9 @@ prettyPrintSingleError full e = prettyPrintErrorMessage <$> onTypesInErrorMessag
390390 paras [ line $ "Unnecessary FFI implementations have been provided for module " ++ show mn ++ ": "
391391 , indent . line $ path
392392 ]
393− goSimple (MultipleFFIModules mn path1 path2) =
394− paras [ line $ "Multiple FFI implementations have been provided for module " ++ show mn ++ ": "
395− , indent . line $ path1
396− , indent . line $ path2
397− ]
393+ goSimple (MultipleFFIModules mn paths) =
394+ paras $ [ line $ "Multiple FFI implementations have been provided for module " ++ show mn ++ ": " ]
395+ ++ map (indent . line) paths
398396 goSimple (ErrorParsingPrelude err) =
399397 paras [ line "Error parsing prelude: "
400398 , indent . line . show $ err
src/Language/PureScript/Parser/JS.hs+13−3
@@ -20,8 +20,11 @@ module Language.PureScript.Parser.JS
2020 ) where
2121
2222import Control.Applicative ((*>), (<*))
23−import Control.Monad (msum)
23+import Control.Monad (forM_, when, msum)
2424import Control.Monad.Error.Class (MonadError(..))
25+import Control.Monad.Writer.Class (MonadWriter(..))
26+import Data.Function (on)
27+import Data.List (sortBy, groupBy)
2528import Language.PureScript.Errors
2629import Language.PureScript.Names
2730import Language.PureScript.Parser.Common
@@ -32,13 +35,20 @@ import qualified Text.Parsec as PS
3235
3336type ForeignJS = String
3437
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))
3641parseForeignModulesFromFiles files = do
37− -- TODO: emit MultipleFFIModules error when duplicates are found
3842 foreigns <- parU files $ \(path, file) ->
3943 case findModuleName (lines file) of
4044 Just name -> return (name, (path, file))
4145 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
4252 return $ M.fromList foreigns
4353
4454findModuleName :: [String] -> Maybe ModuleName