summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenzo <lortabac@gmx.com>2016-07-22 16:37:18 +0200
committerLorenzo <lortabac@gmx.com>2016-07-22 16:37:18 +0200
commit3d713e9f2c08dc40e67340b9e6717bb6f6adb20c (patch)
treea47e54995a9ab68fee09516f33f7358c2f087069
parent72d2b11efe4580fd0632f1037e8b0dd04da2999a (diff)
downloadhakyll-3d713e9f2c08dc40e67340b9e6717bb6f6adb20c.tar.gz
Fail if template is not parsed until eof
This should fix the second problem in #376.
-rw-r--r--src/Hakyll/Web/Template/Internal.hs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/Hakyll/Web/Template/Internal.hs b/src/Hakyll/Web/Template/Internal.hs
index 45db2e4..aa8e080 100644
--- a/src/Hakyll/Web/Template/Internal.hs
+++ b/src/Hakyll/Web/Template/Internal.hs
@@ -120,15 +120,22 @@ instance Binary TemplateExpr where
--------------------------------------------------------------------------------
readTemplate :: String -> Template
-readTemplate input = case P.parse template "" input of
+readTemplate input = case P.parse topLevelTemplate "" input of
Left err -> error $ "Cannot parse template: " ++ show err
Right t -> t
+--------------------------------------------------------------------------------
+topLevelTemplate :: P.Parser Template
+topLevelTemplate = Template <$>
+ P.manyTill templateElement P.eof
--------------------------------------------------------------------------------
template :: P.Parser Template
-template = Template <$>
- (P.many $ chunk <|> escaped <|> conditional <|> for <|> partial <|> expr)
+template = Template <$> P.many templateElement
+
+--------------------------------------------------------------------------------
+templateElement :: P.Parser TemplateElement
+templateElement = chunk <|> escaped <|> conditional <|> for <|> partial <|> expr
--------------------------------------------------------------------------------