git.iko.soy/typeable/pandoc
on master help sign in
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."

commit328655e8636bc524829ae56ffd5ef15ad21f3917 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 19 Jun 2017, 22:41 (9 years ago) parentb6a38ed
2 files changed+9−3
src/Text/Pandoc/Class.hs+7−2 src/Text/Pandoc/Parsing.hs+2−1
src/Text/Pandoc/Class.hs+7−2
@@ -79,7 +79,7 @@ import qualified Text.Pandoc.Shared as IO ( readDataFile
7979import qualified Text.Pandoc.UTF8 as UTF8
8080import Text.Pandoc.Compat.Time (UTCTime)
8181import Text.Pandoc.Logging
82−import Text.Parsec (ParsecT, getPosition)
82+import Text.Parsec (ParsecT, getPosition, sourceLine, sourceName)
8383import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
8484import Text.Pandoc.MIME (MimeType, getMimeType, extensionFromMimeType)
8585import Text.Pandoc.Definition
@@ -576,7 +576,12 @@ instance PandocMonad m => PandocMonad (ParsecT s st m) where
576576 when tracing $ do
577577 pos <- getPosition
578578 Debug.Trace.trace
579− ("[trace] Parsed " ++ msg ++ " at " ++ show pos) (return ())
579+ ("[trace] Parsed " ++ msg ++ " at line " ++
580+ show (sourceLine pos) ++
581+ if sourceName pos == "chunk"
582+ then " of chunk"
583+ else "")
584+ (return ())
580585 logOutput = lift . logOutput
581586
582587
src/Text/Pandoc/Parsing.hs+2−1
@@ -189,7 +189,7 @@ import qualified Text.Pandoc.Builder as B
189189import Text.Pandoc.XML (fromEntities)
190190import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
191191import Text.Parsec hiding (token)
192−import Text.Parsec.Pos (newPos)
192+import Text.Parsec.Pos (newPos, initialPos)
193193import Data.Char ( toLower, toUpper, ord, chr, isAscii, isAlphaNum,
194194 isHexDigit, isSpace, isPunctuation )
195195import Data.List ( intercalate, transpose, isSuffixOf )
@@ -366,6 +366,7 @@ parseFromString :: Monad m
366366 -> ParserT String st m a
367367parseFromString parser str = do
368368 oldPos <- getPosition
369+ setPosition $ initialPos "chunk"
369370 oldInput <- getInput
370371 setInput str
371372 result <- parser