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

Copyright (c) Martin Zeller, 2016 BSD2 Martin Zeller experimental non-portable Safe Haskell2010

Text.ABNF.Document

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 [Document a] Terminal a

Instances

 Source # Methodsfmap :: (a -> b) -> Document a -> Document b #(<\$) :: a -> Document b -> Document a # Eq a => Eq (Document a) Source # Methods(==) :: Document a -> Document a -> Bool #(/=) :: Document a -> Document a -> Bool # Show a => Show (Document a) Source # MethodsshowsPrec :: Int -> Document a -> ShowS #show :: Document a -> String #showList :: [Document a] -> ShowS #

# 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.

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

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.

Arguments

 :: Text Identifier to search for -> Document a Document to search in -> [Document a]

Similar to lookupDocument, lookupDocument' will find a Document with a particular identifier. This, however, will only find immediate children and will not recurse.

# Parsing documents

Re-exported from Text.ABNF.Document.Parser

generateParser :: Rule -> Parser (Document Text) Source #

Generate an attoparsec parser

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