|
14 | 14 |
|
15 | 15 | {-# LANGUAGE FlexibleContexts #-} |
16 | 16 |
|
17 | | -module Foreign (parseForeignModulesFromFiles) where |
| 17 | +module Language.PureScript.Parser.JS (parseForeignModulesFromFiles) where |
18 | 18 |
|
19 | 19 | import Control.Applicative ((*>), (<*)) |
20 | 20 | import Control.Monad (msum) |
21 | 21 | import Control.Monad.Error.Class (MonadError(..)) |
| 22 | +import Language.PureScript.Errors |
| 23 | +import Language.PureScript.Names |
| 24 | +import Language.PureScript.Parser.Common |
| 25 | +import Language.PureScript.Parser.Lexer |
| 26 | +import Prelude hiding (lex) |
22 | 27 | import qualified Data.Map as M |
23 | | -import qualified Language.PureScript as P |
24 | 28 | import qualified Text.Parsec as PS |
25 | 29 |
|
26 | | -parseForeignModulesFromFiles :: (MonadError P.MultipleErrors m, Functor m) => [(FilePath, String)] -> m (M.Map P.ModuleName String) |
| 30 | +parseForeignModulesFromFiles :: (MonadError MultipleErrors m, Functor m) => [(FilePath, String)] -> m (M.Map ModuleName String) |
27 | 31 | parseForeignModulesFromFiles files = do |
28 | | - foreigns <- P.parU files $ \(path, file) -> |
| 32 | + foreigns <- parU files $ \(path, file) -> |
29 | 33 | case findModuleName (lines file) of |
30 | 34 | Just name -> return (name, file) |
31 | | - Nothing -> throwError (P.errorMessage $ P.ErrorParsingFFIModule path) |
| 35 | + Nothing -> throwError (errorMessage $ ErrorParsingFFIModule path) |
32 | 36 | return $ M.fromList foreigns |
33 | 37 |
|
34 | | -findModuleName :: [String] -> Maybe P.ModuleName |
| 38 | +findModuleName :: [String] -> Maybe ModuleName |
35 | 39 | findModuleName = msum . map parseComment |
36 | 40 | where |
37 | | - parseComment :: String -> Maybe P.ModuleName |
| 41 | + parseComment :: String -> Maybe ModuleName |
38 | 42 | parseComment s = either (const Nothing) Just $ |
39 | | - P.lex "" s >>= P.runTokenParser "" (P.symbol' "//" *> P.reserved "module" *> P.moduleName <* PS.eof) |
| 43 | + lex "" s >>= runTokenParser "" (symbol' "//" *> reserved "module" *> moduleName <* PS.eof) |
0 commit comments