summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Util/Parser.hs
blob: e958b76700e20de3ced9e5c0557bdd0a29dbf29f (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
--------------------------------------------------------------------------------
-- | Parser utilities
module Hakyll.Core.Util.Parser
    ( metadataKey
    , reservedKeys
    ) where


--------------------------------------------------------------------------------
import           Control.Applicative ((<|>))
import           Control.Monad       (mzero)
import qualified Text.Parsec         as P
import           Text.Parsec.String  (Parser)


--------------------------------------------------------------------------------
metadataKey :: Parser String
metadataKey = do
    i <- (:) <$> P.letter <*> (P.many $ P.alphaNum <|> P.oneOf "_-.")
    if i `elem` reservedKeys then mzero else return i


--------------------------------------------------------------------------------
reservedKeys :: [String]
reservedKeys = ["if", "else", "endif", "for", "sep", "endfor", "partial"]