Added invert function. Fixes #60

This commit is contained in:
Gabriel Gonzalez 2015-06-14 17:18:55 -07:00
parent d575bf0949
commit d5e04e14d7

View file

@ -81,6 +81,7 @@ module Turtle.Pattern (
, prefix
, suffix
, has
, invert
, once
, star
, plus
@ -426,6 +427,18 @@ signed p = do
sign <- (char '+' *> pure id) <|> (char '-' *> pure negate) <|> (pure id)
fmap sign p
{-| @(`invert` p)@ succeeds if @p@ fails and fails if @p@ succeeds
>>> match (invert "A") "A"
[]
>>> match (invert "A") "B"
[()]
-}
invert :: Pattern a -> Pattern ()
invert p = Pattern (StateT (\str -> case runStateT (runPattern p) str of
[] -> [((), "")]
_ -> [] ))
{-| Match a `Char`, but return `Text`
>>> match (once (char '1')) "1"