summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilFreeman <>2013-12-27 03:30:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2013-12-27 03:30:00 (GMT)
commit77baf77dcf786d88e44810a2421d88678d99c2eb (patch)
tree3ac03ea9d90b3faa4372c592f7c0742cbb8d5b3f
parent88e4f7156ceb7f6c36368b83fd2c0ddf9ece98ea (diff)
version 0.2.20.2.2
-rw-r--r--purescript.cabal2
-rw-r--r--src/Main.hs27
2 files changed, 22 insertions, 7 deletions
diff --git a/purescript.cabal b/purescript.cabal
index dc510dd..2d03365 100644
--- a/purescript.cabal
+++ b/purescript.cabal
@@ -1,5 +1,5 @@
name: purescript
-version: 0.2.1.2
+version: 0.2.2
cabal-version: >=1.8
build-type: Simple
license: MIT
diff --git a/src/Main.hs b/src/Main.hs
index 64a4e69..f9ec73a 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -20,12 +20,17 @@ import Control.Applicative
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 @@ compile input output externs = do
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 :: Term (Maybe FilePath)
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