{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
module Text.Pandoc.Readers.Roff
( FontSpec(..)
, defaultFontSpec
, LinePart(..)
, Arg
, TableOption
, CellFormat(..)
, TableRow
, RoffToken(..)
, RoffTokens(..)
, linePartsToText
, lexRoff
)
where
import Safe (lastDef)
import Control.Monad (void, mzero, mplus, guard)
import Control.Monad.Except (throwError)
import Text.Pandoc.Class.PandocMonad
(getResourcePath, readFileFromDirs, PandocMonad(..), report)
import Data.Char (isLower, toLower, toUpper, chr, isAscii, isAlphaNum)
import Data.Default (Default)
import qualified Data.Map as M
import Data.List (intercalate)
import qualified Data.Text as T
import Text.Pandoc.Logging (LogMessage(..))
import Text.Pandoc.Options
import Text.Pandoc.Parsing
import Text.Pandoc.Shared (safeRead)
import Text.Pandoc.RoffChar (characterCodes, combiningAccents)
import qualified Data.Sequence as Seq
import qualified Data.Foldable as Foldable
import qualified Data.Text.Normalize as Normalize
data FontSpec = FontSpec{ FontSpec -> Bool
fontBold :: Bool
, FontSpec -> Bool
fontItalic :: Bool
, FontSpec -> Bool
fontMonospace :: Bool
} deriving (Int -> FontSpec -> ShowS
[FontSpec] -> ShowS
FontSpec -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FontSpec] -> ShowS
$cshowList :: [FontSpec] -> ShowS
show :: FontSpec -> String
$cshow :: FontSpec -> String
showsPrec :: Int -> FontSpec -> ShowS
$cshowsPrec :: Int -> FontSpec -> ShowS
Show, FontSpec -> FontSpec -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FontSpec -> FontSpec -> Bool
$c/= :: FontSpec -> FontSpec -> Bool
== :: FontSpec -> FontSpec -> Bool
$c== :: FontSpec -> FontSpec -> Bool
Eq, Eq FontSpec
FontSpec -> FontSpec -> Bool
FontSpec -> FontSpec -> Ordering
FontSpec -> FontSpec -> FontSpec
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FontSpec -> FontSpec -> FontSpec
$cmin :: FontSpec -> FontSpec -> FontSpec
max :: FontSpec -> FontSpec -> FontSpec
$cmax :: FontSpec -> FontSpec -> FontSpec
>= :: FontSpec -> FontSpec -> Bool
$c>= :: FontSpec -> FontSpec -> Bool
> :: FontSpec -> FontSpec -> Bool
$c> :: FontSpec -> FontSpec -> Bool
<= :: FontSpec -> FontSpec -> Bool
$c<= :: FontSpec -> FontSpec -> Bool
< :: FontSpec -> FontSpec -> Bool
$c< :: FontSpec -> FontSpec -> Bool
compare :: FontSpec -> FontSpec -> Ordering
$ccompare :: FontSpec -> FontSpec -> Ordering
Ord)
defaultFontSpec :: FontSpec
defaultFontSpec :: FontSpec
defaultFontSpec = Bool -> Bool -> Bool -> FontSpec
FontSpec Bool
False Bool
False Bool
False
data LinePart = RoffStr T.Text
| Font FontSpec
| MacroArg Int
deriving Int -> LinePart -> ShowS
[LinePart] -> ShowS
LinePart -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LinePart] -> ShowS
$cshowList :: [LinePart] -> ShowS
show :: LinePart -> String
$cshow :: LinePart -> String
showsPrec :: Int -> LinePart -> ShowS
$cshowsPrec :: Int -> LinePart -> ShowS
Show
type Arg = [LinePart]
type TableOption = (T.Text, T.Text)
data CellFormat =
CellFormat
{ CellFormat -> Char
columnType :: Char
, CellFormat -> Bool
pipePrefix :: Bool
, CellFormat -> Bool
pipeSuffix :: Bool
, CellFormat -> [Text]
columnSuffixes :: [T.Text]
} deriving (Int -> CellFormat -> ShowS
[CellFormat] -> ShowS
CellFormat -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CellFormat] -> ShowS
$cshowList :: [CellFormat] -> ShowS
show :: CellFormat -> String
$cshow :: CellFormat -> String
showsPrec :: Int -> CellFormat -> ShowS
$cshowsPrec :: Int -> CellFormat -> ShowS
Show, CellFormat -> CellFormat -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CellFormat -> CellFormat -> Bool
$c/= :: CellFormat -> CellFormat -> Bool
== :: CellFormat -> CellFormat -> Bool
$c== :: CellFormat -> CellFormat -> Bool
Eq, Eq CellFormat
CellFormat -> CellFormat -> Bool
CellFormat -> CellFormat -> Ordering
CellFormat -> CellFormat -> CellFormat
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CellFormat -> CellFormat -> CellFormat
$cmin :: CellFormat -> CellFormat -> CellFormat
max :: CellFormat -> CellFormat -> CellFormat
$cmax :: CellFormat -> CellFormat -> CellFormat
>= :: CellFormat -> CellFormat -> Bool
$c>= :: CellFormat -> CellFormat -> Bool
> :: CellFormat -> CellFormat -> Bool
$c> :: CellFormat -> CellFormat -> Bool
<= :: CellFormat -> CellFormat -> Bool
$c<= :: CellFormat -> CellFormat -> Bool
< :: CellFormat -> CellFormat -> Bool
$c< :: CellFormat -> CellFormat -> Bool
compare :: CellFormat -> CellFormat -> Ordering
$ccompare :: CellFormat -> CellFormat -> Ordering
Ord)
type TableRow = ([CellFormat], [RoffTokens])
data RoffToken = TextLine [LinePart]
| EmptyLine
| ControlLine T.Text [Arg] SourcePos
| Tbl [TableOption] [TableRow] SourcePos
deriving Int -> RoffToken -> ShowS
[RoffToken] -> ShowS
RoffToken -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoffToken] -> ShowS
$cshowList :: [RoffToken] -> ShowS
show :: RoffToken -> String
$cshow :: RoffToken -> String
showsPrec :: Int -> RoffToken -> ShowS
$cshowsPrec :: Int -> RoffToken -> ShowS
Show
newtype RoffTokens = RoffTokens { RoffTokens -> Seq RoffToken
unRoffTokens :: Seq.Seq RoffToken }
deriving (Int -> RoffTokens -> ShowS
[RoffTokens] -> ShowS
RoffTokens -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoffTokens] -> ShowS
$cshowList :: [RoffTokens] -> ShowS
show :: RoffTokens -> String
$cshow :: RoffTokens -> String
showsPrec :: Int -> RoffTokens -> ShowS
$cshowsPrec :: Int -> RoffTokens -> ShowS
Show, NonEmpty RoffTokens -> RoffTokens
RoffTokens -> RoffTokens -> RoffTokens
forall b. Integral b => b -> RoffTokens -> RoffTokens
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> RoffTokens -> RoffTokens
$cstimes :: forall b. Integral b => b -> RoffTokens -> RoffTokens
sconcat :: NonEmpty RoffTokens -> RoffTokens
$csconcat :: NonEmpty RoffTokens -> RoffTokens
<> :: RoffTokens -> RoffTokens -> RoffTokens
$c<> :: RoffTokens -> RoffTokens -> RoffTokens
Semigroup, Semigroup RoffTokens
RoffTokens
[RoffTokens] -> RoffTokens
RoffTokens -> RoffTokens -> RoffTokens
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [RoffTokens] -> RoffTokens
$cmconcat :: [RoffTokens] -> RoffTokens
mappend :: RoffTokens -> RoffTokens -> RoffTokens
$cmappend :: RoffTokens -> RoffTokens -> RoffTokens
mempty :: RoffTokens
$cmempty :: RoffTokens
Monoid)
singleTok :: RoffToken -> RoffTokens
singleTok :: RoffToken -> RoffTokens
singleTok RoffToken
t = Seq RoffToken -> RoffTokens
RoffTokens (forall a. a -> Seq a
Seq.singleton RoffToken
t)
data RoffMode = NormalMode
| CopyMode
deriving Int -> RoffMode -> ShowS
[RoffMode] -> ShowS
RoffMode -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoffMode] -> ShowS
$cshowList :: [RoffMode] -> ShowS
show :: RoffMode -> String
$cshow :: RoffMode -> String
showsPrec :: Int -> RoffMode -> ShowS
$cshowsPrec :: Int -> RoffMode -> ShowS
Show
data RoffState = RoffState { RoffState -> Map Text RoffTokens
customMacros :: M.Map T.Text RoffTokens
, RoffState -> FontSpec
prevFont :: FontSpec
, RoffState -> FontSpec
currentFont :: FontSpec
, RoffState -> Char
tableTabChar :: Char
, RoffState -> RoffMode
roffMode :: RoffMode
, RoffState -> Maybe Bool
lastExpression :: Maybe Bool
, RoffState -> Bool
afterConditional :: Bool
} deriving Int -> RoffState -> ShowS
[RoffState] -> ShowS
RoffState -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RoffState] -> ShowS
$cshowList :: [RoffState] -> ShowS
show :: RoffState -> String
$cshow :: RoffState -> String
showsPrec :: Int -> RoffState -> ShowS
$cshowsPrec :: Int -> RoffState -> ShowS
Show
instance Default RoffState where
def :: RoffState
def = RoffState { customMacros :: Map Text RoffTokens
customMacros = forall k a. Ord k => [(k, a)] -> Map k a
M.fromList
forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(Text
n, Text
s) ->
(Text
n, RoffToken -> RoffTokens
singleTok
([LinePart] -> RoffToken
TextLine [Text -> LinePart
RoffStr Text
s])))
[ (Text
"Tm", Text
"\x2122")
, (Text
"lq", Text
"\x201C")
, (Text
"rq", Text
"\x201D")
, (Text
"R", Text
"\x00AE") ]
, prevFont :: FontSpec
prevFont = FontSpec
defaultFontSpec
, currentFont :: FontSpec
currentFont = FontSpec
defaultFontSpec
, tableTabChar :: Char
tableTabChar = Char
'\t'
, roffMode :: RoffMode
roffMode = RoffMode
NormalMode
, lastExpression :: Maybe Bool
lastExpression = forall a. Maybe a
Nothing
, afterConditional :: Bool
afterConditional = Bool
False
}
type RoffLexer m = ParsecT Sources RoffState m
eofline :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s u m ()
eofline :: forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
eofline = forall (f :: * -> *) a. Functor f => f a -> f ()
void forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
eof forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> () forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"\\}")
spacetab :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s u m Char
spacetab :: forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
' ' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\t'
characterCodeMap :: M.Map T.Text Char
characterCodeMap :: Map Text Char
characterCodeMap =
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(Char
x,Text
y) -> (Text
y,Char
x)) [(Char, Text)]
characterCodes
combiningAccentsMap :: M.Map T.Text Char
combiningAccentsMap :: Map Text Char
combiningAccentsMap =
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (\(Char
x,Text
y) -> (Text
y,Char
x)) [(Char, Text)]
combiningAccents
escape :: PandocMonad m => RoffLexer m [LinePart]
escape :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escape = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *). PandocMonad m => RoffLexer m ()
backslash
forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escapeGlyph forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escapeNormal
escapeGlyph :: PandocMonad m => RoffLexer m [LinePart]
escapeGlyph :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escapeGlyph = do
Char
c <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf [Char
'[',Char
'('])
forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
Char -> Text -> RoffLexer m [LinePart]
resolveGlyph Char
c
resolveGlyph :: PandocMonad m => Char -> T.Text -> RoffLexer m [LinePart]
resolveGlyph :: forall (m :: * -> *).
PandocMonad m =>
Char -> Text -> RoffLexer m [LinePart]
resolveGlyph Char
delimChar Text
glyph = do
let cs :: Text
cs = Text -> Text -> Text -> Text
T.replace Text
"_u" Text
" u" Text
glyph
(case Text -> [Text]
T.words Text
cs of
[] -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
[Text
s] -> case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
s Map Text Char
characterCodeMap forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Text -> Maybe Char
readUnicodeChar Text
s of
Maybe Char
Nothing -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
Just Char
c -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
c]
(Text
s:[Text]
ss) -> do
Char
basechar <- case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
s Map Text Char
characterCodeMap forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus`
Text -> Maybe Char
readUnicodeChar Text
s of
Maybe Char
Nothing ->
case Text -> String
T.unpack Text
s of
[Char
ch] | Char -> Bool
isAscii Char
ch Bool -> Bool -> Bool
&& Char -> Bool
isAlphaNum Char
ch ->
forall (m :: * -> *) a. Monad m => a -> m a
return Char
ch
String
_ -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
Just Char
c -> forall (m :: * -> *) a. Monad m => a -> m a
return Char
c
let addAccents :: [Text] -> Text -> m Text
addAccents [] Text
xs = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ NormalizationMode -> Text -> Text
Normalize.normalize NormalizationMode
Normalize.NFC forall a b. (a -> b) -> a -> b
$
Text -> Text
T.reverse Text
xs
addAccents (Text
a:[Text]
as) Text
xs =
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
a Map Text Char
combiningAccentsMap forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
`mplus` Text -> Maybe Char
readUnicodeChar Text
a of
Just Char
x -> [Text] -> Text -> m Text
addAccents [Text]
as forall a b. (a -> b) -> a -> b
$ Char -> Text -> Text
T.cons Char
x Text
xs
Maybe Char
Nothing -> forall (m :: * -> *) a. MonadPlus m => m a
mzero
forall {m :: * -> *}. MonadPlus m => [Text] -> Text -> m Text
addAccents [Text]
ss (Char -> Text
T.singleton Char
basechar) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
xs -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
xs])
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> case Char
delimChar of
Char
'[' -> forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m [LinePart]
escUnknown (Text
"\\[" forall a. Semigroup a => a -> a -> a
<> Text
glyph forall a. Semigroup a => a -> a -> a
<> Text
"]")
Char
'(' -> forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m [LinePart]
escUnknown (Text
"\\(" forall a. Semigroup a => a -> a -> a
<> Text
glyph)
Char
'\'' -> forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m [LinePart]
escUnknown (Text
"\\C'" forall a. Semigroup a => a -> a -> a
<> Text
glyph forall a. Semigroup a => a -> a -> a
<> Text
"'")
Char
_ -> forall (m :: * -> *) a. MonadFail m => String -> m a
Prelude.fail String
"resolveGlyph: unknown glyph delimiter"
readUnicodeChar :: T.Text -> Maybe Char
readUnicodeChar :: Text -> Maybe Char
readUnicodeChar Text
t = case Text -> Maybe (Char, Text)
T.uncons Text
t of
Just (Char
'u', Text
cs) | Text -> Int
T.length Text
cs forall a. Ord a => a -> a -> Bool
> Int
3 -> Int -> Char
chr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead (Text
"0x" forall a. Semigroup a => a -> a -> a
<> Text
cs)
Maybe (Char, Text)
_ -> forall a. Maybe a
Nothing
escapeNormal :: PandocMonad m => RoffLexer m [LinePart]
escapeNormal :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escapeNormal = do
Char
c <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"{}"
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => RoffLexer m ()
expandString
case Char
c of
Char
' ' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
" "]
Char
'"' -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))
Char
'#' -> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
Char
'%' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'&' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
')' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'*' -> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escString
Char
',' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'-' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"-"]
Char
'.' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"."]
Char
'/' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'0' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\x2007"]
Char
':' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'A' -> forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m [LinePart]
checkDefined
Char
'B' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'B' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'C' -> forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
Char -> Text -> RoffLexer m [LinePart]
resolveGlyph Char
'\''
Char
'D' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'D' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'E' -> do
RoffMode
mode <- RoffState -> RoffMode
roffMode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case RoffMode
mode of
RoffMode
CopyMode -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
RoffMode
NormalMode -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\\"]
Char
'H' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'H' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'L' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'L' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'M' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'M' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))]
Char
'N' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'N' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'O' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'O' [forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf [Char
'0',Char
'1'])]
Char
'R' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'R' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'S' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'S' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'V' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'V' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum]
Char
'X' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'X' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'Y' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'Y' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))]
Char
'Z' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'Z' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'\'' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"'"]
Char
'\n' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'^' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\x200A"]
Char
'_' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"_"]
Char
'`' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"`"]
Char
'a' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'b' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'b' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'c' -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Char
'd' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'd' []
Char
'e' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\\"]
Char
'f' -> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escFont
Char
'g' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'g' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))]
Char
'h' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'h' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'k' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'k' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))]
Char
'l' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'l' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'm' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'm' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))]
Char
'n' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'm' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))]
Char
'o' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'o' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'p' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'p' []
Char
'r' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'r' []
Char
's' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
's' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg, forall (m :: * -> *). PandocMonad m => RoffLexer m Text
signedNumber]
Char
't' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\t"]
Char
'u' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'u' []
Char
'v' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'v' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'w' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'w' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'x' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'x' [forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg]
Char
'z' -> forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
'z' [forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar]
Char
'|' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\x2006"]
Char
'~' -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\160"]
Char
'\\' -> do
RoffMode
mode <- RoffState -> RoffMode
roffMode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case RoffMode
mode of
RoffMode
CopyMode -> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\'
RoffMode
NormalMode -> forall (m :: * -> *) a. Monad m => a -> m a
return Char
'\\'
forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\\"]
Char
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
c]
escIgnore :: PandocMonad m
=> Char
-> [RoffLexer m T.Text]
-> RoffLexer m [LinePart]
escIgnore :: forall (m :: * -> *).
PandocMonad m =>
Char -> [RoffLexer m Text] -> RoffLexer m [LinePart]
escIgnore Char
c [RoffLexer m Text]
argparsers = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
Text
arg <- forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) st a.
Monad m =>
ParsecT Sources st m a -> ParsecT Sources st m (a, Text)
withRaw (forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [RoffLexer m Text]
argparsers) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) a. Monad m => a -> m a
return Text
""
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent (Text
"\\" forall a. Semigroup a => a -> a -> a
<> Char -> Text -> Text
T.cons Char
c Text
arg) SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
escUnknown :: PandocMonad m => T.Text -> RoffLexer m [LinePart]
escUnknown :: forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m [LinePart]
escUnknown Text
s = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent Text
s SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\xFFFD"]
signedNumber :: PandocMonad m => RoffLexer m T.Text
signedNumber :: forall (m :: * -> *). PandocMonad m => RoffLexer m Text
signedNumber = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
Text
sign <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" (Text
"-" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> Text
"" forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'+')
Text
ds <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
sign forall a. Semigroup a => a -> a -> a
<> Text
ds)
escapeArg :: PandocMonad m => RoffLexer m T.Text
escapeArg :: forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'[' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => RoffLexer m ()
expandString forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf [Char
'\n',Char
']']) (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
']')
, forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'(' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall (m :: * -> *). PandocMonad m => RoffLexer m ()
expandString forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*>
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
2 (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/=Char
'\n'))
]
expandString :: PandocMonad m => RoffLexer m ()
expandString :: forall (m :: * -> *). PandocMonad m => RoffLexer m ()
expandString = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\'
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'*'
Text
cs <- forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
Text
s <- [LinePart] -> Text
linePartsToText forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *).
PandocMonad m =>
Text -> SourcePos -> RoffLexer m [LinePart]
resolveText Text
cs SourcePos
pos
forall (m :: * -> *) u. Monad m => Text -> ParsecT Sources u m ()
addToInput Text
s
quoteArg :: PandocMonad m => RoffLexer m T.Text
quoteArg :: forall (m :: * -> *). PandocMonad m => RoffLexer m Text
quoteArg = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\'' forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf [Char
'\n',Char
'\'']) (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\'')
escFont :: PandocMonad m => RoffLexer m [LinePart]
escFont :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escFont = do
Text
font <- forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
FontSpec
font' <- if Text -> Bool
T.null Text
font Bool -> Bool -> Bool
|| Text
font forall a. Eq a => a -> a -> Bool
== Text
"P"
then RoffState -> FontSpec
prevFont forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
else forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Char -> FontSpec -> FontSpec
processFontLetter FontSpec
defaultFontSpec forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
font
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
st -> RoffState
st{ prevFont :: FontSpec
prevFont = RoffState -> FontSpec
currentFont RoffState
st
, currentFont :: FontSpec
currentFont = FontSpec
font' }
forall (m :: * -> *) a. Monad m => a -> m a
return [FontSpec -> LinePart
Font FontSpec
font']
where
processFontLetter :: Char -> FontSpec -> FontSpec
processFontLetter Char
c FontSpec
fs
| Char -> Bool
isLower Char
c = Char -> FontSpec -> FontSpec
processFontLetter (Char -> Char
toUpper Char
c) FontSpec
fs
processFontLetter Char
'B' FontSpec
fs = FontSpec
fs{ fontBold :: Bool
fontBold = Bool
True }
processFontLetter Char
'I' FontSpec
fs = FontSpec
fs{ fontItalic :: Bool
fontItalic = Bool
True }
processFontLetter Char
'C' FontSpec
fs = FontSpec
fs{ fontMonospace :: Bool
fontMonospace = Bool
True }
processFontLetter Char
_ FontSpec
fs = FontSpec
fs
lexComment :: PandocMonad m => RoffLexer m RoffTokens
= do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
".\\\""
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"\n"
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
eofline
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
lexMacro :: PandocMonad m => RoffLexer m RoffTokens
lexMacro :: forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexMacro = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
RoffState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall (f :: * -> *). Alternative f => Bool -> f ()
guard forall a b. (a -> b) -> a -> b
$ SourcePos -> Int
sourceColumn SourcePos
pos forall a. Eq a => a -> a -> Bool
== Int
1 Bool -> Bool -> Bool
|| RoffState -> Bool
afterConditional RoffState
st
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\''
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
Text
macroName <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
manyChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isAlphaNum)
case Text
macroName of
Text
"nop" -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Text
"ie" -> forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m RoffTokens
lexConditional Text
"ie"
Text
"if" -> forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m RoffTokens
lexConditional Text
"if"
Text
"el" -> forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m RoffTokens
lexConditional Text
"el"
Text
"while" -> forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m RoffTokens
lexConditional Text
"while"
Text
_ -> do
[[LinePart]]
args <- forall (m :: * -> *). PandocMonad m => RoffLexer m [[LinePart]]
lexArgs
case Text
macroName of
Text
"" -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Text
"TS" -> forall (m :: * -> *).
PandocMonad m =>
SourcePos -> RoffLexer m RoffTokens
lexTable SourcePos
pos
Text
"de" -> forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexMacroDef [[LinePart]]
args
Text
"de1" -> forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexMacroDef [[LinePart]]
args
Text
"ds" -> forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexStringDef [[LinePart]]
args
Text
"ds1" -> forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexStringDef [[LinePart]]
args
Text
"sp" -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ RoffToken -> RoffTokens
singleTok RoffToken
EmptyLine
Text
"so" -> forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexIncludeFile [[LinePart]]
args
Text
_ -> forall (m :: * -> *).
PandocMonad m =>
Text -> [[LinePart]] -> SourcePos -> RoffLexer m RoffTokens
resolveMacro Text
macroName [[LinePart]]
args SourcePos
pos
lexTable :: PandocMonad m => SourcePos -> RoffLexer m RoffTokens
lexTable :: forall (m :: * -> *).
PandocMonad m =>
SourcePos -> RoffLexer m RoffTokens
lexTable SourcePos
pos = do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexComment
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
[TableOption]
opts <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall (m :: * -> *). PandocMonad m => RoffLexer m [TableOption]
tableOptions forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [] forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';')
case forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Text
"tab" [TableOption]
opts of
Just (Text -> Maybe (Char, Text)
T.uncons -> Just (Char
c, Text
_)) -> forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
st -> RoffState
st{ tableTabChar :: Char
tableTabChar = Char
c }
Maybe Text
_ -> forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
st -> RoffState
st{ tableTabChar :: Char
tableTabChar = Char
'\t' }
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexComment
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
[TableRow]
rows <- forall (m :: * -> *). PandocMonad m => RoffLexer m [TableRow]
lexTableRows
[[TableRow]]
morerows <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
".T&"
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
forall (m :: * -> *). PandocMonad m => RoffLexer m [TableRow]
lexTableRows
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
".TE"
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
eofline
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ RoffToken -> RoffTokens
singleTok forall a b. (a -> b) -> a -> b
$ [TableOption] -> [TableRow] -> SourcePos -> RoffToken
Tbl [TableOption]
opts ([TableRow]
rows forall a. Semigroup a => a -> a -> a
<> forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[TableRow]]
morerows) SourcePos
pos
lexTableRows :: PandocMonad m => RoffLexer m [TableRow]
lexTableRows :: forall (m :: * -> *). PandocMonad m => RoffLexer m [TableRow]
lexTableRows = do
[[CellFormat]]
aligns <- forall (m :: * -> *). PandocMonad m => RoffLexer m [[CellFormat]]
tableFormatSpec
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexComment
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
".sp" forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spaceChar forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline))
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
[[RoffTokens]]
rows <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
".TE") forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
".T&")) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>>
forall (m :: * -> *). PandocMonad m => RoffLexer m [RoffTokens]
tableRow)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [[CellFormat]]
aligns [[RoffTokens]]
rows
tableCell :: PandocMonad m => RoffLexer m RoffTokens
tableCell :: forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
tableCell = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
(forall {u}. ParsecT Sources u m String
enclosedCell forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> ParsecT Sources RoffState m String
simpleCell) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: * -> *).
PandocMonad m =>
SourcePos -> Text -> m RoffTokens
lexRoff SourcePos
pos forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
where
enclosedCell :: ParsecT Sources u m String
enclosedCell = do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"T{")
forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"T}"))
simpleCell :: ParsecT Sources RoffState m String
simpleCell = do
Char
tabChar <- RoffState -> Char
tableTabChar forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
tabChar forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline) forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar)
tableRow :: PandocMonad m => RoffLexer m [RoffTokens]
tableRow :: forall (m :: * -> *). PandocMonad m => RoffLexer m [RoffTokens]
tableRow = do
Char
tabChar <- RoffState -> Char
tableTabChar forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
RoffTokens
c <- forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
tableCell
[RoffTokens]
cs <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
tabChar forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
tableCell)
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
eofline
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexComment
forall (m :: * -> *) a. Monad m => a -> m a
return (RoffTokens
cforall a. a -> [a] -> [a]
:[RoffTokens]
cs)
tableOptions :: PandocMonad m => RoffLexer m [TableOption]
tableOptions :: forall (m :: * -> *). PandocMonad m => RoffLexer m [TableOption]
tableOptions = forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => RoffLexer m TableOption
tableOption forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
';'
tableOption :: PandocMonad m => RoffLexer m TableOption
tableOption :: forall (m :: * -> *). PandocMonad m => RoffLexer m TableOption
tableOption = do
Text
k <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
letter
Text
v <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Text
"" forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'('
forall s (m :: * -> *) t st a.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m a -> ParsecT s st m Text
manyTillChar forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
')')
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
',' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab)
forall (m :: * -> *) a. Monad m => a -> m a
return (Text
k,Text
v)
tableFormatSpec :: PandocMonad m => RoffLexer m [[CellFormat]]
tableFormatSpec :: forall (m :: * -> *). PandocMonad m => RoffLexer m [[CellFormat]]
tableFormatSpec = do
[CellFormat]
first <- forall (m :: * -> *). PandocMonad m => RoffLexer m [CellFormat]
tableFormatSpecLine
[[CellFormat]]
rest <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
',') forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => RoffLexer m [CellFormat]
tableFormatSpecLine
let speclines :: [[CellFormat]]
speclines = [CellFormat]
firstforall a. a -> [a] -> [a]
:[[CellFormat]]
rest
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
spaces
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ [[CellFormat]]
speclines forall a. Semigroup a => a -> a -> a
<> forall a. a -> [a]
repeat (forall a. a -> [a] -> a
lastDef [] [[CellFormat]]
speclines)
tableFormatSpecLine :: PandocMonad m => RoffLexer m [CellFormat]
tableFormatSpecLine :: forall (m :: * -> *). PandocMonad m => RoffLexer m [CellFormat]
tableFormatSpecLine =
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall (m :: * -> *). PandocMonad m => RoffLexer m CellFormat
tableColFormat forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
tableColFormat :: PandocMonad m => RoffLexer m CellFormat
tableColFormat :: forall (m :: * -> *). PandocMonad m => RoffLexer m CellFormat
tableColFormat = do
Bool
pipePrefix' <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False
forall a b. (a -> b) -> a -> b
$ Bool
True forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"|" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t a u.
(Stream s m t, Show a) =>
ParsecT s u m a -> ParsecT s u m ()
notFollowedBy forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab)
Char
c <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf [Char
'a',Char
'A',Char
'c',Char
'C',Char
'l',Char
'L',Char
'n',Char
'N',Char
'r',Char
'R',Char
's',Char
'S',Char
'^',Char
'_',Char
'-',
Char
'=',Char
'|']
[Text]
suffixes <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(do Char
x <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
oneOf [Char
'b',Char
'B',Char
'd',Char
'D',Char
'e',Char
'E',Char
'f',Char
'F',Char
'i',Char
'I',Char
'm',Char
'M',
Char
'p',Char
'P',Char
't',Char
'T',Char
'u',Char
'U',Char
'v',Char
'V',Char
'w',Char
'W',Char
'x',Char
'X', Char
'z',Char
'Z']
String
num <- case Char -> Char
toLower Char
x of
Char
'w' -> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(do forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'('
String
xs <- forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
')')
forall (m :: * -> *) a. Monad m => a -> m a
return (String
"(" forall a. Semigroup a => a -> a -> a
<> String
xs forall a. Semigroup a => a -> a -> a
<> String
")")) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
forall (m :: * -> *) a. Monad m => a -> m a
return String
""
Char
'f' -> forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
Char
'm' -> forall s (m :: * -> *) t u a.
Stream s m t =>
Int -> ParsecT s u m a -> ParsecT s u m [a]
count Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
Char
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return String
""
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack forall a b. (a -> b) -> a -> b
$ Char
x forall a. a -> [a] -> [a]
: String
num)
Bool
pipeSuffix' <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Bool
False forall a b. (a -> b) -> a -> b
$ Bool
True forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"|"
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ CellFormat
{ columnType :: Char
columnType = Char
c
, pipePrefix :: Bool
pipePrefix = Bool
pipePrefix'
, pipeSuffix :: Bool
pipeSuffix = Bool
pipeSuffix'
, columnSuffixes :: [Text]
columnSuffixes = [Text]
suffixes }
lexConditional :: PandocMonad m => T.Text -> RoffLexer m RoffTokens
lexConditional :: forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m RoffTokens
lexConditional Text
mname = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
Maybe Bool
mbtest <- if Text
mname forall a. Eq a => a -> a -> Bool
== Text
"el"
then forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. RoffState -> Maybe Bool
lastExpression forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
else forall (m :: * -> *). PandocMonad m => RoffLexer m (Maybe Bool)
expression
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
RoffState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
RoffTokens
ifPart <- do
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline
forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexGroup
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> do forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
s -> RoffState
s{ afterConditional :: Bool
afterConditional = Bool
True }
RoffTokens
t <- forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
manToken
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
s -> RoffState
s{ afterConditional :: Bool
afterConditional = Bool
False }
forall (m :: * -> *) a. Monad m => a -> m a
return RoffTokens
t
case Maybe Bool
mbtest of
Maybe Bool
Nothing -> do
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState RoffState
st
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent (Char -> Text -> Text
T.cons Char
'.' Text
mname) SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
Just Bool
True -> forall (m :: * -> *) a. Monad m => a -> m a
return RoffTokens
ifPart
Just Bool
False -> do
forall (m :: * -> *) u s. Monad m => u -> ParsecT s u m ()
setState RoffState
st
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
expression :: PandocMonad m => RoffLexer m (Maybe Bool)
expression :: forall (m :: * -> *). PandocMonad m => RoffLexer m (Maybe Bool)
expression = do
Text
raw <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> Char -> ParsecT s st m Text -> ParsecT s st m Text
charsInBalanced Char
'(' Char
')' (Char -> Text
T.singleton forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy (forall a. Eq a => a -> a -> Bool
/= Char
'\n')))
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
nonspaceChar
forall {m :: * -> *} {s}.
Monad m =>
Maybe Bool -> ParsecT s RoffState m (Maybe Bool)
returnValue forall a b. (a -> b) -> a -> b
$
case Text
raw of
Text
"1" -> forall a. a -> Maybe a
Just Bool
True
Text
"n" -> forall a. a -> Maybe a
Just Bool
True
Text
"t" -> forall a. a -> Maybe a
Just Bool
False
Text
_ -> forall a. Maybe a
Nothing
where
returnValue :: Maybe Bool -> ParsecT s RoffState m (Maybe Bool)
returnValue Maybe Bool
v = do
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
st -> RoffState
st{ lastExpression :: Maybe Bool
lastExpression = Maybe Bool
v }
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Bool
v
lexGroup :: PandocMonad m => RoffLexer m RoffTokens
lexGroup :: forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexGroup = do
forall {u}. ParsecT Sources u m String
groupstart
forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
manToken forall {u}. ParsecT Sources u m String
groupend
where
groupstart :: ParsecT Sources u m String
groupstart = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"\\{" forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional (forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"\\\n"))
groupend :: ParsecT Sources u m String
groupend = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"\\}"
lexIncludeFile :: PandocMonad m => [Arg] -> RoffLexer m RoffTokens
lexIncludeFile :: forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexIncludeFile [[LinePart]]
args = do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
case [[LinePart]]
args of
([LinePart]
f:[[LinePart]]
_) -> do
let fp :: Text
fp = [LinePart] -> Text
linePartsToText [LinePart]
f
[String]
dirs <- forall (m :: * -> *). PandocMonad m => m [String]
getResourcePath
Maybe Text
result <- forall (m :: * -> *).
PandocMonad m =>
[String] -> String -> m (Maybe Text)
readFileFromDirs [String]
dirs forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
fp
case Maybe Text
result of
Maybe Text
Nothing -> forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
CouldNotLoadIncludeFile Text
fp SourcePos
pos
Just Text
s -> forall (m :: * -> *) u. Monad m => Text -> ParsecT Sources u m ()
addToInput Text
s
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
resolveMacro :: PandocMonad m
=> T.Text -> [Arg] -> SourcePos -> RoffLexer m RoffTokens
resolveMacro :: forall (m :: * -> *).
PandocMonad m =>
Text -> [[LinePart]] -> SourcePos -> RoffLexer m RoffTokens
resolveMacro Text
macroName [[LinePart]]
args SourcePos
pos = do
Map Text RoffTokens
macros <- RoffState -> Map Text RoffTokens
customMacros forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
macroName Map Text RoffTokens
macros of
Maybe RoffTokens
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ RoffToken -> RoffTokens
singleTok forall a b. (a -> b) -> a -> b
$ Text -> [[LinePart]] -> SourcePos -> RoffToken
ControlLine Text
macroName [[LinePart]]
args SourcePos
pos
Just RoffTokens
ts -> do
let fillLP :: LinePart -> [LinePart] -> [LinePart]
fillLP (MacroArg Int
i) [LinePart]
zs =
case forall a. Int -> [a] -> [a]
drop (Int
i forall a. Num a => a -> a -> a
- Int
1) [[LinePart]]
args of
[] -> [LinePart]
zs
([LinePart]
ys:[[LinePart]]
_) -> [LinePart]
ys forall a. Semigroup a => a -> a -> a
<> [LinePart]
zs
fillLP LinePart
z [LinePart]
zs = LinePart
z forall a. a -> [a] -> [a]
: [LinePart]
zs
let fillMacroArg :: RoffToken -> RoffToken
fillMacroArg (TextLine [LinePart]
lineparts) =
[LinePart] -> RoffToken
TextLine (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr LinePart -> [LinePart] -> [LinePart]
fillLP [] [LinePart]
lineparts)
fillMacroArg RoffToken
x = RoffToken
x
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Seq RoffToken -> RoffTokens
RoffTokens forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RoffToken -> RoffToken
fillMacroArg forall b c a. (b -> c) -> (a -> b) -> a -> c
. RoffTokens -> Seq RoffToken
unRoffTokens forall a b. (a -> b) -> a -> b
$ RoffTokens
ts
lexStringDef :: PandocMonad m => [Arg] -> RoffLexer m RoffTokens
lexStringDef :: forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexStringDef [[LinePart]]
args = do
case [[LinePart]]
args of
[] -> forall (m :: * -> *) a. MonadFail m => String -> m a
Prelude.fail String
"No argument to .ds"
([LinePart]
x:[[LinePart]]
ys) -> do
let ts :: RoffTokens
ts = RoffToken -> RoffTokens
singleTok forall a b. (a -> b) -> a -> b
$ [LinePart] -> RoffToken
TextLine (forall a. [a] -> [[a]] -> [a]
intercalate [Text -> LinePart
RoffStr Text
" " ] [[LinePart]]
ys)
let stringName :: Text
stringName = [LinePart] -> Text
linePartsToText [LinePart]
x
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
st ->
RoffState
st{ customMacros :: Map Text RoffTokens
customMacros = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
stringName RoffTokens
ts (RoffState -> Map Text RoffTokens
customMacros RoffState
st) }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
lexMacroDef :: PandocMonad m => [Arg] -> RoffLexer m RoffTokens
lexMacroDef :: forall (m :: * -> *).
PandocMonad m =>
[[LinePart]] -> RoffLexer m RoffTokens
lexMacroDef [[LinePart]]
args = do
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
st -> RoffState
st{ roffMode :: RoffMode
roffMode = RoffMode
CopyMode }
(Text
macroName, Text
stopMacro) <-
case [[LinePart]]
args of
([LinePart]
x : [LinePart]
y : [[LinePart]]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return ([LinePart] -> Text
linePartsToText [LinePart]
x, [LinePart] -> Text
linePartsToText [LinePart]
y)
([LinePart]
x:[[LinePart]]
_) -> forall (m :: * -> *) a. Monad m => a -> m a
return ([LinePart] -> Text
linePartsToText [LinePart]
x, Text
".")
[] -> forall (m :: * -> *) a. MonadFail m => String -> m a
Prelude.fail String
"No argument to .de"
let stop :: ParsecT Sources RoffState m ()
stop = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\''
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
Text -> ParsecT s u m Text
textStr Text
stopMacro
[[LinePart]]
_ <- forall (m :: * -> *). PandocMonad m => RoffLexer m [[LinePart]]
lexArgs
forall (m :: * -> *) a. Monad m => a -> m a
return ()
RoffTokens
ts <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a end.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m end -> ParsecT s u m [a]
manyTill forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
manToken ParsecT Sources RoffState m ()
stop
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \RoffState
st ->
RoffState
st{ customMacros :: Map Text RoffTokens
customMacros = forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
macroName RoffTokens
ts (RoffState -> Map Text RoffTokens
customMacros RoffState
st)
, roffMode :: RoffMode
roffMode = RoffMode
NormalMode }
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
lexArgs :: PandocMonad m => RoffLexer m [Arg]
lexArgs :: forall (m :: * -> *). PandocMonad m => RoffLexer m [[LinePart]]
lexArgs = do
[[LinePart]]
args <- forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
oneArg
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
eofline
forall (m :: * -> *) a. Monad m => a -> m a
return [[LinePart]]
args
where
oneArg :: PandocMonad m => RoffLexer m [LinePart]
oneArg :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
oneArg = do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"\\\n"
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
quotedArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
plainArg
plainArg :: PandocMonad m => RoffLexer m [LinePart]
plainArg :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
plainArg = do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
macroArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escape forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
regularText forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT Sources u m [LinePart]
unescapedQuote)
where
unescapedQuote :: ParsecT Sources u m [LinePart]
unescapedQuote = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\""]
quotedArg :: PandocMonad m => RoffLexer m [LinePart]
quotedArg :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
quotedArg = do
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m ()
skipMany forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"'
[LinePart]
xs <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
macroArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escape forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
regularText
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
spaceTabChar forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall {u}. ParsecT Sources u m [LinePart]
escapedQuote)
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"'
forall (m :: * -> *) a. Monad m => a -> m a
return [LinePart]
xs
where
escapedQuote :: ParsecT Sources u m [LinePart]
escapedQuote = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"'
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"'
forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\""]
checkDefined :: PandocMonad m => T.Text -> RoffLexer m [LinePart]
checkDefined :: forall (m :: * -> *).
PandocMonad m =>
Text -> RoffLexer m [LinePart]
checkDefined Text
name = do
Map Text RoffTokens
macros <- RoffState -> Map Text RoffTokens
customMacros forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Text
name Map Text RoffTokens
macros of
Just RoffTokens
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"1"]
Maybe RoffTokens
Nothing -> forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"0"]
escString :: PandocMonad m => RoffLexer m [LinePart]
escString :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escString = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
(do Text
cs <- forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
anyChar
forall (m :: * -> *).
PandocMonad m =>
Text -> SourcePos -> RoffLexer m [LinePart]
resolveText Text
cs SourcePos
pos)
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall a. Monoid a => a
mempty forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'S'
resolveText :: PandocMonad m
=> T.Text -> SourcePos -> RoffLexer m [LinePart]
resolveText :: forall (m :: * -> *).
PandocMonad m =>
Text -> SourcePos -> RoffLexer m [LinePart]
resolveText Text
stringname SourcePos
pos = do
RoffTokens Seq RoffToken
ts <- forall (m :: * -> *).
PandocMonad m =>
Text -> [[LinePart]] -> SourcePos -> RoffLexer m RoffTokens
resolveMacro Text
stringname [] SourcePos
pos
case forall (t :: * -> *) a. Foldable t => t a -> [a]
Foldable.toList Seq RoffToken
ts of
[TextLine [LinePart]
xs] -> forall (m :: * -> *) a. Monad m => a -> m a
return [LinePart]
xs
[RoffToken]
_ -> do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent (Text
"unknown string " forall a. Semigroup a => a -> a -> a
<> Text
stringname) SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
lexLine :: PandocMonad m => RoffLexer m RoffTokens
lexLine :: forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexLine = do
RoffMode
mode <- RoffState -> RoffMode
roffMode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case RoffMode
mode of
RoffMode
CopyMode -> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m String
string String
"\\&"
RoffMode
NormalMode -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
[LinePart]
lnparts <- forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
linePart
forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m ()
eofline
forall {m :: * -> *}. Monad m => [LinePart] -> m RoffTokens
go [LinePart]
lnparts
where
go :: [LinePart] -> m RoffTokens
go [] = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Monoid a => a
mempty
go (RoffStr Text
"" : [LinePart]
xs) = [LinePart] -> m RoffTokens
go [LinePart]
xs
go [LinePart]
xs = forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ RoffToken -> RoffTokens
singleTok forall a b. (a -> b) -> a -> b
$ [LinePart] -> RoffToken
TextLine [LinePart]
xs
linePart :: PandocMonad m => RoffLexer m [LinePart]
linePart :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
linePart = forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
macroArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
escape forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
regularText forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
quoteChar forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
spaceTabChar
backslash :: PandocMonad m => RoffLexer m ()
backslash :: forall (m :: * -> *). PandocMonad m => RoffLexer m ()
backslash = do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\'
RoffMode
mode <- RoffState -> RoffMode
roffMode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
case RoffMode
mode of
RoffMode
CopyMode -> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
optional forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'\\'
RoffMode
NormalMode -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
macroArg :: PandocMonad m => RoffLexer m [LinePart]
macroArg :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
macroArg = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
SourcePos
pos <- forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition
forall (m :: * -> *). PandocMonad m => RoffLexer m ()
backslash
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'$'
Text
x <- forall (m :: * -> *). PandocMonad m => RoffLexer m Text
escapeArg forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char, Monad m) =>
Int -> ParsecT s st m Char -> ParsecT s st m Text
countChar Int
1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit
case forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead Text
x of
Just Int
i -> forall (m :: * -> *) a. Monad m => a -> m a
return [Int -> LinePart
MacroArg Int
i]
Maybe Int
Nothing -> do
forall (m :: * -> *). PandocMonad m => LogMessage -> m ()
report forall a b. (a -> b) -> a -> b
$ Text -> SourcePos -> LogMessage
SkippedContent (Text
"illegal macro argument " forall a. Semigroup a => a -> a -> a
<> Text
x) SourcePos
pos
forall (m :: * -> *) a. Monad m => a -> m a
return []
regularText :: PandocMonad m => RoffLexer m [LinePart]
regularText :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
regularText = do
Text
s <- forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
String -> ParsecT s u m Char
noneOf String
"\n\r\t \\\""
forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
s]
quoteChar :: PandocMonad m => RoffLexer m [LinePart]
quoteChar :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
quoteChar = do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'"'
forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr Text
"\""]
spaceTabChar :: PandocMonad m => RoffLexer m [LinePart]
spaceTabChar :: forall (m :: * -> *). PandocMonad m => RoffLexer m [LinePart]
spaceTabChar = do
Char
c <- forall s (m :: * -> *) u.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
spacetab
forall (m :: * -> *) a. Monad m => a -> m a
return [Text -> LinePart
RoffStr forall a b. (a -> b) -> a -> b
$ Char -> Text
T.singleton Char
c]
lexEmptyLine :: PandocMonad m => RoffLexer m RoffTokens
lexEmptyLine :: forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexEmptyLine = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
newline forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (RoffToken -> RoffTokens
singleTok RoffToken
EmptyLine)
manToken :: PandocMonad m => RoffLexer m RoffTokens
manToken :: forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
manToken = forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexComment forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexMacro forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexLine forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
lexEmptyLine
linePartsToText :: [LinePart] -> T.Text
linePartsToText :: [LinePart] -> Text
linePartsToText = forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map LinePart -> Text
go
where
go :: LinePart -> Text
go (RoffStr Text
s) = Text
s
go LinePart
_ = forall a. Monoid a => a
mempty
lexRoff :: PandocMonad m => SourcePos -> T.Text -> m RoffTokens
lexRoff :: forall (m :: * -> *).
PandocMonad m =>
SourcePos -> Text -> m RoffTokens
lexRoff SourcePos
pos Text
txt = do
Either PandocError RoffTokens
eithertokens <- forall (m :: * -> *) t st a.
(Monad m, ToSources t) =>
ParsecT Sources st m a -> st -> t -> m (Either PandocError a)
readWithM (do forall (m :: * -> *) s u. Monad m => SourcePos -> ParsecT s u m ()
setPosition SourcePos
pos
forall a. Monoid a => [a] -> a
mconcat forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall (m :: * -> *). PandocMonad m => RoffLexer m RoffTokens
manToken) forall a. Default a => a
def Text
txt
case Either PandocError RoffTokens
eithertokens of
Left PandocError
e -> forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError PandocError
e
Right RoffTokens
tokenz -> forall (m :: * -> *) a. Monad m => a -> m a
return RoffTokens
tokenz