frontmatter-0.1.0.2: Parses frontmatter as used in Jekyll markdown files.

Safe HaskellNone
LanguageHaskell2010

Data.Frontmatter

Contents

Synopsis

Frontmatter parser

frontmatter :: Parser ByteString Source

A parser for a frontmatter; returns it as a ByteString. Doesn't fail even if it's empty. When it fails; returns a a IResult with the whole input rather than consuming it.

frontmatterYaml :: FromJSON a => Parser a Source

Parses a YAML frontmatter or JSON frontmatter from a ByteString as a Value. Because of how Data.Yaml is implemented using aeson, this will succeed for JSON frontmatters as well as YAML ones.

Utility functions

parseFrontmatter :: ByteString -> Result ByteString Source

Parse a frontmatter from a ByteString returning a Result. Just extracts whatever is on the frontmatter; doesn't care what it is.

parseYamlFrontmatter :: FromJSON a => ByteString -> Result a Source

Parse a frontmatter from a ByteString returning a 'FromJSON a'. Will parse both JSON and YAML.

Re-exports

parse :: Parser a -> ByteString -> Result a

Run a parser.

maybeResult :: Result r -> Maybe r

Convert a Result value to a Maybe value. A Partial result is treated as failure.

eitherResult :: Result r -> Either String r

Convert a Result value to an Either value. A Partial result is treated as failure.

data IResult i r :: * -> * -> *

The result of a parse. This is parameterised over the type i of string that was processed.

This type is an instance of Functor, where fmap transforms the value in a Done result.

Constructors

Fail i [String] String

The parse failed. The i parameter is the input that had not yet been consumed when the failure occurred. The [String] is a list of contexts in which the error occurred. The String is the message describing the error, if any.

Partial (i -> IResult i r)

Supply this continuation with more input so that the parser can resume. To indicate that no more input is available, pass an empty string to the continuation.

Note: if you get a Partial result, do not call its continuation more than once.

Done i r

The parse succeeded. The i parameter is the input that had not yet been consumed (if any) when the parse succeeded.

Instances

Functor (IResult i) 
(Show i, Show r) => Show (IResult i r) 
(NFData i, NFData r) => NFData (IResult i r)