diff options
| author | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-05-04 11:36:58 +0200 |
|---|---|---|
| committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2013-05-04 11:36:58 +0200 |
| commit | 4100083709a894225717dbe3068f73057e908dd6 (patch) | |
| tree | bd519b91f8e3dcbdab03a5807112997d56d55d75 /src/Hakyll/Core | |
| parent | 28bc3f1f3b98f3bf4c8601af8eb8fa7a9c226ed2 (diff) | |
| download | hakyll-4100083709a894225717dbe3068f73057e908dd6.tar.gz | |
Style changes, move stuff to common parser module
Diffstat (limited to 'src/Hakyll/Core')
| -rw-r--r-- | src/Hakyll/Core/Compiler/Internal.hs | 7 | ||||
| -rw-r--r-- | src/Hakyll/Core/Provider/Metadata.hs | 7 | ||||
| -rw-r--r-- | src/Hakyll/Core/Util/Parser.hs | 25 |
3 files changed, 35 insertions, 4 deletions
diff --git a/src/Hakyll/Core/Compiler/Internal.hs b/src/Hakyll/Core/Compiler/Internal.hs index fbb7528..5b3e466 100644 --- a/src/Hakyll/Core/Compiler/Internal.hs +++ b/src/Hakyll/Core/Compiler/Internal.hs @@ -1,9 +1,9 @@ -------------------------------------------------------------------------------- -- | Internally used compiler module +{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} -{-# LANGUAGE FlexibleInstances #-} -{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE MultiParamTypeClasses #-} module Hakyll.Core.Compiler.Internal ( -- * Types CompilerRead (..) @@ -31,7 +31,7 @@ import Control.Applicative (Alternative (..), Applicative (..), (<$>)) import Control.Exception (SomeException, handle) import Control.Monad (forM_) -import Control.Monad.Error +import Control.Monad.Error (MonadError (..)) import Data.Monoid (Monoid (..)) import Data.Set (Set) import qualified Data.Set as S @@ -149,6 +149,7 @@ instance MonadMetadata Compiler where getMetadata = compilerGetMetadata getMatches = compilerGetMatches + -------------------------------------------------------------------------------- instance MonadError [String] Compiler where throwError = compilerThrow diff --git a/src/Hakyll/Core/Provider/Metadata.hs b/src/Hakyll/Core/Provider/Metadata.hs index 0d94ad7..fe2857a 100644 --- a/src/Hakyll/Core/Provider/Metadata.hs +++ b/src/Hakyll/Core/Provider/Metadata.hs @@ -4,6 +4,9 @@ module Hakyll.Core.Provider.Metadata ( loadMetadata , metadata , page + + -- This parser can be reused in some places + , metadataKey ) where @@ -23,6 +26,7 @@ import Text.Parsec.String (Parser) import Hakyll.Core.Identifier import Hakyll.Core.Metadata import Hakyll.Core.Provider.Internal +import Hakyll.Core.Util.Parser import Hakyll.Core.Util.String @@ -93,7 +97,8 @@ newline = P.string "\n" <|> P.string "\r\n" -- | Parse a single metadata field metadataField :: Parser (String, String) metadataField = do - key <- P.manyTill P.alphaNum $ P.char ':' + key <- metadataKey + _ <- P.char ':' P.skipMany1 inlineSpace <?> "space followed by metadata for: " ++ key value <- P.manyTill P.anyChar newline trailing' <- P.many trailing diff --git a/src/Hakyll/Core/Util/Parser.hs b/src/Hakyll/Core/Util/Parser.hs new file mode 100644 index 0000000..afa72c1 --- /dev/null +++ b/src/Hakyll/Core/Util/Parser.hs @@ -0,0 +1,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"] |
