git.iko.soy/typeable/pandoc
on master help sign in
Fix inline parsing in grid table cells.

* T.P.Parsing: Change type of `setLastStrPos` so it takes a `Maybe SourcePos` rather than a `SourcePos`. [API change] * T.P.Parsing: Make `parseFromString'` and `gridTableWith` and `gridTableWith'` polymorphic in the parser state, constraining it with `HasLastStrPosition`. [API change] Closes #5708.

commit21c44da17aa62e1147fbe6d36e8dcbe3ff43dd08 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 26 Aug 2019, 15:25 (7 years ago) parent180f534
3 files changed+18−16
src/Text/Pandoc/Parsing.hs+16−14 src/Text/Pandoc/Readers/Muse.hs+1−1 src/Text/Pandoc/Readers/Org/ParserState.hs+1−1
src/Text/Pandoc/Parsing.hs+16−14
@@ -456,14 +456,14 @@ parseFromString parser str = do
456456
457457-- | Like 'parseFromString' but specialized for 'ParserState'.
458458-- This resets 'stateLastStrPos', which is almost always what we want.
459−parseFromString' :: (Stream s m Char, IsString s)
460− => ParserT s ParserState m a
459+parseFromString' :: (Stream s m Char, IsString s, HasLastStrPosition u)
460+ => ParserT s u m a
461461 -> String
462− -> ParserT s ParserState m a
462+ -> ParserT s u m a
463463parseFromString' parser str = do
464− oldStrPos <- stateLastStrPos <$> getState
464+ oldLastStrPos <- getLastStrPos <$> getState
465465 res <- parseFromString parser str
466− updateState $ \st -> st{ stateLastStrPos = oldStrPos }
466+ updateState $ setLastStrPos oldLastStrPos
467467 return res
468468
469469-- | Parse raw line block up to and including blank lines.
@@ -908,7 +908,8 @@ widthsFromIndices numColumns' indices =
908908-- (which may be grid), then the rows,
909909-- which may be grid, separated by blank lines, and
910910-- ending with a footer (dashed line followed by blank line).
911−gridTableWith :: (Stream s m Char, HasReaderOptions st, Monad mf, IsString s)
911+gridTableWith :: (Stream s m Char, HasReaderOptions st, HasLastStrPosition st,
912+ Monad mf, IsString s)
912913 => ParserT s st m (mf Blocks) -- ^ Block list parser
913914 -> Bool -- ^ Headerless table
914915 -> ParserT s st m (mf Blocks)
@@ -916,7 +917,8 @@ gridTableWith blocks headless =
916917 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
917918 (gridTableSep '-') gridTableFooter
918919
919−gridTableWith' :: (Stream s m Char, HasReaderOptions st, Monad mf, IsString s)
920+gridTableWith' :: (Stream s m Char, HasReaderOptions st, HasLastStrPosition st,
921+ Monad mf, IsString s)
920922 => ParserT s st m (mf Blocks) -- ^ Block list parser
921923 -> Bool -- ^ Headerless table
922924 -> ParserT s st m (TableComponents mf)
@@ -955,7 +957,7 @@ gridTableSep :: Stream s m Char => Char -> ParserT s st m Char
955957gridTableSep ch = try $ gridDashedLines ch >> return '\n'
956958
957959-- | Parse header for a grid table.
958−gridTableHeader :: (Stream s m Char, Monad mf, IsString s)
960+gridTableHeader :: (Stream s m Char, Monad mf, IsString s, HasLastStrPosition st)
959961 => Bool -- ^ Headerless table
960962 -> ParserT s st m (mf Blocks)
961963 -> ParserT s st m (mf [Blocks], [Alignment], [Int])
@@ -978,7 +980,7 @@ gridTableHeader headless blocks = try $ do
978980 then replicate (length underDashes) ""
979981 else map (unlines . map trim) $ transpose
980982 $ map (gridTableSplitLine indices) rawContent
981− heads <- sequence <$> mapM (parseFromString blocks . trim) rawHeads
983+ heads <- sequence <$> mapM (parseFromString' blocks . trim) rawHeads
982984 return (heads, aligns, indices)
983985
984986gridTableRawLine :: Stream s m Char => [Int] -> ParserT s st m [String]
@@ -988,7 +990,7 @@ gridTableRawLine indices = do
988990 return (gridTableSplitLine indices line)
989991
990992-- | Parse row of grid table.
991−gridTableRow :: (Stream s m Char, Monad mf, IsString s)
993+gridTableRow :: (Stream s m Char, Monad mf, IsString s, HasLastStrPosition st)
992994 => ParserT s st m (mf Blocks)
993995 -> [Int]
994996 -> ParserT s st m (mf [Blocks])
@@ -999,7 +1001,7 @@ gridTableRow blocks indices = do
9991001 compactifyCell bs = case compactify [bs] of
10001002 [] -> mempty
10011003 x:_ -> x
1002− cells <- sequence <$> mapM (parseFromString blocks) cols
1004+ cells <- sequence <$> mapM (parseFromString' blocks) cols
10031005 return $ fmap (map compactifyCell) cells
10041006
10051007removeOneLeadingSpace :: [String] -> [String]
@@ -1124,11 +1126,11 @@ instance HasMacros ParserState where
11241126 updateMacros f st = st{ stateMacros = f $ stateMacros st }
11251127
11261128class HasLastStrPosition st where
1127− setLastStrPos :: SourcePos -> st -> st
1129+ setLastStrPos :: Maybe SourcePos -> st -> st
11281130 getLastStrPos :: st -> Maybe SourcePos
11291131
11301132instance HasLastStrPosition ParserState where
1131− setLastStrPos pos st = st{ stateLastStrPos = Just pos }
1133+ setLastStrPos pos st = st{ stateLastStrPos = pos }
11321134 getLastStrPos st = stateLastStrPos st
11331135
11341136class HasLogMessages st where
@@ -1202,7 +1204,7 @@ guardDisabled ext = getOption readerExtensions >>= guard . not . extensionEnable
12021204
12031205-- | Update the position on which the last string ended.
12041206updateLastStrPos :: (Stream s m a, HasLastStrPosition st) => ParserT s st m ()
1205−updateLastStrPos = getPosition >>= updateState . setLastStrPos
1207+updateLastStrPos = getPosition >>= updateState . setLastStrPos . Just
12061208
12071209-- | Whether we are right after the end of a string.
12081210notAfterString :: (Stream s m a, HasLastStrPosition st) => ParserT s st m Bool
src/Text/Pandoc/Readers/Muse.hs+1−1
@@ -93,7 +93,7 @@ instance HasIdentifierList MuseState where
9393 updateIdentifierList f st = st{ museIdentifierList = f $ museIdentifierList st }
9494
9595instance HasLastStrPosition MuseState where
96− setLastStrPos pos st = st{ museLastStrPos = Just pos }
96+ setLastStrPos pos st = st{ museLastStrPos = pos }
9797 getLastStrPos st = museLastStrPos st
9898
9999instance HasLogMessages MuseState where
src/Text/Pandoc/Readers/Org/ParserState.hs+1−1
@@ -133,7 +133,7 @@ instance HasReaderOptions OrgParserState where
133133
134134instance HasLastStrPosition OrgParserState where
135135 getLastStrPos = orgStateLastStrPos
136− setLastStrPos pos st = st{ orgStateLastStrPos = Just pos }
136+ setLastStrPos pos st = st{ orgStateLastStrPos = pos }
137137
138138instance Monad m => HasQuoteContext st (ReaderT OrgParserLocal m) where
139139 getQuoteContext = asks orgLocalQuoteContext