| Copyright | (c) Martin Zeller, 2016 |
|---|---|
| License | BSD2 |
| Maintainer | Martin Zeller <mz.bremerhaven@gmail.com> |
| Stability | experimental |
| Portability | non-portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Text.ABNF.Document
Description
- data Document a = Document Text [Content a]
- data Content a
- = Terminal a
- | NonTerminal (Document a)
- filterDocument :: forall a. (Document a -> Bool) -> Document a -> Maybe (Document a)
- squashDocument :: Monoid a => Document a -> Document a
- squashDocumentOn :: forall a. Monoid a => (Document a -> Bool) -> Document a -> Document a
- squashContent :: Monoid a => [Content a] -> a
- generateParser :: Rule -> Parser (Document Text)
- parseDocument :: Rule -> Text -> Either String (Document Text)
Document types
Re-exported from Text.ABNF.Document.Types
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
| Terminal a | |
| NonTerminal (Document a) |
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 |
Filter documents according to some predicate.
Similar to filter in the Prelude.
squashDocument :: Monoid a => Document a -> Document a Source
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.
Parsing documents
Re-exported from Text.ABNF.Document.Parser
generateParser :: Rule -> Parser (Document Text) Source
Generate an attoparsec parser