Skip to content

Commit a198281

Browse files
committedJul 30, 2014
Merge pull request #6 from dancingrobot84/fix-satisfy
Broken satisfy
2 parents fdae3b1 + aeb92a9 commit a198281

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed
 

‎examples/Test.purs

+8-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ exprTest = buildExprParser [[Infix (string "/" >>= \_ -> return (/)) AssocRight]
4646
,[Infix (string "*" >>= \_ -> return (*)) AssocRight]
4747
,[Infix (string "-" >>= \_ -> return (-)) AssocRight]
4848
,[Infix (string "+" >>= \_ -> return (+)) AssocRight]] digit
49-
49+
50+
manySatisfyTest :: Parser String [String]
51+
manySatisfyTest = do
52+
r <- many1 $ satisfy (\s -> s /= "?")
53+
string "?"
54+
return r
55+
5056
main = do
5157
parseTest nested "(((a)))"
5258
parseTest (many (string "a")) "aaa"
@@ -60,3 +66,4 @@ main = do
6066
return as) "a,a,a,"
6167
parseTest opTest "a+b+c"
6268
parseTest exprTest "1*2+3/4-5"
69+
parseTest manySatisfyTest "ab?"

‎src/Text/Parsing/Parser/String.purs

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ char = ParserT $ \s' ->
3434
_ -> { consumed: true, input: drop 1 s', result: Right (charAt 0 s') }
3535

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

4142
whiteSpace :: forall m. (Monad m) => ParserT String m String
4243
whiteSpace = do

0 commit comments

Comments
 (0)
Please sign in to comment.