Copyright | (c) Martin Zeller, 2016 |
---|---|
License | BSD2 |
Maintainer | Martin Zeller <mz.bremerhaven@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
- data 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
- lookupDocument :: forall a. Text -> Document a -> [Document a]
- lookupDocument' :: forall a. Text -> Document a -> [Document a]
- getContent :: Monoid a => Document 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.
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.
:: (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.
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
Looks up nested Document
s with a particular identifier.
NB: Will not recurse into matching documents.
Similar to lookupDocument
, lookupDocument'
will find a Document
with
a particular identifier. This, however, will only find immediate children and
will not recurse.
getContent :: Monoid a => Document a -> a Source #
Parsing documents
Re-exported from Text.ABNF.Document.Parser
generateParser :: Rule -> Parser (Document Text) Source #
Generate an attoparsec parser