import qualified Data.Ascii as A
import Data.Attoparsec.Char8 as P
import qualified Data.Attoparsec.Lazy as LP
import qualified Data.Ascii as A
import Data.Attoparsec.Char8 as P
import qualified Data.Attoparsec.Lazy as LP
import Language.Haskell.Exts.Pretty
import Language.Haskell.Exts.Syntax
import Network.HTTP.Lucu.MIMEType
import Language.Haskell.Exts.Pretty
import Language.Haskell.Exts.Syntax
import Network.HTTP.Lucu.MIMEType
-- |Read an Apache mime.types and parse it.
parseExtMapFile ∷ FilePath → IO ExtMap
parseExtMapFile fpath
= do file ← B.readFile fpath
-- |Read an Apache mime.types and parse it.
parseExtMapFile ∷ FilePath → IO ExtMap
parseExtMapFile fpath
= do file ← B.readFile fpath
-extMapP ∷ Parser [ (MIMEType, [Text]) ]
-extMapP = do xs ← P.many (comment <|> validLine <|> emptyLine)
- endOfInput
- return $ catMaybes xs
+extMap ∷ Parser [ (MIMEType, [Text]) ]
+extMap = catMaybes <$> P.many (try comment <|> try validLine <|> emptyLine)
where
isSpc ∷ Char → Bool
isSpc c = c ≡ '\x20' ∨ c ≡ '\x09'
comment ∷ Parser (Maybe (MIMEType, [Text]))
where
isSpc ∷ Char → Bool
isSpc c = c ≡ '\x20' ∨ c ≡ '\x09'
comment ∷ Parser (Maybe (MIMEType, [Text]))
skipWhile isSpc
exts ← sepBy extP (skipWhile isSpc)
return $ Just (mime, exts)
skipWhile isSpc
exts ← sepBy extP (skipWhile isSpc)
return $ Just (mime, exts)
extP = decodeUtf8 <$> takeWhile1 (\c → (¬) (isSpc c ∨ c ≡ '\x0A'))
emptyLine ∷ Parser (Maybe (MIMEType, [Text]))
extP = decodeUtf8 <$> takeWhile1 (\c → (¬) (isSpc c ∨ c ≡ '\x0A'))
emptyLine ∷ Parser (Maybe (MIMEType, [Text]))
return Nothing
compile ∷ Ord k ⇒ [(v, [k])] → Either (k, v, v) (Map k v)
return Nothing
compile ∷ Ord k ⇒ [(v, [k])] → Either (k, v, v) (Map k v)
--
-- The module "Network.HTTP.Lucu.MIMEType.DefaultExtensionMap" is
-- surely generated using this function.
serializeExtMap ∷ ExtMap → String → String → String
--
-- The module "Network.HTTP.Lucu.MIMEType.DefaultExtensionMap" is
-- surely generated using this function.
serializeExtMap ∷ ExtMap → String → String → String
= let hsModule = Module (⊥) (ModuleName moduleName) modPragma
Nothing (Just exports) imports decls
modPragma = [ LanguagePragma (⊥) [ name (show OverloadedStrings) ] ]
= let hsModule = Module (⊥) (ModuleName moduleName) modPragma
Nothing (Just exports) imports decls
modPragma = [ LanguagePragma (⊥) [ name (show OverloadedStrings) ] ]
decls = [ TypeSig (⊥) [name variableName]
(TyCon (UnQual (name "ExtMap")))
, nameBind (⊥) (name variableName) extMapExp
decls = [ TypeSig (⊥) [name variableName]
(TyCon (UnQual (name "ExtMap")))
, nameBind (⊥) (name variableName) extMapExp
]
comment = concat [ "{- !!! WARNING !!!\n"
, " This file is automatically generated.\n"
]
comment = concat [ "{- !!! WARNING !!!\n"
, " This file is automatically generated.\n"