File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed Expand file tree Collapse file tree 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]
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+
5056main = 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?"
Original file line number Diff line number Diff line change @@ -34,9 +34,10 @@ char = ParserT $ \s' ->
3434 _ -> { consumed: true , input: drop 1 s', result: Right (charAt 0 s') }
3535
3636satisfy :: 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
4142whiteSpace :: forall m . (Monad m ) => ParserT String m String
4243whiteSpace = do
You can’t perform that action at this time.
0 commit comments