aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-19 22:41:09 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-06-19 22:41:09 +0200
commit328655e8636bc524829ae56ffd5ef15ad21f3917 (patch)
treef70efd5bc2805bd1a3dd2adc8d78d0a097fa797e /src/Text/Pandoc
parentb6a38ed1114eae604706694aaca920b86ed28385 (diff)
downloadpandoc-328655e8636bc524829ae56ffd5ef15ad21f3917.tar.gz
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."
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Class.hs9
-rw-r--r--src/Text/Pandoc/Parsing.hs3
2 files changed, 9 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index a7194f8d5..120ba8fee 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -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
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index cd51bff69..eb5b37f40 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -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