@@ -10,6 +10,7 @@ module Idris.Package.Parser where
11import Idris.CmdOptions
11import Idris.CmdOptions
12import Idris.Imports
12import Idris.Imports
13+import Idris.Options (Opt)
13import Idris.Package.Common
14import Idris.Package.Common
14import Idris.Parser (moduleName)
15import Idris.Parser (moduleName)
15import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier, isEol,
16import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier, isEol,
@@ -19,6 +20,7 @@ import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier, isEol,
19import Control.Applicative
20import Control.Applicative
20import Control.Monad.State.Strict
21import Control.Monad.State.Strict
21import Data.List (union)
22import Data.List (union)
23+import qualified Options.Applicative as Opts
22import System.Directory (doesFileExist)
24import System.Directory (doesFileExist)
23import System.Exit
25import System.Exit
24import System.FilePath (isValid, takeExtension, takeFileName)
26import System.FilePath (isValid, takeExtension, takeFileName)
@@ -109,11 +111,19 @@ clause name p f = do value <- reserved name *> lchar '=' *> p <* someSpace
109commaSep :: Parsing m => m a -> m [a]
111commaSep :: Parsing m => m a -> m [a]
110commaSep p = P.sepBy1 p (lchar ',')
112commaSep p = P.sepBy1 p (lchar ',')
114+pOptions :: PParser [Opt]
116+ str <- stringLiteral
117+ case execArgParserPure (words str) of
118+ Opts.Success a -> return a
119+ Opts.Failure e -> fail $ fst $ Opts.renderFailure e ""
120+ _ -> fail "Unexpected error"
112pClause :: PParser ()
122pClause :: PParser ()
113pClause = clause "executable" filename (\st v -> st { execout = Just v })
123pClause = clause "executable" filename (\st v -> st { execout = Just v })
114 <|> clause "main" (iName []) (\st v -> st { idris_main = Just v })
124 <|> clause "main" (iName []) (\st v -> st { idris_main = Just v })
115 <|> clause "sourcedir" identifier (\st v -> st { sourcedir = v })
125 <|> clause "sourcedir" identifier (\st v -> st { sourcedir = v })
116− <|> clause "opts" (pureArgParser . words <$> stringLiteral) (\st v -> st { idris_opts = v ++ idris_opts st })
126+ <|> clause "opts" pOptions (\st v -> st { idris_opts = v ++ idris_opts st })
117 <|> clause "pkgs" (commaSep (pPkgName <* someSpace)) (\st ps ->
127 <|> clause "pkgs" (commaSep (pPkgName <* someSpace)) (\st ps ->
118 let pkgs = pureArgParser $ concatMap (\x -> ["-p", show x]) ps
128 let pkgs = pureArgParser $ concatMap (\x -> ["-p", show x]) ps
119 in st { pkgdeps = ps `union` pkgdeps st
129 in st { pkgdeps = ps `union` pkgdeps st