Skip to content

Commit ecf36ef

Browse files
authored
Merge pull request #47 from mlang/Discard
Avoid Discard constraints
2 parents 2511d02 + 3940ace commit ecf36ef

File tree

3 files changed

+13
-30
lines changed

3 files changed

+13
-30
lines changed

src/Text/Parsing/Parser/Combinators.purs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,15 @@ infix 3 asErrorMessage as <??>
5252
-- | parens = between (string "(") (string ")")
5353
-- | ```
5454
between :: forall m s a open close. Monad m => ParserT s m open -> ParserT s m close -> ParserT s m a -> ParserT s m a
55-
between open close p = do
56-
open
57-
a <- p
58-
close
59-
pure a
55+
between open close p = open *> p <* close
6056

6157
-- | Provide a default result in the case where a parser fails without consuming input.
6258
option :: forall m s a. Monad m => a -> ParserT s m a -> ParserT s m a
6359
option a p = p <|> pure a
6460

6561
-- | Optionally parse something, failing quietly.
6662
optional :: forall m s a. Monad m => ParserT s m a -> ParserT s m Unit
67-
optional p = (do p
68-
pure unit) <|> pure unit
63+
optional p = (void p) <|> pure unit
6964

7065
-- | pure `Nothing` in the case where a parser fails without consuming input.
7166
optionMaybe :: forall m s a. Monad m => ParserT s m a -> ParserT s m (Maybe a)
@@ -99,9 +94,7 @@ sepBy p sep = sepBy1 p sep <|> pure Nil
9994
sepBy1 :: forall m s a sep. Monad m => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
10095
sepBy1 p sep = do
10196
a <- p
102-
as <- many $ do
103-
sep
104-
p
97+
as <- many $ sep *> p
10598
pure (a : as)
10699

107100
-- | Parse phrases delimited and optionally terminated by a separator.
@@ -112,23 +105,17 @@ sepEndBy p sep = sepEndBy1 p sep <|> pure Nil
112105
sepEndBy1 :: forall m s a sep. Monad m => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
113106
sepEndBy1 p sep = do
114107
a <- p
115-
(do sep
108+
(do _ <- sep
116109
as <- sepEndBy p sep
117110
pure (a : as)) <|> pure (singleton a)
118111

119112
-- | Parse phrases delimited and terminated by a separator, requiring at least one match.
120113
endBy1 :: forall m s a sep. Monad m => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
121-
endBy1 p sep = some $ do
122-
a <- p
123-
sep
124-
pure a
114+
endBy1 p sep = some $ p <* sep
125115

126116
-- | Parse phrases delimited and terminated by a separator.
127117
endBy :: forall m s a sep. Monad m => ParserT s m a -> ParserT s m sep -> ParserT s m (List a)
128-
endBy p sep = many $ do
129-
a <- p
130-
sep
131-
pure a
118+
endBy p sep = many $ p <* sep
132119

133120
-- | Parse phrases delimited by a right-associative operator.
134121
-- |
@@ -189,9 +176,7 @@ notFollowedBy p = try $ (try p *> fail "Negated parser succeeded") <|> pure unit
189176
manyTill :: forall s a m e. Monad m => ParserT s m a -> ParserT s m e -> ParserT s m (List a)
190177
manyTill p end = scan
191178
where
192-
scan = (do
193-
end
194-
pure Nil)
179+
scan = (end $> Nil)
195180
<|> (do
196181
x <- p
197182
xs <- scan

src/Text/Parsing/Parser/String.purs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ whiteSpace = do
7979

8080
-- | Skip whitespace characters.
8181
skipSpaces :: forall s m. (StringLike s, Monad m) => ParserT s m Unit
82-
skipSpaces = do
83-
whiteSpace
84-
pure unit
82+
skipSpaces = void whiteSpace
8583

8684
-- | Match one of the characters in the array.
8785
oneOf :: forall s m. (StringLike s, Monad m) => Array Char -> ParserT s m Char

src/Text/Parsing/Parser/Token.purs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ makeTokenParser (LanguageDef languageDef)
414414

415415
stringEscape :: ParserT String m (Maybe Char)
416416
stringEscape = do
417-
char '\\'
417+
_ <- char '\\'
418418
(escapeGap $> Nothing) <|> (escapeEmpty $> Nothing) <|> (Just <$> escapeCode)
419419

420420
escapeEmpty :: ParserT String m Char
@@ -430,7 +430,7 @@ makeTokenParser (LanguageDef languageDef)
430430

431431
charControl :: ParserT String m Char
432432
charControl = do
433-
char '^'
433+
_ <- char '^'
434434
code <- upper
435435
pure <<< fromCharCode $ toCharCode code - toCharCode 'A' + 1
436436

@@ -537,7 +537,7 @@ makeTokenParser (LanguageDef languageDef)
537537

538538
fraction :: ParserT String m Number
539539
fraction = "fraction" <??> do
540-
char '.'
540+
_ <- char '.'
541541
digits <- Array.some digit <?> "fraction"
542542
maybe (fail "not digit") pure $ foldr op (Just 0.0) digits
543543
where
@@ -549,7 +549,7 @@ makeTokenParser (LanguageDef languageDef)
549549

550550
exponent' :: ParserT String m Number
551551
exponent' = "exponent" <??> do
552-
oneOf ['e', 'E']
552+
_ <- oneOf ['e', 'E']
553553
f <- sign
554554
e <- decimal <?> "exponent"
555555
pure $ power (f e)
@@ -604,7 +604,7 @@ makeTokenParser (LanguageDef languageDef)
604604
where
605605
go :: ParserT String m Unit
606606
go = do
607-
string name
607+
_ <- string name
608608
notFollowedBy languageDef.opLetter <?> "end of " <> name
609609

610610
operator :: ParserT String m String

0 commit comments

Comments
 (0)