File tree 2 files changed +12
-4
lines changed
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,13 @@ exprTest = buildExprParser [[Infix (string "/" >>= \_ -> return (/)) AssocRight]
46
46
,[Infix (string " *" >>= \_ -> return (*)) AssocRight ]
47
47
,[Infix (string " -" >>= \_ -> return (-)) AssocRight ]
48
48
,[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
+
50
56
main = do
51
57
parseTest nested " (((a)))"
52
58
parseTest (many (string " a" )) " aaa"
@@ -60,3 +66,4 @@ main = do
60
66
return as) " a,a,a,"
61
67
parseTest opTest " a+b+c"
62
68
parseTest exprTest " 1*2+3/4-5"
69
+ parseTest manySatisfyTest " ab?"
Original file line number Diff line number Diff line change @@ -34,9 +34,10 @@ char = ParserT $ \s' ->
34
34
_ -> { consumed: true , input: drop 1 s', result: Right (charAt 0 s') }
35
35
36
36
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"
40
41
41
42
whiteSpace :: forall m . (Monad m ) => ParserT String m String
42
43
whiteSpace = do
You can’t perform that action at this time.
0 commit comments