Fail if template is not parsed until eof

This should fix the second problem in #376.
This commit is contained in:
Lorenzo 2016-07-22 16:37:18 +02:00
parent 72d2b11efe
commit 3d713e9f2c

View file

@ -120,15 +120,22 @@ instance Binary TemplateExpr where
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
readTemplate :: String -> Template 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 Left err -> error $ "Cannot parse template: " ++ show err
Right t -> t Right t -> t
--------------------------------------------------------------------------------
topLevelTemplate :: P.Parser Template
topLevelTemplate = Template <$>
P.manyTill templateElement P.eof
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
template :: P.Parser Template template :: P.Parser Template
template = Template <$> template = Template <$> P.many templateElement
(P.many $ chunk <|> escaped <|> conditional <|> for <|> partial <|> expr)
--------------------------------------------------------------------------------
templateElement :: P.Parser TemplateElement
templateElement = chunk <|> escaped <|> conditional <|> for <|> partial <|> expr
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------