The first version of incremental-parser has been released on Hackage [1]. It's yet another parser combinator<br>library, providing the usual set of Applicative and Monad combinators. Apart from this, it has three twists that make it<br>
unique.<br><br> First, the parser is incremental. That means it can be fed its input in chunks, and in proper circumstances it can<br>also provide the parsed output in chunks. For this to be possible the result type must be a Monoid. The complete parsing<br>
result is then a concatenation of the partial results.<br><br> In order to make the incremental parsing easier, the combinator set is optimized for monoidal results. The usual<br>combinator many1, for example, assumes the result type is a monoid and concatenates its components instead of<br>
constructing a list.<br><br>In Parsec:<br>> many1 :: Stream s m t => ParsecT s u m a -> ParsecT s u m [a]<br><br>In incremental-parser:<br>> many1 :: (Monoid s, Monoid r) => Parser s r -> Parser s r<br><br>
<br> The second weirdness is that the the parser is generic in its input stream type, but this type is parameterized in a<br>holistic way. There is no separate token type. Primitive parsers that need to peek into the input require its type to be<br>
an instance of a monoid subclass.<br><br>In Parsec:<br>> string :: Stream s m Char => String -> ParsecT s u m String<br>> char :: Stream s m Char => Char -> ParsecT s u m Char<br>> anyToken :: (Stream s m t, Show t) => ParsecT s u m t<br>
<br>In Attoparsec:<br>> string :: ByteString -> Parser ByteString<br>> word8 :: Word8 -> Parser Word8<br>> anyWord8 :: Parser Word8<br><br>In incremental-parser:<br>> string :: (LeftCancellativeMonoid s, MonoidNull s) => s -> Parser s s<br>
> token :: (Eq s, FactorialMonoid s) => s -> Parser s s<br>> anyToken :: FactorialMonoid s => Parser s s<br><br> The monoid subclasses referenced above provide methods for analyzing and subdividing the input stream. The classes<br>
are not particularly demanding, and any reasonable input stream should be able to accommodate them easily. The library<br>comes with instances for lists, ByteString, and Text.<br><br>> class Monoid m => MonoidNull m where<br>
> mnull :: m -> Bool<br><br>> class Monoid m => LeftCancellativeMonoid m where<br>> mstripPrefix :: m -> m -> Maybe m<br><br>> class Monoid m => FactorialMonoid m where<br>> factors :: m -> [m]<br>
> primePrefix :: m -> m<br>> ...<br><br><br> Finally, the library being implemented on the basis of Brzozowski derivatives, it can provide both the symmetric and<br>the left-biased choice, <|> and <<|>. This is the same design choice made by Text.ParserCombinators.ReadP and<br>
uu-parsinglib. Parsec and its progeny on the other hand provide only the faster left-biased choice, at some cost to the<br>expressiveness of the combinator language.<br><br>[1] <a href="http://hackage.haskell.org/package/incremental-parser-0.1">http://hackage.haskell.org/package/incremental-parser-0.1</a><br>
<br>