Skip to content

Commit 6ab282b

Browse files
committed
Merge satisfy changes from master
2 parents a06e466 + a198281 commit 6ab282b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

examples/Test.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ exprTest = buildExprParser [[Infix (string "/" >>= \_ -> return (/)) AssocRight]
4949
,[Infix (string "-" >>= \_ -> return (-)) AssocRight]
5050
,[Infix (string "+" >>= \_ -> return (+)) AssocRight]] digit
5151

52+
manySatisfyTest :: Parser String [String]
53+
manySatisfyTest = do
54+
r <- many1 $ satisfy (\s -> s /= "?")
55+
string "?"
56+
return r
57+
5258
main = do
5359
parseTest nested "(((a)))"
5460
parseTest (many (string "a")) "aaa"
@@ -62,3 +68,4 @@ main = do
6268
return as) "a,a,a,"
6369
parseTest opTest "a+b+c"
6470
parseTest exprTest "1*2+3/4-5"
71+
parseTest manySatisfyTest "ab?"

src/Text/Parsing/Parser/String.purs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ char = ParserT $ \s' ->
3232
_ -> { consumed: true, input: drop 1 s', result: Right (charAt 0 s') }
3333

3434
satisfy :: forall m. (Monad m) => (String -> Boolean) -> ParserT String m String
35-
satisfy f = do
36-
p <- char
37-
if f p then return p else fail "Character did not satisfy predicate"
35+
satisfy f = try do
36+
c <- char
37+
if f c then return c
38+
else fail "Character did not satisfy predicate"
3839

3940
whiteSpace :: forall m. (Monad m) => ParserT String m String
4041
whiteSpace = do

0 commit comments

Comments
 (0)