Skip to content

Commit 1ebc4e3

Browse files
authored
Merge pull request #26 from mlang/Discard
Avoid Discard constraints
2 parents 9781f0a + aef2640 commit 1ebc4e3

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

src/Text/Parsing/StringParser/Combinators.purs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ infixl 3 withError as <?>
6161

6262
-- | Parse a string between opening and closing markers.
6363
between :: forall a open close. Parser open -> Parser close -> Parser a -> Parser a
64-
between open close p = do
65-
open
66-
a <- p
67-
close
68-
pure a
64+
between open close p = open *> p <* close
6965

7066
-- | Parse a value with a default value in case of failure.
7167
option :: forall a. a -> Parser a -> Parser a
@@ -87,9 +83,7 @@ sepBy p sep = sepBy1 p sep <|> pure Nil
8783
sepBy1 :: forall a sep. Parser a -> Parser sep -> Parser (List a)
8884
sepBy1 p sep = do
8985
a <- p
90-
as <- many $ do
91-
sep
92-
p
86+
as <- many $ sep *> p
9387
pure (Cons a as)
9488

9589
-- | Parse zero or more separated values, optionally ending with a separator.
@@ -100,23 +94,17 @@ sepEndBy p sep = sepEndBy1 p sep <|> pure Nil
10094
sepEndBy1 :: forall a sep. Parser a -> Parser sep -> Parser (List a)
10195
sepEndBy1 p sep = do
10296
a <- p
103-
(do sep
97+
(do _ <- sep
10498
as <- sepEndBy p sep
10599
pure (Cons a as)) <|> pure (singleton a)
106100

107101
-- | Parse zero or more separated values, ending with a separator.
108102
endBy1 :: forall a sep. Parser a -> Parser sep -> Parser (List a)
109-
endBy1 p sep = many1 $ do
110-
a <- p
111-
sep
112-
pure a
103+
endBy1 p sep = many1 $ p <* sep
113104

114105
-- | Parse one or more separated values, ending with a separator.
115106
endBy :: forall a sep. Parser a -> Parser sep -> Parser (List a)
116-
endBy p sep = many $ do
117-
a <- p
118-
sep
119-
pure a
107+
endBy p sep = many $ p <* sep
120108

121109
-- | Parse zero or more values separated by a right-associative operator.
122110
chainr :: forall a. Parser a -> Parser (a -> a -> a) -> a -> Parser a

0 commit comments

Comments
 (0)