{-# LANGUAGE FlexibleContexts #-}
module Idris.Package.Parser where
import Idris.CmdOptions
import Idris.Imports
import Idris.Options (Opt)
import Idris.Package.Common
import Idris.Parser (moduleName)
import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier,
identifierWithExtraChars, isEol, lchar,
packageName, parseErrorDoc, reserved, runparser,
someSpace, stringLiteral)
import Control.Applicative
import Control.Monad.State.Strict
import Data.List (union)
import qualified Options.Applicative as Opts
import System.Directory (doesFileExist)
import System.Exit
import System.FilePath (isValid, takeExtension, takeFileName)
import Text.Megaparsec ((<?>))
import qualified Text.Megaparsec as P
import qualified Text.PrettyPrint.ANSI.Leijen as PP
type PParser = Parser PkgDesc
parseDesc :: FilePath -> IO PkgDesc
parseDesc :: FilePath -> IO PkgDesc
parseDesc FilePath
fp = do
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (FilePath -> FilePath
takeExtension FilePath
fp FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== FilePath
".ipkg") (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
unwords [FilePath
"The presented iPKG file does not have a '.ipkg' extension:", FilePath -> FilePath
forall a. Show a => a -> FilePath
show FilePath
fp]
ExitCode -> IO ()
forall a. ExitCode -> IO a
exitWith (Int -> ExitCode
ExitFailure Int
1)
Bool
res <- FilePath -> IO Bool
doesFileExist FilePath
fp
if Bool
res
then do
FilePath
p <- FilePath -> IO FilePath
readFile FilePath
fp
case Parser PkgDesc PkgDesc
-> PkgDesc -> FilePath -> FilePath -> Either ParseError PkgDesc
forall st res.
Parser st res
-> st -> FilePath -> FilePath -> Either ParseError res
runparser Parser PkgDesc PkgDesc
pPkg PkgDesc
defaultPkg FilePath
fp FilePath
p of
Left ParseError
err -> FilePath -> IO PkgDesc
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (Doc -> FilePath
forall a. Show a => a -> FilePath
show (Doc -> FilePath) -> Doc -> FilePath
forall a b. (a -> b) -> a -> b
$ Doc -> Doc
PP.plain (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ ParseError -> Doc
parseErrorDoc ParseError
err)
Right PkgDesc
x -> PkgDesc -> IO PkgDesc
forall (m :: * -> *) a. Monad m => a -> m a
return PkgDesc
x
else do
FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
unwords [ FilePath
"The presented iPKG file does not exist:", FilePath -> FilePath
forall a. Show a => a -> FilePath
show FilePath
fp]
ExitCode -> IO PkgDesc
forall a. ExitCode -> IO a
exitWith (Int -> ExitCode
ExitFailure Int
1)
pPkg :: PParser PkgDesc
pPkg :: Parser PkgDesc PkgDesc
pPkg = do
FilePath -> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (m :: * -> *). Parsing m => FilePath -> m ()
reserved FilePath
"package"
PkgName
p <- PParser PkgName
pPkgName
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (m :: * -> *). Parsing m => m ()
someSpace
(PkgDesc -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((PkgDesc -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ())
-> (PkgDesc -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a b. (a -> b) -> a -> b
$ \PkgDesc
st -> PkgDesc
st { pkgname :: PkgName
pkgname = PkgName
p }
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) [()]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
some StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
pClause
PkgDesc
st <- Parser PkgDesc PkgDesc
forall s (m :: * -> *). MonadState s m => m s
get
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
P.eof
PkgDesc -> Parser PkgDesc PkgDesc
forall (m :: * -> *) a. Monad m => a -> m a
return PkgDesc
st
pPkgName :: PParser PkgName
pPkgName :: PParser PkgName
pPkgName = ((FilePath -> PParser PkgName)
-> (PkgName -> PParser PkgName)
-> Either FilePath PkgName
-> PParser PkgName
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either FilePath -> PParser PkgName
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail PkgName -> PParser PkgName
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either FilePath PkgName -> PParser PkgName)
-> (FilePath -> Either FilePath PkgName)
-> FilePath
-> PParser PkgName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Either FilePath PkgName
pkgName (FilePath -> PParser PkgName)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> PParser PkgName
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
packageName) PParser PkgName -> FilePath -> PParser PkgName
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"PkgName"
filename :: Parsing m => m String
filename :: m FilePath
filename = (do
FilePath
filename <- m FilePath
forall (m :: * -> *). Parsing m => m FilePath
stringLiteral
m FilePath -> m FilePath -> m FilePath
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Name -> FilePath
forall a. Show a => a -> FilePath
show (Name -> FilePath) -> m Name -> m FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [FilePath] -> m Name
forall (m :: * -> *). Parsing m => [FilePath] -> m Name
iName []
case FilePath -> Maybe FilePath
filenameErrorMessage FilePath
filename of
Just FilePath
errorMessage -> FilePath -> m FilePath
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
errorMessage
Maybe FilePath
Nothing -> FilePath -> m FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
filename)
m FilePath -> FilePath -> m FilePath
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> FilePath -> m a
<?> FilePath
"filename"
where
filenameErrorMessage :: FilePath -> Maybe String
filenameErrorMessage :: FilePath -> Maybe FilePath
filenameErrorMessage FilePath
path = (FilePath -> Maybe FilePath)
-> (() -> Maybe FilePath) -> Either FilePath () -> Maybe FilePath
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (Maybe FilePath -> () -> Maybe FilePath
forall a b. a -> b -> a
const Maybe FilePath
forall a. Maybe a
Nothing) (Either FilePath () -> Maybe FilePath)
-> Either FilePath () -> Maybe FilePath
forall a b. (a -> b) -> a -> b
$ do
FilePath -> Either FilePath ()
checkEmpty FilePath
path
FilePath -> Either FilePath ()
checkValid FilePath
path
FilePath -> Either FilePath ()
checkNoDirectoryComponent FilePath
path
where
checkThat :: Bool -> a -> Either a ()
checkThat Bool
ok a
message =
if Bool
ok then () -> Either a ()
forall a b. b -> Either a b
Right () else a -> Either a ()
forall a b. a -> Either a b
Left a
message
checkEmpty :: FilePath -> Either FilePath ()
checkEmpty FilePath
path =
Bool -> FilePath -> Either FilePath ()
forall a. Bool -> a -> Either a ()
checkThat (FilePath
path FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
/= FilePath
"") FilePath
"filename must not be empty"
checkValid :: FilePath -> Either FilePath ()
checkValid FilePath
path =
Bool -> FilePath -> Either FilePath ()
forall a. Bool -> a -> Either a ()
checkThat (FilePath -> Bool
System.FilePath.isValid FilePath
path)
FilePath
"filename must contain only valid characters"
checkNoDirectoryComponent :: FilePath -> Either FilePath ()
checkNoDirectoryComponent FilePath
path =
Bool -> FilePath -> Either FilePath ()
forall a. Bool -> a -> Either a ()
checkThat (FilePath
path FilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
== FilePath -> FilePath
takeFileName FilePath
path)
FilePath
"filename must contain no directory component"
textUntilEol :: Parsing m => m String
textUntilEol :: m FilePath
textUntilEol = m Char -> m FilePath
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many ((Token FilePath -> Bool) -> m (Token FilePath)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
P.satisfy (Bool -> Bool
not (Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Bool
isEol)) m FilePath -> m () -> m FilePath
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
forall (m :: * -> *). Parsing m => m ()
eol m FilePath -> m () -> m FilePath
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* m ()
forall (m :: * -> *). Parsing m => m ()
someSpace
clause :: String -> PParser a -> (PkgDesc -> a -> PkgDesc) -> PParser ()
clause :: FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
name PParser a
p PkgDesc -> a -> PkgDesc
f = do a
value <- FilePath -> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (m :: * -> *). Parsing m => FilePath -> m ()
reserved FilePath
name StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) Char
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char -> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) Char
forall (m :: * -> *). Parsing m => Char -> m Char
lchar Char
'=' StateT PkgDesc (WriterT FC (Parsec Void FilePath)) Char
-> PParser a -> PParser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> PParser a
p PParser a
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> PParser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (m :: * -> *). Parsing m => m ()
someSpace
(PkgDesc -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((PkgDesc -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ())
-> (PkgDesc -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a b. (a -> b) -> a -> b
$ \PkgDesc
st -> PkgDesc -> a -> PkgDesc
f PkgDesc
st a
value
commaSep :: Parsing m => m a -> m [a]
commaSep :: m a -> m [a]
commaSep m a
p = m a -> m Char -> m [a]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
P.sepBy1 m a
p (Char -> m Char
forall (m :: * -> *). Parsing m => Char -> m Char
lchar Char
',')
pOptions :: PParser [Opt]
pOptions :: PParser [Opt]
pOptions = do
FilePath
str <- StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
stringLiteral
case [FilePath] -> ParserResult [Opt]
execArgParserPure (FilePath -> [FilePath]
words FilePath
str) of
Opts.Success [Opt]
a -> [Opt] -> PParser [Opt]
forall (m :: * -> *) a. Monad m => a -> m a
return [Opt]
a
Opts.Failure ParserFailure ParserHelp
e -> FilePath -> PParser [Opt]
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail (FilePath -> PParser [Opt]) -> FilePath -> PParser [Opt]
forall a b. (a -> b) -> a -> b
$ (FilePath, ExitCode) -> FilePath
forall a b. (a, b) -> a
fst ((FilePath, ExitCode) -> FilePath)
-> (FilePath, ExitCode) -> FilePath
forall a b. (a -> b) -> a -> b
$ ParserFailure ParserHelp -> FilePath -> (FilePath, ExitCode)
Opts.renderFailure ParserFailure ParserHelp
e FilePath
""
ParserResult [Opt]
_ -> FilePath -> PParser [Opt]
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
"Unexpected error"
libIdentifier :: Parsing m => m String
libIdentifier :: m FilePath
libIdentifier = FilePath -> m FilePath
forall (m :: * -> *). Parsing m => FilePath -> m FilePath
identifierWithExtraChars FilePath
"_'-."
pClause :: PParser ()
pClause :: StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
pClause = FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"executable" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
filename (\PkgDesc
st FilePath
v -> PkgDesc
st { execout :: Maybe FilePath
execout = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser Name
-> (PkgDesc -> Name -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"main" ([FilePath] -> PParser Name
forall (m :: * -> *). Parsing m => [FilePath] -> m Name
iName []) (\PkgDesc
st Name
v -> PkgDesc
st { idris_main :: Maybe Name
idris_main = Name -> Maybe Name
forall a. a -> Maybe a
Just Name
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"sourcedir" (StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
identifier StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
stringLiteral) (\PkgDesc
st FilePath
v -> PkgDesc
st { sourcedir :: FilePath
sourcedir = FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser [Opt]
-> (PkgDesc -> [Opt] -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"opts" PParser [Opt]
pOptions (\PkgDesc
st [Opt]
v -> PkgDesc
st { idris_opts :: [Opt]
idris_opts = [Opt]
v [Opt] -> [Opt] -> [Opt]
forall a. [a] -> [a] -> [a]
++ PkgDesc -> [Opt]
idris_opts PkgDesc
st })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser [PkgName]
-> (PkgDesc -> [PkgName] -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"pkgs" (PParser PkgName -> PParser [PkgName]
forall (m :: * -> *) a. Parsing m => m a -> m [a]
commaSep (PParser PkgName
pPkgName PParser PkgName
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> PParser PkgName
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (m :: * -> *). Parsing m => m ()
someSpace)) (\PkgDesc
st [PkgName]
ps ->
let pkgs :: [Opt]
pkgs = [FilePath] -> [Opt]
pureArgParser ([FilePath] -> [Opt]) -> [FilePath] -> [Opt]
forall a b. (a -> b) -> a -> b
$ (PkgName -> [FilePath]) -> [PkgName] -> [FilePath]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\PkgName
x -> [FilePath
"-p", PkgName -> FilePath
forall a. Show a => a -> FilePath
show PkgName
x]) [PkgName]
ps
in PkgDesc
st { pkgdeps :: [PkgName]
pkgdeps = [PkgName]
ps [PkgName] -> [PkgName] -> [PkgName]
forall a. Eq a => [a] -> [a] -> [a]
`union` PkgDesc -> [PkgName]
pkgdeps PkgDesc
st
, idris_opts :: [Opt]
idris_opts = [Opt]
pkgs [Opt] -> [Opt] -> [Opt]
forall a. [a] -> [a] -> [a]
++ PkgDesc -> [Opt]
idris_opts PkgDesc
st })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser [Name]
-> (PkgDesc -> [Name] -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"modules" (PParser Name -> PParser [Name]
forall (m :: * -> *) a. Parsing m => m a -> m [a]
commaSep PParser Name
forall (m :: * -> *). Parsing m => m Name
moduleName) (\PkgDesc
st [Name]
v -> PkgDesc
st { modules :: [Name]
modules = PkgDesc -> [Name]
modules PkgDesc
st [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name]
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser [FilePath]
-> (PkgDesc -> [FilePath] -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"libs" (StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> PParser [FilePath]
forall (m :: * -> *) a. Parsing m => m a -> m [a]
commaSep StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
libIdentifier) (\PkgDesc
st [FilePath]
v -> PkgDesc
st { libdeps :: [FilePath]
libdeps = PkgDesc -> [FilePath]
libdeps PkgDesc
st [FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ [FilePath]
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser [FilePath]
-> (PkgDesc -> [FilePath] -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"objs" (StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> PParser [FilePath]
forall (m :: * -> *) a. Parsing m => m a -> m [a]
commaSep StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
identifier) (\PkgDesc
st [FilePath]
v -> PkgDesc
st { objs :: [FilePath]
objs = PkgDesc -> [FilePath]
objs PkgDesc
st [FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ [FilePath]
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser Name
-> (PkgDesc -> Name -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"makefile" ([FilePath] -> PParser Name
forall (m :: * -> *). Parsing m => [FilePath] -> m Name
iName []) (\PkgDesc
st Name
v -> PkgDesc
st { makefile :: Maybe FilePath
makefile = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just (Name -> FilePath
forall a. Show a => a -> FilePath
show Name
v) })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> PParser [Name]
-> (PkgDesc -> [Name] -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"tests" (PParser Name -> PParser [Name]
forall (m :: * -> *) a. Parsing m => m a -> m [a]
commaSep ([FilePath] -> PParser Name
forall (m :: * -> *). Parsing m => [FilePath] -> m Name
iName [])) (\PkgDesc
st [Name]
v -> PkgDesc
st { idris_tests :: [Name]
idris_tests = PkgDesc -> [Name]
idris_tests PkgDesc
st [Name] -> [Name] -> [Name]
forall a. [a] -> [a] -> [a]
++ [Name]
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"version" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkgversion :: Maybe FilePath
pkgversion = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"readme" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkgreadme :: Maybe FilePath
pkgreadme = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"license" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkglicense :: Maybe FilePath
pkglicense = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"homepage" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkghomepage :: Maybe FilePath
pkghomepage = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"sourceloc" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkgsourceloc :: Maybe FilePath
pkgsourceloc = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"bugtracker" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkgbugtracker :: Maybe FilePath
pkgbugtracker = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"brief" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
stringLiteral (\PkgDesc
st FilePath
v -> PkgDesc
st { pkgbrief :: Maybe FilePath
pkgbrief = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"author" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkgauthor :: Maybe FilePath
pkgauthor = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })
StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> FilePath
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
-> (PkgDesc -> FilePath -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
forall a.
FilePath
-> PParser a
-> (PkgDesc -> a -> PkgDesc)
-> StateT PkgDesc (WriterT FC (Parsec Void FilePath)) ()
clause FilePath
"maintainer" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\PkgDesc
st FilePath
v -> PkgDesc
st { pkgmaintainer :: Maybe FilePath
pkgmaintainer = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })