Skip to content

Commit 088590b

Browse files
authored
Merge pull request #176 from haskell/alternative-many
Alternative.many = many; Alternative.some = many1
2 parents cda16b0 + b15fcc1 commit 088590b

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

ChangeLog.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### 3.1.17.0
2+
3+
- Move `many1 :: ParsecT s u m a -> ParsecT s u m [a]` to `Text.Parsec.Prim`.
4+
Drop `Stream` constraint requirement.
5+
- Implement `Alternative.many/some` using `Text.Parsec.Prim.many/many1`,
6+
instead of default implementation.
7+
18
### 3.1.16.0
29

310
- Add `tokens'` and `string'` combinators which don't consume the prefix.

parsec.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.12
22
name: parsec
3-
version: 3.1.16.1
3+
version: 3.1.17.0
44

55
synopsis: Monadic parser combinators
66
description: Parsec is designed from scratch as an industrial-strength parser

src/Text/Parsec/Combinator.hs

-18
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,6 @@ skipMany p = scan
106106
scan = do{ p; scan } <|> return ()
107107
-}
108108

109-
-- | @many1 p@ applies the parser @p@ /one/ or more times. Returns a
110-
-- list of the returned values of @p@.
111-
--
112-
-- > word = many1 letter
113-
114-
many1 :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m [a]
115-
{-# INLINABLE many1 #-}
116-
many1 p = do{ x <- p; xs <- many p; return (x:xs) }
117-
{-
118-
many p = scan id
119-
where
120-
scan f = do{ x <- p
121-
; scan (\tail -> f (x:tail))
122-
}
123-
<|> return (f [])
124-
-}
125-
126-
127109
-- | @sepBy p sep@ parses /zero/ or more occurrences of @p@, separated
128110
-- by @sep@. Returns a list of values returned by @p@.
129111
--

src/Text/Parsec/Prim.hs

+13
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ module Text.Parsec.Prim
6161
, many
6262
, skipMany
6363
, manyAccum
64+
, many1
6465
, runPT
6566
, runP
6667
, runParserT
@@ -270,6 +271,9 @@ instance Applicative.Alternative (ParsecT s u m) where
270271
empty = mzero
271272
(<|>) = mplus
272273

274+
many = many
275+
some = many1
276+
273277
instance Monad (ParsecT s u m) where
274278
return = Applicative.pure
275279
p >>= f = parserBind p f
@@ -715,6 +719,15 @@ many p
715719
= do xs <- manyAccum (:) p
716720
return (reverse xs)
717721

722+
-- | @many1 p@ applies the parser @p@ /one/ or more times. Returns a
723+
-- list of the returned values of @p@.
724+
--
725+
-- > word = many1 letter
726+
727+
many1 :: ParsecT s u m a -> ParsecT s u m [a]
728+
{-# INLINABLE many1 #-}
729+
many1 p = do{ x <- p; xs <- many p; return (x:xs) }
730+
718731
-- | @skipMany p@ applies the parser @p@ /zero/ or more times, skipping
719732
-- its result.
720733
--

0 commit comments

Comments
 (0)