2016-04-23 21:27:39 +03:00
|
|
|
--- * doc
|
2016-04-28 23:23:20 +03:00
|
|
|
-- Lines beginning "--- *" are collapsible orgstruct nodes. Emacs users,
|
2016-04-23 03:43:16 +03:00
|
|
|
-- (add-hook 'haskell-mode-hook
|
2016-04-23 21:27:39 +03:00
|
|
|
-- (lambda () (set-variable 'orgstruct-heading-prefix-regexp "--- " t))
|
2016-04-23 03:43:16 +03:00
|
|
|
-- 'orgstruct-mode)
|
2016-04-28 23:23:20 +03:00
|
|
|
-- and press TAB on nodes to expand/collapse.
|
2016-04-23 03:43:16 +03:00
|
|
|
|
2008-10-01 04:29:58 +04:00
|
|
|
{-|
|
2008-10-03 06:28:58 +04:00
|
|
|
|
2012-03-24 22:08:11 +04:00
|
|
|
A reader for hledger's journal file format
|
|
|
|
(<http://hledger.org/MANUAL.html#the-journal-file>). hledger's journal
|
|
|
|
format is a compatible subset of c++ ledger's
|
|
|
|
(<http://ledger-cli.org/3.0/doc/ledger3.html#Journal-Format>), so this
|
|
|
|
reader should handle many ledger files as well. Example:
|
2007-03-12 10:40:33 +03:00
|
|
|
|
2008-10-01 05:40:32 +04:00
|
|
|
@
|
2012-03-24 22:08:11 +04:00
|
|
|
2012\/3\/24 gift
|
|
|
|
expenses:gifts $10
|
|
|
|
assets:cash
|
2008-10-01 05:40:32 +04:00
|
|
|
@
|
2008-10-01 04:29:58 +04:00
|
|
|
|
2016-05-18 05:46:54 +03:00
|
|
|
Journal format supports the include directive which can read files in
|
|
|
|
other formats, so the other file format readers need to be importable
|
|
|
|
here. Some low-level journal syntax parsers which those readers also
|
|
|
|
use are therefore defined separately in Hledger.Read.Common, avoiding
|
|
|
|
import cycles.
|
|
|
|
|
2007-02-09 04:23:12 +03:00
|
|
|
-}
|
2007-07-04 16:05:54 +04:00
|
|
|
|
2016-04-23 21:27:39 +03:00
|
|
|
--- * module
|
|
|
|
|
2018-06-04 22:30:43 +03:00
|
|
|
{-# LANGUAGE CPP, RecordWildCards, NamedFieldPuns, NoMonoLocalBinds, ScopedTypeVariables, FlexibleContexts, TupleSections, OverloadedStrings, PackageImports #-}
|
2016-04-23 03:43:16 +03:00
|
|
|
|
2010-11-15 10:01:46 +03:00
|
|
|
module Hledger.Read.JournalReader (
|
2016-04-28 23:23:20 +03:00
|
|
|
--- * exports
|
|
|
|
|
2012-03-24 22:08:11 +04:00
|
|
|
-- * Reader
|
|
|
|
reader,
|
2016-04-23 03:43:16 +03:00
|
|
|
|
|
|
|
-- * Parsing utils
|
2015-06-29 02:20:28 +03:00
|
|
|
genericSourcePos,
|
2016-04-23 03:43:16 +03:00
|
|
|
parseAndFinaliseJournal,
|
2016-05-07 02:58:07 +03:00
|
|
|
runJournalParser,
|
|
|
|
rjp,
|
2016-04-23 03:43:16 +03:00
|
|
|
|
|
|
|
-- * Parsers used elsewhere
|
2012-03-24 22:08:11 +04:00
|
|
|
getParentAccount,
|
2015-10-17 21:51:45 +03:00
|
|
|
journalp,
|
|
|
|
directivep,
|
|
|
|
defaultyeardirectivep,
|
|
|
|
marketpricedirectivep,
|
2014-02-06 06:55:38 +04:00
|
|
|
datetimep,
|
2016-02-20 02:14:25 +03:00
|
|
|
datep,
|
2015-09-25 03:23:52 +03:00
|
|
|
modifiedaccountnamep,
|
2014-02-06 01:02:24 +04:00
|
|
|
postingp,
|
2015-05-16 21:51:35 +03:00
|
|
|
statusp,
|
2014-02-27 23:47:36 +04:00
|
|
|
emptyorcommentlinep,
|
2019-07-17 01:30:15 +03:00
|
|
|
followingcommentp,
|
|
|
|
accountaliasp
|
2016-05-18 05:46:54 +03:00
|
|
|
|
2012-03-24 22:08:11 +04:00
|
|
|
-- * Tests
|
2018-09-06 23:08:26 +03:00
|
|
|
,tests_JournalReader
|
2010-05-31 05:15:18 +04:00
|
|
|
)
|
2010-03-13 02:46:20 +03:00
|
|
|
where
|
2016-04-23 21:27:39 +03:00
|
|
|
--- * imports
|
2019-12-01 20:31:36 +03:00
|
|
|
-- import qualified Prelude (fail)
|
|
|
|
-- import "base-compat-batteries" Prelude.Compat hiding (fail, readFile)
|
lib, cli, ui: start using Control.Monad.Fail, allow base-compat 0.11
fail is moving out of Monad and into it's own MonadFail class.
This will be enforced in GHC 8.8 (I think).
base-compat/base-compat-batteries 0.11.0 have adapted to this,
and are approaching stackage nightly
(https://github.com/commercialhaskell/stackage/issues/4802).
hledger is now ready to build with base-compat-batteries 0.11.0, once
all of our deps do (eg aeson). We are still compatible with the older
0.10.x and GHC 7.10.3 as well.
For now we are using both fails:
- new fail (from Control.Monad.Fail), used in our parsers, imported
via base-compat-batteries Control.Monad.Fail.Compat to work with
older GHC versions.
- old fail (from GHC.Base, exported by Prelude, Control.Monad,
Control.Monad.State.Strict, Prelude.Compat, ...), used in easytest's
Test, since I couldn't find their existing fail implementation to update.
To reduce (my) confusion, these are imported carefully, consistently,
and qualified everywhere as Fail.fail and Prelude.fail, with clashing
re-exports suppressed, like so:
import Prelude hiding (fail)
import qualified Prelude (fail)
import Control.Monad.State.Strict hiding (fail)
import "base-compat-batteries" Prelude.Compat hiding (fail)
import qualified "base-compat-batteries" Control.Monad.Fail.Compat as Fail
2019-09-09 03:13:47 +03:00
|
|
|
import qualified "base-compat-batteries" Control.Monad.Fail.Compat as Fail (fail)
|
2012-03-30 01:19:35 +04:00
|
|
|
import qualified Control.Exception as C
|
lib, cli, ui: start using Control.Monad.Fail, allow base-compat 0.11
fail is moving out of Monad and into it's own MonadFail class.
This will be enforced in GHC 8.8 (I think).
base-compat/base-compat-batteries 0.11.0 have adapted to this,
and are approaching stackage nightly
(https://github.com/commercialhaskell/stackage/issues/4802).
hledger is now ready to build with base-compat-batteries 0.11.0, once
all of our deps do (eg aeson). We are still compatible with the older
0.10.x and GHC 7.10.3 as well.
For now we are using both fails:
- new fail (from Control.Monad.Fail), used in our parsers, imported
via base-compat-batteries Control.Monad.Fail.Compat to work with
older GHC versions.
- old fail (from GHC.Base, exported by Prelude, Control.Monad,
Control.Monad.State.Strict, Prelude.Compat, ...), used in easytest's
Test, since I couldn't find their existing fail implementation to update.
To reduce (my) confusion, these are imported carefully, consistently,
and qualified everywhere as Fail.fail and Prelude.fail, with clashing
re-exports suppressed, like so:
import Prelude hiding (fail)
import qualified Prelude (fail)
import Control.Monad.State.Strict hiding (fail)
import "base-compat-batteries" Prelude.Compat hiding (fail)
import qualified "base-compat-batteries" Control.Monad.Fail.Compat as Fail
2019-09-09 03:13:47 +03:00
|
|
|
import Control.Monad (forM_, when, void)
|
|
|
|
import Control.Monad.IO.Class (MonadIO, liftIO)
|
2019-01-15 23:57:51 +03:00
|
|
|
import Control.Monad.Except (ExceptT(..), runExceptT)
|
lib, cli, ui: start using Control.Monad.Fail, allow base-compat 0.11
fail is moving out of Monad and into it's own MonadFail class.
This will be enforced in GHC 8.8 (I think).
base-compat/base-compat-batteries 0.11.0 have adapted to this,
and are approaching stackage nightly
(https://github.com/commercialhaskell/stackage/issues/4802).
hledger is now ready to build with base-compat-batteries 0.11.0, once
all of our deps do (eg aeson). We are still compatible with the older
0.10.x and GHC 7.10.3 as well.
For now we are using both fails:
- new fail (from Control.Monad.Fail), used in our parsers, imported
via base-compat-batteries Control.Monad.Fail.Compat to work with
older GHC versions.
- old fail (from GHC.Base, exported by Prelude, Control.Monad,
Control.Monad.State.Strict, Prelude.Compat, ...), used in easytest's
Test, since I couldn't find their existing fail implementation to update.
To reduce (my) confusion, these are imported carefully, consistently,
and qualified everywhere as Fail.fail and Prelude.fail, with clashing
re-exports suppressed, like so:
import Prelude hiding (fail)
import qualified Prelude (fail)
import Control.Monad.State.Strict hiding (fail)
import "base-compat-batteries" Prelude.Compat hiding (fail)
import qualified "base-compat-batteries" Control.Monad.Fail.Compat as Fail
2019-09-09 03:13:47 +03:00
|
|
|
import Control.Monad.State.Strict (get,modify',put)
|
|
|
|
import Control.Monad.Trans.Class (lift)
|
2016-05-07 19:54:01 +03:00
|
|
|
import qualified Data.Map.Strict as M
|
2019-11-29 02:22:12 +03:00
|
|
|
#if !(MIN_VERSION_base(4,11,0))
|
|
|
|
import Data.Monoid ((<>))
|
|
|
|
#endif
|
lib: textification: parse stream
10% more allocation, but 35% lower maximum residency, and slightly quicker.
hledger -f data/100x100x10.journal stats
<<ghc: 39327768 bytes, 77 GCs, 196834/269496 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.010 elapsed), 0.020 MUT (0.092 elapsed), 0.014 GC (0.119 elapsed) :ghc>>
<<ghc: 42842136 bytes, 84 GCs, 194010/270912 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.009 elapsed), 0.016 MUT (0.029 elapsed), 0.012 GC (0.120 elapsed) :ghc>>
hledger -f data/1000x1000x10.journal stats
<<ghc: 314291440 bytes, 612 GCs, 2070776/6628048 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.000 elapsed), 0.128 MUT (0.144 elapsed), 0.059 GC (0.070 elapsed) :ghc>>
<<ghc: 349558872 bytes, 681 GCs, 1397597/4106384 avg/max bytes residency (7 samples), 11M in use, 0.000 INIT (0.004 elapsed), 0.124 MUT (0.133 elapsed), 0.047 GC (0.053 elapsed) :ghc>>
hledger -f data/10000x1000x10.journal stats
<<ghc: 3070026824 bytes, 5973 GCs, 12698030/62951784 avg/max bytes residency (10 samples), 124M in use, 0.000 INIT (0.002 elapsed), 1.268 MUT (1.354 elapsed), 0.514 GC (0.587 elapsed) :ghc>>
<<ghc: 3424013128 bytes, 6658 GCs, 11405501/41071624 avg/max bytes residency (11 samples), 111M in use, 0.000 INIT (0.001 elapsed), 1.343 MUT (1.406 elapsed), 0.511 GC (0.573 elapsed) :ghc>>
hledger -f data/100000x1000x10.journal stats
<<ghc: 30753387392 bytes, 59811 GCs, 117615462/666703600 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.000 elapsed), 12.068 MUT (12.238 elapsed), 6.015 GC (7.190 elapsed) :ghc>>
<<ghc: 34306530696 bytes, 66727 GCs, 76806196/414629312 avg/max bytes residency (14 samples), 1009M in use, 0.000 INIT (0.010 elapsed), 14.357 MUT (16.370 elapsed), 5.298 GC (6.534 elapsed) :ghc>>
2016-05-25 01:58:23 +03:00
|
|
|
import Data.Text (Text)
|
2017-11-03 03:53:37 +03:00
|
|
|
import Data.String
|
|
|
|
import Data.List
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
import qualified Data.Text as T
|
2011-05-28 08:11:44 +04:00
|
|
|
import Data.Time.Calendar
|
|
|
|
import Data.Time.LocalTime
|
2016-04-28 23:23:20 +03:00
|
|
|
import Safe
|
2018-05-22 01:47:56 +03:00
|
|
|
import Text.Megaparsec hiding (parse)
|
|
|
|
import Text.Megaparsec.Char
|
2018-06-11 22:49:14 +03:00
|
|
|
import Text.Megaparsec.Custom
|
2011-05-28 08:11:44 +04:00
|
|
|
import Text.Printf
|
2012-03-24 22:08:11 +04:00
|
|
|
import System.FilePath
|
2018-07-24 20:53:13 +03:00
|
|
|
import "Glob" System.FilePath.Glob hiding (match)
|
2010-11-15 10:18:35 +03:00
|
|
|
|
2018-08-20 16:28:40 +03:00
|
|
|
import Hledger.Data
|
|
|
|
import Hledger.Read.Common
|
2016-05-18 05:46:54 +03:00
|
|
|
import Hledger.Read.TimeclockReader (timeclockfilep)
|
|
|
|
import Hledger.Read.TimedotReader (timedotfilep)
|
2011-05-28 08:11:44 +04:00
|
|
|
import Hledger.Utils
|
2010-03-13 02:46:20 +03:00
|
|
|
|
2016-05-25 04:28:26 +03:00
|
|
|
-- $setup
|
|
|
|
-- >>> :set -XOverloadedStrings
|
2010-03-13 02:46:20 +03:00
|
|
|
|
2016-04-23 21:27:39 +03:00
|
|
|
--- * reader
|
2010-03-13 02:46:20 +03:00
|
|
|
|
2010-06-25 18:56:48 +04:00
|
|
|
reader :: Reader
|
2016-11-19 00:24:57 +03:00
|
|
|
reader = Reader
|
|
|
|
{rFormat = "journal"
|
|
|
|
,rExtensions = ["journal", "j", "hledger", "ledger"]
|
|
|
|
,rParser = parse
|
2016-11-20 21:42:12 +03:00
|
|
|
,rExperimental = False
|
2016-11-19 00:24:57 +03:00
|
|
|
}
|
2010-06-25 18:56:48 +04:00
|
|
|
|
2010-05-30 23:11:58 +04:00
|
|
|
-- | Parse and post-process a "Journal" from hledger's journal file
|
2010-05-31 05:15:18 +04:00
|
|
|
-- format, or give an error.
|
2018-04-17 00:47:04 +03:00
|
|
|
parse :: InputOpts -> FilePath -> Text -> ExceptT String IO Journal
|
2018-09-27 19:50:31 +03:00
|
|
|
parse iopts = parseAndFinaliseJournal journalp' iopts
|
2018-04-18 01:58:53 +03:00
|
|
|
where
|
2019-07-15 13:28:52 +03:00
|
|
|
journalp' = do
|
2018-04-18 01:58:53 +03:00
|
|
|
-- reverse parsed aliases to ensure that they are applied in order given on commandline
|
2019-07-15 13:28:52 +03:00
|
|
|
mapM_ addAccountAlias (reverse $ aliasesFromOpts iopts)
|
2018-04-18 01:58:53 +03:00
|
|
|
journalp
|
|
|
|
|
|
|
|
-- | Get the account name aliases from options, if any.
|
|
|
|
aliasesFromOpts :: InputOpts -> [AccountAlias]
|
|
|
|
aliasesFromOpts = map (\a -> fromparse $ runParser accountaliasp ("--alias "++quoteIfNeeded a) $ T.pack a)
|
|
|
|
. aliases_
|
2010-03-13 02:46:20 +03:00
|
|
|
|
2016-04-23 21:27:39 +03:00
|
|
|
--- * parsers
|
|
|
|
--- ** journal
|
2012-03-24 22:08:11 +04:00
|
|
|
|
2016-05-23 10:32:55 +03:00
|
|
|
-- | A journal parser. Accumulates and returns a "ParsedJournal",
|
|
|
|
-- which should be finalised/validated before use.
|
|
|
|
--
|
2018-09-27 19:50:31 +03:00
|
|
|
-- >>> rejp (journalp <* eof) "2015/1/1\n a 0\n"
|
|
|
|
-- Right (Right Journal with 1 transactions, 1 accounts)
|
2016-05-23 10:32:55 +03:00
|
|
|
--
|
2018-09-27 19:50:31 +03:00
|
|
|
journalp :: MonadIO m => ErroringJournalParser m ParsedJournal
|
2015-10-17 21:51:45 +03:00
|
|
|
journalp = do
|
2016-05-23 10:32:55 +03:00
|
|
|
many addJournalItemP
|
2010-11-13 18:03:40 +03:00
|
|
|
eof
|
2016-07-29 18:57:10 +03:00
|
|
|
get
|
2016-05-23 10:32:55 +03:00
|
|
|
|
|
|
|
-- | A side-effecting parser; parses any kind of journal item
|
|
|
|
-- and updates the parse state accordingly.
|
2018-09-27 19:50:31 +03:00
|
|
|
addJournalItemP :: MonadIO m => ErroringJournalParser m ()
|
lib: textification: comments and tags
No change.
hledger -f data/100x100x10.journal stats
<<ghc: 42859576 bytes, 84 GCs, 193781/269984 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.016 MUT (0.020 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
<<ghc: 42859576 bytes, 84 GCs, 193781/269984 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.018 elapsed), 0.009 GC (0.013 elapsed) :ghc>>
hledger -f data/1000x1000x10.journal stats
<<ghc: 349576344 bytes, 681 GCs, 1407388/4091680 avg/max bytes residency (7 samples), 11M in use, 0.000 INIT (0.000 elapsed), 0.124 MUT (0.130 elapsed), 0.047 GC (0.055 elapsed) :ghc>>
<<ghc: 349576280 bytes, 681 GCs, 1407388/4091680 avg/max bytes residency (7 samples), 11M in use, 0.000 INIT (0.000 elapsed), 0.126 MUT (0.132 elapsed), 0.049 GC (0.058 elapsed) :ghc>>
hledger -f data/10000x1000x10.journal stats
<<ghc: 3424030664 bytes, 6658 GCs, 11403359/41071624 avg/max bytes residency (11 samples), 111M in use, 0.000 INIT (0.000 elapsed), 1.207 MUT (1.228 elapsed), 0.473 GC (0.528 elapsed) :ghc>>
<<ghc: 3424030760 bytes, 6658 GCs, 11403874/41077288 avg/max bytes residency (11 samples), 111M in use, 0.000 INIT (0.002 elapsed), 1.234 MUT (1.256 elapsed), 0.470 GC (0.520 elapsed) :ghc>>
hledger -f data/100000x1000x10.journal stats
<<ghc: 34306547448 bytes, 66727 GCs, 76805504/414629288 avg/max bytes residency (14 samples), 1009M in use, 0.000 INIT (0.003 elapsed), 12.615 MUT (12.813 elapsed), 4.656 GC (5.291 elapsed) :ghc>>
<<ghc: 34306547320 bytes, 66727 GCs, 76805504/414629288 avg/max bytes residency (14 samples), 1009M in use, 0.000 INIT (0.009 elapsed), 12.802 MUT (13.065 elapsed), 4.774 GC (5.441 elapsed) :ghc>>
2016-05-25 03:09:20 +03:00
|
|
|
addJournalItemP =
|
2016-05-23 10:32:55 +03:00
|
|
|
-- all journal line types can be distinguished by the first
|
|
|
|
-- character, can use choice without backtracking
|
|
|
|
choice [
|
|
|
|
directivep
|
2016-07-29 18:57:10 +03:00
|
|
|
, transactionp >>= modify' . addTransaction
|
2018-07-30 21:29:45 +03:00
|
|
|
, transactionmodifierp >>= modify' . addTransactionModifier
|
2016-07-29 18:57:10 +03:00
|
|
|
, periodictransactionp >>= modify' . addPeriodicTransaction
|
2019-06-04 03:26:27 +03:00
|
|
|
, marketpricedirectivep >>= modify' . addPriceDirective
|
2018-05-16 03:59:49 +03:00
|
|
|
, void (lift emptyorcommentlinep)
|
|
|
|
, void (lift multilinecommentp)
|
2016-05-23 10:32:55 +03:00
|
|
|
] <?> "transaction or directive"
|
2010-09-23 03:02:19 +04:00
|
|
|
|
2016-04-23 21:27:39 +03:00
|
|
|
--- ** directives
|
2016-04-23 03:43:16 +03:00
|
|
|
|
2016-05-23 10:32:55 +03:00
|
|
|
-- | Parse any journal directive and update the parse state accordingly.
|
|
|
|
-- Cf http://hledger.org/manual.html#directives,
|
|
|
|
-- http://ledger-cli.org/3.0/doc/ledger3.html#Command-Directives
|
2018-09-27 19:50:31 +03:00
|
|
|
directivep :: MonadIO m => ErroringJournalParser m ()
|
2016-05-27 01:51:59 +03:00
|
|
|
directivep = (do
|
2011-08-03 03:28:53 +04:00
|
|
|
optional $ char '!'
|
2017-11-03 03:53:37 +03:00
|
|
|
choice [
|
2015-10-17 21:51:45 +03:00
|
|
|
includedirectivep
|
|
|
|
,aliasdirectivep
|
|
|
|
,endaliasesdirectivep
|
|
|
|
,accountdirectivep
|
2016-04-04 20:18:59 +03:00
|
|
|
,applyaccountdirectivep
|
2016-05-07 19:54:01 +03:00
|
|
|
,commoditydirectivep
|
2016-04-04 20:18:59 +03:00
|
|
|
,endapplyaccountdirectivep
|
2015-10-17 21:51:45 +03:00
|
|
|
,tagdirectivep
|
|
|
|
,endtagdirectivep
|
|
|
|
,defaultyeardirectivep
|
|
|
|
,defaultcommoditydirectivep
|
|
|
|
,commodityconversiondirectivep
|
|
|
|
,ignoredpricecommoditydirectivep
|
2011-08-03 03:28:53 +04:00
|
|
|
]
|
2016-05-27 01:51:59 +03:00
|
|
|
) <?> "directive"
|
2010-03-13 02:46:20 +03:00
|
|
|
|
2018-09-27 19:50:31 +03:00
|
|
|
includedirectivep :: MonadIO m => ErroringJournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
includedirectivep = do
|
2011-08-04 11:49:10 +04:00
|
|
|
string "include"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2018-07-23 14:48:45 +03:00
|
|
|
filename <- T.unpack <$> takeWhileP Nothing (/= '\n') -- don't consume newline yet
|
2018-06-06 09:21:00 +03:00
|
|
|
|
2018-09-30 04:32:08 +03:00
|
|
|
parentoff <- getOffset
|
|
|
|
parentpos <- getSourcePos
|
2018-06-06 09:21:00 +03:00
|
|
|
|
2018-09-30 04:32:08 +03:00
|
|
|
filepaths <- getFilePaths parentoff parentpos filename
|
2018-07-23 12:39:01 +03:00
|
|
|
|
2018-07-23 12:30:10 +03:00
|
|
|
forM_ filepaths $ parseChild parentpos
|
2018-06-06 09:21:00 +03:00
|
|
|
|
|
|
|
void newline
|
|
|
|
|
2018-07-23 12:30:10 +03:00
|
|
|
where
|
2018-09-30 04:32:08 +03:00
|
|
|
getFilePaths
|
|
|
|
:: MonadIO m => Int -> SourcePos -> FilePath -> JournalParser m [FilePath]
|
|
|
|
getFilePaths parseroff parserpos filename = do
|
2018-10-10 02:12:57 +03:00
|
|
|
let curdir = takeDirectory (sourceName parserpos)
|
|
|
|
filename' <- lift $ expandHomePath filename
|
2018-07-24 20:41:50 +03:00
|
|
|
`orRethrowIOError` (show parserpos ++ " locating " ++ filename)
|
2018-07-23 15:36:45 +03:00
|
|
|
-- Compiling filename as a glob pattern works even if it is a literal
|
2018-10-10 02:12:57 +03:00
|
|
|
fileglob <- case tryCompileWith compDefault{errorRecovery=False} filename' of
|
2018-07-23 15:36:45 +03:00
|
|
|
Right x -> pure x
|
2018-09-25 22:33:31 +03:00
|
|
|
Left e -> customFailure $
|
2018-09-30 04:32:08 +03:00
|
|
|
parseErrorAt parseroff $ "Invalid glob pattern: " ++ e
|
2018-07-24 23:05:38 +03:00
|
|
|
-- Get all matching files in the current working directory, sorting in
|
|
|
|
-- lexicographic order to simulate the output of 'ls'.
|
|
|
|
filepaths <- liftIO $ sort <$> globDir1 fileglob curdir
|
2018-07-23 15:36:45 +03:00
|
|
|
if (not . null) filepaths
|
|
|
|
then pure filepaths
|
2018-09-30 04:32:08 +03:00
|
|
|
else customFailure $ parseErrorAt parseroff $
|
2018-09-25 22:33:31 +03:00
|
|
|
"No existing files match pattern: " ++ filename
|
2018-07-23 15:36:45 +03:00
|
|
|
|
2018-09-27 22:44:42 +03:00
|
|
|
parseChild :: MonadIO m => SourcePos -> FilePath -> ErroringJournalParser m ()
|
2018-07-23 12:30:10 +03:00
|
|
|
parseChild parentpos filepath = do
|
2018-09-27 22:44:42 +03:00
|
|
|
parentj <- get
|
|
|
|
|
|
|
|
let parentfilestack = jincludefilestack parentj
|
|
|
|
when (filepath `elem` parentfilestack) $
|
lib, cli, ui: start using Control.Monad.Fail, allow base-compat 0.11
fail is moving out of Monad and into it's own MonadFail class.
This will be enforced in GHC 8.8 (I think).
base-compat/base-compat-batteries 0.11.0 have adapted to this,
and are approaching stackage nightly
(https://github.com/commercialhaskell/stackage/issues/4802).
hledger is now ready to build with base-compat-batteries 0.11.0, once
all of our deps do (eg aeson). We are still compatible with the older
0.10.x and GHC 7.10.3 as well.
For now we are using both fails:
- new fail (from Control.Monad.Fail), used in our parsers, imported
via base-compat-batteries Control.Monad.Fail.Compat to work with
older GHC versions.
- old fail (from GHC.Base, exported by Prelude, Control.Monad,
Control.Monad.State.Strict, Prelude.Compat, ...), used in easytest's
Test, since I couldn't find their existing fail implementation to update.
To reduce (my) confusion, these are imported carefully, consistently,
and qualified everywhere as Fail.fail and Prelude.fail, with clashing
re-exports suppressed, like so:
import Prelude hiding (fail)
import qualified Prelude (fail)
import Control.Monad.State.Strict hiding (fail)
import "base-compat-batteries" Prelude.Compat hiding (fail)
import qualified "base-compat-batteries" Control.Monad.Fail.Compat as Fail
2019-09-09 03:13:47 +03:00
|
|
|
Fail.fail ("Cyclic include: " ++ filepath)
|
2018-09-27 22:44:42 +03:00
|
|
|
|
|
|
|
childInput <- lift $ readFilePortably filepath
|
|
|
|
`orRethrowIOError` (show parentpos ++ " reading " ++ filepath)
|
|
|
|
let initChildj = newJournalWithParseStateFrom filepath parentj
|
|
|
|
|
|
|
|
let parser = choiceInState
|
|
|
|
[ journalp
|
|
|
|
, timeclockfilep
|
|
|
|
, timedotfilep
|
|
|
|
] -- can't include a csv file yet, that reader is special
|
|
|
|
updatedChildj <- journalAddFile (filepath, childInput) <$>
|
|
|
|
parseIncludeFile parser initChildj filepath childInput
|
|
|
|
|
|
|
|
-- discard child's parse info, combine other fields
|
|
|
|
put $ updatedChildj <> parentj
|
|
|
|
|
|
|
|
newJournalWithParseStateFrom :: FilePath -> Journal -> Journal
|
|
|
|
newJournalWithParseStateFrom filepath j = mempty{
|
|
|
|
jparsedefaultyear = jparsedefaultyear j
|
|
|
|
,jparsedefaultcommodity = jparsedefaultcommodity j
|
|
|
|
,jparseparentaccounts = jparseparentaccounts j
|
|
|
|
,jparsealiases = jparsealiases j
|
|
|
|
,jcommodities = jcommodities j
|
|
|
|
-- ,jparsetransactioncount = jparsetransactioncount j
|
|
|
|
,jparsetimeclockentries = jparsetimeclockentries j
|
|
|
|
,jincludefilestack = filepath : jincludefilestack j
|
|
|
|
}
|
2016-05-23 10:32:55 +03:00
|
|
|
|
|
|
|
-- | Lift an IO action into the exception monad, rethrowing any IO
|
|
|
|
-- error with the given message prepended.
|
2018-06-06 09:21:00 +03:00
|
|
|
orRethrowIOError :: MonadIO m => IO a -> String -> TextParser m a
|
|
|
|
orRethrowIOError io msg = do
|
|
|
|
eResult <- liftIO $ (Right <$> io) `C.catch` \(e::C.IOException) -> pure $ Left $ printf "%s:\n%s" msg (show e)
|
|
|
|
case eResult of
|
|
|
|
Right res -> pure res
|
lib, cli, ui: start using Control.Monad.Fail, allow base-compat 0.11
fail is moving out of Monad and into it's own MonadFail class.
This will be enforced in GHC 8.8 (I think).
base-compat/base-compat-batteries 0.11.0 have adapted to this,
and are approaching stackage nightly
(https://github.com/commercialhaskell/stackage/issues/4802).
hledger is now ready to build with base-compat-batteries 0.11.0, once
all of our deps do (eg aeson). We are still compatible with the older
0.10.x and GHC 7.10.3 as well.
For now we are using both fails:
- new fail (from Control.Monad.Fail), used in our parsers, imported
via base-compat-batteries Control.Monad.Fail.Compat to work with
older GHC versions.
- old fail (from GHC.Base, exported by Prelude, Control.Monad,
Control.Monad.State.Strict, Prelude.Compat, ...), used in easytest's
Test, since I couldn't find their existing fail implementation to update.
To reduce (my) confusion, these are imported carefully, consistently,
and qualified everywhere as Fail.fail and Prelude.fail, with clashing
re-exports suppressed, like so:
import Prelude hiding (fail)
import qualified Prelude (fail)
import Control.Monad.State.Strict hiding (fail)
import "base-compat-batteries" Prelude.Compat hiding (fail)
import qualified "base-compat-batteries" Control.Monad.Fail.Compat as Fail
2019-09-09 03:13:47 +03:00
|
|
|
Left errMsg -> Fail.fail errMsg
|
2016-05-23 10:32:55 +03:00
|
|
|
|
2019-01-14 15:43:13 +03:00
|
|
|
-- Parse an account directive, adding its info to the journal's
|
|
|
|
-- list of account declarations.
|
2017-07-27 14:59:55 +03:00
|
|
|
accountdirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
accountdirectivep = do
|
2019-01-15 03:21:40 +03:00
|
|
|
off <- getOffset -- XXX figure out a more precise position later
|
|
|
|
|
2016-04-04 20:18:59 +03:00
|
|
|
string "account"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2019-01-15 03:21:40 +03:00
|
|
|
|
journal: account directives can declare account types
Previously you had to use one of the standard english account names
(assets, liabilities..) for top-level accounts, if you wanted to use
the bs/bse/cf/is commands.
Now, account directives can specify which of the big five categories
an account belongs to - asset, liability, equity, revenue or expense -
by writing one of the letters A, L, E, R or X two or more spaces after
the account name (where the numeric account code used to be).
This might change. Some thoughts influencing the current syntax:
- easy to type and read
- does not require multiple lines
- does not depend on any particular account numbering scheme
- allows more types later if needed
- still anglocentric, but only a little
- could be treated as syntactic sugar for account tags later
- seems to be compatible with (ignored by) current Ledger
The current design permits unlimited account type declarations anywhere
in the account tree. So you could declare a liability account somewhere
under assets, and maybe a revenue account under that, and another asset
account even further down. In such cases you start to see oddities like
accounts appearing in multiple places in a tree-mode report. In theory
the reports will still behave reasonably, but this has not been tested
too hard. In any case this is clearly too much freedom. I have left it
this way, for now, in case it helps with:
- modelling contra accounts ?
- multiple files. I suspect the extra expressiveness may come in handy
when combining multiple files with account type declarations,
rewriting account names, apply parent accounts etc.
If we only allowed type declarations on top-level accounts, or
only allowed a single account of each type, complications seem likely.
2018-09-27 04:34:48 +03:00
|
|
|
-- the account name, possibly modified by preceding alias or apply account directives
|
|
|
|
acct <- modifiedaccountnamep
|
2019-01-15 03:21:40 +03:00
|
|
|
|
|
|
|
-- maybe an account type code (ALERX) after two or more spaces
|
|
|
|
-- XXX added in 1.11, deprecated in 1.13, remove in 1.14
|
|
|
|
mtypecode :: Maybe Char <- lift $ optional $ try $ do
|
2019-07-15 13:28:52 +03:00
|
|
|
skipSome spacenonewline -- at least one more space in addition to the one consumed by modifiedaccountp
|
2019-01-15 03:21:40 +03:00
|
|
|
choice $ map char "ALERX"
|
|
|
|
|
2019-01-14 15:43:13 +03:00
|
|
|
-- maybe a comment, on this and/or following lines
|
|
|
|
(cmt, tags) <- lift transactioncommentp
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2019-01-14 15:43:13 +03:00
|
|
|
-- maybe Ledger-style subdirectives (ignored)
|
2018-06-06 08:44:02 +03:00
|
|
|
skipMany indentedlinep
|
journal: account directives can declare account types
Previously you had to use one of the standard english account names
(assets, liabilities..) for top-level accounts, if you wanted to use
the bs/bse/cf/is commands.
Now, account directives can specify which of the big five categories
an account belongs to - asset, liability, equity, revenue or expense -
by writing one of the letters A, L, E, R or X two or more spaces after
the account name (where the numeric account code used to be).
This might change. Some thoughts influencing the current syntax:
- easy to type and read
- does not require multiple lines
- does not depend on any particular account numbering scheme
- allows more types later if needed
- still anglocentric, but only a little
- could be treated as syntactic sugar for account tags later
- seems to be compatible with (ignored by) current Ledger
The current design permits unlimited account type declarations anywhere
in the account tree. So you could declare a liability account somewhere
under assets, and maybe a revenue account under that, and another asset
account even further down. In such cases you start to see oddities like
accounts appearing in multiple places in a tree-mode report. In theory
the reports will still behave reasonably, but this has not been tested
too hard. In any case this is clearly too much freedom. I have left it
this way, for now, in case it helps with:
- modelling contra accounts ?
- multiple files. I suspect the extra expressiveness may come in handy
when combining multiple files with account type declarations,
rewriting account names, apply parent accounts etc.
If we only allowed type declarations on top-level accounts, or
only allowed a single account of each type, complications seem likely.
2018-09-27 04:34:48 +03:00
|
|
|
|
2019-01-15 03:21:40 +03:00
|
|
|
-- an account type may have been set by account type code or a tag;
|
|
|
|
-- the latter takes precedence
|
|
|
|
let
|
|
|
|
mtypecode' :: Maybe Text = maybe
|
|
|
|
(T.singleton <$> mtypecode)
|
|
|
|
Just
|
|
|
|
$ lookup accountTypeTagName tags
|
|
|
|
metype = parseAccountTypeCode <$> mtypecode'
|
|
|
|
|
journal: account directives can declare account types
Previously you had to use one of the standard english account names
(assets, liabilities..) for top-level accounts, if you wanted to use
the bs/bse/cf/is commands.
Now, account directives can specify which of the big five categories
an account belongs to - asset, liability, equity, revenue or expense -
by writing one of the letters A, L, E, R or X two or more spaces after
the account name (where the numeric account code used to be).
This might change. Some thoughts influencing the current syntax:
- easy to type and read
- does not require multiple lines
- does not depend on any particular account numbering scheme
- allows more types later if needed
- still anglocentric, but only a little
- could be treated as syntactic sugar for account tags later
- seems to be compatible with (ignored by) current Ledger
The current design permits unlimited account type declarations anywhere
in the account tree. So you could declare a liability account somewhere
under assets, and maybe a revenue account under that, and another asset
account even further down. In such cases you start to see oddities like
accounts appearing in multiple places in a tree-mode report. In theory
the reports will still behave reasonably, but this has not been tested
too hard. In any case this is clearly too much freedom. I have left it
this way, for now, in case it helps with:
- modelling contra accounts ?
- multiple files. I suspect the extra expressiveness may come in handy
when combining multiple files with account type declarations,
rewriting account names, apply parent accounts etc.
If we only allowed type declarations on top-level accounts, or
only allowed a single account of each type, complications seem likely.
2018-09-27 04:34:48 +03:00
|
|
|
-- update the journal
|
2019-01-14 15:43:13 +03:00
|
|
|
addAccountDeclaration (acct, cmt, tags)
|
2019-01-15 03:21:40 +03:00
|
|
|
case metype of
|
|
|
|
Nothing -> return ()
|
|
|
|
Just (Right t) -> addDeclaredAccountType acct t
|
|
|
|
Just (Left err) -> customFailure $ parseErrorAt off err
|
|
|
|
|
|
|
|
-- The special tag used for declaring account type. XXX change to "class" ?
|
|
|
|
accountTypeTagName = "type"
|
|
|
|
|
|
|
|
parseAccountTypeCode :: Text -> Either String AccountType
|
|
|
|
parseAccountTypeCode s =
|
|
|
|
case T.toLower s of
|
|
|
|
"asset" -> Right Asset
|
|
|
|
"a" -> Right Asset
|
|
|
|
"liability" -> Right Liability
|
|
|
|
"l" -> Right Liability
|
|
|
|
"equity" -> Right Equity
|
|
|
|
"e" -> Right Equity
|
|
|
|
"revenue" -> Right Revenue
|
|
|
|
"r" -> Right Revenue
|
|
|
|
"expense" -> Right Expense
|
|
|
|
"x" -> Right Expense
|
|
|
|
_ -> Left err
|
|
|
|
where
|
|
|
|
err = "invalid account type code "++T.unpack s++", should be one of " ++
|
|
|
|
(intercalate ", " $ ["A","L","E","R","X","ASSET","LIABILITY","EQUITY","REVENUE","EXPENSE"])
|
2019-01-14 15:43:13 +03:00
|
|
|
|
|
|
|
-- Add an account declaration to the journal, auto-numbering it.
|
|
|
|
addAccountDeclaration :: (AccountName,Text,[Tag]) -> JournalParser m ()
|
|
|
|
addAccountDeclaration (a,cmt,tags) =
|
|
|
|
modify' (\j ->
|
|
|
|
let
|
|
|
|
decls = jdeclaredaccounts j
|
|
|
|
d = (a, nullaccountdeclarationinfo{
|
|
|
|
adicomment = cmt
|
|
|
|
,aditags = tags
|
|
|
|
,adideclarationorder = length decls + 1
|
|
|
|
})
|
|
|
|
in
|
|
|
|
j{jdeclaredaccounts = d:decls})
|
2016-12-10 02:57:17 +03:00
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
indentedlinep :: JournalParser m String
|
2018-03-25 16:53:44 +03:00
|
|
|
indentedlinep = lift (skipSome spacenonewline) >> (rstrip <$> lift restofline)
|
2016-05-07 19:54:01 +03:00
|
|
|
|
2016-05-09 06:56:34 +03:00
|
|
|
-- | Parse a one-line or multi-line commodity directive.
|
|
|
|
--
|
2018-06-06 21:21:17 +03:00
|
|
|
-- >>> Right _ <- rjp commoditydirectivep "commodity $1.00"
|
|
|
|
-- >>> Right _ <- rjp commoditydirectivep "commodity $\n format $1.00"
|
|
|
|
-- >>> Right _ <- rjp commoditydirectivep "commodity $\n\n" -- a commodity with no format
|
|
|
|
-- >>> Right _ <- rjp commoditydirectivep "commodity $1.00\n format $1.00" -- both, what happens ?
|
2018-06-06 08:52:28 +03:00
|
|
|
commoditydirectivep :: JournalParser m ()
|
2018-06-11 23:29:18 +03:00
|
|
|
commoditydirectivep = commoditydirectiveonelinep <|> commoditydirectivemultilinep
|
2016-05-09 06:56:34 +03:00
|
|
|
|
|
|
|
-- | Parse a one-line commodity directive.
|
|
|
|
--
|
2018-06-06 21:21:17 +03:00
|
|
|
-- >>> Right _ <- rjp commoditydirectiveonelinep "commodity $1.00"
|
|
|
|
-- >>> Right _ <- rjp commoditydirectiveonelinep "commodity $1.00 ; blah\n"
|
2018-06-06 08:52:28 +03:00
|
|
|
commoditydirectiveonelinep :: JournalParser m ()
|
2016-05-09 06:56:34 +03:00
|
|
|
commoditydirectiveonelinep = do
|
2018-09-30 04:32:08 +03:00
|
|
|
(off, Amount{acommodity,astyle}) <- try $ do
|
2018-06-11 23:29:18 +03:00
|
|
|
string "commodity"
|
|
|
|
lift (skipSome spacenonewline)
|
2018-09-30 04:32:08 +03:00
|
|
|
off <- getOffset
|
2018-06-11 23:29:18 +03:00
|
|
|
amount <- amountp
|
2018-09-30 04:32:08 +03:00
|
|
|
pure $ (off, amount)
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2018-05-16 23:18:10 +03:00
|
|
|
_ <- lift followingcommentp
|
2018-04-21 07:56:06 +03:00
|
|
|
let comm = Commodity{csymbol=acommodity, cformat=Just $ dbg2 "style from commodity directive" astyle}
|
|
|
|
if asdecimalpoint astyle == Nothing
|
2018-09-30 04:32:08 +03:00
|
|
|
then customFailure $ parseErrorAt off pleaseincludedecimalpoint
|
2018-04-21 07:56:06 +03:00
|
|
|
else modify' (\j -> j{jcommodities=M.insert acommodity comm $ jcommodities j})
|
|
|
|
|
|
|
|
pleaseincludedecimalpoint :: String
|
2018-08-17 09:37:26 +03:00
|
|
|
pleaseincludedecimalpoint = "to avoid ambiguity, please include a decimal separator in commodity directives"
|
2016-05-09 06:56:34 +03:00
|
|
|
|
|
|
|
-- | Parse a multi-line commodity directive, containing 0 or more format subdirectives.
|
|
|
|
--
|
2018-06-06 21:21:17 +03:00
|
|
|
-- >>> Right _ <- rjp commoditydirectivemultilinep "commodity $ ; blah \n format $1.00 ; blah"
|
2018-06-06 08:52:28 +03:00
|
|
|
commoditydirectivemultilinep :: JournalParser m ()
|
2016-05-09 06:56:34 +03:00
|
|
|
commoditydirectivemultilinep = do
|
2016-05-07 19:54:01 +03:00
|
|
|
string "commodity"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2016-07-29 18:57:10 +03:00
|
|
|
sym <- lift commoditysymbolp
|
2018-05-16 23:18:10 +03:00
|
|
|
_ <- lift followingcommentp
|
2016-05-07 19:54:01 +03:00
|
|
|
mformat <- lastMay <$> many (indented $ formatdirectivep sym)
|
|
|
|
let comm = Commodity{csymbol=sym, cformat=mformat}
|
2016-07-29 18:57:10 +03:00
|
|
|
modify' (\j -> j{jcommodities=M.insert sym comm $ jcommodities j})
|
2016-05-23 10:32:55 +03:00
|
|
|
where
|
2018-03-25 16:53:44 +03:00
|
|
|
indented = (lift (skipSome spacenonewline) >>)
|
2016-05-07 19:54:01 +03:00
|
|
|
|
|
|
|
-- | Parse a format (sub)directive, throwing a parse error if its
|
|
|
|
-- symbol does not match the one given.
|
2018-06-06 08:52:28 +03:00
|
|
|
formatdirectivep :: CommoditySymbol -> JournalParser m AmountStyle
|
2016-05-07 19:54:01 +03:00
|
|
|
formatdirectivep expectedsym = do
|
|
|
|
string "format"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2018-09-30 04:32:08 +03:00
|
|
|
off <- getOffset
|
2016-05-07 19:54:01 +03:00
|
|
|
Amount{acommodity,astyle} <- amountp
|
2018-05-16 23:18:10 +03:00
|
|
|
_ <- lift followingcommentp
|
2016-05-07 19:54:01 +03:00
|
|
|
if acommodity==expectedsym
|
2019-07-15 13:28:52 +03:00
|
|
|
then
|
2018-04-21 07:56:06 +03:00
|
|
|
if asdecimalpoint astyle == Nothing
|
2018-09-30 04:32:08 +03:00
|
|
|
then customFailure $ parseErrorAt off pleaseincludedecimalpoint
|
2018-04-21 07:56:06 +03:00
|
|
|
else return $ dbg2 "style from format subdirective" astyle
|
2018-09-30 04:32:08 +03:00
|
|
|
else customFailure $ parseErrorAt off $
|
2016-05-07 19:54:01 +03:00
|
|
|
printf "commodity directive symbol \"%s\" and format directive symbol \"%s\" should be the same" expectedsym acommodity
|
|
|
|
|
2017-11-03 03:53:37 +03:00
|
|
|
keywordp :: String -> JournalParser m ()
|
|
|
|
keywordp = (() <$) . string . fromString
|
|
|
|
|
|
|
|
spacesp :: JournalParser m ()
|
2018-03-25 16:53:44 +03:00
|
|
|
spacesp = () <$ lift (skipSome spacenonewline)
|
2017-11-03 03:53:37 +03:00
|
|
|
|
|
|
|
-- | Backtracking parser similar to string, but allows varying amount of space between words
|
|
|
|
keywordsp :: String -> JournalParser m ()
|
|
|
|
keywordsp = try . sequence_ . intersperse spacesp . map keywordp . words
|
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
applyaccountdirectivep :: JournalParser m ()
|
2016-04-04 20:18:59 +03:00
|
|
|
applyaccountdirectivep = do
|
2017-11-03 03:53:37 +03:00
|
|
|
keywordsp "apply account" <?> "apply account directive"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2016-07-29 18:57:10 +03:00
|
|
|
parent <- lift accountnamep
|
2011-08-04 11:49:10 +04:00
|
|
|
newline
|
|
|
|
pushParentAccount parent
|
2010-03-13 02:46:20 +03:00
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
endapplyaccountdirectivep :: JournalParser m ()
|
2016-04-04 20:18:59 +03:00
|
|
|
endapplyaccountdirectivep = do
|
2017-11-03 03:53:37 +03:00
|
|
|
keywordsp "end apply account" <?> "end apply account directive"
|
2011-08-04 11:49:10 +04:00
|
|
|
popParentAccount
|
2010-03-13 02:46:20 +03:00
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
aliasdirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
aliasdirectivep = do
|
2011-08-04 12:45:18 +04:00
|
|
|
string "alias"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2016-07-29 18:57:10 +03:00
|
|
|
alias <- lift accountaliasp
|
2015-05-14 22:50:32 +03:00
|
|
|
addAccountAlias alias
|
2011-08-04 12:45:18 +04:00
|
|
|
|
2016-07-29 18:57:10 +03:00
|
|
|
accountaliasp :: TextParser m AccountAlias
|
2015-05-14 22:50:32 +03:00
|
|
|
accountaliasp = regexaliasp <|> basicaliasp
|
|
|
|
|
2016-07-29 18:57:10 +03:00
|
|
|
basicaliasp :: TextParser m AccountAlias
|
2015-05-14 22:50:32 +03:00
|
|
|
basicaliasp = do
|
2018-07-16 17:28:58 +03:00
|
|
|
-- dbgparse 0 "basicaliasp"
|
2016-07-29 18:57:10 +03:00
|
|
|
old <- rstrip <$> (some $ noneOf ("=" :: [Char]))
|
2015-05-14 22:50:32 +03:00
|
|
|
char '='
|
2018-03-25 16:53:44 +03:00
|
|
|
skipMany spacenonewline
|
2018-09-30 04:32:08 +03:00
|
|
|
new <- rstrip <$> anySingle `manyTill` eolof -- eol in journal, eof in command lines, normally
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
return $ BasicAlias (T.pack old) (T.pack new)
|
2015-05-14 22:50:32 +03:00
|
|
|
|
2016-07-29 18:57:10 +03:00
|
|
|
regexaliasp :: TextParser m AccountAlias
|
2015-05-14 22:50:32 +03:00
|
|
|
regexaliasp = do
|
2018-07-16 17:28:58 +03:00
|
|
|
-- dbgparse 0 "regexaliasp"
|
2015-05-14 22:50:32 +03:00
|
|
|
char '/'
|
2016-07-29 18:57:10 +03:00
|
|
|
re <- some $ noneOf ("/\n\r" :: [Char]) -- paranoid: don't try to read past line end
|
2015-05-14 22:50:32 +03:00
|
|
|
char '/'
|
2018-03-25 16:53:44 +03:00
|
|
|
skipMany spacenonewline
|
2015-05-14 22:50:32 +03:00
|
|
|
char '='
|
2018-03-25 16:53:44 +03:00
|
|
|
skipMany spacenonewline
|
2018-09-30 04:32:08 +03:00
|
|
|
repl <- anySingle `manyTill` eolof
|
2015-05-14 22:50:32 +03:00
|
|
|
return $ RegexAlias re repl
|
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
endaliasesdirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
endaliasesdirectivep = do
|
2017-11-03 03:53:37 +03:00
|
|
|
keywordsp "end aliases" <?> "end aliases directive"
|
2011-08-04 12:45:18 +04:00
|
|
|
clearAccountAliases
|
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
tagdirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
tagdirectivep = do
|
2011-08-04 11:49:10 +04:00
|
|
|
string "tag" <?> "tag directive"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2016-07-29 18:57:10 +03:00
|
|
|
_ <- lift $ some nonspace
|
|
|
|
lift restofline
|
2016-05-23 10:32:55 +03:00
|
|
|
return ()
|
2007-02-09 04:23:12 +03:00
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
endtagdirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
endtagdirectivep = do
|
2017-11-03 03:53:37 +03:00
|
|
|
(keywordsp "end tag" <|> keywordp "pop") <?> "end tag or pop directive"
|
2016-07-29 18:57:10 +03:00
|
|
|
lift restofline
|
2016-05-23 10:32:55 +03:00
|
|
|
return ()
|
2011-08-04 11:49:10 +04:00
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
defaultyeardirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
defaultyeardirectivep = do
|
2011-08-04 11:49:10 +04:00
|
|
|
char 'Y' <?> "default year"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2016-07-29 18:57:10 +03:00
|
|
|
y <- some digitChar
|
2011-08-04 11:49:10 +04:00
|
|
|
let y' = read y
|
|
|
|
failIfInvalidYear y
|
|
|
|
setYear y'
|
|
|
|
|
2018-06-06 08:52:28 +03:00
|
|
|
defaultcommoditydirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
defaultcommoditydirectivep = do
|
2011-08-04 11:49:10 +04:00
|
|
|
char 'D' <?> "default commodity"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2018-09-30 04:32:08 +03:00
|
|
|
off <- getOffset
|
2018-04-21 07:56:06 +03:00
|
|
|
Amount{acommodity,astyle} <- amountp
|
2016-07-29 18:57:10 +03:00
|
|
|
lift restofline
|
2018-04-21 07:56:06 +03:00
|
|
|
if asdecimalpoint astyle == Nothing
|
2018-09-30 04:32:08 +03:00
|
|
|
then customFailure $ parseErrorAt off pleaseincludedecimalpoint
|
2018-04-21 07:56:06 +03:00
|
|
|
else setDefaultCommodityAndStyle (acommodity, astyle)
|
2007-02-09 04:23:12 +03:00
|
|
|
|
2019-06-04 03:26:27 +03:00
|
|
|
marketpricedirectivep :: JournalParser m PriceDirective
|
2015-10-17 21:51:45 +03:00
|
|
|
marketpricedirectivep = do
|
2015-08-10 02:20:02 +03:00
|
|
|
char 'P' <?> "market price"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2014-08-08 18:27:32 +04:00
|
|
|
date <- try (do {LocalTime d _ <- datetimep; return d}) <|> datep -- a time is ignored
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2016-07-29 18:57:10 +03:00
|
|
|
symbol <- lift commoditysymbolp
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2012-11-20 01:20:10 +04:00
|
|
|
price <- amountp
|
2016-07-29 18:57:10 +03:00
|
|
|
lift restofline
|
2019-06-04 03:26:27 +03:00
|
|
|
return $ PriceDirective date symbol price
|
2008-12-16 13:54:20 +03:00
|
|
|
|
2017-07-27 14:59:55 +03:00
|
|
|
ignoredpricecommoditydirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
ignoredpricecommoditydirectivep = do
|
2010-03-13 01:52:57 +03:00
|
|
|
char 'N' <?> "ignored-price commodity"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2016-07-29 18:57:10 +03:00
|
|
|
lift commoditysymbolp
|
|
|
|
lift restofline
|
2016-05-23 10:32:55 +03:00
|
|
|
return ()
|
2010-03-13 01:52:57 +03:00
|
|
|
|
2018-06-06 08:52:28 +03:00
|
|
|
commodityconversiondirectivep :: JournalParser m ()
|
2015-10-17 21:51:45 +03:00
|
|
|
commodityconversiondirectivep = do
|
2010-03-13 04:10:10 +03:00
|
|
|
char 'C' <?> "commodity conversion"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipSome spacenonewline)
|
2012-11-20 01:20:10 +04:00
|
|
|
amountp
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2010-03-13 04:10:10 +03:00
|
|
|
char '='
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2012-11-20 01:20:10 +04:00
|
|
|
amountp
|
2016-07-29 18:57:10 +03:00
|
|
|
lift restofline
|
2016-05-23 10:32:55 +03:00
|
|
|
return ()
|
2010-03-13 04:10:10 +03:00
|
|
|
|
2016-04-23 21:27:39 +03:00
|
|
|
--- ** transactions
|
2016-04-23 03:43:16 +03:00
|
|
|
|
2018-07-30 21:29:45 +03:00
|
|
|
transactionmodifierp :: JournalParser m TransactionModifier
|
|
|
|
transactionmodifierp = do
|
2011-08-04 11:49:10 +04:00
|
|
|
char '=' <?> "modifier transaction"
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2018-07-26 17:54:21 +03:00
|
|
|
querytxt <- lift $ T.strip <$> descriptionp
|
|
|
|
(_comment, _tags) <- lift transactioncommentp -- TODO apply these to modified txns ?
|
2016-04-28 23:23:20 +03:00
|
|
|
postings <- postingsp Nothing
|
2018-07-30 21:29:45 +03:00
|
|
|
return $ TransactionModifier querytxt postings
|
2009-01-23 02:42:34 +03:00
|
|
|
|
2018-05-15 03:50:35 +03:00
|
|
|
-- | Parse a periodic transaction
|
2018-10-09 21:54:40 +03:00
|
|
|
--
|
|
|
|
-- This reuses periodexprp which parses period expressions on the command line.
|
2019-07-15 13:28:52 +03:00
|
|
|
-- This is awkward because periodexprp supports relative and partial dates,
|
2018-10-09 21:54:40 +03:00
|
|
|
-- which we don't really need here, and it doesn't support the notion of a
|
|
|
|
-- default year set by a Y directive, which we do need to consider here.
|
|
|
|
-- We resolve it as follows: in periodic transactions' period expressions,
|
|
|
|
-- if there is a default year Y in effect, partial/relative dates are calculated
|
|
|
|
-- relative to Y/1/1. If not, they are calculated related to today as usual.
|
2018-06-09 05:45:29 +03:00
|
|
|
periodictransactionp :: MonadIO m => JournalParser m PeriodicTransaction
|
2015-10-17 21:51:45 +03:00
|
|
|
periodictransactionp = do
|
2018-06-13 02:39:56 +03:00
|
|
|
|
|
|
|
-- first line
|
2011-08-04 11:49:10 +04:00
|
|
|
char '~' <?> "periodic transaction"
|
2018-06-09 05:45:29 +03:00
|
|
|
lift $ skipMany spacenonewline
|
2018-06-13 02:39:56 +03:00
|
|
|
-- a period expression
|
2018-09-30 04:32:08 +03:00
|
|
|
off <- getOffset
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2018-10-09 23:31:32 +03:00
|
|
|
-- if there's a default year in effect, use Y/1/1 as base for partial/relative dates
|
2018-10-09 21:54:40 +03:00
|
|
|
today <- liftIO getCurrentDay
|
|
|
|
mdefaultyear <- getYear
|
|
|
|
let refdate = case mdefaultyear of
|
2019-07-15 13:28:52 +03:00
|
|
|
Nothing -> today
|
2018-10-09 21:54:40 +03:00
|
|
|
Just y -> fromGregorian y 1 1
|
2018-11-14 05:14:54 +03:00
|
|
|
periodExcerpt <- lift $ excerpt_ $
|
|
|
|
singlespacedtextsatisfyingp (\c -> c /= ';' && c /= '\n')
|
|
|
|
let periodtxt = T.strip $ getExcerptText periodExcerpt
|
|
|
|
|
|
|
|
-- first parsing with 'singlespacedtextp', then "re-parsing" with
|
|
|
|
-- 'periodexprp' saves 'periodexprp' from having to respect the single-
|
|
|
|
-- and double-space parsing rules
|
|
|
|
(interval, span) <- lift $ reparseExcerpt periodExcerpt $ do
|
|
|
|
pexp <- periodexprp refdate
|
|
|
|
(<|>) eof $ do
|
|
|
|
offset1 <- getOffset
|
|
|
|
void takeRest
|
|
|
|
offset2 <- getOffset
|
|
|
|
customFailure $ parseErrorAtRegion offset1 offset2 $
|
|
|
|
"remainder of period expression cannot be parsed"
|
|
|
|
<> "\nperhaps you need to terminate the period expression with a double space?"
|
2019-01-09 16:13:23 +03:00
|
|
|
<> "\na double space is required between period expression and description/comment"
|
2018-11-14 05:14:54 +03:00
|
|
|
pure pexp
|
2018-10-09 23:31:32 +03:00
|
|
|
|
2018-06-09 05:45:29 +03:00
|
|
|
-- In periodic transactions, the period expression has an additional constraint:
|
|
|
|
case checkPeriodicTransactionStartDate interval span periodtxt of
|
2018-09-30 04:32:08 +03:00
|
|
|
Just e -> customFailure $ parseErrorAt off e
|
2018-06-12 22:29:22 +03:00
|
|
|
Nothing -> pure ()
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2019-01-11 15:45:19 +03:00
|
|
|
status <- lift statusp <?> "cleared status"
|
|
|
|
code <- lift codep <?> "transaction code"
|
|
|
|
description <- lift $ T.strip <$> descriptionp
|
|
|
|
(comment, tags) <- lift transactioncommentp
|
2018-10-09 21:54:40 +03:00
|
|
|
-- next lines; use same year determined above
|
|
|
|
postings <- postingsp (Just $ first3 $ toGregorian refdate)
|
2018-06-13 02:39:56 +03:00
|
|
|
|
2018-06-12 22:29:22 +03:00
|
|
|
return $ nullperiodictransaction{
|
2018-06-13 02:39:56 +03:00
|
|
|
ptperiodexpr=periodtxt
|
2018-06-12 22:29:22 +03:00
|
|
|
,ptinterval=interval
|
|
|
|
,ptspan=span
|
|
|
|
,ptstatus=status
|
|
|
|
,ptcode=code
|
|
|
|
,ptdescription=description
|
|
|
|
,ptcomment=comment
|
|
|
|
,pttags=tags
|
|
|
|
,ptpostings=postings
|
|
|
|
}
|
2010-11-13 02:54:21 +03:00
|
|
|
|
2012-05-15 05:49:05 +04:00
|
|
|
-- | Parse a (possibly unbalanced) transaction.
|
2018-06-06 08:52:28 +03:00
|
|
|
transactionp :: JournalParser m Transaction
|
2015-10-17 21:51:45 +03:00
|
|
|
transactionp = do
|
2018-07-16 17:28:58 +03:00
|
|
|
-- dbgparse 0 "transactionp"
|
2018-09-30 04:32:08 +03:00
|
|
|
startpos <- getSourcePos
|
2014-08-08 18:27:32 +04:00
|
|
|
date <- datep <?> "transaction"
|
2018-05-24 07:36:19 +03:00
|
|
|
edate <- optional (lift $ secondarydatep date) <?> "secondary date"
|
2016-07-29 18:57:10 +03:00
|
|
|
lookAhead (lift spacenonewline <|> newline) <?> "whitespace or newline"
|
|
|
|
status <- lift statusp <?> "cleared status"
|
2018-05-22 04:52:34 +03:00
|
|
|
code <- lift codep <?> "transaction code"
|
2018-06-06 08:52:28 +03:00
|
|
|
description <- lift $ T.strip <$> descriptionp
|
2018-06-06 08:44:02 +03:00
|
|
|
(comment, tags) <- lift transactioncommentp
|
|
|
|
let year = first3 $ toGregorian date
|
|
|
|
postings <- postingsp (Just year)
|
2018-09-30 04:32:08 +03:00
|
|
|
endpos <- getSourcePos
|
2018-06-09 05:35:27 +03:00
|
|
|
let sourcepos = journalSourcePos startpos endpos
|
2019-01-04 23:01:45 +03:00
|
|
|
return $ txnTieKnot $ Transaction 0 "" sourcepos date edate status code description comment tags postings
|
2007-02-09 04:23:12 +03:00
|
|
|
|
2016-04-23 21:27:39 +03:00
|
|
|
--- ** postings
|
2007-02-09 04:23:12 +03:00
|
|
|
|
2016-04-28 23:23:20 +03:00
|
|
|
-- Parse the following whitespace-beginning lines as postings, posting
|
|
|
|
-- tags, and/or comments (inferring year, if needed, from the given date).
|
2018-06-06 08:52:28 +03:00
|
|
|
postingsp :: Maybe Year -> JournalParser m [Posting]
|
2018-06-06 08:44:02 +03:00
|
|
|
postingsp mTransactionYear = many (postingp mTransactionYear) <?> "postings"
|
2014-09-11 00:07:53 +04:00
|
|
|
|
2018-06-06 08:52:28 +03:00
|
|
|
-- linebeginningwithspaces :: JournalParser m String
|
2012-05-14 22:52:22 +04:00
|
|
|
-- linebeginningwithspaces = do
|
2018-03-25 16:53:44 +03:00
|
|
|
-- sp <- lift (skipSome spacenonewline)
|
2012-05-14 22:52:22 +04:00
|
|
|
-- c <- nonspace
|
2016-07-29 18:57:10 +03:00
|
|
|
-- cs <- lift restofline
|
2012-05-14 22:52:22 +04:00
|
|
|
-- return $ sp ++ (c:cs) ++ "\n"
|
2007-02-09 04:23:12 +03:00
|
|
|
|
2018-06-06 08:52:28 +03:00
|
|
|
postingp :: Maybe Year -> JournalParser m Posting
|
2018-06-06 08:44:02 +03:00
|
|
|
postingp mTransactionYear = do
|
2018-07-26 10:29:02 +03:00
|
|
|
-- lift $ dbgparse 0 "postingp"
|
2018-05-10 07:40:33 +03:00
|
|
|
(status, account) <- try $ do
|
|
|
|
lift (skipSome spacenonewline)
|
|
|
|
status <- lift statusp
|
|
|
|
lift (skipMany spacenonewline)
|
|
|
|
account <- modifiedaccountnamep
|
|
|
|
return (status, account)
|
lib: textification begins! account names
The first of several conversions from String to (strict) Text, hopefully
reducing space and time usage.
This one shows a small improvement, with GHC 7.10.3 and text-1.2.2.1:
hledger -f data/100x100x10.journal stats
string: <<ghc: 39471064 bytes, 77 GCs, 198421/275048 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.001 elapsed), 0.015 MUT (0.020 elapsed), 0.010 GC (0.014 elapsed) :ghc>>
text: <<ghc: 39268024 bytes, 77 GCs, 197018/270840 avg/max bytes residency (3 samples), 2M in use, 0.000 INIT (0.002 elapsed), 0.016 MUT (0.022 elapsed), 0.009 GC (0.011 elapsed) :ghc>>
hledger -f data/1000x100x10.journal stats
string: <<ghc: 318555920 bytes, 617 GCs, 2178997/7134472 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.001 elapsed), 0.129 MUT (0.136 elapsed), 0.067 GC (0.077 elapsed) :ghc>>
text: <<ghc: 314248496 bytes, 612 GCs, 2074045/6617960 avg/max bytes residency (7 samples), 16M in use, 0.000 INIT (0.003 elapsed), 0.137 MUT (0.145 elapsed), 0.067 GC (0.079 elapsed) :ghc>>
hledger -f data/10000x100x10.journal stats
string: <<ghc: 3114763608 bytes, 6026 GCs, 18858950/75552024 avg/max bytes residency (11 samples), 201M in use, 0.000 INIT (0.000 elapsed), 1.331 MUT (1.372 elapsed), 0.699 GC (0.812 elapsed) :ghc>>
text: <<ghc: 3071468920 bytes, 5968 GCs, 14120344/62951360 avg/max bytes residency (9 samples), 124M in use, 0.000 INIT (0.003 elapsed), 1.272 MUT (1.349 elapsed), 0.513 GC (0.578 elapsed) :ghc>>
hledger -f data/100000x100x10.journal stats
string: <<ghc: 31186579432 bytes, 60278 GCs, 135332581/740228992 avg/max bytes residency (13 samples), 1697M in use, 0.000 INIT (0.008 elapsed), 14.677 MUT (15.508 elapsed), 7.081 GC (8.074 elapsed) :ghc>>
text: <<ghc: 30753427672 bytes, 59763 GCs, 117595958/666457240 avg/max bytes residency (14 samples), 1588M in use, 0.000 INIT (0.008 elapsed), 13.713 MUT (13.966 elapsed), 6.220 GC (7.108 elapsed) :ghc>>
2016-05-24 04:16:21 +03:00
|
|
|
let (ptype, account') = (accountNamePostingType account, textUnbracket account)
|
2018-06-21 03:33:29 +03:00
|
|
|
lift (skipMany spacenonewline)
|
|
|
|
amount <- option missingmixedamt $ Mixed . (:[]) <$> amountp
|
2018-10-12 06:37:20 +03:00
|
|
|
lift (skipMany spacenonewline)
|
|
|
|
massertion <- optional $ balanceassertionp
|
2015-10-17 21:51:45 +03:00
|
|
|
_ <- fixedlotpricep
|
2018-03-25 16:53:44 +03:00
|
|
|
lift (skipMany spacenonewline)
|
2018-06-06 08:44:02 +03:00
|
|
|
(comment,tags,mdate,mdate2) <- lift $ postingcommentp mTransactionYear
|
2014-11-03 08:52:12 +03:00
|
|
|
return posting
|
2016-04-28 23:23:20 +03:00
|
|
|
{ pdate=mdate
|
|
|
|
, pdate2=mdate2
|
2014-11-03 08:52:12 +03:00
|
|
|
, pstatus=status
|
|
|
|
, paccount=account'
|
|
|
|
, pamount=amount
|
|
|
|
, pcomment=comment
|
|
|
|
, ptype=ptype
|
|
|
|
, ptags=tags
|
|
|
|
, pbalanceassertion=massertion
|
|
|
|
}
|
2012-12-06 04:28:23 +04:00
|
|
|
|
2018-08-20 16:18:41 +03:00
|
|
|
--- * tests
|
2018-08-20 10:22:31 +03:00
|
|
|
|
2018-09-06 23:08:26 +03:00
|
|
|
tests_JournalReader = tests "JournalReader" [
|
2018-08-20 10:22:31 +03:00
|
|
|
|
2018-08-20 12:38:51 +03:00
|
|
|
let p = lift accountnamep :: JournalParser IO AccountName in
|
|
|
|
tests "accountnamep" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "basic" $ assertParse p "a:b:c"
|
|
|
|
-- ,test "empty inner component" $ assertParseError p "a::c" "" -- TODO
|
|
|
|
-- ,test "empty leading component" $ assertParseError p ":b:c" "x"
|
|
|
|
-- ,test "empty trailing component" $ assertParseError p "a:b:" "x"
|
2018-08-20 10:22:31 +03:00
|
|
|
]
|
|
|
|
|
2018-08-20 12:38:51 +03:00
|
|
|
-- "Parse a date in YYYY/MM/DD format.
|
|
|
|
-- Hyphen (-) and period (.) are also allowed as separators.
|
|
|
|
-- The year may be omitted if a default year has been set.
|
|
|
|
-- Leading zeroes may be omitted."
|
2019-11-27 00:56:14 +03:00
|
|
|
,tests "datep" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "YYYY/MM/DD" $ assertParseEq datep "2018/01/01" (fromGregorian 2018 1 1)
|
|
|
|
,test "YYYY-MM-DD" $ assertParse datep "2018-01-01"
|
|
|
|
,test "YYYY.MM.DD" $ assertParse datep "2018.01.01"
|
|
|
|
,test "yearless date with no default year" $ assertParseError datep "1/1" "current year is unknown"
|
|
|
|
,test "yearless date with default year" $ do
|
2018-09-30 04:32:08 +03:00
|
|
|
let s = "1/1"
|
|
|
|
ep <- parseWithState mempty{jparsedefaultyear=Just 2018} datep s
|
2019-11-27 00:56:14 +03:00
|
|
|
either (assertFailure . ("parse error at "++) . customErrorBundlePretty) (const $ return ()) ep
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "no leading zero" $ assertParse datep "2018/1/1"
|
2019-11-27 00:56:14 +03:00
|
|
|
]
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "datetimep" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
let
|
|
|
|
good = assertParse datetimep
|
|
|
|
bad = (\t -> assertParseError datetimep t "")
|
|
|
|
good "2011/1/1 00:00"
|
|
|
|
good "2011/1/1 23:59:59"
|
|
|
|
bad "2011/1/1"
|
|
|
|
bad "2011/1/1 24:00:00"
|
|
|
|
bad "2011/1/1 00:60:00"
|
|
|
|
bad "2011/1/1 00:00:60"
|
|
|
|
bad "2011/1/1 3:5:7"
|
|
|
|
-- timezone is parsed but ignored
|
|
|
|
let t = LocalTime (fromGregorian 2018 1 1) (TimeOfDay 0 0 (fromIntegral 0))
|
|
|
|
assertParseEq datetimep "2018/1/1 00:00-0800" t
|
|
|
|
assertParseEq datetimep "2018/1/1 00:00+1234" t
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2018-08-20 10:22:31 +03:00
|
|
|
,tests "periodictransactionp" [
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
test "more period text in comment after one space" $ assertParseEq periodictransactionp
|
2019-07-15 13:28:52 +03:00
|
|
|
"~ monthly from 2018/6 ;In 2019 we will change this\n"
|
2018-08-20 10:22:31 +03:00
|
|
|
nullperiodictransaction {
|
|
|
|
ptperiodexpr = "monthly from 2018/6"
|
|
|
|
,ptinterval = Months 1
|
2018-08-20 16:39:34 +03:00
|
|
|
,ptspan = DateSpan (Just $ fromGregorian 2018 6 1) Nothing
|
2018-08-20 10:22:31 +03:00
|
|
|
,ptdescription = ""
|
|
|
|
,ptcomment = "In 2019 we will change this\n"
|
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "more period text in description after two spaces" $ assertParseEq periodictransactionp
|
2019-07-15 13:28:52 +03:00
|
|
|
"~ monthly from 2018/6 In 2019 we will change this\n"
|
2018-08-20 10:22:31 +03:00
|
|
|
nullperiodictransaction {
|
|
|
|
ptperiodexpr = "monthly from 2018/6"
|
|
|
|
,ptinterval = Months 1
|
2018-08-20 16:39:34 +03:00
|
|
|
,ptspan = DateSpan (Just $ fromGregorian 2018 6 1) Nothing
|
2018-11-14 05:14:54 +03:00
|
|
|
,ptdescription = "In 2019 we will change this"
|
|
|
|
,ptcomment = ""
|
2018-08-20 10:22:31 +03:00
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "Next year in description" $ assertParseEq periodictransactionp
|
2018-08-20 10:22:31 +03:00
|
|
|
"~ monthly Next year blah blah\n"
|
|
|
|
nullperiodictransaction {
|
|
|
|
ptperiodexpr = "monthly"
|
|
|
|
,ptinterval = Months 1
|
|
|
|
,ptspan = DateSpan Nothing Nothing
|
2018-11-14 05:14:54 +03:00
|
|
|
,ptdescription = "Next year blah blah"
|
|
|
|
,ptcomment = ""
|
2018-08-20 10:22:31 +03:00
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "Just date, no description" $ assertParseEq periodictransactionp
|
2019-01-11 15:45:19 +03:00
|
|
|
"~ 2019-01-04\n"
|
|
|
|
nullperiodictransaction {
|
|
|
|
ptperiodexpr = "2019-01-04"
|
|
|
|
,ptinterval = NoInterval
|
|
|
|
,ptspan = DateSpan (Just $ fromGregorian 2019 1 4) (Just $ fromGregorian 2019 1 5)
|
|
|
|
,ptdescription = ""
|
|
|
|
,ptcomment = ""
|
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "Just date, no description + empty transaction comment" $ assertParse periodictransactionp
|
2019-01-11 15:45:19 +03:00
|
|
|
"~ 2019-01-04\n ;\n a 1\n b\n"
|
|
|
|
|
2018-08-20 12:38:51 +03:00
|
|
|
]
|
2018-08-20 10:22:31 +03:00
|
|
|
|
2018-08-20 16:18:41 +03:00
|
|
|
,tests "postingp" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "basic" $ assertParseEq (postingp Nothing)
|
2018-08-20 16:18:41 +03:00
|
|
|
" expenses:food:dining $10.00 ; a: a a \n ; b: b b \n"
|
|
|
|
posting{
|
2019-07-15 13:28:52 +03:00
|
|
|
paccount="expenses:food:dining",
|
|
|
|
pamount=Mixed [usd 10],
|
|
|
|
pcomment="a: a a\nb: b b\n",
|
2018-08-20 16:18:41 +03:00
|
|
|
ptags=[("a","a a"), ("b","b b")]
|
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "posting dates" $ assertParseEq (postingp Nothing)
|
2018-08-20 16:18:41 +03:00
|
|
|
" a 1. ; date:2012/11/28, date2=2012/11/29,b:b\n"
|
|
|
|
nullposting{
|
|
|
|
paccount="a"
|
|
|
|
,pamount=Mixed [num 1]
|
|
|
|
,pcomment="date:2012/11/28, date2=2012/11/29,b:b\n"
|
|
|
|
,ptags=[("date", "2012/11/28"), ("date2=2012/11/29,b", "b")] -- TODO tag name parsed too greedily
|
2018-08-20 16:39:34 +03:00
|
|
|
,pdate=Just $ fromGregorian 2012 11 28
|
|
|
|
,pdate2=Nothing -- Just $ fromGregorian 2012 11 29
|
2018-08-20 16:18:41 +03:00
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "posting dates bracket syntax" $ assertParseEq (postingp Nothing)
|
2018-08-20 16:18:41 +03:00
|
|
|
" a 1. ; [2012/11/28=2012/11/29]\n"
|
|
|
|
nullposting{
|
|
|
|
paccount="a"
|
|
|
|
,pamount=Mixed [num 1]
|
|
|
|
,pcomment="[2012/11/28=2012/11/29]\n"
|
|
|
|
,ptags=[]
|
2019-07-15 13:28:52 +03:00
|
|
|
,pdate= Just $ fromGregorian 2012 11 28
|
2018-08-20 16:18:41 +03:00
|
|
|
,pdate2=Just $ fromGregorian 2012 11 29
|
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "quoted commodity symbol with digits" $ assertParse (postingp Nothing) " a 1 \"DE123\"\n"
|
2018-08-20 16:18:41 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "balance assertion and fixed lot price" $ assertParse (postingp Nothing) " a 1 \"DE123\" =$1 { =2.2 EUR} \n"
|
2018-10-12 09:17:16 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "balance assertion over entire contents of account" $ assertParse (postingp Nothing) " a $1 == $1\n"
|
2018-08-20 16:18:41 +03:00
|
|
|
]
|
|
|
|
|
2018-08-20 12:38:51 +03:00
|
|
|
,tests "transactionmodifierp" [
|
2010-03-13 04:10:10 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
test "basic" $ assertParseEq transactionmodifierp
|
2018-08-20 12:38:51 +03:00
|
|
|
"= (some value expr)\n some:postings 1.\n"
|
|
|
|
nulltransactionmodifier {
|
|
|
|
tmquerytxt = "(some value expr)"
|
2018-11-13 22:42:23 +03:00
|
|
|
,tmpostingrules = [nullposting{paccount="some:postings", pamount=Mixed[num 1]}]
|
2018-08-20 12:38:51 +03:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2018-08-20 16:18:41 +03:00
|
|
|
,tests "transactionp" [
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
test "just a date" $ assertParseEq transactionp "2015/1/1\n" nulltransaction{tdate=fromGregorian 2015 1 1}
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "more complex" $ assertParseEq transactionp
|
2018-08-20 16:18:41 +03:00
|
|
|
(T.unlines [
|
|
|
|
"2012/05/14=2012/05/15 (code) desc ; tcomment1",
|
|
|
|
" ; tcomment2",
|
|
|
|
" ; ttag1: val1",
|
|
|
|
" * a $1.00 ; pcomment1",
|
|
|
|
" ; pcomment2",
|
|
|
|
" ; ptag1: val1",
|
|
|
|
" ; ptag2: val2"
|
|
|
|
])
|
|
|
|
nulltransaction{
|
|
|
|
tsourcepos=JournalSourcePos "" (1,7), -- XXX why 7 here ?
|
2019-01-04 23:01:45 +03:00
|
|
|
tprecedingcomment="",
|
2018-08-20 16:39:34 +03:00
|
|
|
tdate=fromGregorian 2012 5 14,
|
|
|
|
tdate2=Just $ fromGregorian 2012 5 15,
|
2018-08-20 16:18:41 +03:00
|
|
|
tstatus=Unmarked,
|
|
|
|
tcode="code",
|
|
|
|
tdescription="desc",
|
|
|
|
tcomment="tcomment1\ntcomment2\nttag1: val1\n",
|
|
|
|
ttags=[("ttag1","val1")],
|
|
|
|
tpostings=[
|
|
|
|
nullposting{
|
|
|
|
pdate=Nothing,
|
|
|
|
pstatus=Cleared,
|
|
|
|
paccount="a",
|
|
|
|
pamount=Mixed [usd 1],
|
|
|
|
pcomment="pcomment1\npcomment2\nptag1: val1\nptag2: val2\n",
|
|
|
|
ptype=RegularPosting,
|
|
|
|
ptags=[("ptag1","val1"),("ptag2","val2")],
|
|
|
|
ptransaction=Nothing
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "parses a well-formed transaction" $
|
2019-11-27 23:46:29 +03:00
|
|
|
assertBool "" $ isRight $ rjp transactionp $ T.unlines
|
2018-08-20 16:18:41 +03:00
|
|
|
["2007/01/28 coopportunity"
|
|
|
|
," expenses:food:groceries $47.18"
|
|
|
|
," assets:checking $-47.18"
|
|
|
|
,""
|
|
|
|
]
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "does not parse a following comment as part of the description" $
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParseEqOn transactionp "2009/1/1 a ;comment\n b 1\n" tdescription "a"
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "parses a following whitespace line" $
|
2019-11-27 23:46:29 +03:00
|
|
|
assertBool "" $ isRight $ rjp transactionp $ T.unlines
|
2018-08-20 16:18:41 +03:00
|
|
|
["2012/1/1"
|
|
|
|
," a 1"
|
|
|
|
," b"
|
|
|
|
," "
|
|
|
|
]
|
2019-01-11 15:45:19 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "parses an empty transaction comment following whitespace line" $
|
2019-11-27 23:46:29 +03:00
|
|
|
assertBool "" $ isRight $ rjp transactionp $ T.unlines
|
2019-01-11 15:45:19 +03:00
|
|
|
["2012/1/1"
|
|
|
|
," ;"
|
|
|
|
," a 1"
|
|
|
|
," b"
|
|
|
|
," "
|
|
|
|
]
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "comments everywhere, two postings parsed" $
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParseEqOn transactionp
|
2018-08-20 16:18:41 +03:00
|
|
|
(T.unlines
|
|
|
|
["2009/1/1 x ; transaction comment"
|
|
|
|
," a 1 ; posting 1 comment"
|
|
|
|
," ; posting 1 comment 2"
|
|
|
|
," b"
|
|
|
|
," ; posting 2 comment"
|
|
|
|
])
|
|
|
|
(length . tpostings)
|
|
|
|
2
|
2019-07-15 13:28:52 +03:00
|
|
|
|
2018-08-20 16:18:41 +03:00
|
|
|
]
|
2018-08-19 21:01:20 +03:00
|
|
|
|
2018-08-20 12:38:51 +03:00
|
|
|
-- directives
|
|
|
|
|
|
|
|
,tests "directivep" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "supports !" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParseE directivep "!account a\n"
|
|
|
|
assertParseE directivep "!D 1.0\n"
|
|
|
|
]
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-27 00:56:14 +03:00
|
|
|
,tests "accountdirectivep" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "with-comment" $ assertParse accountdirectivep "account a:b ; a comment\n"
|
|
|
|
,test "does-not-support-!" $ assertParseError accountdirectivep "!account a:b\n" ""
|
|
|
|
,test "account-type-code" $ assertParse accountdirectivep "account a:b A\n"
|
|
|
|
,test "account-type-tag" $ assertParseStateOn accountdirectivep "account a:b ; type:asset\n"
|
2019-11-27 00:56:14 +03:00
|
|
|
jdeclaredaccounts
|
|
|
|
[("a:b", AccountDeclarationInfo{adicomment = "type:asset\n"
|
|
|
|
,aditags = [("type","asset")]
|
|
|
|
,adideclarationorder = 1
|
|
|
|
})
|
|
|
|
]
|
2019-01-15 03:21:40 +03:00
|
|
|
]
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "commodityconversiondirectivep" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParse commodityconversiondirectivep "C 1h = $50.00\n"
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "defaultcommoditydirectivep" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParse defaultcommoditydirectivep "D $1,000.0\n"
|
|
|
|
assertParseError defaultcommoditydirectivep "D $1000\n" "please include a decimal separator"
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-27 00:56:14 +03:00
|
|
|
,tests "defaultyeardirectivep" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "1000" $ assertParse defaultyeardirectivep "Y 1000" -- XXX no \n like the others
|
|
|
|
,test "999" $ assertParseError defaultyeardirectivep "Y 999" "bad year number"
|
|
|
|
,test "12345" $ assertParse defaultyeardirectivep "Y 12345"
|
2019-11-27 00:56:14 +03:00
|
|
|
]
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "ignoredpricecommoditydirectivep" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParse ignoredpricecommoditydirectivep "N $\n"
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-27 00:56:14 +03:00
|
|
|
,tests "includedirectivep" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "include" $ assertParseErrorE includedirectivep "include nosuchfile\n" "No existing files match pattern: nosuchfile"
|
|
|
|
,test "glob" $ assertParseErrorE includedirectivep "include nosuchfile*\n" "No existing files match pattern: nosuchfile*"
|
2019-11-27 00:56:14 +03:00
|
|
|
]
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "marketpricedirectivep" $ assertParseEq marketpricedirectivep
|
2018-08-20 12:38:51 +03:00
|
|
|
"P 2017/01/30 BTC $922.83\n"
|
2019-06-04 03:26:27 +03:00
|
|
|
PriceDirective{
|
|
|
|
pddate = fromGregorian 2017 1 30,
|
|
|
|
pdcommodity = "BTC",
|
|
|
|
pdamount = usd 922.83
|
2018-08-20 12:38:51 +03:00
|
|
|
}
|
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "tagdirectivep" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParse tagdirectivep "tag foo \n"
|
2018-08-20 12:38:51 +03:00
|
|
|
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "endtagdirectivep" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
assertParse endtagdirectivep "end tag \n"
|
|
|
|
assertParse endtagdirectivep "pop \n"
|
2018-09-04 01:42:24 +03:00
|
|
|
|
|
|
|
,tests "journalp" [
|
2019-11-29 02:29:03 +03:00
|
|
|
test "empty file" $ assertParseEqE journalp "" nulljournal
|
2018-09-04 01:42:24 +03:00
|
|
|
]
|
|
|
|
|
2019-01-25 19:51:45 +03:00
|
|
|
-- these are defined here rather than in Common so they can use journalp
|
2019-11-29 02:29:03 +03:00
|
|
|
,test "parseAndFinaliseJournal" $ do
|
2019-11-27 23:46:29 +03:00
|
|
|
ej <- runExceptT $ parseAndFinaliseJournal journalp definputopts "" "2019-1-1\n"
|
|
|
|
let Right j = ej
|
|
|
|
assertEqual "" [""] $ journalFilePaths j
|
2019-01-15 23:57:51 +03:00
|
|
|
|
2018-08-17 14:42:43 +03:00
|
|
|
]
|