From bf40d28c8bb9698387f528c06628d4d005df9389 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 25 Apr 2025 13:59:18 -1000 Subject: [PATCH] imp: config files (and maybe timedot files) no longer require a final newline --- hledger-lib/Hledger/Read/Common.hs | 5 +++-- hledger/Hledger/Cli/Conf.hs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index d058d9194..b9981a85d 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -426,7 +426,7 @@ getYear = fmap jparsedefaultyear get dp :: String -> TextParser m () dp = const $ return () -- no-op --- dp = dbgparse 1 -- trace parse state at this --debug level +-- dp = dbgparse 0 -- trace parse state at this --debug level -- | Get the decimal mark that has been specified for parsing, if any -- (eg by the CSV decimal-mark rule, or possibly a future journal directive). @@ -1299,6 +1299,7 @@ emptyorcommentlinep = do -- | A newer comment line parser. -- Parses a line which is empty, all blanks, or whose first non-blank character is one of those provided. +-- A final newline is optional. emptyorcommentlinep2 :: [Char] -> TextParser m () emptyorcommentlinep2 cs = label ("empty line or comment line beginning with "++cs) $ do @@ -1308,7 +1309,7 @@ emptyorcommentlinep2 cs = where commentp = do choice (map (some.char) cs) - takeWhileP Nothing (/='\n') <* newline + takeWhileP Nothing (/='\n') <* optional newline -- | Is this a character that, as the first non-whitespace on a line, -- starts a comment line ? diff --git a/hledger/Hledger/Cli/Conf.hs b/hledger/Hledger/Cli/Conf.hs index 93516107d..d90de20c5 100644 --- a/hledger/Hledger/Cli/Conf.hs +++ b/hledger/Hledger/Cli/Conf.hs @@ -227,7 +227,7 @@ parseConf = runParser confp dp :: String -> TextParser m () dp = const $ return () -- no-op --- dp = dbgparse 1 -- trace parse state at this --debug level +-- dp = dbgparse 0 -- trace parse state at this --debug level whitespacep, commentlinesp, restoflinep :: TextParser Identity () whitespacep = void $ {- dp "whitespacep" >> -} many spacenonewline @@ -274,7 +274,7 @@ arglinep = do -- dp "arglinep3" a <- some $ noneOf "#\n" -- dp "arglinep4" - restoflinep + restoflinep <|> whitespacep -- whitespace / same-line comment, possibly with no newline commentlinesp return $ strip a