git.iko.soy/typeable/pandoc
on master help sign in
Roff reader: rename RoffToken constructors so they're shorter.
ffd3aa4John MacFarlane
src/Text/Pandoc/Readers/Man.hs+36−36
@@ -115,9 +115,9 @@ parseBlock = choice [ parseList
115parseTable :: PandocMonad m => ManParser m Blocks
115parseTable :: PandocMonad m => ManParser m Blocks
116parseTable = do
116parseTable = do
117 modifyState $ \st -> st { tableCellsPlain = True }
117 modifyState $ \st -> st { tableCellsPlain = True }
118− let isRoffTable (RoffTable{}) = True
118+ let isTbl (Tbl{}) = True
119− isRoffTable _ = False
119+ isTbl _ = False
120− RoffTable _opts rows pos <- msatisfy isRoffTable
120+ Tbl _opts rows pos <- msatisfy isTbl
121 case rows of
121 case rows of
122 ((as,_):_) -> try (do
122 ((as,_):_) -> try (do
123 let as' = map (columnTypeToAlignment . columnType) as
123 let as' = map (columnTypeToAlignment . columnType) as
@@ -167,7 +167,7 @@ parseTable = do
167 isHrule ([cellfmt], _) = columnType cellfmt `elem` ['_','-','=']
167 isHrule ([cellfmt], _) = columnType cellfmt `elem` ['_','-','=']
168 isHrule (_, [RoffTokens ss]) =
168 isHrule (_, [RoffTokens ss]) =
169 case Foldable.toList ss of
169 case Foldable.toList ss of
170− [RoffTextLine [RoffStr [c]]] -> c `elem` ['_','-','=']
170+ [TextLine [RoffStr [c]]] -> c `elem` ['_','-','=']
171 _ -> False
171 _ -> False
172 isHrule _ = False
172 isHrule _ = False
173
173
@@ -199,7 +199,7 @@ msatisfy :: Monad m => (RoffToken -> Bool) -> ParserT [RoffToken] st m RoffToken
199msatisfy predic = tokenPrim show nextPos testTok
199msatisfy predic = tokenPrim show nextPos testTok
200 where
200 where
201 testTok t = if predic t then Just t else Nothing
201 testTok t = if predic t then Just t else Nothing
202− nextPos _pos _x (RoffControlLine _ _ pos':_) = pos'
202+ nextPos _pos _x (ControlLine _ _ pos':_) = pos'
203 nextPos pos _x _xs = updatePosString
203 nextPos pos _x _xs = updatePosString
204 (setSourceColumn
204 (setSourceColumn
205 (setSourceLine pos $ sourceLine pos + 1) 1) ""
205 (setSourceLine pos $ sourceLine pos + 1) 1) ""
@@ -208,25 +208,25 @@ mtoken :: PandocMonad m => ManParser m RoffToken
208mtoken = msatisfy (const True)
208mtoken = msatisfy (const True)
209
209
210mline :: PandocMonad m => ManParser m RoffToken
210mline :: PandocMonad m => ManParser m RoffToken
211−mline = msatisfy isRoffTextLine where
211+mline = msatisfy isTextLine where
212− isRoffTextLine (RoffTextLine _) = True
212+ isTextLine (TextLine _) = True
213− isRoffTextLine _ = False
213+ isTextLine _ = False
214
214
215memptyLine :: PandocMonad m => ManParser m RoffToken
215memptyLine :: PandocMonad m => ManParser m RoffToken
216−memptyLine = msatisfy isRoffEmptyLine where
216+memptyLine = msatisfy isEmptyLine where
217− isRoffEmptyLine RoffEmptyLine = True
217+ isEmptyLine EmptyLine = True
218− isRoffEmptyLine _ = False
218+ isEmptyLine _ = False
219
219
220mmacro :: PandocMonad m => String -> ManParser m RoffToken
220mmacro :: PandocMonad m => String -> ManParser m RoffToken
221−mmacro mk = msatisfy isRoffControlLine where
221+mmacro mk = msatisfy isControlLine where
222− isRoffControlLine (RoffControlLine mk' _ _) | mk == mk' = True
222+ isControlLine (ControlLine mk' _ _) | mk == mk' = True
223 | otherwise = False
223 | otherwise = False
224− isRoffControlLine _ = False
224+ isControlLine _ = False
225
225
226mmacroAny :: PandocMonad m => ManParser m RoffToken
226mmacroAny :: PandocMonad m => ManParser m RoffToken
227−mmacroAny = msatisfy isRoffControlLine where
227+mmacroAny = msatisfy isControlLine where
228− isRoffControlLine RoffControlLine{} = True
228+ isControlLine ControlLine{} = True
229− isRoffControlLine _ = False
229+ isControlLine _ = False
230
230
231--
231--
232-- RoffToken -> Block functions
232-- RoffToken -> Block functions
@@ -234,7 +234,7 @@ mmacroAny = msatisfy isRoffControlLine where
234
234
235parseTitle :: PandocMonad m => ManParser m Blocks
235parseTitle :: PandocMonad m => ManParser m Blocks
236parseTitle = do
236parseTitle = do
237− (RoffControlLine _ args _) <- mmacro "TH"
237+ (ControlLine _ args _) <- mmacro "TH"
238 let adjustMeta =
238 let adjustMeta =
239 case args of
239 case args of
240 (x:y:z:_) -> setMeta "title" (linePartsToInlines x) .
240 (x:y:z:_) -> setMeta "title" (linePartsToInlines x) .
@@ -305,8 +305,8 @@ parseInline :: PandocMonad m => ManParser m Inlines
305parseInline = try $ do
305parseInline = try $ do
306 tok <- mtoken
306 tok <- mtoken
307 case tok of
307 case tok of
308− RoffTextLine lparts -> return $ linePartsToInlines lparts
308+ TextLine lparts -> return $ linePartsToInlines lparts
309− RoffControlLine mname args pos -> handleInlineMacro mname args pos
309+ ControlLine mname args pos -> handleInlineMacro mname args pos
310 _ -> mzero
310 _ -> mzero
311
311
312handleInlineMacro :: PandocMonad m
312handleInlineMacro :: PandocMonad m
@@ -337,14 +337,14 @@ handleInlineMacro mname args _pos = do
337
337
338parseBold :: PandocMonad m => [Arg] -> ManParser m Inlines
338parseBold :: PandocMonad m => [Arg] -> ManParser m Inlines
339parseBold [] = do
339parseBold [] = do
340− RoffTextLine lparts <- mline
340+ TextLine lparts <- mline
341 return $ strong $ linePartsToInlines lparts
341 return $ strong $ linePartsToInlines lparts
342parseBold args = return $
342parseBold args = return $
343 strong $ mconcat $ intersperse B.space $ map linePartsToInlines args
343 strong $ mconcat $ intersperse B.space $ map linePartsToInlines args
344
344
345parseItalic :: PandocMonad m => [Arg] -> ManParser m Inlines
345parseItalic :: PandocMonad m => [Arg] -> ManParser m Inlines
346parseItalic [] = do
346parseItalic [] = do
347− RoffTextLine lparts <- mline
347+ TextLine lparts <- mline
348 return $ emph $ linePartsToInlines lparts
348 return $ emph $ linePartsToInlines lparts
349parseItalic args = return $
349parseItalic args = return $
350 emph $ mconcat $ intersperse B.space $ map linePartsToInlines args
350 emph $ mconcat $ intersperse B.space $ map linePartsToInlines args
@@ -358,12 +358,12 @@ parseAlternatingFonts constructors args = return $ mconcat $
358
358
359lineInl :: PandocMonad m => ManParser m Inlines
359lineInl :: PandocMonad m => ManParser m Inlines
360lineInl = do
360lineInl = do
361− (RoffTextLine fragments) <- mline
361+ (TextLine fragments) <- mline
362 return $ linePartsToInlines fragments
362 return $ linePartsToInlines fragments
363
363
364bareIP :: PandocMonad m => ManParser m RoffToken
364bareIP :: PandocMonad m => ManParser m RoffToken
365bareIP = msatisfy isBareIP where
365bareIP = msatisfy isBareIP where
366− isBareIP (RoffControlLine "IP" [] _) = True
366+ isBareIP (ControlLine "IP" [] _) = True
367 isBareIP _ = False
367 isBareIP _ = False
368
368
369endmacro :: PandocMonad m => String -> ManParser m ()
369endmacro :: PandocMonad m => String -> ManParser m ()
@@ -372,8 +372,8 @@ endmacro name = void (mmacro name)
372 <|> lookAhead eof
372 <|> lookAhead eof
373 where
373 where
374 newBlockMacro = msatisfy isNewBlockMacro
374 newBlockMacro = msatisfy isNewBlockMacro
375− isNewBlockMacro (RoffControlLine "SH" _ _) = True
375+ isNewBlockMacro (ControlLine "SH" _ _) = True
376− isNewBlockMacro (RoffControlLine "SS" _ _) = True
376+ isNewBlockMacro (ControlLine "SS" _ _) = True
377 isNewBlockMacro _ = False
377 isNewBlockMacro _ = False
378
378
379parseCodeBlock :: PandocMonad m => ManParser m Blocks
379parseCodeBlock :: PandocMonad m => ManParser m Blocks
@@ -390,16 +390,16 @@ parseCodeBlock = try $ do
390 codeline = do
390 codeline = do
391 tok <- mtoken
391 tok <- mtoken
392 case tok of
392 case tok of
393− RoffControlLine "PP" _ _ -> return $ Just "" -- .PP sometimes used for blank line
393+ ControlLine "PP" _ _ -> return $ Just "" -- .PP sometimes used for blank line
394− RoffControlLine mname args pos -> do
394+ ControlLine mname args pos -> do
395 (Just . query getText <$> handleInlineMacro mname args pos) <|>
395 (Just . query getText <$> handleInlineMacro mname args pos) <|>
396 do report $ SkippedContent ('.':mname) pos
396 do report $ SkippedContent ('.':mname) pos
397 return Nothing
397 return Nothing
398− RoffTable _ _ pos -> do
398+ Tbl _ _ pos -> do
399 report $ SkippedContent "TABLE" pos
399 report $ SkippedContent "TABLE" pos
400 return $ Just "TABLE"
400 return $ Just "TABLE"
401− RoffEmptyLine -> return $ Just ""
401+ EmptyLine -> return $ Just ""
402− RoffTextLine ss
402+ TextLine ss
403 | not (null ss)
403 | not (null ss)
404 , all isFontToken ss -> return Nothing
404 , all isFontToken ss -> return Nothing
405 | otherwise -> return $ Just $ linePartsToString ss
405 | otherwise -> return $ Just $ linePartsToString ss
@@ -417,7 +417,7 @@ parseCodeBlock = try $ do
417
417
418parseHeader :: PandocMonad m => ManParser m Blocks
418parseHeader :: PandocMonad m => ManParser m Blocks
419parseHeader = do
419parseHeader = do
420− RoffControlLine name args _ <- mmacro "SH" <|> mmacro "SS"
420+ ControlLine name args _ <- mmacro "SH" <|> mmacro "SS"
421 contents <- if null args
421 contents <- if null args
422 then lineInl
422 then lineInl
423 else return $ mconcat $ intersperse B.space
423 else return $ mconcat $ intersperse B.space
@@ -440,7 +440,7 @@ listTypeMatches (Just _) _ = False
440
440
441listItem :: PandocMonad m => Maybe ListType -> ManParser m (ListType, Blocks)
441listItem :: PandocMonad m => Maybe ListType -> ManParser m (ListType, Blocks)
442listItem mbListType = try $ do
442listItem mbListType = try $ do
443− (RoffControlLine _ args _) <- mmacro "IP"
443+ (ControlLine _ args _) <- mmacro "IP"
444 case args of
444 case args of
445 (arg1 : _) -> do
445 (arg1 : _) -> do
446 let cs = linePartsToString arg1
446 let cs = linePartsToString arg1
@@ -491,7 +491,7 @@ parseDefinitionList = definitionList <$> many1 definitionListItem
491parseLink :: PandocMonad m => [Arg] -> ManParser m Inlines
491parseLink :: PandocMonad m => [Arg] -> ManParser m Inlines
492parseLink args = do
492parseLink args = do
493 contents <- mconcat <$> many lineInl
493 contents <- mconcat <$> many lineInl
494− RoffControlLine _ endargs _ <- mmacro "UE"
494+ ControlLine _ endargs _ <- mmacro "UE"
495 let url = case args of
495 let url = case args of
496 [] -> ""
496 [] -> ""
497 (x:_) -> linePartsToString x
497 (x:_) -> linePartsToString x
@@ -503,7 +503,7 @@ parseLink args = do
503parseEmailLink :: PandocMonad m => [Arg] -> ManParser m Inlines
503parseEmailLink :: PandocMonad m => [Arg] -> ManParser m Inlines
504parseEmailLink args = do
504parseEmailLink args = do
505 contents <- mconcat <$> many lineInl
505 contents <- mconcat <$> many lineInl
506− RoffControlLine _ endargs _ <- mmacro "ME"
506+ ControlLine _ endargs _ <- mmacro "ME"
507 let url = case args of
507 let url = case args of
508 [] -> ""
508 [] -> ""
509 (x:_) -> "mailto:" ++ linePartsToString x
509 (x:_) -> "mailto:" ++ linePartsToString x
@@ -516,7 +516,7 @@ skipUnkownMacro :: PandocMonad m => ManParser m Blocks
516skipUnkownMacro = do
516skipUnkownMacro = do
517 tok <- mmacroAny
517 tok <- mmacroAny
518 case tok of
518 case tok of
519− RoffControlLine mkind _ pos -> do
519+ ControlLine mkind _ pos -> do
520 report $ SkippedContent ('.':mkind) pos
520 report $ SkippedContent ('.':mkind) pos
521 return mempty
521 return mempty
522 _ -> fail "the impossible happened"
522 _ -> fail "the impossible happened"
src/Text/Pandoc/Readers/Roff.hs+14−14
@@ -101,10 +101,10 @@ data CellFormat =
101
101
102type TableRow = ([CellFormat], [RoffTokens])
102type TableRow = ([CellFormat], [RoffTokens])
103
103
104−data RoffToken = RoffTextLine [LinePart]
104+data RoffToken = TextLine [LinePart]
105− | RoffEmptyLine
105+ | EmptyLine
106− | RoffControlLine String [Arg] SourcePos
106+ | ControlLine String [Arg] SourcePos
107− | RoffTable [TableOption] [TableRow] SourcePos
107+ | Tbl [TableOption] [TableRow] SourcePos
108 deriving Show
108 deriving Show
109
109
110newtype RoffTokens = RoffTokens { unRoffTokens :: Seq.Seq RoffToken }
110newtype RoffTokens = RoffTokens { unRoffTokens :: Seq.Seq RoffToken }
@@ -128,7 +128,7 @@ instance Default RoffState where
128 def = RoffState { customMacros = M.fromList
128 def = RoffState { customMacros = M.fromList
129 $ map (\(n, s) ->
129 $ map (\(n, s) ->
130 (n, singleTok
130 (n, singleTok
131− (RoffTextLine [RoffStr s])))
131+ (TextLine [RoffStr s])))
132 [ ("Tm", "\x2122")
132 [ ("Tm", "\x2122")
133 , ("lq", "\x201C")
133 , ("lq", "\x201C")
134 , ("rq", "\x201D")
134 , ("rq", "\x201D")
@@ -370,7 +370,7 @@ lexMacro = do
370 "de1" -> lexMacroDef args
370 "de1" -> lexMacroDef args
371 "ds" -> lexStringDef args
371 "ds" -> lexStringDef args
372 "ds1" -> lexStringDef args
372 "ds1" -> lexStringDef args
373− "sp" -> return $ singleTok RoffEmptyLine
373+ "sp" -> return $ singleTok EmptyLine
374 "so" -> lexIncludeFile args
374 "so" -> lexIncludeFile args
375 _ -> resolveMacro macroName args pos
375 _ -> resolveMacro macroName args pos
376
376
@@ -394,7 +394,7 @@ lexTable pos = do
394 string ".TE"
394 string ".TE"
395 skipMany spacetab
395 skipMany spacetab
396 eofline
396 eofline
397− return $ singleTok $ RoffTable opts (rows ++ concat morerows) pos
397+ return $ singleTok $ Tbl opts (rows ++ concat morerows) pos
398
398
399lexTableRows :: PandocMonad m => RoffLexer m [TableRow]
399lexTableRows :: PandocMonad m => RoffLexer m [TableRow]
400lexTableRows = do
400lexTableRows = do
@@ -531,15 +531,15 @@ resolveMacro :: PandocMonad m
531resolveMacro macroName args pos = do
531resolveMacro macroName args pos = do
532 macros <- customMacros <$> getState
532 macros <- customMacros <$> getState
533 case M.lookup macroName macros of
533 case M.lookup macroName macros of
534− Nothing -> return $ singleTok $ RoffControlLine macroName args pos
534+ Nothing -> return $ singleTok $ ControlLine macroName args pos
535 Just ts -> do
535 Just ts -> do
536 let fillLP (MacroArg i) zs =
536 let fillLP (MacroArg i) zs =
537 case drop (i - 1) args of
537 case drop (i - 1) args of
538 [] -> zs
538 [] -> zs
539 (ys:_) -> ys ++ zs
539 (ys:_) -> ys ++ zs
540 fillLP z zs = z : zs
540 fillLP z zs = z : zs
541− let fillMacroArg (RoffTextLine lineparts) =
541+ let fillMacroArg (TextLine lineparts) =
542− RoffTextLine (foldr fillLP [] lineparts)
542+ TextLine (foldr fillLP [] lineparts)
543 fillMacroArg x = x
543 fillMacroArg x = x
544 return $ RoffTokens . fmap fillMacroArg . unRoffTokens $ ts
544 return $ RoffTokens . fmap fillMacroArg . unRoffTokens $ ts
545
545
@@ -548,7 +548,7 @@ lexStringDef args = do -- string definition
548 case args of
548 case args of
549 [] -> fail "No argument to .ds"
549 [] -> fail "No argument to .ds"
550 (x:ys) -> do
550 (x:ys) -> do
551− let ts = singleTok $ RoffTextLine (intercalate [RoffStr " " ] ys)
551+ let ts = singleTok $ TextLine (intercalate [RoffStr " " ] ys)
552 let stringName = linePartsToString x
552 let stringName = linePartsToString x
553 modifyState $ \st ->
553 modifyState $ \st ->
554 st{ customMacros = M.insert stringName ts (customMacros st) }
554 st{ customMacros = M.insert stringName ts (customMacros st) }
@@ -631,7 +631,7 @@ escString = try $ do
631 resolveString stringname pos = do
631 resolveString stringname pos = do
632 RoffTokens ts <- resolveMacro stringname [] pos
632 RoffTokens ts <- resolveMacro stringname [] pos
633 case Foldable.toList ts of
633 case Foldable.toList ts of
634− [RoffTextLine xs] -> return xs
634+ [TextLine xs] -> return xs
635 _ -> do
635 _ -> do
636 report $ SkippedContent ("unknown string " ++ stringname) pos
636 report $ SkippedContent ("unknown string " ++ stringname) pos
637 return mempty
637 return mempty
@@ -649,7 +649,7 @@ lexLine = do
649 -- this can happen if the line just contains \f[C], for example.
649 -- this can happen if the line just contains \f[C], for example.
650 go [] = return mempty
650 go [] = return mempty
651 go (RoffStr "" : xs) = go xs
651 go (RoffStr "" : xs) = go xs
652− go xs = return $ singleTok $ RoffTextLine xs
652+ go xs = return $ singleTok $ TextLine xs
653
653
654linePart :: PandocMonad m => RoffLexer m [LinePart]
654linePart :: PandocMonad m => RoffLexer m [LinePart]
655linePart = macroArg <|> escape <|>
655linePart = macroArg <|> escape <|>
@@ -694,7 +694,7 @@ spaceTabChar = do
694 return [RoffStr [c]]
694 return [RoffStr [c]]
695
695
696lexEmptyLine :: PandocMonad m => RoffLexer m RoffTokens
696lexEmptyLine :: PandocMonad m => RoffLexer m RoffTokens
697−lexEmptyLine = newline >> return (singleTok RoffEmptyLine)
697+lexEmptyLine = newline >> return (singleTok EmptyLine)
698
698
699manToken :: PandocMonad m => RoffLexer m RoffTokens
699manToken :: PandocMonad m => RoffLexer m RoffTokens
700manToken = lexComment <|> lexMacro <|> lexLine <|> lexEmptyLine
700manToken = lexComment <|> lexMacro <|> lexLine <|> lexEmptyLine