1-----------------------------------------------------------------------------
4-- Copyright : (c) Phil Freeman 2013
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
13-----------------------------------------------------------------------------
17import qualified Language.PureScript as P
18import System.Console.CmdTheLine
19import Control.Applicative
20import Control.Monad (forM)
21import System.Exit (exitSuccess, exitFailure)
22import qualified System.IO.UTF8 as U
23import Text.Parsec (ParseError)
25readInput :: Maybe [FilePath] -> IO (Either ParseError [P.Module])
26readInput Nothing = getContents >>= return . P.runIndentParser P.parseModules
27readInput (Just input) = fmap (fmap concat . sequence) $ forM input $ \inputFile -> do
28 text <- U.readFile inputFile
29 return $ P.runIndentParser P.parseModules text
31compile :: P.Options -> Maybe [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
32compile opts input output externs = do
33 modules <- readInput input
39 case P.compile opts ms of
43 Right (js, exts, _) -> do
45 Just path -> U.writeFile path js
46 Nothing -> U.putStrLn js
49 Just filePath -> U.writeFile filePath exts
53useStdIn = value . flag $ (optInfo [ "s", "stdin" ])
54 { optDoc = "Read from standard input" }
56inputFiles :: Term [FilePath]
57inputFiles = value $ posAny [] $ posInfo
58 { posDoc = "The input .ps files" }
60outputFile :: Term (Maybe FilePath)
61outputFile = value $ opt Nothing $ (optInfo [ "o", "output" ])
62 { optDoc = "The output .js file" }
64externsFile :: Term (Maybe FilePath)
65externsFile = value $ opt Nothing $ (optInfo [ "e", "externs" ])
66 { optDoc = "The output .e.ps file" }
69tco = value $ flag $ (optInfo [ "tco" ])
70 { optDoc = "Perform tail call optimizations" }
72performRuntimeTypeChecks :: Term Bool
73performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
74 { optDoc = "Generate runtime type checks" }
76options :: Term P.Options
77options = P.Options <$> tco <*> performRuntimeTypeChecks
79stdInOrInputFiles :: Term (Maybe [FilePath])
80stdInOrInputFiles = combine <$> useStdIn <*> inputFiles
82 combine False input = Just input
83 combine True _ = Nothing
86term = compile <$> options <*> stdInOrInputFiles <*> outputFile <*> externsFile
92 , termDoc = "Compiles PureScript to Javascript"
96main = run (term, termInfo)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list