summaryrefslogtreecommitdiff
path: root/src/Hakyll/Parsec.hs
blob: a1cc7062184880790e3343341a17bae49b893044 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Hakyll.Parsec
    ( compileParsec
    , compileParsec_
    , parsecCompiler
    , parsecCompiler_
    ) where

import Prolog
import Hakyll
import Text.Parsec
import Hakyll.Error

-- evalParsec :: (MonadError [String] m) => Either ParseError a -> m a
-- evalParsec = either (throwError . fmap messageString . errorMessages) pure

compileParsec :: (MonadError [String] m, Stream s Identity t) => Parsec s u a -> u -> Item s -> m (Item a)
compileParsec p u itm@(Item i _) = traverse (liftErr . runParser p u (show i)) itm

compileParsec_ :: (MonadError [String] m, Stream s Identity t) => Parsec s () a -> Item s -> m (Item a)
compileParsec_ p = compileParsec p ()

parsecCompiler :: (Stream s Identity t, StringConv LazyByteString s) => Parsec s u a -> u -> Compiler (Item a)
parsecCompiler p u = getResourceLBS >>= compileParsec p u . fmap toSL

parsecCompiler_ :: (Stream s Identity t, StringConv LazyByteString s) => Parsec s () a -> Compiler (Item a)
parsecCompiler_ p = parsecCompiler p ()