on master help sign in
Improvements to ipkg files for dependancies.
0d78f19Jan de Muijnck-Hughes
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+39−26
@@ -2,7 +2,13 @@
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−
5+-- ------------------------------------------------------------- [ PParser.hs ]
6+-- Module : PParser.hs
7+-- Copyright : (c) The Idris Community.
8+-- License : see LICENSE
9+--
10+-- The parser for Idris ipkg files.
11+-- -------------------------------------------------------------------- [ EOH ]
6module Pkg.PParser where
12module Pkg.PParser where
7
13
8import Text.Trifecta hiding (span, charLiteral, natural, symbol, char, string, whiteSpace)
14import Text.Trifecta hiding (span, charLiteral, natural, symbol, char, string, whiteSpace)
@@ -18,21 +24,20 @@ import Control.Applicative
18
24
19import Util.System
25import Util.System
20
26
21−
22type PParser = StateT PkgDesc IdrisInnerParser
27type PParser = StateT PkgDesc IdrisInnerParser
23
28
24−data PkgDesc = PkgDesc { pkgname :: String,
29+data PkgDesc = PkgDesc {
30+ pkgname :: String
25− libdeps :: [String],
31+ , libdeps :: [String]
26− objs :: [String],
32+ , objs :: [String]
27− makefile :: Maybe String,
33+ , makefile :: Maybe String
28− idris_opts :: [Opt],
34+ , idris_opts :: [Opt]
29− sourcedir :: String,
35+ , sourcedir :: String
30− modules :: [Name],
36+ , modules :: [Name]
31− idris_main :: Name,
37+ , idris_main :: Name
32− execout :: Maybe String,
38+ , execout :: Maybe String
33− idris_tests :: [Name]
39+ , idris_tests :: [Name]
34− }
35− deriving Show
40+ } deriving (Show)
36
41
37instance HasLastTokenSpan PParser where
42instance HasLastTokenSpan PParser where
38 getLastTokenSpan = return Nothing
43 getLastTokenSpan = return Nothing
@@ -44,23 +49,25 @@ instance TokenParsing PParser where
44#endif
49#endif
45 someSpace = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
50 someSpace = many (simpleWhiteSpace <|> singleLineComment <|> multiLineComment) *> pure ()
46
51
47−
52+defaultPkg :: PkgDesc
48defaultPkg = PkgDesc "" [] [] Nothing [] "" [] (sUN "") Nothing []
53defaultPkg = PkgDesc "" [] [] Nothing [] "" [] (sUN "") Nothing []
49
54
50parseDesc :: FilePath -> IO PkgDesc
55parseDesc :: FilePath -> IO PkgDesc
51−parseDesc fp = do p <- readFile fp
56+parseDesc fp = do
57+ p <- readFile fp
52− case runparser pPkg defaultPkg fp p of
58+ case runparser pPkg defaultPkg fp p of
53− Failure err -> fail (show err)
59+ Failure err -> fail (show err)
54− Success x -> return x
60+ Success x -> return x
55
61
56pPkg :: PParser PkgDesc
62pPkg :: PParser PkgDesc
63+pPkg = do
57−pPkg = do reserved "package"; p <- fst <$> identifier
64+ reserved "package"; p <- fst <$> identifier
58− st <- get
65+ st <- get
59− put (st { pkgname = p })
66+ put (st { pkgname = p })
60− some pClause
67+ some pClause
61− st <- get
68+ st <- get
62− eof
69+ eof
63− return st
70+ return st
64
71
65pClause :: PParser ()
72pClause :: PParser ()
66pClause = do reserved "executable"; lchar '=';
73pClause = do reserved "executable"; lchar '=';
@@ -80,6 +87,11 @@ pClause = do reserved "executable"; lchar '=';
80 st <- get
87 st <- get
81 let args = pureArgParser (words opts)
88 let args = pureArgParser (words opts)
82 put (st { idris_opts = args })
89 put (st { idris_opts = args })
90+ <|> do reserved "pkgs"; lchar '=';
91+ ps <- sepBy1 (fst <$> identifier) (lchar ',')
92+ st <- get
93+ let pkgs = pureArgParser $ map (\x -> unwords ["-p", x]) ps
94+ put (st {idris_opts = idris_opts st ++ pkgs})
83 <|> do reserved "modules"; lchar '=';
95 <|> do reserved "modules"; lchar '=';
84 ms <- sepBy1 (fst <$> iName []) (lchar ',')
96 ms <- sepBy1 (fst <$> iName []) (lchar ',')
85 st <- get
97 st <- get
@@ -101,3 +113,4 @@ pClause = do reserved "executable"; lchar '=';
101 st <- get
113 st <- get
102 put st { idris_tests = idris_tests st ++ ts }
114 put st { idris_tests = idris_tests st ++ ts }
103
115
116+-- -------------------------------------------------------------------- [ EOF ]