abnf-0.3.1.0: Parse ABNF and generate parsers for the specified document

Copyright(c) Martin Zeller, 2016
LicenseBSD2
MaintainerMartin Zeller <mz.bremerhaven@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe
LanguageHaskell2010

Text.ABNF.Document

Contents

Description

 

Synopsis

Document types

Re-exported from Text.ABNF.Document.Types

data Document a Source

A Document represents a tree of the parsed input. Directly after parsing, every Rule that was applied, gets a node in the tree.

You can use filterDocument and squashDocumentOn to reduce the tree into a more managable shape.

Constructors

Document Text [Content a] 

Instances

Reducing documents

Re-exported from Text.ABNF.Document.Operations

In most cases, you don't want to work with the full tree of a Document. You can use these cases to filterDocument away any branches you do not need and squashDocumentOn those, where you don't need it as fine-grained.

This is incredibly useful if you have rules that parse single characters.

filterDocument Source

Arguments

:: (Document a -> Bool)

Predicate to check

-> Document a

Document to filter

-> Maybe (Document a)

Returns Nothing if the predicate fails, cascades otherwise

Filter documents according to some predicate. Similar to filter in the Prelude.

squashDocument :: Monoid a => Document a -> Document a Source

Squash all contents of a Document into a single Terminal

squashDocumentOn :: forall a. Monoid a => (Document a -> Bool) -> Document a -> Document a Source

Squash all contents of a Document which matches the predicate See also squashDocument

squashContent :: Monoid a => [Content a] -> a Source

Squash all contents using the Monoid instance of a, cascading into NonTerminals.

lookupDocument Source

Arguments

:: Text

Identifier to search for

-> Document a

Document to search in

-> [Document a] 

Looks up nested Documents with a particular identifier. NB: Will not recurse into matching documents.

Parsing documents

Re-exported from Text.ABNF.Document.Parser

parseDocument Source

Arguments

:: Rule

Rule to parse against

-> Text

Text to parse

-> Either String (Document Text)

Return a String describing the error or the successfully parsed Document.

The format of the String is as returned by attoparsec.

Convenience function to directly parse a Document