Skip to content

Commit

Permalink
Expand elem
Browse files Browse the repository at this point in the history
Doesn't seem to noticeably speed-up e.g. hackage-tests,
but I guess there is no harm in this either
  • Loading branch information
phadej committed Feb 24, 2020
1 parent e6e4e62 commit 1da03c8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Cabal/Distribution/Types/PkgconfigName.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ instance Pretty PkgconfigName where
pretty = Disp.text . unPkgconfigName

instance Parsec PkgconfigName where
parsec = mkPkgconfigName <$> P.munch1 (\c -> isAlphaNum c || c `elem` "+-._")
parsec = mkPkgconfigName <$> P.munch1 isNameChar where
-- https://gitlab.haskell.org/ghc/ghc/issues/17752
isNameChar '-' = True
isNameChar '_' = True
isNameChar '.' = True
isNameChar '+' = True
isNameChar c = isAlphaNum c

instance NFData PkgconfigName where
rnf (PkgconfigName pkg) = rnf pkg
10 changes: 9 additions & 1 deletion Cabal/Distribution/Types/PkgconfigVersionRange.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pkgconfigParser = P.spaces >> expr where
factor = parens expr <|> prim

prim = do
op <- P.munch1 (`elem` "<>=^-") P.<?> "operator"
op <- P.munch1 isOpChar P.<?> "operator"
case op of
"-" -> anyPkgconfigVersion <$ (P.string "any" *> P.spaces)

Expand All @@ -98,6 +98,14 @@ pkgconfigParser = P.spaces >> expr where

_ -> P.unexpected $ "Unknown version operator " ++ show op

-- https://gitlab.haskell.org/ghc/ghc/issues/17752
isOpChar '<' = True
isOpChar '=' = True
isOpChar '>' = True
isOpChar '^' = True
isOpChar '-' = True
isOpChar _ = False

afterOp f = do
P.spaces
v <- parsec
Expand Down
8 changes: 7 additions & 1 deletion Cabal/Distribution/Types/UnitId.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ instance Pretty UnitId where
-- GHC accepts for @-package-id@.
--
instance Parsec UnitId where
parsec = mkUnitId <$> P.munch1 (\c -> isAlphaNum c || c `elem` "-_.+")
parsec = mkUnitId <$> P.munch1 isUnitChar where
-- https://gitlab.haskell.org/ghc/ghc/issues/17752
isUnitChar '-' = True
isUnitChar '_' = True
isUnitChar '.' = True
isUnitChar '+' = True
isUnitChar c = isAlphaNum c

-- | If you need backwards compatibility, consider using 'display'
-- instead, which is supported by all versions of Cabal.
Expand Down
10 changes: 9 additions & 1 deletion Cabal/Distribution/Types/VersionRange/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ versionRangeParser digitParser = expr
factor = parens expr <|> prim

prim = do
op <- P.munch1 (`elem` "<>=^-") P.<?> "operator"
op <- P.munch1 isOpChar P.<?> "operator"
case op of
"-" -> anyVersion <$ P.string "any" <|> P.string "none" *> noVersion'

Expand Down Expand Up @@ -325,6 +325,14 @@ versionRangeParser digitParser = expr
">" -> pure $ laterVersion v
_ -> fail $ "Unknown version operator " ++ show op

-- https://gitlab.haskell.org/ghc/ghc/issues/17752
isOpChar '<' = True
isOpChar '=' = True
isOpChar '>' = True
isOpChar '^' = True
isOpChar '-' = True
isOpChar _ = False

-- Note: There are other features:
-- && and || since 1.8
-- x.y.* (wildcard) since 1.6
Expand Down

0 comments on commit 1da03c8

Please sign in to comment.