Commit Graph

692 Commits

Author SHA1 Message Date
Simon Michael
3dce879731 ;timedot: fix accidentally committed debug output breaking CI 2020-02-29 11:39:16 -08:00
Simon Michael
2c8a6e988f lib: Hledger.Read.CsvReader cleanup
Exports added: CsvRecord, CsvValue, csvFileFor

Exports removed: expandIncludes, parseAndValidateCsvRules, transactionFromCsvRecord
2020-02-27 23:37:32 -08:00
Simon Michael
5365fde3bc ;lib: Hledger.Read.TimeclockReader cleanup 2020-02-27 22:51:27 -08:00
Simon Michael
1bb33be54d ;lib: Hledger.Read.TimedotReader cleanup 2020-02-27 22:49:53 -08:00
Simon Michael
af67c327ff ;lib: Hledger.Read.JournalReader cleanup 2020-02-27 22:44:35 -08:00
Simon Michael
2e5afd0a9f ;lib: Hledger.Read.Common cleanup 2020-02-27 22:44:27 -08:00
Simon Michael
8535939f33 ;timedot: update parser tracing 2020-02-27 18:11:07 -08:00
Simon Michael
bc4ea83d86 ;csv: refactor transactionFromCsvRecord 2020-02-27 12:58:30 -08:00
Simon Michael
2dd6e2d797 ;csv: refactor transactionFromCsvRecord 2020-02-27 12:09:39 -08:00
Simon Michael
b18f71a81b ;csv: extract mkPosting! and refactor 2020-02-27 11:51:11 -08:00
Simon Michael
f2767477ab ;csv: refactor transactionFromCsvRecord, extract those helpers 2020-02-27 11:19:37 -08:00
Simon Michael
6f08eed719 ;csv: refactor transactionFromCsvRecord, note forgotten rule
Clarify some helpers. Also note the forgotten default-accountN rule.
2020-02-27 11:03:58 -08:00
Simon Michael
5a2f28f3ac ;csv: refactor transactionFromCsvRecord
[ci skip]
2020-02-27 01:23:28 -08:00
Simon Michael
a87baf4b29 ;csv: refactor: rename JournalFieldName -> HledgerFieldName 2020-02-27 01:00:35 -08:00
Simon Michael
be5fc09ebb ;csv: refactor: more transactionFromCsvRecord cleanups 2020-02-27 00:41:10 -08:00
Simon Michael
93358d72b4 ;csv: refactor transactionFromCsvRecord 2020-02-27 00:30:45 -08:00
Simon Michael
02f2e3bd9b csv: refine unknown accounts more thoroughly, a better fix for #1192 2020-02-26 22:45:49 -08:00
Simon Michael
58bb0df5ab csv: undo failed #1192 fix, causing "_unknown_" accounts; refactor
Restore the old logic, while also trying to clarify this
transaction-generating code, and add some tests.
See also #1198.
2020-02-26 21:46:11 -08:00
Simon Michael
fb788a64e8 ;csv: cleanups, drop match operator for now 2020-02-26 11:52:47 -08:00
Simon Michael
d537f1fe07 csv: allow single field matching; more docs and tests 2020-02-26 08:55:55 -08:00
Simon Michael
becd891dd1 ;csv: Matcher type, simplify 2020-02-25 13:44:45 -08:00
Simon Michael
1cbce98a68 ;csv: refactor, ConditionalBlock ADT 2020-02-25 13:44:45 -08:00
Simon Michael
7ec25da13a web: edit/upload: normalise line endings, avoiding parse errors (#1194)
Renamed: writeValidJournal -> writeJournalTextIfValidAndChanged

Added comments clarifying line ending behaviour of:
add, import, appendToJournalFileOrStdout, readFilePortably,
writeFileWithBackupIfChanged, writeJournalTextIfValidAndChanged

Summary of current behaviour:

- hledger add and import commands will append with (at least some)
  unix line endings, possibly causing the file to have mixed line
  endings

- hledger-web edit and upload forms will write the file with
  the current system's native line endings, ie changing all
  line endings if the file previously used foreign line endings.
2020-02-24 14:04:44 -08:00
Simon Michael
2d90074b2e ;csv: avoid a potential display of internal placeholder (#1192)
With a multicommodity amount, the unknown account name will always be
"expenses:unknown".
2020-02-15 14:02:53 -08:00
Simon Michael
017d3355f8 csv: allow manual assignment of "expenses:unknown" again (fix #1192) 2020-02-15 13:52:59 -08:00
Jakob Schöttl
50acfc9119 Fix documentation, make ISO date format standard in some places 2020-02-09 07:26:54 -08:00
Simon Michael
b3711488a7 lib: apply canonical display styles to auto posting amounts too 2020-01-31 06:00:06 -08:00
Simon Michael
fccd88149d ;lib: refactor, clarify finaliseJournal a bit 2020-01-31 05:39:16 -08:00
Simon Michael
80ab45984b csv: also recognise .tsv, .ssv extensions; document thoroughly (#1179) 2020-01-20 12:58:47 -08:00
Jakob Schöttl
c7a88b50fb Fix timeclock format parsing
Fix presumably copy-paste errors

timeclock format has only timeclock lines or empty/comment lines

Update test format to v3, add new tests

Throw error on unexpected clock codes in timeclock format

Fix missing case in pattern matching
2020-01-12 13:17:36 -08:00
Aleksandar Dimitrov
3ead97975c Inline function, add debug statement 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
9011aaa5ba Refactor getSeparator 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
92f680875f Parse reserved words case insensitively 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
8df4e1ed83 Remove --separator command line argument 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
02d9205af7 Allow separator to be overridden from command line
This also fixes that parsing separators on the command line and the
rules file was not handled the same way.
2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
b524a088c7 Implement getting separator from rules 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
32ccc3a2b2 Add directive 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
ec0f55d18e Add missing type signature 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
b104b3b8a3 Explictly discard result 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
42d585d20b Refactor: rename variable 2020-01-05 14:45:57 -08:00
Aleksandar Dimitrov
63cda87e86 Whitespace 2020-01-05 14:45:57 -08:00
Brian Wignall
2852f9dbee Fix typos 2019-12-21 12:09:05 -08:00
Simon Michael
47567cd770 ;fix some warnings with GHC 8.10 alpha
hledger is GHC 8.10 ready!
2019-12-14 17:30:19 -08:00
Simon Michael
13e6c7dfdf lib: drop "assertion" alias for nullassertion
Perhaps we'll stick with the null* convention. Fixes a warning in Transaction.hs.
2019-12-09 06:08:03 -08:00
Simon Michael
a0b92e02b9 Revert "remove old fail compatibility imports that are obsolete ?"
They are needed with ghc <8.4, not for fail but for <> I think.
Try cleaning up again another time.
This reverts commit 318ce7eb07.
2019-12-01 11:32:51 -08:00
Simon Michael
318ce7eb07 remove old fail compatibility imports that are obsolete ? 2019-12-01 08:31:50 -08:00
Simon Michael
2b2a0b3cf8 ;tests: use "test" alias for testCase everywhere
Easier to type and read, and a little clearer to my eyes;
"testCase" implies a single case, but it can contain many assertions.
2019-11-28 15:33:33 -08:00
Simon Michael
030b633cd6 ;fix build issues with old GHC versions 2019-11-28 15:22:12 -08:00
Simon Michael
b36f6df110 tests: port all unit tests to tasty, second pass (#1090)
Hledger.Util.Tests helpers have been cleaned up, and test names are
now shown.

Tests have been cleaned up a bit. Some groups of unnamed tests have
been collapsed into a single named test containing a sequence of
assertions. The test command counts named tests, not assertions, so
the reported unit test count has dropped from 199 to 188.
2019-11-27 13:17:34 -08:00
Simon Michael
13a3542464 tests: port all unit tests to tasty, first cut (#1090)
easytest is not actively maintained and requires an old version of
hedgehog which does not support base-compat 0.11 & ghc 8.8.

This is still using the old easytest helpers, and not displaying test
names properly.
2019-11-27 12:43:43 -08:00
Dmitry Astapov
aa051a05cf lib: support generation of (un)balanced virtual postings in csv reader 2019-11-23 10:28:10 -08:00
Brian Wignall
f8269e21ab Fix some simple typos 2019-11-20 13:33:33 -08:00
Mykola Orliuk
097486a247 ;lib: re-enable doctests 2019-11-19 03:58:56 -08:00
Dmitry Astapov
c4d650e6ad lib: balance-style -> balance-type 2019-11-13 09:06:25 -08:00
Dmitry Astapov
39bc183340 lib: csv reader gets balance-style directive 2019-11-13 09:06:25 -08:00
Simon Michael
fb3c1a132c csv: fix parsing of whitespace on line after an if block (fix #1120) 2019-11-13 05:41:32 -08:00
Dmitry Astapov
94f912e558 lib: better resolution of csv field aliases ("balance" vs "balance1", etc) 2019-11-12 12:20:09 -08:00
Simon Michael
c4d7cc198a csv: finalise and check journals generated from CSV (#1000)
Invalid transactions generated from CSV will now be rejected.
I updated some csv tests to avoid this, except for 21, which
probably needs more cleanup.
2019-11-07 18:58:12 -08:00
Simon Michael
5264a7ebc1 ;lib: refactor, split out finaliseJournal 2019-11-07 18:08:41 -08:00
Dmitry Astapov
fc001da1ef lib: expenses:unknown is a much better default account name 2019-11-05 21:16:42 +00:00
Dmitry Astapov
c66ccc5cee lib: do not try to balance transaction in csv reader 2019-11-05 21:16:42 +00:00
Dmitry Astapov
95ec5715cc lib: better compatibility code in csv reader 2019-11-05 21:16:42 +00:00
Dmitry Astapov
d62f84bec2 lib: csv reader does not generate postings if account="" 2019-11-05 21:16:42 +00:00
Dmitry Astapov
8d24a40150 lib: csv parser fills out amounts on all postings, if possible 2019-11-05 21:16:42 +00:00
Dmitry Astapov
637741a755 lib: amount1 is no longer magical 2019-11-05 21:16:42 +00:00
Dmitry Astapov
977592e49c lib: typo fix, "expense:unknown" -> "expenses:unknown" 2019-11-05 21:16:42 +00:00
Dmitry Astapov
3c7d5d466d lib, doc, test: csv parser gains "end" command for "if" block 2019-11-05 21:16:42 +00:00
Dmitry Astapov
f92590f92c lib: allow zero postings in csv reader 2019-11-05 21:16:42 +00:00
Dmitry Astapov
1ab8631264 lib: change default rules file text to mention "amount1" 2019-11-05 21:16:42 +00:00
Dmitry Astapov
32cbe4c7b3 lib: better inference for unknown account names in csv parser 2019-11-05 21:16:42 +00:00
Dmitry Astapov
b5d4918c16 lib: allow recursive interpolation of fields with underscores in names 2019-11-05 21:16:42 +00:00
Dmitry Astapov
38db7eb24d lib: implement skip end in csv reader 2019-11-05 21:16:42 +00:00
Dmitry Astapov
b2ba1086b6 lib: fixed validation rules for minimul viable csv rules to include account1 etc 2019-11-05 21:16:42 +00:00
Dmitry Astapov
f1ab107400 lib, doc: extended "skip" in "if" body to "skip N" 2019-11-05 21:16:42 +00:00
Dmitry Astapov
f108b52171 lib: fix for #1001 - empty field assignment consumes next line 2019-11-05 21:16:42 +00:00
Dmitry Astapov
5dac141a7e lib: implement conditional line skips in csv (fixes #1076) 2019-11-05 21:16:42 +00:00
Dmitry Astapov
f74df08e98 lib: fix accidental switch of income:unknown and expence:unknown in csv parser 2019-11-05 21:16:42 +00:00
Dmitry Astapov
77fa81ea4d lib: fix error message formatting (header displayed twice) 2019-11-05 21:16:42 +00:00
Dmitry Astapov
825b9ce5b3 lib: fixed amount vs amount1 conflict detection in csv parser 2019-11-05 21:16:42 +00:00
Dmitry Astapov
881422cd0f lib: fix recursive interpolation in CSV parser for fields with dashes 2019-11-05 21:16:42 +00:00
Dmitry Astapov
e4476dd2f1 lib: more robust "unknown" account assignment in csv parser 2019-11-05 21:16:42 +00:00
Dmitry Astapov
28ca65b99a lib: more explicit conditions for using legacy csv parser 2019-11-05 21:16:42 +00:00
Dmitry Astapov
e4add6df83 lib: fix for multiline descriptions in csv (fixes #841, #416) 2019-11-05 21:16:42 +00:00
Dmitry Astapov
9aab476d53 lib: csv parser supports up to 9 postings. Fixes #570, #627 2019-11-05 21:16:42 +00:00
Mykola Orliuk
78146978f4 ;lib: store raw opts unquoted
It looks like we only need quote when we build query and in some
messages.

Fixes simonmichael/hledger#1079
2019-10-19 14:44:08 -07:00
Simon Michael
eff1b31c86 csv: allow csv records with varying lengths, padding with empties
Sometimes trailing empty fields are omitted entirely (including the
commas) in CSV records. (I see this in exported Google spreadsheets.)
Now we don't raise an error in this case, instead we automatically pad
any "short" records with empty fields. Not yet well tested.
2019-10-07 14:54:36 -10:00
Simon Michael
9967ead4c5 ;lib: let commodityStylesFromAmounts & co. return an error (#793, #1091)
And if they did, the stats command would now throw an error.

Changed:
journalApplyCommodityStyles
journalInferCommodityStyles
commodityStylesFromAmounts
2019-09-27 15:09:39 -10:00
Simon Michael
64f49a8c02 ;doc: journal: rewrite Amounts; switch to "digit group mark" term (#1091) 2019-09-27 14:25:32 -10:00
Simon Michael
7ffe38677a ;lib: parseAndFinaliseJournal: note txns order issue (#1091) 2019-09-25 23:07:22 -10:00
Simon Michael
6037d701b6 ;lib: document RawNumber, AmbiguousNumber, DigitGrp (#1091) 2019-09-25 21:26:06 -10:00
Simon Michael
f92b2fe6ef ;lib: csv: refactor: clarify, get rid of some IO/ExceptT
Rule parsing doesn't need IO (since we are doing expandIncludes as a
pre-parsing step).
2019-09-14 03:45:37 -07:00
Simon Michael
3c05662ce2 ;lib: csv: clarify confusing imports 2019-09-13 18:11:40 -07:00
Simon Michael
46caa1d4ef ;lib: csv: rename error-prone default rules 2019-09-13 17:51:14 -07:00
Simon Michael
499e20c0b2 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-08 17:13:47 -07:00
Simon Michael
1cbbe8f43d memoise market valuation, making it fast (#999) 2019-08-19 02:16:39 +01:00
Simon Michael
6e3a264f17 lib: export aliasnamep for hledger-check (#1072) 2019-07-16 23:30:15 +01:00
Caleb Maclennan
11d9e5eb6a code: Strip extraneous trailing whitespace from Haskell sources 2019-07-15 16:40:49 +01:00
Simon Michael
0a3af8d9ee csv: strip outer whitespace when interpolating CSV values (#1051)
This removes a potential snag in amount field assignments, and
hopefully is harmless and acceptable otherwise.
2019-06-14 16:43:12 -07:00
Simon Michael
d2b3185062 csv: don't show invalid inter-field spaces in CSV error messages
Errors involving a record like:

2000-01-01,a,"1"

displayed the record with extra spaces:

the CSV record is:       "2000-01-01", "a", "1"

which was not accurate or valid RFC-4180.
2019-06-14 16:17:40 -07:00
Simon Michael
692620180e ;lib: refactor: change AmountPrice to a Maybe
I've wanted to do this for a long time; now that prices are in flux,
seems a good time.
2019-06-13 15:50:01 -07:00
Simon Michael
adb6ee40eb lib: clarify price types (#131)
dropped journalPrices

renamed Price to AmountPrice,  AKA "transaction price"

renamed MarketPrice to PriceDirective.

added new MarketPrice (more pure form of PriceDirective without the amount style information)

Prices is now a more efficient data structure, but not used yet.
2019-06-13 15:50:01 -07:00
Simon Michael
90af360792 csv: fix parse error printing, broken since 1.11 (#1038) 2019-06-06 23:10:31 -07:00
Simon Michael
61e8ccbf88 csv: accept a balance field assignment instead of an amount (#1000) 2019-04-03 10:46:26 -07:00
Dmitry Astapov
3c3200fa66 lib: csv parser support for 'balance2', 'balance' renamed to 'balance1' 2019-03-15 16:18:43 -07:00
Simon Michael
c5df73910f csv: update some parse errors which weren't in human format
cf
https://www.reddit.com/r/plaintextaccounting/comments/axekse/hledger_how_to_create_curved_brackets_with_rule/
2019-03-05 06:23:11 -08:00
Simon Michael
8789a442a8 lib: inclusive balance assertions (=* and ==*) 2019-02-20 09:14:30 -08:00
Simon Michael
3b47b58aec lib: clarify transaction balancing & balance assertion checking 2019-02-20 09:14:30 -08:00
Simon Michael
d1f122f15e refactor: clarify, note issues (#893) 2019-02-01 15:35:33 -08:00
Simon Michael
d6e075dacd refactor journalModifyTransactions, modifyTransactions
API changes:

Hledger.Data.TransactionModifier
-transactionModifierToFunction
+modifyTransactions

Hledger.Read.Common.applyTransactionModifiers -> Hledger.Data.Journal.journalModifyTransactions
2019-02-01 11:31:04 -08:00
Simon Michael
550e33a558 journal: fix balance assertions/assignments & prices (#824)
Hopefully this is will do it. This restores the past behaviour:

- parsing prices in balance assertions/assignments
- ignoring them in assertions
- using them in assignments
- and printing them

and clarifies tests and docs.
2019-01-25 12:41:10 -08:00
Simon Michael
94d5c6f111 journal: allow prices in balance assertions, but ignore (#824, #958) 2019-01-25 08:59:37 -08:00
Simon Michael
b02f81572c lib: comment
[ci skip]
2019-01-25 08:51:45 -08:00
Simon Michael
a61216ac3c journal: allow account types to be set with a type: tag 2019-01-18 16:40:35 -08:00
Simon Michael
763903ebda journal: save account directives' comments, tags, declaration order 2019-01-18 16:40:35 -08:00
Simon Michael
899946f270 journal: account directive: stop supporting account sort codes
Eg "account   1000". (Introduced in 1.9, deprecated in 1.11, removed in 1.13.)
2019-01-18 16:40:35 -08:00
Dmitry Astapov
faa5b0fba7 lib: fix parsing of status/code/desc/comments in period txn 2019-01-16 17:17:18 -08:00
Simon Michael
c5ae8e6891 comments 2019-01-16 13:58:04 -08:00
Simon Michael
5ee79797e1 better fix for #949, don't reverse same-day assertions with --auto 2019-01-16 09:10:58 -08:00
Simon Michael
274b1c12a1 whitespace 2019-01-15 12:58:05 -08:00
Simon Michael
f1441be404 lib: basic unit test for parseAndFinaliseJournal 2019-01-15 12:57:51 -08:00
Simon Michael
228fc9eb3c preserve correct file order when using --auto (fixes #949)
And clarify parseAndFinaliseJournal a bit.
2019-01-15 06:14:47 -08:00
Simon Michael
e99f80d374 lib: try to clarify periodic transaction double-space error 2019-01-14 15:33:13 -08:00
Simon Michael
86a91c514d lib: disallow prices in balance assertions/assignments (fix #824)
(and in Ledger-style {=FIXEDLOTPRICES} )
2019-01-05 07:35:54 +00:00
Simon Michael
6f36702141 lib: rename, reposition tprecedingcomment field 2019-01-05 07:35:54 +00:00
Simon Michael
5908414d77 lib: amultiplier -> aismultiplier 2019-01-05 07:35:54 +00:00
Simon Michael
3b0cb701ac lib: reorder Amount fields for clearer debug output 2019-01-05 07:35:54 +00:00
Simon Michael
2e525f5600 lib: accountdirectivep: update unit tests 2018-12-02 16:41:16 -08:00
Alex Chen
83a63a4ef5 lib: minor cleanup in 'periodictransactionp' 2018-11-22 14:09:32 -08:00
Alex Chen
519297051d lib: restore previous period expression parser behaviour (PR #807)
- parse a period expression by first extracting words separated by
  single spaces, then by "re-parsing" this text with 'periodexprp'
- this way, the period expression parsers do not need to know about
  the single- or double-space rules
2018-11-22 14:09:32 -08:00
Simon Michael
4b5b9f46db lib: TransactionModifier: clarify 2018-11-13 16:35:46 -08:00
Samuel May
e57ef9e9a9 lib: journal: Add support for exact assertions 2018-10-22 09:55:14 -07:00
Samuel May
cde91fc5f4 lib: Make BalanceAssertion a full datatype
Note: simplifies/moves whitespace parsing out of the balance assertion
parser.
2018-10-22 09:55:14 -07:00
Jesse Rosenthal
a6a73e36e3 Finish removing journalFinalise (#903)
* journal: Get rid of `journalFinalise` and use granular functions

Complete the process started in 53b3e2bd. This gets rid of the
`journalFinalise` function and uses the smaller steps, in order to
have more granular control.

* journal: Change order of operations in finalization

We want to make sure that we add the filepath after the order is
reversed, so the added filepath is on the head and not the tail (as it
would be if it were reversed after it was added).

* journal: Refine granular finalization functions

This commit fixes two of the granular finalization functions:

1. Rename `journalSetTime` to `journalSetLastReadTime` and improve
   documentation.

2. Remove `journalSetFilePath`. It's redundant with `journalAddFile`
   currently in `Hledger.Read.Common`. The only difference between the
   functions is where the file is added (we keep the one in which it
   is added to the tail), so we change the position vis-a-vis
   reversal.
2018-10-16 08:51:51 -07:00
Simon Michael
b72f9697a2 lib: journal: account: allow whitespace or a comment after the account name 2018-10-13 13:09:49 -07:00
Jesse Rosenthal
53b3e2bd94 journal: split up the parts of journalFinalise, and use them as needed.
`journalFinalise` is only used in the `parseAndFinaliseJournal`
functions, but it needs to be run differently at different stages when
transaction modifiers are applied. This change breaks it into smaller
functions, and uses those smaller parts in `parseAndFinaliseJournal`
as needed.
2018-10-12 07:39:53 -07:00
Jesse Rosenthal
20f134c96b read: only run finalise twice if there are modifiers
Previously we ran if `--auto` was set. But this adds a small
performance hit if `--auto` becomes default. Now we only run twice if
there are transactionModifiers AND `--auto` is set. So even if auto is
specified, there will be no penalty if there are no modifiers.
2018-10-12 07:39:53 -07:00
Jesse Rosenthal
5a3462ce48 read: Integrate transaction modifiers with journal finalization
Currently, automated transactions are added before the journal is
finalized. This means that no inferred values will be picked up. We
change the procedure, if `auto_` is set, to

 1. first run `journalFinalise` without assertion checking (assertions
    might be wrong until automated transactions), but with reordering
 2. Insert transaction modifiers
 3. Run `journalFinalise` again, this time with assertion checking as
    set in the options, and without reordering.

If `auto_` is not set, all works as before.

Closes: #893
2018-10-12 07:39:53 -07:00
Simon Michael
c1236fa6e9 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-10-09 14:24:59 -10:00
Mykola Orliuk
8c6a418325 lib: fix home path expansion in includes
fixes simonmichael/hledger#896
2018-10-09 13:35:40 -10:00
Simon Michael
8c7c59017a lib: fix my wrong merge of #880 more 2018-10-09 15:26:15 -07:00
Simon Michael
f6e095e794 lib: fix my wrong merge of #880 2018-10-09 14:06:22 -07:00
Simon Michael
88887e5458
Merge branch 'master' into ExceptTLayer 2018-10-09 10:31:32 -10:00
Simon Michael
278802e648 journal: Y affects dates in periodic transactions (fix #892) 2018-10-09 11:54:40 -07:00
Alex Chen
2cbc41e088 Merge branch 'master' into ExceptTLayer 2018-10-09 11:19:45 -06:00
Simon Michael
190eee5485 lib: comment
[ci skip]
2018-10-05 11:05:39 -10:00
Alex Chen
3d2584d869 lib: switch to megaparsec 7 2018-09-30 20:15:12 -06:00
Alex Chen
31d4e930e7 lib: Re-implement 'includedirectivep' with the new 'ExceptT' layer
- Parse errors encountered in include files are treated as "final" parse
  errors in the parent file, preventing backtracking and fixing an issue
  in #853
2018-09-29 22:54:49 -06:00
Alex Chen
3e54fc77a4 lib: make 'includedirectivep' an 'ErroringJournalParser'
- Update tests as well, requiring test utilities in Utils/Test.hs
  analogous to the those for 'JournalParser' but instead for
  'ErroringJournalParser'
2018-09-29 22:34:52 -06:00
Alex Chen
855a8f1985 lib: Re-implement the 'ExceptT' layer of the parser
We previously had another parser type, 'type ErroringJournalParser =
ExceptT String ...' for throwing parse errors without the possibility of
backtracking. This parser type was removed under the assumption that it
would be possible to write our parser without this capability. However,
after a hairy backtracking bug, we would now prefer to have the option
to prevent backtracking.

- Define a 'FinalParseError' type specifically for the 'ExceptT' layer
- Any parse error can be raised as a "final" parse error
- Tracks the stack of include files for parser errors, anticipating the
  removal of the tracking of stacks of include files in megaparsec 7
  - Although a stack of include files is also tracked in the 'StateT
    Journal' layer of the parser, it seems easier to guarantee correct
    error messages in the 'ExceptT FinalParserError' layer
  - This does not make the 'StateT Journal' stack redundant because the
    'ExceptT FinalParseError' stack cannot be used to detect cycles of
    include files
2018-09-29 22:33:34 -06:00
Alex Chen
2b3c97e1af lib: tweak custom parse errors
- Don't immediately throw custom parse errors into 'ParsecT'; rather,
  just construct and return them
- This anticipates the re-implementation of an 'ExceptT' layer of the
  parser, which should be able throw custom parse errors
2018-09-29 22:32:34 -06:00
Alex Chen
5e1f0ba6f7 lib: add a field to 'Journal' for a stack of include files
- In anticipation of megaparsec 7, which removes support for stacks of
  include files (as far as I can tell)
- Intended for the 'StateT Journal' layer of the parser
  - A stack of include files would be better in a 'ReaderT' layer, but I
    don't want to add another layer to the parser
- Intended for detecting cycles of include files
  - Potential issue: for proper error messages for include file cycles,
    we must remember to provide the filepath of the root journal file via
    the initial journal state passed to a 'JournalParser'; I imagine
    that we may forget to do so because in all other cases it is okay
    not to do so.
2018-09-29 22:32:27 -06:00
Simon Michael
3de8c11de1 journal: a new account sorting mechanism, and a bunch of sorting fixes
A bunch of account sorting changes that got intermingled.

First, account codes have been dropped. They can still be parsed and
will be ignored, for now. I don't know if anyone used them.
Instead, account display order is now controlled by the order of account
directives, if any. From the mail list:

  I'd like to drop account codes, introduced in hledger 1.9 to control
  the display order of accounts. In my experience,

  - they are tedious to maintain
  - they duplicate/compete with the natural tendency to arrange account
    directives to match your mental chart of accounts
  - they duplicate/compete with the tree structure created by account
    names

  and it gets worse if you think about using them more extensively,
  eg to classify accounts by type.

  Instead, I plan to just let the position (parse order) of account
  directives determine the display order of those declared accounts.
  Undeclared accounts will be displayed after declared accounts,
  sorted alphabetically as usual.

Second, the various account sorting modes have been implemented more
widely and more correctly. All sorting modes (alphabetically, by account
declaration, by amount) should now work correctly in almost all commands
and modes (non-tabular and tabular balance reports, tree and flat modes,
the accounts command). Sorting bugs have been fixed, eg #875.
Only the budget report (balance --budget) does not yet support sorting.

Comprehensive functional tests for sorting in the accounts and balance
commands have been added. If you are confused by some sorting behaviour,
studying these tests is recommended, as sorting gets tricky.
2018-09-22 21:45:07 -10:00
Simon Michael
598129ad6a lib: pushAccount -> pushDeclaredAccount 2018-09-22 21:06:29 -10:00
Simon Michael
059ad9eb76 refactor: jaccounts -> jdeclaredaccounts 2018-09-17 05:52:13 -07:00
Simon Michael
23bdac41d9 csv: merge lucamolteni's cassava/custom separators (squashed) (#829)
commit 5ba464de76
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Sep 7 17:54:12 2018 +0200

    Fix CI 2

commit f060ae9449
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Sep 7 17:30:08 2018 +0200

    Fix CI build

commit af0719a33b
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Sep 7 17:19:01 2018 +0200

    Fix rebase

commit 1a24ddfa54
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Aug 10 16:25:24 2018 +0200

    Fixed some GHC warnings

commit 1ac43398a3
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Aug 10 16:14:49 2018 +0200

    Fix .cabal

commit 422456b925
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jul 1 22:56:20 2018 +0200

    Removed to-do list

commit 1118b762e4
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jul 1 22:53:28 2018 +0200

    Better test

commit 1146ed0941
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jul 1 15:32:28 2018 +0200

    Fix parsing

commit 4fc2374b2b
Author: Luca Molteni <volothamp@gmail.com>
Date:   Thu Jun 21 22:11:11 2018 +0200

    Parsing of separator

commit f7a61737f1
Author: Luca Molteni <volothamp@gmail.com>
Date:   Thu Jun 21 14:29:23 2018 +0200

    Almost separator in options

commit ac8841cf3b
Author: Luca Molteni <volothamp@gmail.com>
Date:   Thu Jun 21 14:16:59 2018 +0200

    Separator in parseCSV

commit 92a8b9f6ba
Author: Luca Molteni <volothamp@gmail.com>
Date:   Thu Jun 21 13:30:41 2018 +0200

    separator option

commit ec417a81ae
Author: Luca Molteni <volothamp@gmail.com>
Date:   Thu Jun 21 10:45:26 2018 +0200

    Removed one qualified import

commit 8b2f386c2f
Author: Luca Molteni <volothamp@gmail.com>
Date:   Wed Jun 20 14:01:12 2018 +0200

    Removed string conversions

commit a14d0e099e
Author: Luca Molteni <volothamp@gmail.com>
Date:   Wed Jun 20 10:23:20 2018 +0200

    custom delimiter in cassava

commit 694d48e2bc
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jun 10 17:51:54 2018 +0200

    Use Text.getContents - remove UTF-8 compatibility library

commit a7ada2cc60
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jun 10 17:49:34 2018 +0200

    todo list

commit 58ec47d398
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jun 10 17:45:22 2018 +0200

    CSV test now has unicode characters

commit b7851e94c3
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jun 10 16:59:39 2018 +0200

    Use decode from Text

commit 79f59fd28c
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sun Jun 10 13:28:57 2018 +0200

    Use Text and Lazy Bytestring

commit 470c9bcb8d
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 15:30:22 2018 +0200

    Use megaparsec error

commit f978848ba2
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 15:22:07 2018 +0200

    Renamed qualify and remove Parsec

commit 152587fde2
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 15:12:36 2018 +0200

    Use cassava mega parsec

commit cf281577a3
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 14:01:47 2018 +0200

    Removed Data.Vector

commit 1272e8e758
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 12:16:18 2018 +0200

    Removed Parsec ParseError

commit ae07f04313
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 12:06:14 2018 +0200

    Type sinonim for ParsecError

commit 8e15b253c1
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 11:16:08 2018 +0200

    Replaced with typeclasses

commit 1ed46f9c17
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 11:01:33 2018 +0200

    Replaced Text/CSV with Cassava

commit 362f4111b5
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 10:34:37 2018 +0200

    Use cassava parsin instead of Text/CSV

commit 83e678e371
Author: Luca Molteni <volothamp@gmail.com>
Date:   Sat Jun 9 08:22:51 2018 +0200

    Text CSV error messages

commit f922df71d2
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Jun 8 21:45:20 2018 +0200

    Better types

commit edd130781c
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Jun 8 21:34:59 2018 +0200

    Conversion to Text CSV type

commit 0799383214
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Jun 8 16:06:21 2018 +0200

    First function with cassava

commit e92aeb151f
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Jun 8 13:47:34 2018 +0200

    Added cassava as dependency

commit 5ea005c558
Author: Luca Molteni <volothamp@gmail.com>
Date:   Fri Jun 8 13:18:47 2018 +0200

    Better .gitignore for multi idea modules
2018-09-07 12:34:51 -07:00
Simon Michael
91b111b60d rename easytests_* to tests_* 2018-09-06 13:13:26 -07:00
Simon Michael
51618adc37 tests: use is in a few more places 2018-09-04 13:39:21 -07:00
Simon Michael
f3709f241d tests: port Read tests to easytest 2018-09-03 15:42:24 -07:00
Simon Michael
d1cff46ba7 tests: port CsvReader tests to easytest 2018-09-03 15:30:52 -07:00
Simon Michael
cd67f8ea68 tests: clear out old boilerplate 2018-08-31 18:12:17 -07:00
Simon Michael
d1a7cc1c09 port remaining Read.Common tests 2018-08-31 18:12:17 -07:00
Simon Michael
f124007acf tests: dehyphenate test names 2018-08-31 18:12:17 -07:00
Simon Michael
be7866da59 tests: parsedate -> fromGregorian 2018-08-31 18:12:17 -07:00
Simon Michael
f108b56e61 uniquify modules' easytests, simplify imports 2018-08-20 14:31:31 +01:00
Simon Michael
6568784bf6 port remaining JournalReader tests 2018-08-20 14:31:31 +01:00
Simon Michael
9733e0378e journal: restore/port more old unit tests 2018-08-20 10:38:51 +01:00
Simon Michael
9c0483fef2 tests: port another to easytest 2018-08-20 08:22:31 +01:00
Simon Michael
1a38beaad1 drop old transactionp hunit tests 2018-08-19 19:12:26 +01:00
Simon Michael
7706f8498e tests: comment 2018-08-19 19:05:59 +01:00
Simon Michael
89357bb7b6 another parse test helper, use the IO variant always, port more tests 2018-08-19 19:02:59 +01:00
Simon Michael
2778f6cf8f lib: restore some old unit tests
Also change nullsourcepos, tests prefer JournalSourcePos for some reason.
2018-08-19 18:13:01 +01:00
Simon Michael
bdcfba4eaa whitespace 2018-08-18 20:31:47 +01:00
Simon Michael
fc11b5130f journal: another failing test from #807 2018-08-18 19:50:15 +01:00
Simon Michael
d778a92561 tests: export HUnit/EasyTest from Hledger.Utils.Test; more helpers 2018-08-18 15:19:59 +01:00
Simon Michael
e0e21a2c6c lib: note 2018-08-18 07:30:23 +01:00
Simon Michael
9c3a57f615 lib: some test fixes (#823) 2018-08-17 14:18:24 +01:00
Simon Michael
b4c336c874 test/_test/it/_it helpers; refactor easytests
This makes skipping/unskipping tests easier, and improves readability
a bit.

Note it's also possible to just write the test name with no preceding
function, when the type is constrained (see Journal.hs).
2018-08-17 13:40:37 +01:00
Simon Michael
626247bacd journal: unit tests (2 skipped) for periodtransactionp (#823) 2018-08-17 12:42:43 +01:00
Simon Michael
1d775a7a9c lib: D should not affect automated posting multiplier amounts (fix #860) 2018-08-17 07:39:17 +01:00
Simon Michael
13436637c6 lib: "decimal point" -> "decimal separator" in error message 2018-08-17 07:37:26 +01:00
Simon Michael
e35dd19cc8 lib: refactor: tighten up amountwithoutpricep 2018-08-17 06:51:07 +01:00
Simon Michael
e9c5d13ac1 lib: update old failing amountp/postingp tests, at last (#812) 2018-08-16 06:42:52 +01:00
Simon Michael
09d8e302db lib: use unspaced scopes to simplify command lines (#812) 2018-08-16 05:58:17 +01:00
Simon Michael
50d666d5a0 test: refactor, document, organise easytests, port amountp tests (#812) 2018-08-15 19:58:07 +01:00
Simon Michael
69325da110 comment out failing tests to fix CI (#812) 2018-08-15 11:30:53 +01:00
Simon Michael
ab7dc3294e lib: more informative failure output for amount tests (#812) 2018-08-15 11:24:52 +01:00
Simon Michael
e077aeff5f lib: more informative test failure message (#812) 2018-08-14 16:05:06 +01:00
Simon Michael
321635274c lib: move assertParseEqual' (#812) 2018-08-14 16:05:06 +01:00
Simon Michael
b03584dbce lib: parse helper haddocks 2018-08-14 16:05:06 +01:00
Simon Michael
cfaa0501e6 lib: update some journal parser tests (#812) 2018-08-14 16:05:06 +01:00
Jakub Zárybnický
c67404c73d lib: Fix compile errors in tests 2018-08-14 16:05:06 +01:00
Simon Michael
e88a9c4a5f lib: followingcomment: parse no comment as "", not "\n"
Same-line & next-line comments of transactions, postings, etc.
are now parsed a bit more precisely. Previously parsing no comment
gave the same result as an empty comment (a single newline); now
it gives an empty string.

Also, and perhaps as a consequence of the above, when there's no
same-line comment but there is a next-line comment, we'll insert an
empty first line, otherwise next-line comments would get moved up to
the same line when rendered.

Some doctests have been added.
2018-08-03 19:38:55 +01:00
Joseph Weston
40d70ad10b lib: fail when file to include is in stack of 'include' files 2018-08-02 18:43:00 +01:00
Joseph Weston
1d91ea43a5 lib: add whitespace around '$' operator 2018-08-02 18:43:00 +01:00
Simon Michael
d685d1aa9b lib,rewrite: simplify transactionModifierToFunction
This removes transactionModifierToFunction's extra query parameter;
the rewrite command sets it in the TransactionModifier instead, which
I think is equivalent. I had to change one functional test, but it
seems correct now, so perhaps it wasn't working right before ?
2018-08-02 08:25:49 +01:00
Simon Michael
eae9d78bb1 lib: generateAutomaticPostings -> applyTransactionModifiers 2018-08-02 08:25:49 +01:00
Simon Michael
bb36693155 lib: refactor, txnTieKnot automatically 2018-08-02 08:25:49 +01:00
Simon Michael
572f5a4b31 lib: drop parseAndFinaliseJournal', seems unused (api change) 2018-08-02 08:25:49 +01:00
Simon Michael
efc54c4c25 lib: ModifierTransaction -> TransactionModifier; try to clarify a bit 2018-07-30 19:38:21 +01:00
Simon Michael
d9d94e2cf6 journal: fix breakage in auto posting rule parser (#745)
I was negligent and did not test enough. This should ignore
transaction comments in auto posting rules more safely.
It also adds support for trailing comments on the first line of auto
posting rules, which previously were misparsed as part of the query.
2018-07-26 15:54:21 +01:00