summaryrefslogtreecommitdiff
path: root/src/Hakyll/Parsec.hs
diff options
context:
space:
mode:
authorChris Wells <chris@mathematicaster.org>2025-01-25 14:33:21 -0600
committerChris Wells <chris@mathematicaster.org>2025-01-25 14:33:21 -0600
commitca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb (patch)
treebabd478f4191655b2fa26f584c872fb909363ef1 /src/Hakyll/Parsec.hs
parent39d9569a2561f8ea09170b4371deca130c1ebcf9 (diff)
downloadmain-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.gz
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.bz2
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.lz
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.xz
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.tar.zst
main-ca1d4d3d4371c8175ea6addb1ca1b09c3b56a7bb.zip
Adding templates and cleaning up
Diffstat (limited to 'src/Hakyll/Parsec.hs')
-rw-r--r--src/Hakyll/Parsec.hs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Hakyll/Parsec.hs b/src/Hakyll/Parsec.hs
new file mode 100644
index 0000000..edd7b18
--- /dev/null
+++ b/src/Hakyll/Parsec.hs
@@ -0,0 +1,27 @@
+module Hakyll.Parsec
+ ( compileParsec
+ , compileParsec_
+ , parsecCompiler
+ , parsecCompiler_
+ ) where
+
+import Prolog
+import Hakyll
+import Text.Parsec
+import Text.Parsec.Error
+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 ()