on master help sign in
Merge pull request #4623 from unalos/4292

Accepting hyphens in libs declaration in ipkg format.

commitbe4390408e81ffe55414e03e70b384d28337a9cf authorNiklas Larsson <metaniklas@gmail.com> dateWed 26 Dec 2018, 14:30 (8 years ago) parentecf297a78cdbb9
2 files changed+19−10
src/Idris/Package/Parser.hs+9−4 src/Idris/Parser/Helpers.hs+10−6
src/Idris/Package/Parser.hs+9−4
@@ -13,9 +13,10 @@ import Idris.Imports
1313import Idris.Options (Opt)
1414import Idris.Package.Common
1515import Idris.Parser (moduleName)
16−import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier, isEol,
17− lchar, packageName, parseErrorDoc, reserved,
18− runparser, someSpace, stringLiteral)
16+import Idris.Parser.Helpers (Parser, Parsing, eol, iName, identifier,
17+ identifierWithExtraChars, isEol, lchar,
18+ packageName, parseErrorDoc, reserved, runparser,
19+ someSpace, stringLiteral)
1920
2021import Control.Applicative
2122import Control.Monad.State.Strict
@@ -119,6 +120,9 @@ pOptions = do
119120 Opts.Failure e -> fail $ fst $ Opts.renderFailure e ""
120121 _ -> fail "Unexpected error"
121122
123+libIdentifier :: Parsing m => m String
124+libIdentifier = identifierWithExtraChars "_'-."
125+
122126pClause :: PParser ()
123127pClause = clause "executable" filename (\st v -> st { execout = Just v })
124128 <|> clause "main" (iName []) (\st v -> st { idris_main = Just v })
@@ -129,7 +133,7 @@ pClause = clause "executable" filename (\st v -> st { execout = Just v })
129133 in st { pkgdeps = ps `union` pkgdeps st
130134 , idris_opts = pkgs ++ idris_opts st })
131135 <|> clause "modules" (commaSep moduleName) (\st v -> st { modules = modules st ++ v })
132− <|> clause "libs" (commaSep identifier) (\st v -> st { libdeps = libdeps st ++ v })
136+ <|> clause "libs" (commaSep libIdentifier) (\st v -> st { libdeps = libdeps st ++ v })
133137 <|> clause "objs" (commaSep identifier) (\st v -> st { objs = objs st ++ v })
134138 <|> clause "makefile" (iName []) (\st v -> st { makefile = Just (show v) })
135139 <|> clause "tests" (commaSep (iName [])) (\st v -> st { idris_tests = idris_tests st ++ v })
@@ -142,3 +146,4 @@ pClause = clause "executable" filename (\st v -> st { execout = Just v })
142146 <|> clause "brief" stringLiteral (\st v -> st { pkgbrief = Just v })
143147 <|> clause "author" textUntilEol (\st v -> st { pkgauthor = Just v })
144148 <|> clause "maintainer" textUntilEol (\st v -> st { pkgmaintainer = Just v })
149+
src/Idris/Parser/Helpers.hs+10−6
@@ -36,6 +36,7 @@ module Idris.Parser.Helpers
3636 , iName
3737 , name
3838 , identifier
39+ , identifierWithExtraChars
3940 , packageName
4041 -- * Access
4142 , accessibility
@@ -269,10 +270,10 @@ reservedIdentifiers = HS.fromList
269270 , "rewrite", "syntax", "then", "total", "using", "where", "with"
270271 ]
271272
272−identifierOrReserved :: Parsing m => m String
273−identifierOrReserved = token $ P.try $ do
273+identifierOrReservedWithExtraChars :: Parsing m => String -> m String
274+identifierOrReservedWithExtraChars extraChars = token $ P.try $ do
274275 c <- P.satisfy isAlpha <|> P.oneOf "_"
275− cs <- P.many (P.satisfy isAlphaNum <|> P.oneOf "_'.")
276+ cs <- P.many (P.satisfy isAlphaNum <|> P.oneOf extraChars)
276277 return $ c : cs
277278
278279char :: Parsing m => Char -> m Char
@@ -295,13 +296,16 @@ reserved name = token $ P.try $ do
295296 P.notFollowedBy (P.satisfy isAlphaNum <|> P.oneOf "_'.") <?> "end of " ++ name
296297
297298-- | Parses an identifier as a token
298−identifier :: Parsing m => m String
299−identifier = P.try $ do
300− ident <- identifierOrReserved
299+identifierWithExtraChars :: Parsing m => String -> m String
300+identifierWithExtraChars extraChars = P.try $ do
301+ ident <- identifierOrReservedWithExtraChars extraChars
301302 when (ident `HS.member` reservedIdentifiers) $ P.unexpected . P.Label . NonEmpty.fromList $ "reserved " ++ ident
302303 when (ident == "_") $ P.unexpected . P.Label . NonEmpty.fromList $ "wildcard"
303304 return ident
304305
306+identifier :: Parsing m => m String
307+identifier = identifierWithExtraChars "_'."
308+
305309-- | Parses an identifier with possible namespace as a name
306310iName :: Parsing m => [String] -> m Name
307311iName bad = maybeWithNS identifier bad <?> "name"