Tracing: give less misleading line information with parseWithString.

Previously positions would be reported past the end of the chunk.
We now reset the source position within the chunk and report
positions "in chunk."
This commit is contained in:
John MacFarlane 2017-06-19 22:41:09 +02:00
parent b6a38ed111
commit 328655e863
2 changed files with 9 additions and 3 deletions

View file

@ -79,7 +79,7 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Compat.Time (UTCTime)
import Text.Pandoc.Logging
import Text.Parsec (ParsecT, getPosition)
import Text.Parsec (ParsecT, getPosition, sourceLine, sourceName)
import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
import Text.Pandoc.MIME (MimeType, getMimeType, extensionFromMimeType)
import Text.Pandoc.Definition
@ -576,7 +576,12 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
when tracing $ do
pos <- getPosition
Debug.Trace.trace
("[trace] Parsed " ++ msg ++ " at " ++ show pos) (return ())
("[trace] Parsed " ++ msg ++ " at line " ++
show (sourceLine pos) ++
if sourceName pos == "chunk"
then " of chunk"
else "")
(return ())
logOutput = lift . logOutput

View file

@ -189,7 +189,7 @@ import qualified Text.Pandoc.Builder as B
import Text.Pandoc.XML (fromEntities)
import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
import Text.Parsec hiding (token)
import Text.Parsec.Pos (newPos)
import Text.Parsec.Pos (newPos, initialPos)
import Data.Char ( toLower, toUpper, ord, chr, isAscii, isAlphaNum,
isHexDigit, isSpace, isPunctuation )
import Data.List ( intercalate, transpose, isSuffixOf )
@ -366,6 +366,7 @@ parseFromString :: Monad m
-> ParserT String st m a
parseFromString parser str = do
oldPos <- getPosition
setPosition $ initialPos "chunk"
oldInput <- getInput
setInput str
result <- parser