git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Use standard input with -s flag
commit443b866e3341320eeeb3db209e6d581e3c6a3ba2 authorPhil Freeman <paf31@cantab.net> dateThu 26 Dec 2013, 18:31 (13 years ago) parent3059a14
2 files changed+22−7
purescript.cabal+1−1 src/Main.hs+21−6
purescript.cabal+1−1
@@ -1,5 +1,5 @@
11name: purescript
2−version: 0.2.1.2
2+version: 0.2.2
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
src/Main.hs+21−6
@@ -20,12 +20,17 @@ import Control.Applicative
2020import Control.Monad (forM)
2121import System.Exit (exitSuccess, exitFailure)
2222import qualified System.IO.UTF8 as U
23+import Text.Parsec (ParseError)
2324
24−compile :: [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
25+readInput :: Maybe [FilePath] -> IO (Either ParseError [P.Declaration])
26+readInput Nothing = getContents >>= return . P.runIndentParser P.parseDeclarations
27+readInput (Just input) = fmap (fmap concat . sequence) $ forM input $ \inputFile -> do
28+ text <- U.readFile inputFile
29+ return $ P.runIndentParser P.parseDeclarations text
30+
31+compile :: Maybe [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
2532compile input output externs = do
26− asts <- fmap (fmap concat . sequence) $ forM input $ \inputFile -> do
27− text <- U.readFile inputFile
28− return $ P.runIndentParser P.parseDeclarations text
33+ asts <- readInput input
2934 case asts of
3035 Left err -> do
3136 U.print err
@@ -44,8 +49,12 @@ compile input output externs = do
4449 Just filePath -> U.writeFile filePath exts
4550 exitSuccess
4651
52+useStdIn :: Term Bool
53+useStdIn = value . flag $ (optInfo [ "s", "stdin" ])
54+ { optDoc = "Read from standard input" }
55+
4756inputFiles :: Term [FilePath]
48−inputFiles = nonEmpty $ posAny [] $ posInfo
57+inputFiles = value $ posAny [] $ posInfo
4958 { posDoc = "The input .ps files" }
5059
5160outputFile :: Term (Maybe FilePath)
@@ -56,8 +65,14 @@ externsFile :: Term (Maybe FilePath)
5665externsFile = value $ opt Nothing $ (optInfo [ "e", "externs" ])
5766 { optDoc = "The output .e.ps file" }
5867
68+stdInOrInputFiles :: Term (Maybe [FilePath])
69+stdInOrInputFiles = combine <$> useStdIn <*> inputFiles
70+ where
71+ combine False input = Just input
72+ combine True _ = Nothing
73+
5974term :: Term (IO ())
60−term = compile <$> inputFiles <*> outputFile <*> externsFile
75+term = compile <$> stdInOrInputFiles <*> outputFile <*> externsFile
6176
6277termInfo :: TermInfo
6378termInfo = defTI