parsec-permutation 0.1.0.0 → 0.1.1.0
raw patch · 4 files changed
+44/−4 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Text.Parsec.Permutation: runPermParserTill :: Stream s m t => ParsecT s u m end -> PermParser s u m a -> ParsecT s u m a
Files
- README +1/−1
- Text/Parsec/Permutation.hs +21/−2
- parsec-permutation.cabal +1/−1
- tests/PermutationTest.hs +21/−0
README view
@@ -12,5 +12,5 @@ > <*> optionMaybePerm (char 'C' >> char 'D') This parser will return ('A', "BBB", Just 'D') when parsing for example-the strings "BCDABB", "CDBBAB", &etc.+the strings "BCDABB", "CDBBAB", etc.
Text/Parsec/Permutation.hs view
@@ -27,10 +27,11 @@ ---------------------------------------------------------------------------- module Text.Parsec.Permutation- (PermParser, runPermParser, oncePerm, manyPerm, many1Perm,+ (PermParser, runPermParser, runPermParserTill, oncePerm, manyPerm, many1Perm, optionPerm, optionMaybePerm) where +import Control.Monad (void) import Control.Applicative ((<*>), (<$>), Applicative, pure) import Text.Parsec ((<|>), ParsecT, Stream, parserZero, optionMaybe, unexpected) @@ -60,8 +61,26 @@ runPermParser (PermParser value parser) = do result <- optionMaybe parser case result of- Nothing -> maybe (fail "Could not parse all permutations") return value+ Nothing -> fromJustOrFail value Just permParser -> runPermParser permParser++-- | Similar to runPermParser, but attempts parsing permutations only until the+-- given @untilParser@ succeeds (similar to @manyTill@ in Text.Parsec).+runPermParserTill :: Stream s m t+ => ParsecT s u m end -> PermParser s u m a -> ParsecT s u m a+runPermParserTill untilParser (PermParser value parser) =+ do void $ untilParser+ fromJustOrFail value+ <|>+ do result <- optionMaybe parser+ case result of+ Nothing -> unexpected "end of permutation parser"+ Just permParser -> runPermParserTill untilParser permParser++-- Similar to "Data.Maybe.fromJust" but fails with an appropriate error message+fromJustOrFail :: Maybe a -> ParsecT s u m a+fromJustOrFail value =+ maybe (fail "Could not parse all permutations") return value -- | Attempt parsing a value once. Fails if parsing the value succeeds multiple -- times.
parsec-permutation.cabal view
@@ -1,5 +1,5 @@ name: parsec-permutation-version: 0.1.0.0+version: 0.1.1.0 synopsis: Applicative permutation parser for Parsec intended as a replacement for Text.Parsec.Perm. license: BSD3
tests/PermutationTest.hs view
@@ -26,6 +26,27 @@ Left _ -> False Right x -> x == ("qwer", "asdf") +prop_oncePermTill :: Property+prop_oncePermTill = once $+ (requireParse "sdfxa" $ (runPermParserTill (char 'x') $+ (,,,,,) <$> pure 'n'+ <*> oncePerm (char 's')+ <*> oncePerm (char 'f')+ <*> oncePerm (char 'd')+ <*> optionMaybePerm (char 'a')+ <*> optionMaybePerm (char 'x')) <* char 'a')+ == ('n','s','f','d',Nothing,Nothing)++prop_oncePermTill2 :: Property+prop_oncePermTill2 = once $+ (requireParse "sdfax" $ runPermParserTill (char 'x') $+ (,,,,,) <$> pure 'n'+ <*> oncePerm (char 's')+ <*> oncePerm (char 'f')+ <*> oncePerm (char 'd')+ <*> optionMaybePerm (char 'a')+ <*> optionMaybePerm (char 'x')) == ('n','s','f','d',Just 'a',Nothing)+ prop_oncePerm :: Property prop_oncePerm = once $ case parse (runPermParser $ oncePerm $ char 'A') "" "A" of