Skip to content

Commit e3bb00b

Browse files
committed
add notFollowedBy combinator
1 parent 0163961 commit e3bb00b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

docs/Module.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989

9090
manyTill :: forall s a m e. (Monad m) => ParserT s m a -> ParserT s m e -> ParserT s m [a]
9191

92+
notFollowedBy :: forall s a m. (Monad m) => ParserT s m a -> ParserT s m Unit
93+
9294
option :: forall m s a. (Monad m) => a -> ParserT s m a -> ParserT s m a
9395

9496
optionMaybe :: forall m s a. (Functor m, Monad m) => ParserT s m a -> ParserT s m (Maybe a)

src/Text/Parsing/Parser/Combinators.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Data.Either
77

88
import Control.Alt
99
import Control.Alternative
10+
import Control.Apply
1011
import Control.Lazy
1112
import Control.Monad
1213
import Control.Monad.Error.Trans
@@ -120,6 +121,9 @@ lookAhead (ParserT p) = ParserT \s -> do
120121
state <- p s
121122
return state{input = s, consumed = false}
122123

124+
notFollowedBy :: forall s a m. (Monad m) => ParserT s m a -> ParserT s m Unit
125+
notFollowedBy p = try $ (try p *> fail "Negated parser succeeded") <|> return unit
126+
123127
manyTill :: forall s a m e. (Monad m) => ParserT s m a -> ParserT s m e -> ParserT s m [a]
124128
manyTill p end = scan
125129
where

0 commit comments

Comments
 (0)