{-|
Module      : Idris.Package.Parser
Description : `iPKG` file parser and package description information.

License     : BSD3
Maintainer  : The Idris Community.
-}
{-# 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 fp :: 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
== ".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 ["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 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 err :: 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 x :: 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 [ "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 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 "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
$ \st :: 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
<?> "PkgName"

-- | Parses a filename.
-- |
-- | Treated for now as an identifier or a double-quoted string.
filename :: Parsing m => m String
filename :: m FilePath
filename = (do
                -- Treat a double-quoted string as a filename to support spaces.
                -- This also moves away from tying filenames to identifiers, so
                -- it will also accept hyphens
                -- (https://github.com/idris-lang/Idris-dev/issues/2721)
    FilePath
filename <- m FilePath
forall (m :: * -> *). Parsing m => m FilePath
stringLiteral
                -- Through at least version 0.9.19.1, IPKG executable values were
                -- possibly namespaced identifiers, like foo.bar.baz.
            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 errorMessage :: FilePath
errorMessage -> FilePath -> m FilePath
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail FilePath
errorMessage
      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
<?> "filename"
    where
        -- TODO: Report failing span better! We could lookAhead,
        -- or do something with DeltaParsing?
        filenameErrorMessage :: FilePath -> Maybe String
        filenameErrorMessage :: FilePath -> Maybe FilePath
filenameErrorMessage path :: 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 ok :: Bool
ok message :: 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 path :: 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
/= "") "filename must not be empty"

                checkValid :: FilePath -> Either FilePath ()
checkValid path :: FilePath
path =
                    Bool -> FilePath -> Either FilePath ()
forall a. Bool -> a -> Either a ()
checkThat (FilePath -> Bool
System.FilePath.isValid FilePath
path)
                        "filename must contain only valid characters"

                checkNoDirectoryComponent :: FilePath -> Either FilePath ()
checkNoDirectoryComponent path :: 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)
                        "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 name :: FilePath
name p :: PParser a
p f :: 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 '=' 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
$ \st :: PkgDesc
st -> PkgDesc -> a -> PkgDesc
f PkgDesc
st a
value

commaSep   :: Parsing m => m a -> m [a]
commaSep :: m a -> m [a]
commaSep p :: 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 ',')

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 a :: [Opt]
a -> [Opt] -> PParser [Opt]
forall (m :: * -> *) a. Monad m => a -> m a
return [Opt]
a
    Opts.Failure e :: 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 -> PParser [Opt]
forall (m :: * -> *) a. MonadFail m => FilePath -> m a
fail "Unexpected error"

libIdentifier :: Parsing m => m String
libIdentifier :: m FilePath
libIdentifier = FilePath -> m FilePath
forall (m :: * -> *). Parsing m => FilePath -> m FilePath
identifierWithExtraChars "_'-."

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 "executable" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
filename (\st :: PkgDesc
st v :: 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 "main" ([FilePath] -> PParser Name
forall (m :: * -> *). Parsing m => [FilePath] -> m Name
iName []) (\st :: PkgDesc
st v :: 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 "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) (\st :: PkgDesc
st v :: 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 "opts" PParser [Opt]
pOptions (\st :: PkgDesc
st v :: [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 "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)) (\st :: PkgDesc
st ps :: [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 (\x :: PkgName
x -> ["-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 "modules" (PParser Name -> PParser [Name]
forall (m :: * -> *) a. Parsing m => m a -> m [a]
commaSep PParser Name
forall (m :: * -> *). Parsing m => m Name
moduleName) (\st :: PkgDesc
st v :: [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 "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) (\st :: PkgDesc
st v :: [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 "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) (\st :: PkgDesc
st v :: [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 "makefile" ([FilePath] -> PParser Name
forall (m :: * -> *). Parsing m => [FilePath] -> m Name
iName []) (\st :: PkgDesc
st v :: 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 "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 [])) (\st :: PkgDesc
st v :: [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 "version" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: 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 "readme" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: 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 "license" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: 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 "homepage" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: 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 "sourceloc" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: 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 "bugtracker" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: 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 "brief" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
stringLiteral (\st :: PkgDesc
st v :: 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 "author" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: 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 "maintainer" StateT PkgDesc (WriterT FC (Parsec Void FilePath)) FilePath
forall (m :: * -> *). Parsing m => m FilePath
textUntilEol (\st :: PkgDesc
st v :: FilePath
v -> PkgDesc
st { pkgmaintainer :: Maybe FilePath
pkgmaintainer = FilePath -> Maybe FilePath
forall a. a -> Maybe a
Just FilePath
v })