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]
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+
5258main = 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?"
Original file line number Diff line number Diff line change @@ -32,9 +32,10 @@ char = ParserT $ \s' ->
3232 _ -> { consumed: true , input: drop 1 s', result: Right (charAt 0 s') }
3333
3434satisfy :: 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
3940whiteSpace :: forall m . (Monad m ) => ParserT String m String
4041whiteSpace = do
You can’t perform that action at this time.
0 commit comments