git.iko.soy/rowtype-yoga/purescript-native
on ec2c5ea help sign in
70 lines 2.0 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Main
4-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- |
12--
13-----------------------------------------------------------------------------
15module Main where
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
24compile :: [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
25compile 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
29 case asts of
30 Left err -> do
31 U.print err
32 exitFailure
33 Right decls ->
34 case P.compile decls of
35 Left err -> do
36 U.putStrLn err
37 exitFailure
38 Right (js, exts, _) -> do
39 case output of
40 Just path -> U.writeFile path js
41 Nothing -> U.putStrLn js
42 case externs of
43 Nothing -> return ()
44 Just filePath -> U.writeFile filePath exts
45 exitSuccess
47inputFiles :: Term [FilePath]
48inputFiles = nonEmpty $ posAny [] $ posInfo
49 { posDoc = "The input .ps files" }
51outputFile :: Term (Maybe FilePath)
52outputFile = value $ opt Nothing $ (optInfo [ "o", "output" ])
53 { optDoc = "The output .js file" }
55externsFile :: Term (Maybe FilePath)
56externsFile = value $ opt Nothing $ (optInfo [ "e", "externs" ])
57 { optDoc = "The output .e.ps file" }
59term :: Term (IO ())
60term = compile <$> inputFiles <*> outputFile <*> externsFile
62termInfo :: TermInfo
63termInfo = defTI
64 { termName = "psc"
65 , version = "1.0"
66 , termDoc = "Compiles PureScript to Javascript"
67 }
69main :: IO ()
70main = run (term, termInfo)