Commit e2978f5b authored by Oleg Grenrus's avatar Oleg Grenrus
Browse files

Add simpleParsecBS and use it in scanSpecVersion

parent 8a569d87
...@@ -54,7 +54,7 @@ import Distribution.PackageDescription ...@@ -54,7 +54,7 @@ import Distribution.PackageDescription
import Distribution.PackageDescription.Configuration (freeVars) import Distribution.PackageDescription.Configuration (freeVars)
import Distribution.PackageDescription.FieldGrammar import Distribution.PackageDescription.FieldGrammar
import Distribution.PackageDescription.Quirks (patchQuirks) import Distribution.PackageDescription.Quirks (patchQuirks)
import Distribution.Parsec (parsec, simpleParsec) import Distribution.Parsec (parsec, simpleParsecBS)
import Distribution.Parsec.FieldLineStream (fieldLineStreamFromBS) import Distribution.Parsec.FieldLineStream (fieldLineStreamFromBS)
import Distribution.Parsec.Newtypes (CommaFSep, List, SpecVersion (..), Token) import Distribution.Parsec.Newtypes (CommaFSep, List, SpecVersion (..), Token)
import Distribution.Parsec.Position (Position (..), zeroPos) import Distribution.Parsec.Position (Position (..), zeroPos)
...@@ -859,7 +859,7 @@ scanSpecVersion bs = do ...@@ -859,7 +859,7 @@ scanSpecVersion bs = do
-- --
-- This is currently more tolerant regarding leading 0 digits. -- This is currently more tolerant regarding leading 0 digits.
-- --
ver <- simpleParsec (BS8.unpack vers) ver <- simpleParsecBS vers
guard $ case versionNumbers ver of guard $ case versionNumbers ver of
[_,_] -> True [_,_] -> True
[_,_,_] -> True [_,_,_] -> True
......
...@@ -10,6 +10,7 @@ module Distribution.Parsec ( ...@@ -10,6 +10,7 @@ module Distribution.Parsec (
runParsecParser, runParsecParser,
runParsecParser', runParsecParser',
simpleParsec, simpleParsec,
simpleParsecBS,
simpleParsec', simpleParsec',
simpleParsecW', simpleParsecW',
lexemeParsec, lexemeParsec,
...@@ -50,7 +51,8 @@ import Data.List (transpose) ...@@ -50,7 +51,8 @@ import Data.List (transpose)
import Distribution.CabalSpecVersion import Distribution.CabalSpecVersion
import Distribution.Compat.Prelude import Distribution.Compat.Prelude
import Distribution.Parsec.Error (PError (..), showPError) import Distribution.Parsec.Error (PError (..), showPError)
import Distribution.Parsec.FieldLineStream (FieldLineStream, fieldLineStreamFromString) import Data.ByteString (ByteString)
import Distribution.Parsec.FieldLineStream (FieldLineStream, fieldLineStreamFromString, fieldLineStreamFromBS)
import Distribution.Parsec.Position (Position (..), incPos, retPos, showPos, zeroPos) import Distribution.Parsec.Position (Position (..), incPos, retPos, showPos, zeroPos)
import Distribution.Parsec.Warning (PWarnType (..), PWarning (..), showPWarning) import Distribution.Parsec.Warning (PWarnType (..), PWarning (..), showPWarning)
import Numeric (showIntAtBase) import Numeric (showIntAtBase)
...@@ -176,6 +178,13 @@ simpleParsec ...@@ -176,6 +178,13 @@ simpleParsec
. runParsecParser lexemeParsec "<simpleParsec>" . runParsecParser lexemeParsec "<simpleParsec>"
. fieldLineStreamFromString . fieldLineStreamFromString
-- | Like 'simpleParsec' but for 'ByteString'
simpleParsecBS :: Parsec a => ByteString -> Maybe a
simpleParsecBS
= either (const Nothing) Just
. runParsecParser lexemeParsec "<simpleParsec>"
. fieldLineStreamFromBS
-- | Parse a 'String' with 'lexemeParsec' using specific 'CabalSpecVersion'. -- | Parse a 'String' with 'lexemeParsec' using specific 'CabalSpecVersion'.
-- --
-- @since 3.4.0.0 -- @since 3.4.0.0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment