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)
24import qualified Paths_purescript as Paths
25import Data.Version (showVersion)
27preludeFilename :: IO FilePath
28preludeFilename = Paths.getDataFileName "libraries/prelude/prelude.purs"
30readInput :: Maybe [FilePath] -> IO (Either ParseError [P.Module])
31readInput Nothing = getContents >>= return . P.runIndentParser P.parseModules
32readInput (Just input) = fmap (fmap concat . sequence) $ forM input $ \inputFile -> do
33 text <- U.readFile inputFile
34 return $ P.runIndentParser P.parseModules text
36compile :: P.Options -> Maybe [FilePath] -> Maybe FilePath -> Maybe FilePath -> IO ()
37compile opts input output externs = do
38 modules <- readInput input
44 case P.compile opts ms of
48 Right (js, exts, _) -> do
50 Just path -> U.writeFile path js
51 Nothing -> U.putStrLn js
54 Just filePath -> U.writeFile filePath exts
58useStdIn = value . flag $ (optInfo [ "s", "stdin" ])
59 { optDoc = "Read from standard input" }
61inputFiles :: Term [FilePath]
62inputFiles = value $ posAny [] $ posInfo
63 { posDoc = "The input .ps files" }
65outputFile :: Term (Maybe FilePath)
66outputFile = value $ opt Nothing $ (optInfo [ "o", "output" ])
67 { optDoc = "The output .js file" }
69externsFile :: Term (Maybe FilePath)
70externsFile = value $ opt Nothing $ (optInfo [ "e", "externs" ])
71 { optDoc = "The output .e.ps file" }
74tco = value $ flag $ (optInfo [ "tco" ])
75 { optDoc = "Perform tail call optimizations" }
77performRuntimeTypeChecks :: Term Bool
78performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
79 { optDoc = "Generate runtime type checks" }
82noPrelude = value $ flag $ (optInfo [ "no-prelude" ])
83 { optDoc = "Omit the Prelude" }
86magicDo = value $ flag $ (optInfo [ "magic-do" ])
87 { optDoc = "Overload the do keyword to generate efficient code specifically for the Eff monad." }
90runMain = value $ flag $ (optInfo [ "run-main" ])
91 { optDoc = "Generate code to run the main method in the Main module." }
93options :: Term P.Options
94options = P.Options <$> tco <*> performRuntimeTypeChecks <*> magicDo <*> runMain
96stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
97stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles
99 combine False True input = Just (prelude : input)
100 combine False False input = Just input
101 combine True _ _ = Nothing
103term :: FilePath -> Term (IO ())
104term prelude = compile <$> options <*> stdInOrInputFiles prelude <*> outputFile <*> externsFile
109 , version = showVersion $ Paths.version
110 , termDoc = "Compiles PureScript to Javascript"
115 prelude <- preludeFilename
116 run (term prelude, 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