git.iko.soy/typeable/pandoc
on master help sign in
style issues
2ca50e9Yan Pas
src/Text/Pandoc/Readers/Man.hs+9−12
@@ -31,10 +31,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
31
32Conversion of man to 'Pandoc' document.
32Conversion of man to 'Pandoc' document.
33-}
33-}
34−module Text.Pandoc.Readers.Man (readMan) where --testFile
34+module Text.Pandoc.Readers.Man (readMan) where
35
35
36import Prelude
36import Prelude
37−import Control.Monad (liftM)
37+import Control.Monad (liftM, void)
38import Control.Monad.Except (throwError)
38import Control.Monad.Except (throwError)
39import Data.Char (isDigit, isUpper, isLower)
39import Data.Char (isDigit, isUpper, isLower)
40import Data.Default (Default)
40import Data.Default (Default)
@@ -123,13 +123,11 @@ readMan :: PandocMonad m => ReaderOptions -> T.Text -> m Pandoc
123readMan opts txt = do
123readMan opts txt = do
124 eithertokens <- readWithM lexMan def (T.unpack $ crFilter txt)
124 eithertokens <- readWithM lexMan def (T.unpack $ crFilter txt)
125 case eithertokens of
125 case eithertokens of
126+ Left e -> throwError e
126 Right tokenz -> do
127 Right tokenz -> do
127 let state = def {stateOptions = opts} :: ParserState
128 let state = def {stateOptions = opts} :: ParserState
128 eitherdoc <- readWithMTokens parseMan state tokenz
129 eitherdoc <- readWithMTokens parseMan state tokenz
129− case eitherdoc of
130+ either throwError return eitherdoc
130− Right doc -> return doc
131− Left e -> throwError e
132− Left e -> throwError e
133
131
134 where
132 where
135
133
@@ -139,7 +137,8 @@ readMan opts txt = do
139 -> [ManToken] -- ^ input
137 -> [ManToken] -- ^ input
140 -> m (Either PandocError a)
138 -> m (Either PandocError a)
141 readWithMTokens parser state input =
139 readWithMTokens parser state input =
142− mapLeft (PandocParsecError . (intercalate "\n") $ show <$> input) `liftM` runParserT parser state "source" input
140+ let leftF = PandocParsecError . (intercalate "\n") $ show <$> input
141+ in mapLeft leftF `liftM` runParserT parser state "source" input
143
142
144 mapLeft :: (a -> c) -> Either a b -> Either c b
143 mapLeft :: (a -> c) -> Either a b -> Either c b
145 mapLeft f (Left x) = Left $ f x
144 mapLeft f (Left x) = Left $ f x
@@ -166,12 +165,12 @@ parseMan = do
166 isNull _ = False
165 isNull _ = False
167
166
168eofline :: Stream s m Char => ParsecT s u m ()
167eofline :: Stream s m Char => ParsecT s u m ()
169−eofline = (newline >> return ()) <|> eof
168+eofline = void newline <|> eof
170
169
171spacetab :: Stream s m Char => ParsecT s u m Char
170spacetab :: Stream s m Char => ParsecT s u m Char
172spacetab = char ' ' <|> char '\t'
171spacetab = char ' ' <|> char '\t'
173
172
174−-- TODO handle more cases
173+-- TODO add other sequences from man (7) groff
175escapeLexer :: PandocMonad m => ManLexer m EscapeThing
174escapeLexer :: PandocMonad m => ManLexer m EscapeThing
176escapeLexer = do
175escapeLexer = do
177 char '\\'
176 char '\\'
@@ -225,9 +224,7 @@ escapeLexer = do
225 return ENothing
224 return ENothing
226
225
227currentFont :: PandocMonad m => ManLexer m FontKind
226currentFont :: PandocMonad m => ManLexer m FontKind
228−currentFont = do
229− RoffState {fontKind = fk} <- getState
227+currentFont = fontKind <$> getState
230− return fk
231
228
232-- separate function from lexMacro since real man files sometimes do not follow the rules
229-- separate function from lexMacro since real man files sometimes do not follow the rules
233lexComment :: PandocMonad m => ManLexer m ManToken
230lexComment :: PandocMonad m => ManLexer m ManToken