1-----------------------------------------------------------------------------
4-- Copyright : (c) 2013-15 Phil Freeman, Andy Arvanitis, and other contributors
7-- Maintainer : Andy Arvanitis
8-- Stability : experimental
13-----------------------------------------------------------------------------
15{-# LANGUAGE DataKinds #-}
16{-# LANGUAGE FlexibleContexts #-}
17{-# LANGUAGE RecordWildCards #-}
18{-# LANGUAGE TupleSections #-}
22import Control.Applicative
24import Control.Monad.Error.Class (MonadError(..))
25import Control.Monad.Writer.Strict
27import Data.Version (showVersion)
28import qualified Data.Map as M
30import Options.Applicative as Opts
32import System.Exit (exitSuccess, exitFailure)
33import System.IO (hPutStrLn, stderr)
36import qualified Language.PureScript as P
37import qualified Paths_purescript as Paths
42data PCCOptions = PCCOptions
43 { pccmInput :: [FilePath]
44 , pccmForeignInput :: [FilePath]
45 , pccmOutputDir :: FilePath
46 , pccmOpts :: P.Options
47 , pccmUsePrefix :: Bool
50data InputOptions = InputOptions
51 { ioInputFiles :: [FilePath]
54compile :: PCCOptions -> IO ()
55compile (PCCOptions input _ outputDir opts usePrefix) = do
56 when (null input) generateMakefile
57 moduleFiles <- readInput (InputOptions input)
58 case runWriterT (parseInputs moduleFiles []) of
60 hPutStrLn stderr (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
62 Right ((ms, _), warnings) -> do
63 when (P.nonEmpty warnings) $
64 hPutStrLn stderr (P.prettyPrintMultipleWarnings (P.optionsVerboseErrors opts) warnings)
65 let filePathMap = M.fromList $ map (\(fp, P.Module _ _ mn _ _) -> (mn, fp)) ms
66 makeActions = buildMakeActions outputDir filePathMap usePrefix
67 (e, warnings') <- runMake opts $ P.make makeActions (map snd ms)
70 putStrLn (P.prettyPrintMultipleErrors (P.optionsVerboseErrors opts) errs)
72 Right _ -> exitSuccess
74readInput :: InputOptions -> IO [(Either P.RebuildPolicy FilePath, String)]
75readInput InputOptions{..} = forM ioInputFiles $ \inFile -> (Right inFile, ) <$> readUTF8File inFile
77parseInputs :: (Functor m, Applicative m, MonadError P.MultipleErrors m, MonadWriter P.MultipleErrors m)
78 => [(Either P.RebuildPolicy FilePath, String)]
79 -> [(FilePath, P.ForeignJS)]
80 -> m ([(Either P.RebuildPolicy FilePath, P.Module)], M.Map P.ModuleName FilePath)
81parseInputs modules foreigns =
82 (,) <$> P.parseModulesFromFiles (either (const "") id) modules
83 <*> P.parseForeignModulesFromFiles foreigns
85inputFile :: Parser FilePath
86inputFile = strArgument $
88 <> help "The input .purs file(s)"
90inputForeignFile :: Parser FilePath
91inputForeignFile = strOption $
94 <> help "The input .js file(s) providing foreign import implementations"
96outputDirectory :: Parser FilePath
97outputDirectory = strOption $
100 <> Opts.value "output"
102 <> help "The output directory"
104requirePath :: Parser (Maybe FilePath)
105requirePath = optional $ strOption $
107 <> long "require-path"
108 <> help "The path prefix to use for require() calls in the generated code"
113 <> help "Disable tail call optimizations"
115noPrelude :: Parser Bool
118 <> help "Omit the automatic Prelude import"
120noMagicDo :: Parser Bool
123 <> help "Disable the optimization that overloads the do keyword to generate efficient code specifically for the Eff monad."
128 <> help "Skip the optimization phase."
130comments :: Parser Bool
134 <> help "Include comments in the generated code."
136verboseErrors :: Parser Bool
137verboseErrors = switch $
139 <> long "verbose-errors"
140 <> help "Display verbose error messages"
142noPrefix :: Parser Bool
146 <> help "Do not include comment header"
148sourceMaps :: Parser Bool
151 <> help "Generate source maps"
153options :: Parser P.Options
154options = P.Options <$> noTco
159 <*> (not <$> comments)
163pccOptions :: Parser PCCOptions
164pccOptions = PCCOptions <$> many inputFile
165 <*> many inputForeignFile
168 <*> (not <$> noPrefix)
171main = execParser opts >>= compile
173 opts = info (version <*> helper <*> pccOptions) infoModList
174 infoModList = fullDesc <> headerInfo <> footerInfo
175 headerInfo = header "pcc - Compiles PureScript to C++11"
176 footerInfo = footer $ "pcc " ++ showVersion Paths.version
178 version :: Parser (a -> a)
179 version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
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