diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-03-28 22:20:05 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-03-28 22:20:05 -0700 |
commit | 7cb8b60910ede36bba3598f85a06ddde6fc545d0 (patch) | |
tree | 956fd879932010f5ed094ec64eef4eea1c49fe9c /src/Text/Pandoc/Parsing.hs | |
parent | 30969974f065710d3abc8dcfcce92a84af32f1d9 (diff) | |
download | pandoc-7cb8b60910ede36bba3598f85a06ddde6fc545d0.tar.gz |
Parsing: Better error reporting in readWith.
- Specialize readWith to String input.
- On error have it print the line in which the error occurred,
with a caret pointing to the column.
- This should help diagnose parsing problems in LaTeX especially.
Diffstat (limited to 'src/Text/Pandoc/Parsing.hs')
-rw-r--r-- | src/Text/Pandoc/Parsing.hs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index c5e77bec2..72ae828f0 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -764,13 +764,20 @@ gridTableFooter = blanklines --- -- | Parse a string with a given parser and state. -readWith :: Parser [t] ParserState a -- ^ parser - -> ParserState -- ^ initial state - -> [t] -- ^ input +readWith :: Parser [Char] ParserState a -- ^ parser + -> ParserState -- ^ initial state + -> [Char] -- ^ input -> a readWith parser state input = case runParser parser state "source" input of - Left err' -> error $ "\nError:\n" ++ show err' + Left err' -> + let errPos = errorPos err' + errLine = sourceLine errPos + errColumn = sourceColumn errPos + theline = (lines input ++ [""]) !! (errLine - 1) + in error $ "\nError at " ++ show err' ++ "\n" ++ + theline ++ "\n" ++ replicate (errColumn - 1) ' ' ++ + "^" Right result -> result -- | Parse a string with @parser@ (for testing). |