git.iko.soy/typeable/pandoc
on master help sign in
Roff reader: rename RoffToken constructors so they're shorter.
commitffd3aa4f090f9add3521ce88f01b96518489d49c authorJohn MacFarlane <jgm@berkeley.edu> dateTue 30 Oct 2018, 18:16 (8 years ago) parentc465933
2 files changed+50−50
src/Text/Pandoc/Readers/Man.hs+36−36 src/Text/Pandoc/Readers/Roff.hs+14−14
src/Text/Pandoc/Readers/Man.hs+36−36
@@ -115,9 +115,9 @@ parseBlock = choice [ parseList
115115parseTable :: PandocMonad m => ManParser m Blocks
116116parseTable = do
117117 modifyState $ \st -> st { tableCellsPlain = True }
118− let isRoffTable (RoffTable{}) = True
119− isRoffTable _ = False
120− RoffTable _opts rows pos <- msatisfy isRoffTable
118+ let isTbl (Tbl{}) = True
119+ isTbl _ = False
120+ Tbl _opts rows pos <- msatisfy isTbl
121121 case rows of
122122 ((as,_):_) -> try (do
123123 let as' = map (columnTypeToAlignment . columnType) as
@@ -167,7 +167,7 @@ parseTable = do
167167 isHrule ([cellfmt], _) = columnType cellfmt `elem` ['_','-','=']
168168 isHrule (_, [RoffTokens ss]) =
169169 case Foldable.toList ss of
170− [RoffTextLine [RoffStr [c]]] -> c `elem` ['_','-','=']
170+ [TextLine [RoffStr [c]]] -> c `elem` ['_','-','=']
171171 _ -> False
172172 isHrule _ = False
173173
@@ -199,7 +199,7 @@ msatisfy :: Monad m => (RoffToken -> Bool) -> ParserT [RoffToken] st m RoffToken
199199msatisfy predic = tokenPrim show nextPos testTok
200200 where
201201 testTok t = if predic t then Just t else Nothing
202− nextPos _pos _x (RoffControlLine _ _ pos':_) = pos'
202+ nextPos _pos _x (ControlLine _ _ pos':_) = pos'
203203 nextPos pos _x _xs = updatePosString
204204 (setSourceColumn
205205 (setSourceLine pos $ sourceLine pos + 1) 1) ""
@@ -208,25 +208,25 @@ mtoken :: PandocMonad m => ManParser m RoffToken
208208mtoken = msatisfy (const True)
209209
210210mline :: PandocMonad m => ManParser m RoffToken
211−mline = msatisfy isRoffTextLine where
212− isRoffTextLine (RoffTextLine _) = True
213− isRoffTextLine _ = False
211+mline = msatisfy isTextLine where
212+ isTextLine (TextLine _) = True
213+ isTextLine _ = False
214214
215215memptyLine :: PandocMonad m => ManParser m RoffToken
216−memptyLine = msatisfy isRoffEmptyLine where
217− isRoffEmptyLine RoffEmptyLine = True
218− isRoffEmptyLine _ = False
216+memptyLine = msatisfy isEmptyLine where
217+ isEmptyLine EmptyLine = True
218+ isEmptyLine _ = False
219219
220220mmacro :: PandocMonad m => String -> ManParser m RoffToken
221−mmacro mk = msatisfy isRoffControlLine where
222− isRoffControlLine (RoffControlLine mk' _ _) | mk == mk' = True
221+mmacro mk = msatisfy isControlLine where
222+ isControlLine (ControlLine mk' _ _) | mk == mk' = True
223223 | otherwise = False
224− isRoffControlLine _ = False
224+ isControlLine _ = False
225225
226226mmacroAny :: PandocMonad m => ManParser m RoffToken
227−mmacroAny = msatisfy isRoffControlLine where
228− isRoffControlLine RoffControlLine{} = True
229− isRoffControlLine _ = False
227+mmacroAny = msatisfy isControlLine where
228+ isControlLine ControlLine{} = True
229+ isControlLine _ = False
230230
231231--
232232-- RoffToken -> Block functions
@@ -234,7 +234,7 @@ mmacroAny = msatisfy isRoffControlLine where
234234
235235parseTitle :: PandocMonad m => ManParser m Blocks
236236parseTitle = do
237− (RoffControlLine _ args _) <- mmacro "TH"
237+ (ControlLine _ args _) <- mmacro "TH"
238238 let adjustMeta =
239239 case args of
240240 (x:y:z:_) -> setMeta "title" (linePartsToInlines x) .
@@ -305,8 +305,8 @@ parseInline :: PandocMonad m => ManParser m Inlines
305305parseInline = try $ do
306306 tok <- mtoken
307307 case tok of
308− RoffTextLine lparts -> return $ linePartsToInlines lparts
309− RoffControlLine mname args pos -> handleInlineMacro mname args pos
308+ TextLine lparts -> return $ linePartsToInlines lparts
309+ ControlLine mname args pos -> handleInlineMacro mname args pos
310310 _ -> mzero
311311
312312handleInlineMacro :: PandocMonad m
@@ -337,14 +337,14 @@ handleInlineMacro mname args _pos = do
337337
338338parseBold :: PandocMonad m => [Arg] -> ManParser m Inlines
339339parseBold [] = do
340− RoffTextLine lparts <- mline
340+ TextLine lparts <- mline
341341 return $ strong $ linePartsToInlines lparts
342342parseBold args = return $
343343 strong $ mconcat $ intersperse B.space $ map linePartsToInlines args
344344
345345parseItalic :: PandocMonad m => [Arg] -> ManParser m Inlines
346346parseItalic [] = do
347− RoffTextLine lparts <- mline
347+ TextLine lparts <- mline
348348 return $ emph $ linePartsToInlines lparts
349349parseItalic args = return $
350350 emph $ mconcat $ intersperse B.space $ map linePartsToInlines args
@@ -358,12 +358,12 @@ parseAlternatingFonts constructors args = return $ mconcat $
358358
359359lineInl :: PandocMonad m => ManParser m Inlines
360360lineInl = do
361− (RoffTextLine fragments) <- mline
361+ (TextLine fragments) <- mline
362362 return $ linePartsToInlines fragments
363363
364364bareIP :: PandocMonad m => ManParser m RoffToken
365365bareIP = msatisfy isBareIP where
366− isBareIP (RoffControlLine "IP" [] _) = True
366+ isBareIP (ControlLine "IP" [] _) = True
367367 isBareIP _ = False
368368
369369endmacro :: PandocMonad m => String -> ManParser m ()
@@ -372,8 +372,8 @@ endmacro name = void (mmacro name)
372372 <|> lookAhead eof
373373 where
374374 newBlockMacro = msatisfy isNewBlockMacro
375− isNewBlockMacro (RoffControlLine "SH" _ _) = True
376− isNewBlockMacro (RoffControlLine "SS" _ _) = True
375+ isNewBlockMacro (ControlLine "SH" _ _) = True
376+ isNewBlockMacro (ControlLine "SS" _ _) = True
377377 isNewBlockMacro _ = False
378378
379379parseCodeBlock :: PandocMonad m => ManParser m Blocks
@@ -390,16 +390,16 @@ parseCodeBlock = try $ do
390390 codeline = do
391391 tok <- mtoken
392392 case tok of
393− RoffControlLine "PP" _ _ -> return $ Just "" -- .PP sometimes used for blank line
394− RoffControlLine mname args pos -> do
393+ ControlLine "PP" _ _ -> return $ Just "" -- .PP sometimes used for blank line
394+ ControlLine mname args pos -> do
395395 (Just . query getText <$> handleInlineMacro mname args pos) <|>
396396 do report $ SkippedContent ('.':mname) pos
397397 return Nothing
398− RoffTable _ _ pos -> do
398+ Tbl _ _ pos -> do
399399 report $ SkippedContent "TABLE" pos
400400 return $ Just "TABLE"
401− RoffEmptyLine -> return $ Just ""
402− RoffTextLine ss
401+ EmptyLine -> return $ Just ""
402+ TextLine ss
403403 | not (null ss)
404404 , all isFontToken ss -> return Nothing
405405 | otherwise -> return $ Just $ linePartsToString ss
@@ -417,7 +417,7 @@ parseCodeBlock = try $ do
417417
418418parseHeader :: PandocMonad m => ManParser m Blocks
419419parseHeader = do
420− RoffControlLine name args _ <- mmacro "SH" <|> mmacro "SS"
420+ ControlLine name args _ <- mmacro "SH" <|> mmacro "SS"
421421 contents <- if null args
422422 then lineInl
423423 else return $ mconcat $ intersperse B.space
@@ -440,7 +440,7 @@ listTypeMatches (Just _) _ = False
440440
441441listItem :: PandocMonad m => Maybe ListType -> ManParser m (ListType, Blocks)
442442listItem mbListType = try $ do
443− (RoffControlLine _ args _) <- mmacro "IP"
443+ (ControlLine _ args _) <- mmacro "IP"
444444 case args of
445445 (arg1 : _) -> do
446446 let cs = linePartsToString arg1
@@ -491,7 +491,7 @@ parseDefinitionList = definitionList <$> many1 definitionListItem
491491parseLink :: PandocMonad m => [Arg] -> ManParser m Inlines
492492parseLink args = do
493493 contents <- mconcat <$> many lineInl
494− RoffControlLine _ endargs _ <- mmacro "UE"
494+ ControlLine _ endargs _ <- mmacro "UE"
495495 let url = case args of
496496 [] -> ""
497497 (x:_) -> linePartsToString x
@@ -503,7 +503,7 @@ parseLink args = do
503503parseEmailLink :: PandocMonad m => [Arg] -> ManParser m Inlines
504504parseEmailLink args = do
505505 contents <- mconcat <$> many lineInl
506− RoffControlLine _ endargs _ <- mmacro "ME"
506+ ControlLine _ endargs _ <- mmacro "ME"
507507 let url = case args of
508508 [] -> ""
509509 (x:_) -> "mailto:" ++ linePartsToString x
@@ -516,7 +516,7 @@ skipUnkownMacro :: PandocMonad m => ManParser m Blocks
516516skipUnkownMacro = do
517517 tok <- mmacroAny
518518 case tok of
519− RoffControlLine mkind _ pos -> do
519+ ControlLine mkind _ pos -> do
520520 report $ SkippedContent ('.':mkind) pos
521521 return mempty
522522 _ -> fail "the impossible happened"
src/Text/Pandoc/Readers/Roff.hs+14−14
@@ -101,10 +101,10 @@ data CellFormat =
101101
102102type TableRow = ([CellFormat], [RoffTokens])
103103
104−data RoffToken = RoffTextLine [LinePart]
105− | RoffEmptyLine
106− | RoffControlLine String [Arg] SourcePos
107− | RoffTable [TableOption] [TableRow] SourcePos
104+data RoffToken = TextLine [LinePart]
105+ | EmptyLine
106+ | ControlLine String [Arg] SourcePos
107+ | Tbl [TableOption] [TableRow] SourcePos
108108 deriving Show
109109
110110newtype RoffTokens = RoffTokens { unRoffTokens :: Seq.Seq RoffToken }
@@ -128,7 +128,7 @@ instance Default RoffState where
128128 def = RoffState { customMacros = M.fromList
129129 $ map (\(n, s) ->
130130 (n, singleTok
131− (RoffTextLine [RoffStr s])))
131+ (TextLine [RoffStr s])))
132132 [ ("Tm", "\x2122")
133133 , ("lq", "\x201C")
134134 , ("rq", "\x201D")
@@ -370,7 +370,7 @@ lexMacro = do
370370 "de1" -> lexMacroDef args
371371 "ds" -> lexStringDef args
372372 "ds1" -> lexStringDef args
373− "sp" -> return $ singleTok RoffEmptyLine
373+ "sp" -> return $ singleTok EmptyLine
374374 "so" -> lexIncludeFile args
375375 _ -> resolveMacro macroName args pos
376376
@@ -394,7 +394,7 @@ lexTable pos = do
394394 string ".TE"
395395 skipMany spacetab
396396 eofline
397− return $ singleTok $ RoffTable opts (rows ++ concat morerows) pos
397+ return $ singleTok $ Tbl opts (rows ++ concat morerows) pos
398398
399399lexTableRows :: PandocMonad m => RoffLexer m [TableRow]
400400lexTableRows = do
@@ -531,15 +531,15 @@ resolveMacro :: PandocMonad m
531531resolveMacro macroName args pos = do
532532 macros <- customMacros <$> getState
533533 case M.lookup macroName macros of
534− Nothing -> return $ singleTok $ RoffControlLine macroName args pos
534+ Nothing -> return $ singleTok $ ControlLine macroName args pos
535535 Just ts -> do
536536 let fillLP (MacroArg i) zs =
537537 case drop (i - 1) args of
538538 [] -> zs
539539 (ys:_) -> ys ++ zs
540540 fillLP z zs = z : zs
541− let fillMacroArg (RoffTextLine lineparts) =
542− RoffTextLine (foldr fillLP [] lineparts)
541+ let fillMacroArg (TextLine lineparts) =
542+ TextLine (foldr fillLP [] lineparts)
543543 fillMacroArg x = x
544544 return $ RoffTokens . fmap fillMacroArg . unRoffTokens $ ts
545545
@@ -548,7 +548,7 @@ lexStringDef args = do -- string definition
548548 case args of
549549 [] -> fail "No argument to .ds"
550550 (x:ys) -> do
551− let ts = singleTok $ RoffTextLine (intercalate [RoffStr " " ] ys)
551+ let ts = singleTok $ TextLine (intercalate [RoffStr " " ] ys)
552552 let stringName = linePartsToString x
553553 modifyState $ \st ->
554554 st{ customMacros = M.insert stringName ts (customMacros st) }
@@ -631,7 +631,7 @@ escString = try $ do
631631 resolveString stringname pos = do
632632 RoffTokens ts <- resolveMacro stringname [] pos
633633 case Foldable.toList ts of
634− [RoffTextLine xs] -> return xs
634+ [TextLine xs] -> return xs
635635 _ -> do
636636 report $ SkippedContent ("unknown string " ++ stringname) pos
637637 return mempty
@@ -649,7 +649,7 @@ lexLine = do
649649 -- this can happen if the line just contains \f[C], for example.
650650 go [] = return mempty
651651 go (RoffStr "" : xs) = go xs
652− go xs = return $ singleTok $ RoffTextLine xs
652+ go xs = return $ singleTok $ TextLine xs
653653
654654linePart :: PandocMonad m => RoffLexer m [LinePart]
655655linePart = macroArg <|> escape <|>
@@ -694,7 +694,7 @@ spaceTabChar = do
694694 return [RoffStr [c]]
695695
696696lexEmptyLine :: PandocMonad m => RoffLexer m RoffTokens
697−lexEmptyLine = newline >> return (singleTok RoffEmptyLine)
697+lexEmptyLine = newline >> return (singleTok EmptyLine)
698698
699699manToken :: PandocMonad m => RoffLexer m RoffTokens
700700manToken = lexComment <|> lexMacro <|> lexLine <|> lexEmptyLine