on master help sign in
Merge pull request #2668 from jfdm/ipkg-file-improvements
b8a8c79Niklas Larsson
CHANGELOG+3
@@ -35,6 +35,9 @@ Tool updates
35------------
35------------
36* Records are now shown as records in :doc, rather than as the underlying
36* Records are now shown as records in :doc, rather than as the underlying
37 datatype
37 datatype
38+* iPKG files have a new option `pkgs` which takes a comma-separated list
39+ of package names that the idris project depends on. This reduces bloat
40+ in the `opts` option with mutliple package declarations.
38
41
39Miscellaneous updates
42Miscellaneous updates
40---------------------
43---------------------
docs/reference/packages.rst+5−2
@@ -44,8 +44,11 @@ Other common fields which may be present in an ``ipkg`` file are:
44+ ``main = <module>``, which takes the name of the main module, and
44+ ``main = <module>``, which takes the name of the main module, and
45 must be present if the executable field is present.
45 must be present if the executable field is present.
46
46
47−+ ``opts = "<idris options>"``, which allows options (such as other
47++ ``opts = "<idris options>"``, which allows options to be passed to
48− packages) to be passed to Idris.
48+ Idris.
49+
50++ ``pkgs = <pkg name> (',' <pkg name>)+``, a comma separated list of
51+ package names that the Idris package requires.
49
52
50Binding to C
53Binding to C
51------------
54------------
src/Pkg/PParser.hs+31−27
@@ -2,7 +2,6 @@
2#if !(MIN_VERSION_base(4,8,0))
2#if !(MIN_VERSION_base(4,8,0))
3{-# LANGUAGE OverlappingInstances #-}
3{-# LANGUAGE OverlappingInstances #-}
4#endif
4#endif
5−
6module Pkg.PParser where
5module Pkg.PParser where
7
6
8import Text.Trifecta hiding (span, charLiteral, natural, symbol, char, string, whiteSpace)
7import Text.Trifecta hiding (span, charLiteral, natural, symbol, char, string, whiteSpace)
@@ -18,21 +17,20 @@ import Control.Applicative
18
17
19import Util.System
18import Util.System
20
19
21−
22type PParser = StateT PkgDesc IdrisInnerParser
20type PParser = StateT PkgDesc IdrisInnerParser
23
21
24−data PkgDesc = PkgDesc { pkgname :: String,
22+data PkgDesc = PkgDesc {
23+ pkgname :: String
25− libdeps :: [String],
24+ , libdeps :: [String]
26− objs :: [String],
25+ , objs :: [String]
27− makefile :: Maybe String,
26+ , makefile :: Maybe String
28− idris_opts :: [Opt],
27+ , idris_opts :: [Opt]
29− sourcedir :: String,
28+ , sourcedir :: String
30− modules :: [Name],
29+ , modules :: [Name]
31− idris_main :: Name,
30+ , idris_main :: Name
32− execout :: Maybe String,
31+ , execout :: Maybe String
33− idris_tests :: [Name]
32+ , idris_tests :: [Name]
34− }
35− deriving Show
33+ } deriving (Show)
36
34
37instance HasLastTokenSpan PParser where
35instance HasLastTokenSpan PParser where
38 getLastTokenSpan = return Nothing
36 getLastTokenSpan = return Nothing
@@ -44,23 +42,25 @@ instance TokenParsing PParser where
44#endif
42#endif
45 someSpace = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
43 someSpace = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
46
44
47−
45+defaultPkg :: PkgDesc
48defaultPkg = PkgDesc "" [] [] Nothing [] "" [] (sUN "") Nothing []
46defaultPkg = PkgDesc "" [] [] Nothing [] "" [] (sUN "") Nothing []
49
47
50parseDesc :: FilePath -> IO PkgDesc
48parseDesc :: FilePath -> IO PkgDesc
51−parseDesc fp = do p <- readFile fp
49+parseDesc fp = do
50+ p <- readFile fp
52− case runparser pPkg defaultPkg fp p of
51+ case runparser pPkg defaultPkg fp p of
53− Failure err -> fail (show err)
52+ Failure err -> fail (show err)
54− Success x -> return x
53+ Success x -> return x
55
54
56pPkg :: PParser PkgDesc
55pPkg :: PParser PkgDesc
56+pPkg = do
57−pPkg = do reserved "package"; p <- fst <$> identifier
57+ reserved "package"; p <- fst <$> identifier
58− st <- get
58+ st <- get
59− put (st { pkgname = p })
59+ put (st { pkgname = p })
60− some pClause
60+ some pClause
61− st <- get
61+ st <- get
62− eof
62+ eof
63− return st
63+ return st
64
64
65pClause :: PParser ()
65pClause :: PParser ()
66pClause = do reserved "executable"; lchar '=';
66pClause = do reserved "executable"; lchar '=';
@@ -80,6 +80,11 @@ pClause = do reserved "executable"; lchar '=';
80 st <- get
80 st <- get
81 let args = pureArgParser (words opts)
81 let args = pureArgParser (words opts)
82 put (st { idris_opts = args })
82 put (st { idris_opts = args })
83+ <|> do reserved "pkgs"; lchar '=';
84+ ps <- sepBy1 (fst <$> identifier) (lchar ',')
85+ st <- get
86+ let pkgs = pureArgParser $ map (\x -> unwords ["-p", x]) ps
87+ put (st {idris_opts = idris_opts st ++ pkgs})
83 <|> do reserved "modules"; lchar '=';
88 <|> do reserved "modules"; lchar '=';
84 ms <- sepBy1 (fst <$> iName []) (lchar ',')
89 ms <- sepBy1 (fst <$> iName []) (lchar ',')
85 st <- get
90 st <- get
@@ -100,4 +105,3 @@ pClause = do reserved "executable"; lchar '=';
100 ts <- sepBy1 (fst <$> iName []) (lchar ',')
105 ts <- sepBy1 (fst <$> iName []) (lchar ',')
101 st <- get
106 st <- get
102 put st { idris_tests = idris_tests st ++ ts }
107 put st { idris_tests = idris_tests st ++ ts }
103−