mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
lib: cleanup: remove redundant comment parsing alternatives
This commit is contained in:
parent
892a1c6434
commit
188583e232
@ -835,7 +835,7 @@ followingcommentlinesp :: TextParser m [(SourcePos, Text)]
|
|||||||
followingcommentlinesp = do
|
followingcommentlinesp = do
|
||||||
skipMany spacenonewline
|
skipMany spacenonewline
|
||||||
samelineComment@(_, samelineCommentText)
|
samelineComment@(_, samelineCommentText)
|
||||||
<- try commentp <|> (,) <$> (getPosition <* newline) <*> pure ""
|
<- try commentp <|> (,) <$> (getPosition <* eolof) <*> pure ""
|
||||||
newlineComments <- many $ try $ do
|
newlineComments <- many $ try $ do
|
||||||
skipSome spacenonewline -- leading whitespace is required
|
skipSome spacenonewline -- leading whitespace is required
|
||||||
commentp
|
commentp
|
||||||
|
@ -281,7 +281,7 @@ commoditydirectiveonelinep = do
|
|||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
Amount{acommodity,astyle} <- amountp
|
Amount{acommodity,astyle} <- amountp
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
_ <- lift followingcommentp <|> (lift eolof >> return "")
|
_ <- lift followingcommentp
|
||||||
let comm = Commodity{csymbol=acommodity, cformat=Just $ dbg2 "style from commodity directive" astyle}
|
let comm = Commodity{csymbol=acommodity, cformat=Just $ dbg2 "style from commodity directive" astyle}
|
||||||
if asdecimalpoint astyle == Nothing
|
if asdecimalpoint astyle == Nothing
|
||||||
then parserErrorAt pos pleaseincludedecimalpoint
|
then parserErrorAt pos pleaseincludedecimalpoint
|
||||||
@ -298,7 +298,7 @@ commoditydirectivemultilinep = do
|
|||||||
string "commodity"
|
string "commodity"
|
||||||
lift (skipSome spacenonewline)
|
lift (skipSome spacenonewline)
|
||||||
sym <- lift commoditysymbolp
|
sym <- lift commoditysymbolp
|
||||||
_ <- lift followingcommentp <|> (lift eolof >> return "")
|
_ <- lift followingcommentp
|
||||||
mformat <- lastMay <$> many (indented $ formatdirectivep sym)
|
mformat <- lastMay <$> many (indented $ formatdirectivep sym)
|
||||||
let comm = Commodity{csymbol=sym, cformat=mformat}
|
let comm = Commodity{csymbol=sym, cformat=mformat}
|
||||||
modify' (\j -> j{jcommodities=M.insert sym comm $ jcommodities j})
|
modify' (\j -> j{jcommodities=M.insert sym comm $ jcommodities j})
|
||||||
@ -313,7 +313,7 @@ formatdirectivep expectedsym = do
|
|||||||
lift (skipSome spacenonewline)
|
lift (skipSome spacenonewline)
|
||||||
pos <- getPosition
|
pos <- getPosition
|
||||||
Amount{acommodity,astyle} <- amountp
|
Amount{acommodity,astyle} <- amountp
|
||||||
_ <- lift followingcommentp <|> (lift eolof >> return "")
|
_ <- lift followingcommentp
|
||||||
if acommodity==expectedsym
|
if acommodity==expectedsym
|
||||||
then
|
then
|
||||||
if asdecimalpoint astyle == Nothing
|
if asdecimalpoint astyle == Nothing
|
||||||
@ -463,7 +463,7 @@ periodictransactionp = do
|
|||||||
char '~' <?> "periodic transaction"
|
char '~' <?> "periodic transaction"
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
periodexpr <- T.pack . strip <$> descriptionp
|
periodexpr <- T.pack . strip <$> descriptionp
|
||||||
_ <- try (lift followingcommentp) <|> (newline >> return "")
|
_ <- lift followingcommentp
|
||||||
postings <- postingsp Nothing
|
postings <- postingsp Nothing
|
||||||
return $ PeriodicTransaction periodexpr postings
|
return $ PeriodicTransaction periodexpr postings
|
||||||
|
|
||||||
@ -478,7 +478,7 @@ transactionp = do
|
|||||||
status <- lift statusp <?> "cleared status"
|
status <- lift statusp <?> "cleared status"
|
||||||
code <- T.pack <$> lift codep <?> "transaction code"
|
code <- T.pack <$> lift codep <?> "transaction code"
|
||||||
description <- T.pack . strip <$> descriptionp
|
description <- T.pack . strip <$> descriptionp
|
||||||
comment <- try (lift followingcommentp) <|> (newline >> return "")
|
comment <- lift followingcommentp
|
||||||
let tags = commentTags comment
|
let tags = commentTags comment
|
||||||
postings <- postingsp (Just date)
|
postings <- postingsp (Just date)
|
||||||
pos' <- getPosition
|
pos' <- getPosition
|
||||||
@ -606,8 +606,7 @@ postingp mtdate = do
|
|||||||
massertion <- partialbalanceassertionp
|
massertion <- partialbalanceassertionp
|
||||||
_ <- fixedlotpricep
|
_ <- fixedlotpricep
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
(comment,tags,mdate,mdate2) <-
|
(comment,tags,mdate,mdate2) <- followingcommentandtagsp mtdate
|
||||||
try (followingcommentandtagsp mtdate) <|> (newline >> return ("",[],Nothing,Nothing))
|
|
||||||
return posting
|
return posting
|
||||||
{ pdate=mdate
|
{ pdate=mdate
|
||||||
, pdate2=mdate2
|
, pdate2=mdate2
|
||||||
|
Loading…
Reference in New Issue
Block a user