diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 96e3b4f3c..5b36cdd56 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -71,6 +71,8 @@ sourceFirstLine = \case GenericSourcePos _ line _ -> line JournalSourcePos _ (line, _) -> line +-- | Render source position in human-readable form. +-- Keep in sync with Hledger.UI.ErrorScreen.hledgerparseerrorpositionp (temporary). XXX showGenericSourcePos :: GenericSourcePos -> String showGenericSourcePos = \case GenericSourcePos fp line column -> show fp ++ " (line " ++ show line ++ ", column " ++ show column ++ ")" diff --git a/hledger-ui/Hledger/UI/ErrorScreen.hs b/hledger-ui/Hledger/UI/ErrorScreen.hs index c6e95d2f9..4b3c6d275 100644 --- a/hledger-ui/Hledger/UI/ErrorScreen.hs +++ b/hledger-ui/Hledger/UI/ErrorScreen.hs @@ -110,15 +110,27 @@ esHandle _ _ = error "event handler called with wrong screen type, should not ha -- | Parse the file name, line and column number from a hledger parse error message, if possible. -- Temporary, we should keep the original parse error location. XXX +-- Keep in sync with 'Hledger.Data.Transaction.showGenericSourcePos' hledgerparseerrorpositionp :: ParsecT Void String t (String, Int, Int) hledgerparseerrorpositionp = do anySingle `manyTill` char '"' f <- anySingle `manyTill` (oneOf ['"','\n']) - string " (line " - l <- read <$> some digitChar - string ", column " - c <- read <$> some digitChar - return (f, l, c) + choice [ + do + string " (line " + l <- read <$> some digitChar + string ", column " + c <- read <$> some digitChar + return (f, l, c), + do + string " (lines " + l <- read <$> some digitChar + char '-' + some digitChar + char ')' + return (f, l, 1) + ] + -- Unconditionally reload the journal, regenerating the current screen -- and all previous screens in the history.