--- |Parse Apache @mime.types@.
-parseExtMap ∷ Lazy.ByteString → ExtMap
-parseExtMap src
- = case LP.parse pairs src of
- LP.Fail _ eCtx e
- → error $ "Unparsable extension map: "
- ⧺ intercalate ", " eCtx
- ⧺ ": "
- ⧺ e
- LP.Done _ xs
- → case compile xs of
- Right m → ExtMap m
- Left e → error ("Duplicate extension: " ⧺ show e)
- where
- pairs ∷ Parser [(MIMEType, [Text])]
- pairs = do skipMany linebreak
- xs ← sepBy pair (skipMany1 linebreak)
- skipMany linebreak
- endOfInput
- return xs
- <?>
- "pairs"
+instance ConvertAttempt Lazy.ByteString ExtMap where
+ convertAttempt src
+ = case LP.parse pairs src of
+ LP.Fail _ eCtx e
+ → fail $ "Unparsable extension map: "
+ ⊕ intercalate ", " eCtx
+ ⊕ ": "
+ ⊕ e
+ LP.Done _ xs
+ → case compile xs of
+ Right m → return $ ExtMap m
+ Left e → fail $ "Duplicate extension: " ⊕ show e
+ where
+ pairs ∷ Parser [(MIMEType, [Text])]
+ pairs = do skipMany linebreak
+ xs ← sepBy pair (skipMany1 linebreak)
+ skipMany linebreak
+ endOfInput
+ return xs
+ <?>
+ "pairs"