summaryrefslogtreecommitdiff
path: root/lib/Hakyll/Web/Template/Internal
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2019-08-30 11:46:13 +0200
committerGitHub <noreply@github.com>2019-08-30 11:46:13 +0200
commit036c583ea243869f05a5a311c90b94943a2b635c (patch)
treeaadee7988980544f84b83d808707080481568cc5 /lib/Hakyll/Web/Template/Internal
parent779fa66c7b1719e071dc3f4d38a4cc2feb9492c6 (diff)
downloadhakyll-036c583ea243869f05a5a311c90b94943a2b635c.tar.gz
Improve error messages
Diffstat (limited to 'lib/Hakyll/Web/Template/Internal')
-rw-r--r--lib/Hakyll/Web/Template/Internal/Element.hs21
1 files changed, 7 insertions, 14 deletions
diff --git a/lib/Hakyll/Web/Template/Internal/Element.hs b/lib/Hakyll/Web/Template/Internal/Element.hs
index f564355..fc77501 100644
--- a/lib/Hakyll/Web/Template/Internal/Element.hs
+++ b/lib/Hakyll/Web/Template/Internal/Element.hs
@@ -7,14 +7,14 @@ module Hakyll.Web.Template.Internal.Element
, TemplateExpr (..)
, TemplateElement (..)
, templateElems
- , readTemplateElems
- , readTemplateElemsFile
+ , parseTemplateElemsFile
) where
--------------------------------------------------------------------------------
-import Control.Applicative ((<|>))
+import Control.Applicative ((<|>), (<*))
import Control.Monad (void)
+import Control.Arrow (left)
import Data.Binary (Binary, get, getWord8, put, putWord8)
import Data.List (intercalate)
import Data.Maybe (isJust)
@@ -107,17 +107,10 @@ instance Binary TemplateExpr where
2 -> StringLiteral <$> get
_ -> error "Hakyll.Web.Template.Internal: Error reading cached template"
-
---------------------------------------------------------------------------------
-readTemplateElems :: String -> [TemplateElement]
-readTemplateElems = readTemplateElemsFile "{literal}"
-
-
--------------------------------------------------------------------------------
-readTemplateElemsFile :: FilePath -> String -> [TemplateElement]
-readTemplateElemsFile file input = case P.parse templateElems file input of
- Left err -> error $ "Cannot parse template: " ++ show err
- Right t -> t
+parseTemplateElemsFile :: FilePath -> String -> Either String [TemplateElement]
+parseTemplateElemsFile file = left (\e -> "Cannot parse template " ++ show e)
+ . P.parse (templateElems <* P.eof) file
--------------------------------------------------------------------------------
@@ -167,7 +160,7 @@ trimOpen = do
--------------------------------------------------------------------------------
trimClose :: P.Parser Bool
trimClose = do
- trimIfR <- P.optionMaybe $ P.try (P.char '-')
+ trimIfR <- P.optionMaybe $ (P.char '-')
void $ P.char '$'
pure $ isJust trimIfR