purescript 0.2.1.2 → 0.2.2
raw patch · 2 files changed
+22/−7 lines, 2 files
Files
- purescript.cabal +1/−1
- src/Main.hs +21/−6
purescript.cabal view
@@ -1,5 +1,5 @@ name: purescript-version: 0.2.1.2+version: 0.2.2 cabal-version: >=1.8 build-type: Simple license: MIT
src/Main.hs view
@@ -20,12 +20,17 @@ import Control.Monad (forM) import System.Exit (exitSuccess, exitFailure) import qualified System.IO.UTF8 as U+import Text.Parsec (ParseError) -compile :: [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()+readInput :: Maybe [FilePath] -> IO (Either ParseError [P.Declaration])+readInput Nothing = getContents >>= return . P.runIndentParser P.parseDeclarations+readInput (Just input) = fmap (fmap concat . sequence) $ forM input $ \inputFile -> do+ text <- U.readFile inputFile+ return $ P.runIndentParser P.parseDeclarations text++compile :: Maybe [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO () compile input output externs = do- asts <- fmap (fmap concat . sequence) $ forM input $ \inputFile -> do- text <- U.readFile inputFile- return $ P.runIndentParser P.parseDeclarations text+ asts <- readInput input case asts of Left err -> do U.print err@@ -44,8 +49,12 @@ Just filePath -> U.writeFile filePath exts exitSuccess +useStdIn :: Term Bool+useStdIn = value . flag $ (optInfo [ "s", "stdin" ])+ { optDoc = "Read from standard input" }+ inputFiles :: Term [FilePath]-inputFiles = nonEmpty $ posAny [] $ posInfo+inputFiles = value $ posAny [] $ posInfo { posDoc = "The input .ps files" } outputFile :: Term (Maybe FilePath)@@ -56,8 +65,14 @@ externsFile = value $ opt Nothing $ (optInfo [ "e", "externs" ]) { optDoc = "The output .e.ps file" } +stdInOrInputFiles :: Term (Maybe [FilePath])+stdInOrInputFiles = combine <$> useStdIn <*> inputFiles+ where+ combine False input = Just input+ combine True _ = Nothing+ term :: Term (IO ())-term = compile <$> inputFiles <*> outputFile <*> externsFile+term = compile <$> stdInOrInputFiles <*> outputFile <*> externsFile termInfo :: TermInfo termInfo = defTI