From 7e84b4d64363041f1f7e55a069f01825533d9c63 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 18 May 2016 15:06:16 -0700 Subject: [PATCH] lib: rename get/setIndex, add increment fn --- hledger-lib/Hledger/Read/Common.hs | 14 ++++++++++---- hledger-lib/Hledger/Read/JournalReader.hs | 5 ++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 7a465a7f7..260ca7387 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -178,11 +178,17 @@ getAccountAliases = fmap ctxAliases getState clearAccountAliases :: Monad m => JournalParser m () clearAccountAliases = modifyState (\(ctx@Ctx{..}) -> ctx{ctxAliases=[]}) -getIndex :: Monad m => JournalParser m Integer -getIndex = fmap ctxTransactionIndex getState +getTransactionIndex :: Monad m => JournalParser m Integer +getTransactionIndex = fmap ctxTransactionIndex getState -setIndex :: Monad m => Integer -> JournalParser m () -setIndex i = modifyState (\ctx -> ctx{ctxTransactionIndex=i}) +setTransactionIndex :: Monad m => Integer -> JournalParser m () +setTransactionIndex i = modifyState (\ctx -> ctx{ctxTransactionIndex=i}) + +-- | Increment the transaction index by one and return the new value. +incrementTransactionIndex :: Monad m => JournalParser m Integer +incrementTransactionIndex = do + modifyState (\ctx -> ctx{ctxTransactionIndex=ctxTransactionIndex ctx + 1}) + getTransactionIndex journalAddFile :: (FilePath,String) -> Journal -> Journal journalAddFile f j@Journal{files=fs} = j{files=fs++[f]} diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index dabeb95df..856124c2e 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -416,9 +416,8 @@ transactionp = do comment <- try followingcommentp <|> (newline >> return "") let tags = commentTags comment postings <- postingsp (Just date) - i' <- (+1) <$> getIndex - setIndex i' - return $ txnTieKnot $ Transaction i' sourcepos date edate status code description comment tags postings "" + idx <- incrementTransactionIndex + return $ txnTieKnot $ Transaction idx sourcepos date edate status code description comment tags postings "" #ifdef TESTS test_transactionp = do