Commit Graph

247 Commits

Author SHA1 Message Date
Simon Michael
0f5ee154c4 lib: simplify parsers; cleanups (#275)
The journal/timeclock/timedot parsers, instead of constructing (opaque)
journal update functions which are later applied to build the journal,
now construct the journal directly (by modifying the parser state). This
is easier to understand and debug. It also removes any possibility of
the journal updates being a space leak. (They weren't, in fact memory
usage is now slightly higher, but that will be addressed in other ways.)

Also:

Journal data and journal parse info have been merged into one type (for
now), and field names are more consistent.

The ParsedJournal type alias has been added to distinguish being-parsed
and finalised journals.

Journal is now a monoid.

stats: fixed an issue with ordering of include files

journal: fixed an issue with ordering of included same-date transactions

timeclock: sessions can no longer span file boundaries (unclocked-out
sessions will be auto-closed at the end of the file).

expandPath now throws a proper IO error (and requires the IO monad).
2016-05-23 00:44:19 -07:00
Simon Michael
20bfceff2e lib: allow multiple files of different format (#320)
When multiple files are specified with multiple -f options, we now
parse each one individually, rather than just concatenating them, so
they can have different formats.

Directives (like default year or account aliases) no longer carry over
from one file to the next. Limitation or feature ?
2016-05-18 16:41:52 -07:00
Simon Michael
80e8caebe7 func. test for 320 2016-05-18 13:10:41 -07:00
Simon Michael
975e3274ea stats: fix func test 2016-05-17 19:52:19 -07:00
Simon Michael
695d96231c test numbering 2016-05-13 22:10:23 -07:00
Simon Michael
ddefec412f journal: also allow one-line commodity directives 2016-05-08 20:56:34 -07:00
Simon Michael
9304aa1100 journal: commodity format directive overrides inferred style (#295)
The commodity directive's format subdirective can now be used to
override the inferred style for a commodity, eg to increase or decrease
the precision. This doesn't fix the root cause of #295 but is at least a
good workaround.
2016-05-08 09:07:08 -07:00
Simon Michael
8312573fed tests for #295 2016-05-07 18:34:24 -07:00
Malte Brandy
913b8e4c19 Add --pivot option with tests and docs (#323) 2016-05-06 18:27:35 -07:00
Simon Michael
e2ce7c4802 doc, tests: clarify what --date2 does 2016-05-06 16:57:24 -07:00
Simon Michael
856c0b3042 lib: fix bracketed posting dates, parser cleanup (#304)
Bracketed posting dates were fragile; they worked only if you wrote full
10-character dates. Also some semantics were a bit unclear. Now they
should be robust, and have been documented more clearly. This is a
legacy undocumented Ledger syntax, but it improves compatibility and
might be preferable to the more verbose "date:" tags if you write
posting dates often (as I do).

Internally, bracketed posting dates are no longer considered to be tags.
Journal comment, tag, and posting date parsers have been reworked, all
with doctests. Also the journal parser types generally have been
tightened up and clarified, making it much easier to know how to combine
and run them. There's now

-- | A parser of strings with generic user state, monad and return type.
type StringParser u m a = ParsecT String u m a

-- | A string parser with journal-parsing state.
type JournalParser m a = StringParser JournalContext m a

-- | A journal parser that runs in IO and can throw an error mid-parse.
type ErroringJournalParser a = JournalParser (ExceptT String IO) a

and corresponding convenience functions (and short aliases) for running them.
2016-04-28 13:34:57 -07:00
Simon Michael
b0f40bd7c8 tools: fix make functest in a fresh copy 2016-04-21 08:37:37 -07:00
Simon Michael
1fc34d76f8 cli: adapt func tests pass to new --help 2016-04-19 10:44:43 -07:00
Simon Michael
588f36d662 rename timelog format to timeclock 2016-04-12 21:13:19 -07:00
Simon Michael
31a754544a journal: parse account directives
We now parse account directives, like Ledger's. We don't do anything
with them yet. The default parent account feature must now be spelled
"apply account"/"end apply account".
2016-04-04 11:35:39 -07:00
Simon Michael
25cd65442a cli: fix opts parsing regressions from feb
Since commit 7aab544, "-f -" before the command broke command
detection, causing spurious "no such option" errors (and breaking
about 70 functional tests which neither I nor travis noticed).
2016-04-04 11:35:39 -07:00
Simon Michael
0a7fb17635 fix two failing tests 2016-02-19 21:45:39 -08:00
Simon Michael
36970f7b19 lib: fix balance assertion test 2016-02-19 17:52:40 -08:00
Simon Michael
a2b989d898 journal: support ledger3-compatible "apply account" 2016-01-29 07:39:26 -08:00
Simon Michael
8c6d53f912 consolidate some journal format-specific tests 2015-11-22 08:55:29 -08:00
Simon Michael
0a7a6c87f8 clean up price tests 2015-11-22 08:37:02 -08:00
Simon Michael
56a79c479f cleanup 2015-10-12 07:02:36 -07:00
Simon Michael
71921135f6 include P amounts in canonicalisation (fixes #131)
Since market price amounts didn't contribute to the canonical commodity
styles, they were being reset to the null style. And this propagated to
the reported amounts when -V was in effect, causing much confusion.
Now, market prices contribute to canonicalisation and the expected
styles are preserved even with -V.

cf https://github.com/simonmichael/hledger/issues/131#issuecomment-133545140
2015-10-11 16:07:31 -07:00
Simon Michael
eb75946e64 print: always right-align amounts
print now always right-aligns the amounts in an entry, even when they
are wider than 12 characters.

If there is a price, it's considered part of the amount for
right-alignment. Maybe it would be nicer to put amounts and prices in
separate columns ? That will get a little complicated, needs more
discussion/design.

Also some cleanup of postingAsLines.
2015-10-10 15:09:42 -07:00
Simon Michael
cbbe07e3c4 tests/nonascii -> tests/i18n 2015-10-10 13:11:31 -07:00
Simon Michael
3b40edba9c print: fix wide char support, add tests (#242)
The print command wasn't lining up amounts with wide chars in account
names, fixed it properly this time. Transaction and Posting's Show instances
should also be wide-char-aware now.
2015-10-10 11:53:28 -07:00
Simon Michael
5b5e5eeaf4 register: wide-character-aware layout (#242)
Wide characters, eg chinese/japanese/korean characters, are typically
rendered wider than latin characters. In some applications (eg gnome
terminal or osx terminal) and fonts (eg monaco) they are exactly double
width. This is a start at making hledger aware of this. A register
report containing wide characters (in descriptions, account names, or
commodity symbols) should now align its columns correctly, when viewed
with a suitable font and application.
2015-09-28 16:12:20 -10:00
Simon Michael
821f1b7120 lib: fix tests for zero amount style (#230, #276) 2015-09-02 16:38:45 -07:00
Simon Michael
cc98ee39f7 balance, lib: --format/StringFormat improvements
The balance command's --format option (in single-column mode) can now
adjust the rendering of multi-line strings, such as amounts with multiple
commodities. To control this, begin the format string with one of:

 %_  - renders on multiple lines, bottom-aligned (the default)
 %^  - renders on multiple lines, top-aligned
 %,  - render on one line, comma-separated

Also the final total (and the line above it) now adapt themselves to a
custom format.
2015-08-19 20:53:51 -07:00
Simon Michael
21d9945ba9 tests: make functional tests use "hledger" again
Using "hledgerdev" was a hack to help ensure that tests used a fresh
developer build by default. Now they specify "hledger" again, which fits
better with stack. It's up to the tester to make sure the desired
executable is first in PATH or specified with -w. (Note a couple of
tests currently don't obey -w and will always run "hledger", see addons.test).
2015-07-12 12:29:53 -07:00
Simon Michael
25d41acadf update a functional test
the parse error has changed
2015-07-12 12:26:21 -07:00
Simon Michael
745f2dd788 cli: a cabal bench test that works 2015-06-18 09:49:51 -07:00
Imuli
67432f1220 read multiple files: tests 2015-05-28 10:40:48 -07:00
Simon Michael
46bbc9e0aa fix simple aliases that match the whole account name 2015-05-28 10:40:48 -07:00
Simon Michael
c138852dab maybe stop numbering functional tests 2015-05-28 10:40:48 -07:00
Simon Michael
8d75635505 print: limit display precision of generated prices (#262)
When a transaction posts to two commodities without specifying the
conversion price, we generate a price which makes it balance
(cf http://hledger.org/manual.html#prices).

Until now, these generated prices were always shown with full precision
(all available decimal digits) so that a manual calculation with the
displayed numbers would agree.

If there's just one posting in the commodity being priced, we can use an
exact total price and the precision is no problem.

But if there are multiple postings in the commodity being priced, we
must show the averaged unit price. This can be an irrational number,
which with our current Decimal-based implementation would display an
excessive 255 decimal digits. So in this case we now set the price's
display precision to the sum of the (max) display precisions of the
commodities involved. An example:

hledgerdev -f- print
<<<
1/1
    c    C 10.00
    c    C 11.00
    d  D -320.00
>>>
2015/01/01
    c  C 10.00 @ D 15.2381
    c  C 11.00 @ D 15.2381
    d     D -320.00

>>>=0

There might still be cases where this will show more price decimal
places than necessary. For now, YAGNI.
2015-05-27 14:21:19 -07:00
Simon Michael
64bc422b85 forgot to commit status tests 2015-05-16 13:04:22 -07:00
Simon Michael
077e3c6a02 journal: re-add non-regex aliases, as default (#252)
The regex account aliases added in 0.24 trip up people switching between
hledger and Ledger. (Also they are currently slow).

This change makes the old non-regex aliases the default; they are
unsurprising, useful, and pretty close in functionality to Ledger's.

The new regex aliases are also available; they must be enclosed in
forward slashes. Ledger effectively ignores these, which is ok.

Also clarify docs, refactor, and use the same parser for alias
directives and alias options
2015-05-14 13:01:50 -07:00
Simon Michael
5102eca9c3 timelog: support the description field (fix #247) 2015-04-28 13:54:36 -07:00
Simon Michael
6bad57a4d8 tools: bench test update 2015-03-15 18:51:14 -07:00
Simon Michael
592ae9a28e timelog: show hours with 2 decimal places, not 1 2015-02-27 08:37:16 -08:00
Simon Michael
257ce57383 fix balance accumulation across assertions (#195)
A sequence of balance assertions asserting first one commodity, then
another, then the first again, was not working.
2015-01-10 22:17:19 -08:00
Simon Michael
95ced2da80 balance: fix partially-visible totals row
With --no-total in a periodic (non-cumulative, non-historical) balance
report, hide the totals row completely, as in the other modes.
2014-12-27 16:46:37 -08:00
Simon Michael
c138c35d3b register: support date:/date2:/--date2 better (fix #201, #221, #222) 2014-12-24 16:11:30 -08:00
Simon Michael
663e1f5ba9 tests for --date2, date2: (#201) 2014-12-23 06:23:23 -08:00
Simon Michael
20cace6948 tools: some bench tests cleanup or other 2014-12-10 23:13:34 -08:00
Simon Michael
855d4e1131 balance: with --tree and --flat, use the last (fix #219) 2014-12-05 12:56:33 -08:00
Simon Michael
d25fe21834 apply all matching account aliases, not just one directive and one option 2014-10-29 08:20:27 -07:00
Simon Michael
9fa22e0398 account aliases (and regexReplace) now support backreferences 2014-10-29 07:46:49 -07:00
Simon Michael
e892fdc6d5 parsing: aliases now match by regular expression
alias match patterns (the part left of the =) are now case-insensitive
regular expressions matching anywhere in the account name. The
replacement string (the part right of the =) can replace multiple
matches within the account name. The replacement string does not yet
support any of the usual syntax like backreferences.
2014-10-24 15:05:10 -07:00