pipes-attoparsec-0.1.0.1: Utilities to convert an Attoparsec parser into a pipe Pipe.

Safe HaskellNone

Control.Proxy.Attoparsec

Contents

Description

This module provides utilities to turn your Attoparsec Parser a b into a Pipe that parses a values into b values as they flow downstream.

See Control.Proxy.Attoparsec.Tutorial for an extensive introduction with examples.

Synopsis

Parsing Pipe

A Pipe that parses a input flowing downstream into b values is made of at least two smaller cooperating Proxys:

  1. parserInputD: Prepares a input received from upstream to be consumed by a downstream parsing Proxy.
  2. parserD: Repeatedly runs a given Parser a b on input a from upstream, and sends b values downstream.

Given a Parser a b named myParser, the simplest way to use these Proxys together is:

 myParsingPipe :: (Proxy p, Monad m, AttoparsecInput a) => Pipe a b m r
 myParsingPipe = parserInputD >-> parserD myParser

In between these two Proxys, you can place other Proxys to handle extraordinary situations like parsing failures or limiting input length. Control.Proxy.Attoparsec.Control exports some useful Proxys that fit this place. If you skip using any of those, the default behavior is that of skipMalformedChunks: to simply ignore all parsing errors and malformed input, and start parsing new input as soon as it's available.

parserInputD :: (Monad m, Proxy p) => ParserStatus a -> p () a (ParserStatus a) (ParserSupply a) m rSource

Proxy turning a values flowing downstream into ParserSupply a values to be consumed by a downstream parsing Proxy.

This Proxy responds with Resume a to any ParserStatus value received from downstream.

parserD :: (Proxy p, Monad m, AttoparsecInput a) => Parser a b -> () -> p (ParserStatus a) (ParserSupply a) () b m rSource

Proxy using the given Parser a b to repeatedly parse pieces of ParserSupply a values flowing downstream into b values.

When more input is needed, a ParserStatus a value reporting the current parsing status is sent upstream, and in exchange a ParserSupply a value is expected, containing more input to be parsed and directives on how to use it (see ParserSupply documentation).

Modules