mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
lib: Report source positions from internal comment parsers
This commit is contained in:
parent
b06d22a418
commit
09ec6041bd
@ -812,9 +812,11 @@ followingcommentp :: JournalParser m Text
|
|||||||
followingcommentp = do
|
followingcommentp = do
|
||||||
-- ptrace "followingcommentp"
|
-- ptrace "followingcommentp"
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
samelinecomment <- try commentp <|> (newline >> return "")
|
samelinecomment <- try commentp' <|> (newline >> return "")
|
||||||
newlinecomments <- many $ try $ lift (skipSome spacenonewline) >> commentp
|
newlinecomments <- many $ try $ lift (skipSome spacenonewline) >> commentp'
|
||||||
return $ T.unlines $ samelinecomment:newlinecomments
|
return $ T.unlines $ samelinecomment:newlinecomments
|
||||||
|
where
|
||||||
|
commentp' = fmap snd commentp :: JournalParser m Text
|
||||||
|
|
||||||
-- | Parse a possibly multi-line comment following a semicolon, and
|
-- | Parse a possibly multi-line comment following a semicolon, and
|
||||||
-- any tags and/or posting dates within it. Posting dates can be
|
-- any tags and/or posting dates within it. Posting dates can be
|
||||||
@ -872,23 +874,27 @@ followingcommentandtagsp mdefdate = do
|
|||||||
return (comment, tags, mdate, mdate2)
|
return (comment, tags, mdate, mdate2)
|
||||||
|
|
||||||
-- A transaction/posting comment must start with a semicolon.
|
-- A transaction/posting comment must start with a semicolon.
|
||||||
-- This parser ignores leading whitespace.
|
-- This parser discards the leading whitespace of the comment
|
||||||
commentp :: JournalParser m Text
|
-- and returns the source position of the comment's first non-whitespace character.
|
||||||
|
commentp :: JournalParser m (SourcePos, Text)
|
||||||
commentp = commentStartingWithp ";"
|
commentp = commentStartingWithp ";"
|
||||||
|
|
||||||
-- A line (file-level) comment can start with a semicolon, hash,
|
-- A line (file-level) comment can start with a semicolon, hash,
|
||||||
-- or star (allowing org nodes). This parser ignores leading whitespace.
|
-- or star (allowing org nodes).
|
||||||
linecommentp :: JournalParser m Text
|
-- This parser discards the leading whitespace of the comment
|
||||||
|
-- and returns the source position of the comment's first non-whitespace character.
|
||||||
|
linecommentp :: JournalParser m (SourcePos, Text)
|
||||||
linecommentp = commentStartingWithp ";#*"
|
linecommentp = commentStartingWithp ";#*"
|
||||||
|
|
||||||
commentStartingWithp :: [Char] -> JournalParser m Text
|
commentStartingWithp :: [Char] -> JournalParser m (SourcePos, Text)
|
||||||
commentStartingWithp cs = do
|
commentStartingWithp cs = do
|
||||||
-- ptrace "commentStartingWith"
|
-- ptrace "commentStartingWith"
|
||||||
oneOf cs
|
oneOf cs
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
l <- anyChar `manyTill` (lift eolof)
|
startPos <- getPosition
|
||||||
|
content <- T.pack <$> anyChar `manyTill` (lift eolof)
|
||||||
optional newline
|
optional newline
|
||||||
return $ T.pack l
|
return (startPos, content)
|
||||||
|
|
||||||
--- ** tags
|
--- ** tags
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user