From e8756e5bfcd128817b7942cb439ee3287dd0637a Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Tue, 6 May 2014 13:39:23 +0200 Subject: Remove no longer necessary parser error handling. We can now drop some Maybe tests and even lets us strip an error handling monad away in a few places. --- src/Haddock/Interface/ParseModuleHeader.hs | 46 +++++++++++------------------- 1 file changed, 17 insertions(+), 29 deletions(-) (limited to 'src/Haddock/Interface/ParseModuleHeader.hs') diff --git a/src/Haddock/Interface/ParseModuleHeader.hs b/src/Haddock/Interface/ParseModuleHeader.hs index 0be2511f..6848dc63 100644 --- a/src/Haddock/Interface/ParseModuleHeader.hs +++ b/src/Haddock/Interface/ParseModuleHeader.hs @@ -11,14 +11,13 @@ ----------------------------------------------------------------------------- module Haddock.Interface.ParseModuleHeader (parseModuleHeader) where -import Haddock.Types +import Control.Applicative ((<$>)) +import Control.Monad (mplus) +import Data.Char +import DynFlags import Haddock.Parser - +import Haddock.Types import RdrName -import DynFlags - -import Data.Char -import Control.Monad (mplus) -- ----------------------------------------------------------------------------- -- Parsing module headers @@ -26,7 +25,7 @@ import Control.Monad (mplus) -- NB. The headers must be given in the order Module, Description, -- Copyright, License, Maintainer, Stability, Portability, except that -- any or all may be omitted. -parseModuleHeader :: DynFlags -> String -> Either String (HaddockModInfo RdrName, Doc RdrName) +parseModuleHeader :: DynFlags -> String -> (HaddockModInfo RdrName, Doc RdrName) parseModuleHeader dflags str0 = let getKey :: String -> String -> (Maybe String,String) @@ -43,28 +42,17 @@ parseModuleHeader dflags str0 = (stabilityOpt,str7) = getKey "Stability" str6 (portabilityOpt,str8) = getKey "Portability" str7 - description1 :: Either String (Maybe (Doc RdrName)) - description1 = case descriptionOpt of - Nothing -> Right Nothing - Just description -> case parseStringMaybe dflags description of - Nothing -> Left ("Cannot parse Description: " ++ description) - Just doc -> Right (Just doc) - in - case description1 of - Left mess -> Left mess - Right docOpt -> case parseParasMaybe dflags str8 of - Nothing -> Left "Cannot parse header documentation paragraphs" - Just doc -> Right (HaddockModInfo { - hmi_description = docOpt, - hmi_copyright = copyrightOpt, - hmi_license = licenseOpt `mplus` licenceOpt, - hmi_maintainer = maintainerOpt, - hmi_stability = stabilityOpt, - hmi_portability = portabilityOpt, - hmi_safety = Nothing, - hmi_language = Nothing, -- set in LexParseRn - hmi_extensions = [] -- also set in LexParseRn - }, doc) + in (HaddockModInfo { + hmi_description = parseString dflags <$> descriptionOpt, + hmi_copyright = copyrightOpt, + hmi_license = licenseOpt `mplus` licenceOpt, + hmi_maintainer = maintainerOpt, + hmi_stability = stabilityOpt, + hmi_portability = portabilityOpt, + hmi_safety = Nothing, + hmi_language = Nothing, -- set in LexParseRn + hmi_extensions = [] -- also set in LexParseRn + }, parseParas dflags str8) -- | This function is how we read keys. -- -- cgit v1.2.3