incremental-parser: Generic parser library capable of providing partial results from partial input.

[ gpl, library, parsing ] [ Propose Tags ] [ Report a vulnerability ]

This package defines yet another parser combinator library. This one is implemented using the concept of Brzozowski derivatives, tweaked and optimized to work with any monoidal input type. Lists, ByteString, and Text are supported out of the box, as well as any other data type for which the monoid-subclasses package defines instances. If the parser result is also a monoid, its chunks can be extracted incrementally, before the complete input is parsed.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1, 0.2, 0.2.1, 0.2.2, 0.2.3, 0.2.3.1, 0.2.3.2, 0.2.3.3, 0.2.3.4, 0.2.4, 0.2.4.1, 0.2.5, 0.2.5.1, 0.2.5.2, 0.2.5.3, 0.2.5.4, 0.3, 0.3.1, 0.3.1.1, 0.3.2, 0.3.2.1, 0.3.2.2, 0.3.3, 0.4, 0.4.0.1, 0.4.0.2, 0.5, 0.5.0.1, 0.5.0.2, 0.5.0.3, 0.5.0.4, 0.5.0.5, 0.5.1
Change log CHANGELOG.md
Dependencies base (>=4.9 && <5), input-parsers (<0.4), logict (>=0.6 && <0.9), monoid-subclasses (<1.3), parsers (<0.13), rank2classes (>=1.0 && <1.6), transformers (>=0.5 && <0.7) [details]
Tested with ghc >=0
License GPL-3.0-only
Copyright (c) 2011-2023 Mario Blazevic
Author Mario Blazevic
Maintainer blamario@yahoo.com
Category Parsing
Home page https://github.com/blamario/incremental-parser
Source repo head: git clone https://github.com/blamario/incremental-parser
Uploaded by MarioBlazevic at 2023-12-19T15:36:12Z
Distributions Arch:0.5.1, Debian:0.4.0.2, LTSHaskell:0.5.1, NixOS:0.5.1
Reverse Dependencies 5 direct, 10 indirect [details]
Downloads 20875 total (74 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2023-12-19 [all 1 reports]

Readme for incremental-parser-0.5.1

[back to package description]

The incremental-parser library is yet another parser combinator library, providing the usual set of Applicative, Alternative, and Monad combinators. Apart from this, it has four twists that make it unique.

Parsing incrementally

First, the parser is incremental. Not only can it be fed its input in chunks, but in proper circumstances it can also provide its output in parsed chunks. For this to be possible the result type must be a Monoid. The complete parsing result is then a concatenation of the partial results.

In order to make the incremental parsing easier, the combinator set is optimized for monoidal results. Apart from the usual combinators many and some, for example, there are concatMany and concatSome operators.

    many :: Parser s r -> Parser s [r]
    concatMany :: (Monoid s, Monoid r) => Parser s r -> Parser s r

Arbitrary monoidal inputs

The second weirdness, this one shared with Picoparsec, is that the the parser is generic in its input stream type, but this type is parameterized in a holistic way. There is no separate token type. Primitive parsers that need to peek into the input require its type to be an instance of a monoid subclass, from the monoid-subclasses package.

In Parsec:

    string :: Stream s m Char => String -> ParsecT s u m String
    char :: Stream s m Char => Char -> ParsecT s u m Char
    anyToken :: (Stream s m t, Show t) => ParsecT s u m t

In Attoparsec:

    string :: ByteString -> Parser ByteString
    word8 :: Word8 -> Parser Word8
    anyWord8 :: Parser Word8

In incremental-parser and Picoparsec:

    string :: (LeftCancellativeMonoid s, MonoidNull s) => s -> Parser s s
    token :: (Eq s, FactorialMonoid s) => s -> Parser s s
    anyToken :: FactorialMonoid s => Parser s s

Two Alternative alternatives

The library being implemented on the basis of Brzozowski derivatives, it can provide both the symmetric and the left-biased choice, <||> and <<|>. This is the same design choice made by Text.ParserCombinators.ReadP and uu-parsinglib. Parsec and its progeny on the other hand provide only the faster left-biased choice, at some cost to the expressiveness of the combinator language. The standard <|> operator from the Alternative class acts as one or the other of the above, depending on whether the first type parameter of Parser is Symmetric or LeftBiasedLocal.

MonadFix and record

Finally, the parser is an instance of the MonadFix class. Beware of its power. In particular, never ever try to mfix a strict function. This will hang. The argument of mfix takes the value constructed by the argument parser at the very same input position it's looking at. The best and probably the only safe and useful argument to mfix is the record function. See the construct library for examples.