File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,12 @@ exprTest = buildExprParser [[Infix (string "/" >>= \_ -> return (/)) AssocRight]
49
49
,[Infix (string " -" >>= \_ -> return (-)) AssocRight ]
50
50
,[Infix (string " +" >>= \_ -> return (+)) AssocRight ]] digit
51
51
52
+ manySatisfyTest :: Parser String [String ]
53
+ manySatisfyTest = do
54
+ r <- many1 $ satisfy (\s -> s /= " ?" )
55
+ string " ?"
56
+ return r
57
+
52
58
main = do
53
59
parseTest nested " (((a)))"
54
60
parseTest (many (string " a" )) " aaa"
@@ -62,3 +68,4 @@ main = do
62
68
return as) " a,a,a,"
63
69
parseTest opTest " a+b+c"
64
70
parseTest exprTest " 1*2+3/4-5"
71
+ parseTest manySatisfyTest " ab?"
Original file line number Diff line number Diff line change @@ -32,9 +32,10 @@ char = ParserT $ \s' ->
32
32
_ -> { consumed: true , input: drop 1 s', result: Right (charAt 0 s') }
33
33
34
34
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"
38
39
39
40
whiteSpace :: forall m . (Monad m ) => ParserT String m String
40
41
whiteSpace = do
You can’t perform that action at this time.
0 commit comments