@@ -16,15 +16,19 @@
1616
1717module Main where
1818
19−import Control.Monad.IO.Class
2019import Control.Applicative
20+import Control.Monad
2121import Control.Monad.Trans.Class
22+import Control.Monad.Trans.Maybe (MaybeT(..), runMaybeT)
2223
2324import Data.List (nub, isPrefixOf)
2425import Data.Maybe (mapMaybe)
26+import Data.Traversable (traverse)
2527
26−import System.Process
2728import System.Console.Haskeline
29+import System.Directory (findExecutable)
30+import System.Exit
31+import System.Process
2832
2933import qualified Language.PureScript as P
3034import qualified Paths_purescript as Paths
@@ -35,7 +39,7 @@ getPreludeFilename :: IO FilePath
3539getPreludeFilename = Paths.getDataFileName "prelude/prelude.purs"
3640
3741options :: P.Options
38−options = P.Options True False True Nothing True "PS" []
42+options = P.Options True False True (Just "Main") True "PS" []
3943
4044completion :: [P.Module] -> CompletionFunc IO
4145completion ms = completeWord Nothing " \t\n\r" findCompletions
@@ -43,12 +47,12 @@ completion ms = completeWord Nothing " \t\n\r" findCompletions
4347 findCompletions :: String -> IO [Completion]
4448 findCompletions str = do
4549 files <- listFiles str
46− let names = nub $ [ show qual
47− | P.Module moduleName ds <- ms
48− , ident <- mapMaybe getDeclName ds
49− , qual <- [ P.Qualified Nothing ident
50− , P.Qualified (Just (P.ModuleName moduleName)) ident]
51− ]
50+ let names = nub [ show qual
51+ | P.Module moduleName ds <- ms
52+ , ident <- mapMaybe getDeclName ds
53+ , qual <- [ P.Qualified Nothing ident
54+ , P.Qualified (Just (P.ModuleName moduleName)) ident]
55+ ]
5256 let matches = filter (isPrefixOf str) names
5357 return $ map simpleCompletion matches ++ files
5458 getDeclName :: P.Declaration -> Maybe P.Ident
@@ -75,8 +79,12 @@ handleDeclaration loadedModules imports value = do
7579 case P.compile options (loadedModules ++ [m]) of
7680 Left err -> outputStrLn err
7781 Right (js, _, _) -> do
78− output <- liftIO $ readProcess "nodejs" [] js
79− outputStrLn output
82+ process <- lift findNodeProcess
83+ result <- lift $ traverse (\node -> readProcessWithExitCode node [] js) process
84+ case result of
85+ Just (ExitSuccess, out, _) -> outputStrLn out
86+ Just (ExitFailure _, _, err) -> outputStrLn err
87+ Nothing -> outputStrLn "Couldn't find node.js"
8088
8189data Command
8290 = Empty
@@ -108,6 +116,10 @@ loadModule moduleFile = do
108116 moduleText <- U.readFile moduleFile
109117 return . either (Left . show) Right $ P.runIndentParser "" P.parseModules moduleText
110118
119+findNodeProcess :: IO (Maybe String)
120+findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
121+ where names = ["nodejs", "node"]
122+
111123main :: IO ()
112124main = do
113125 preludeFilename <- getPreludeFilename
@@ -121,7 +133,7 @@ main = do
121133 outputStrLn " |_| "
122134 outputStrLn ""
123135 outputStrLn "Expressions are terminated using Ctrl+D"
124− go [P.ProperName "Prelude"] prelude
136+ go [P.ProperName "Prelude", P.ProperName "Eff"] prelude
125137 where
126138 go imports loadedModules = do
127139 cmd <- getCommand