Commit Graph

356 Commits

Author SHA1 Message Date
Peter Simons
8c0c168cd6 Fix the build of hledger-lib with ghc 8.0.x and base-compat 0.10.x.
We don't need to import Data.Monoid because Prelude.Compat exports "<>"
already. In fact, importing that module causes build failures:

    Hledger/Read/Common.hs:725:62: error:
        Ambiguous occurrence ‘<>’
        It could refer to either ‘Sem.<>’,
                                 imported from ‘Prelude.Compat’ at Hledger/Read/Common.hs:97:1-39
                                 (and originally defined in ‘Data.Semigroup’)
                              or ‘Data.Monoid.<>’,
                                 imported from ‘Data.Monoid’ at Hledger/Read/Common.hs:110:1-18

Fixes https://github.com/simonmichael/hledger/issues/794.
2018-06-04 20:58:58 +02:00
Alex Chen
1116261f5a lib: simplify fromRawNumber 2018-05-27 07:50:26 -07:00
Alex Chen
c3f5659d75 lib: add some strictness annotations to the parser
This was done to reverse minor performance regressions introduced in the
previous commits
2018-05-27 07:50:26 -07:00
Alex Chen
d79e707485 lib: remove redundant check in accountnamep 2018-05-27 07:50:26 -07:00
Alex Chen
43aa3d479e lib: fix up runJournalParser 2018-05-27 07:50:26 -07:00
Alex Chen
d56fca1ba2 lib: superficial parser cleanups 2018-05-27 07:50:26 -07:00
Alex Chen
2a492696a9 lib: prevent the parsing of prices of prices 2018-05-27 07:50:26 -07:00
Alex Chen
edf9cc2366 lib: move handling of exponentials into fromRawNumber [API]
- Rationale:
  - The information necessary for applying exponents to a number is more
    explicitly represented in the inputs to `fromRawNumber` than in the outputs
  - This way, `exponentp` may simply return an `Int`
2018-05-27 07:50:26 -07:00
Alex Chen
f7fd6e6525 lib: refactor the raw number parser [API]
- Purpose: to reduce the verbosity of the previous implementation
- Split off `AmbiguousNumber` into its own type
- Introduce a function `AmbiguousNumber -> RawNumber` explicitly capturing the
  disambiguation logic
- Reduce the number of remaining constructors in `RawNumber` to just two,
  `WithSeparator` and `NoSeparator`
  - The choice to distinguish by the presence of digit separators is motivated
    by the need for this information later on when disallowing exponents on
    numbers with digit separators
2018-05-27 07:50:26 -07:00
Alex Chen
6ffa9cb3cd lib: rename pdigitgroup to digitgroupp for consistency 2018-05-27 07:50:26 -07:00
Alex Chen
cf9b2001e7 lib: refactor sign parser
- Extracts the handling of signs out of `fromRawNumber` and into `signp` itself
- Rationale: The sign can be applied independently from the logic in
  `fromRawNumber`
2018-05-27 07:50:26 -07:00
Alex Chen
84c7e2c403 lib: superficial changes to parsers 2018-05-24 09:35:27 -07:00
Alex Chen
121ba92ade lib: refactor the raw number parser [API change] 2018-05-24 09:35:27 -07:00
Alex Chen
93fbac99d3 lib: refactor date parser 2018-05-24 09:35:27 -07:00
Alex Chen
12e8d0e282 lib: change some parsers to use takeWhileP 2018-05-22 12:16:46 -07:00
Alex Chen
558c11596f lib: refactor the account name parser 2018-05-22 12:16:46 -07:00
Alex Chen
b245ec7b3d lib: remove the megaparsec compatability module 2018-05-22 12:16:46 -07:00
Alex Chen
676ea912b3 lib: fix issue where spaces were allowed as decimal points
- Fixes #749
- Also enabling the tests prepared for #749
2018-05-20 20:17:57 -07:00
awjchen
46aae19a54
lib: fix parsing of amounts with a whitespace digits separator 2018-05-20 16:02:59 -06:00
Simon Michael
581d02162c resolve all current build warnings with the supported GHC versions
If I'm lucky.
2018-05-17 20:43:55 -07:00
Alex Chen
67ed2d6cbf lib: superficial changes to comment parsers 2018-05-17 18:15:06 -07:00
Alex Chen
188583e232 lib: cleanup: remove redundant comment parsing alternatives 2018-05-17 18:15:06 -07:00
Alex Chen
892a1c6434 lib: refactor: make the bracketed date tags parser a SimpleTextParser 2018-05-17 18:15:06 -07:00
Alex Chen
0cff1634be lib: refactor: make the bracketed datetags parser a SimpleTextParser in all but type 2018-05-17 18:15:06 -07:00
Alex Chen
b3a91a49d8 lib: refactor: factor out a TextParser from datep 2018-05-17 18:15:06 -07:00
Alex Chen
09fd8132b7 lib: refactor: weaken types of comment parsers 2018-05-17 18:15:06 -07:00
Alex Chen
31b72f0415 lib: replace notChar for backwards compatibility with megaparsec 5 2018-05-16 22:35:22 -07:00
Alex Chen
99e457f1da lib: fix performance regression introduced in 30ae9914 2018-05-15 19:29:59 -07:00
Alex Chen
12ddcb1784 lib: extend export list of Read/Common.hs 2018-05-15 11:52:29 -07:00
Alex Chen
17b11aaf1e lib: refactor parsing of bracketed posting dates 2018-05-15 11:52:29 -07:00
Alex Chen
fcc10f018d lib: merge parsing of date-tags with that of tags 2018-05-15 11:52:29 -07:00
Alex Chen
ec85271a0b lib: refactor tags parser: be more efficient, save SourcePos for later 2018-05-15 11:52:29 -07:00
Stephen Morgan
6c2385331c Allow comments for periodic transactions. 2018-05-14 18:28:27 -07:00
Mykola Orliuk
64c7eb78f4 GHC 8.0 compatibility 2018-05-13 14:41:08 -07:00
Stephen Morgan
5bc5bb5533 Fix doctest error introduced by 49c8c093ac. 2018-05-11 07:25:17 -07:00
Simon Michael
7040289d54 add some exports to fix warnings (#762) 2018-05-11 07:17:38 -07:00
Alex Chen
3aa72bdf16 lib: Clean up new code introduced for #655 2018-05-11 06:41:13 -07:00
Alex Chen
30ae991484 lib: Strip comment before parsing tags (#655) 2018-05-11 06:41:13 -07:00
Alex Chen
09ec6041bd lib: Report source positions from internal comment parsers 2018-05-11 06:41:13 -07:00
Alex Chen
b06d22a418 lib: Refactor common comment parsers 2018-05-11 06:41:13 -07:00
Alex Chen
c2199b1125 lib: Add explicit export list to Common.hs 2018-05-11 06:41:13 -07:00
Alex Chen
a409d09435 lib: restrict backtracking when parsing postings (#747) 2018-05-09 22:09:15 -07:00
Simon Michael
49c8c093ac lib: clarify rawnumberp doc
[ci skip]
2018-05-09 10:22:39 -07:00
Simon Michael
0b380971f7 journal: require a decimal point in commodity/format/D directives
A commodity directive that doesn't specify the decimal point character
increases ambiguity and the chance of misparsing numbers, especially
as it overrides all style information inferred from the journal amounts.
In some cases it caused amounts with a decimal point to be parsed as if
with a digit group separator so 1.234 became 1234.

We could augment it with extra info from the journal amounts, when available,
but it would still be possible to be ambiguous, and that won't be obvious.

A commodity directive is what we recommend to nail down the style.
It seems the simple and really only way to do this reliably is to require
an explicit decimal point character. Most folks probably do this already.

Unfortunately, it makes another potential incompatiblity with ledger and
beancount journals. But the error message will be clear and easy to
work around.
2018-04-20 21:56:06 -07:00
Simon Michael
3f2827424c refactor: number parsing docs 2018-04-20 21:39:06 -07:00
Simon Michael
f2d3b3e1d4 csv: handle the other double negation cases: -(N), ((N)) (fix #736) 2018-04-18 07:39:33 -07:00
Dmitry Astapov
d82370d10b lib, app, web: remove differences between command line and journal file aliases 2018-04-17 16:09:11 -07:00
Dmitry Astapov
ecf49b1e4b lib: auto postings generated before amount inference and balance checks (#729) 2018-04-17 14:33:32 -07:00
Everett Hildenbrandt
c69fbff6d9 CsvReader: print more information about amount-in/out errors 2018-04-15 16:52:52 -07:00
Simon Michael
4ff3a749c6 lib: note an oddity with runJournalParser 2018-03-31 02:44:31 +01:00
Mykola Orliuk
b377bff90a lib: support scientific number notation (#704, #706)
closes simonmichael/hledger#704
2018-03-31 01:49:46 +01:00
Moritz Kiefer
d7b68fbd7d Use skipMany/skipSome for parsing spacenonewline
This avoids allocating the list of space characters only to then
discard it.
2018-03-25 22:59:05 +01:00
Simon Michael
84579bb1b4 silence redundant import warnings with ghc 8.4 2018-03-24 22:51:56 +00:00
Simon Michael
13855d6b53 csv: no csv records is no longer an error 2018-02-01 09:41:03 -08:00
Simon Michael
d420a8b534 journal: account directive: parse and store a numeric account code also 2018-01-23 11:33:23 -08:00
Simon Michael
81e964502b lib: refactor low-level text file reading 2018-01-04 16:17:25 -08:00
Simon Michael
ecdbc05703 Merge branch 'feature/space-as-digits-sep' of https://github.com/ony/hledger into ony-feature/space-as-digits-sep 2017-12-30 09:29:22 -08:00
Nadrieril
9e6e06033f lib: Allow balance-only entries in csv reader 2017-12-14 18:26:29 -08:00
Mykola Orliuk
95db5062d6 journal: inherit commodities in included files
Followup on some comments for simonmichael/hledger#487
2017-12-04 12:26:26 -08:00
Mykola Orliuk
9cdd02e0b0 journal: pretty errors for included files
Fixes simonmichael/hledger#660
2017-12-04 12:26:26 -08:00
Mykola Orliuk
47766ea9d4 journal: support space as digits sep
Resolves simonmichael/hledger#330
2017-11-29 17:20:18 +01:00
Mykola Orliuk
e58272f28f journal: use groups sep and prec for decimal hint
Use whole AmountStyle in process of resolving decimal/groups separator
ambiguity.

Resolve simonmichael/hledger#399
2017-11-27 15:47:56 -08:00
Mykola Orliuk
7cbdeb40a4 journal: get decimal hint from default commodity
If appropriate commodity directive is missing fallback to default
commodity directive to get number representation style.
2017-11-27 15:47:56 -08:00
Mykola Orliuk
b7dbe044b0 journal: use decimal sep hint for amount parser
Make use of commodity format directive as a hint for parsing amount.

Kinda resolves simonmichael/hledger#487
2017-11-27 15:47:56 -08:00
Mykola Orliuk
dafdaec1ca journal: factor out rawnumberp 2017-11-27 15:47:56 -08:00
Mykola Orliuk
bcf7a1add5 journal: make numbers parsing more strict
- Hunt down adjacent punctuations with altering char.
- Add some tests dedicated to parsing amounts.
2017-11-27 15:47:56 -08:00
Mykola Orliuk
53ad035b24 journal: limit scope of directives backtracking
Effectively improves error reporting for directives.

Resolves simonmichael/hledger#402
2017-11-27 14:32:48 -08:00
Simon Michael
4ab71f0d0a journal: clarify that txn/posting comments must start with semicolon 2017-11-01 08:04:25 -07:00
jeevcat
3a9ea65b99 Rewrite of BalanceAssertion type to track its source position.
Fixes #481.
2017-10-16 13:25:03 -07:00
Simon Michael
580ad88dca timedot: fix parsing of month quantities (Nmo)
[ci skip]
2017-09-26 15:11:37 -10:00
Simon Michael
5c85a1dd1c lib: allow trailing whitespace in regex account aliases
Trailing whitespace in the replacement part of a regular expression
account alias is now significant. Eg, slightly flattening some bank
accounts: --alias '/:somebank:/=somebank '
2017-09-22 16:43:03 -10:00
Simon Michael
7edacdf443 cli: import command! hledger import *.csv adds new txns to main file 2017-09-17 18:57:51 -07:00
Simon Michael
669fa706c0 print: --new shows only transactions added since last time
First cut, error messages could be refined etc.
2017-09-15 09:55:17 -07:00
Simon Michael
e3c4a76119 add & use simpler readJournalFilesWithOpts/InputOpts api 2017-09-14 17:43:32 -07:00
Simon Michael
1ebf1fec28 timedot: also provide syntax for seconds, days, weeks, months & years 2017-08-21 17:28:57 -07:00
Simon Michael
5cdb60b69b timedot: allow minutes to be logged as Nm 2017-08-20 13:00:29 -07:00
Simon Michael
16c07c537b csv: also switch which posting is converted to cost
After switching the postings, make sure it's the second which is converted
to cost.
2017-08-15 08:40:52 -07:00
Simon Michael
ce5724fee1 csv: switch the order of generated postings, so account1 is first
This is subjective, but simplifies things as we'll be adding more than
two postings. Free-form entry templates will allow custom orderings
in future.
2017-08-15 08:16:49 -07:00
Simon Michael
d7d5f8a064 add support for megaparsec 6 (fixes #594)
Older megaparsec is still supported.
Also cleans up our custom parser types,
and some text (un)packing is done in different places
(possible performance impact).
2017-07-27 19:20:46 -07:00
Simon Michael
b3b33336b4 csv: show the "creating/using rules file" message only with --debug 2017-07-06 14:07:46 +01:00
Simon Michael
e94f04311d csv: fix multiple includes in one rules file 2017-07-05 16:08:13 +01:00
Simon Michael
6614aab5d7 csv: add newest-first directive for more robust same-day ordering 2017-07-05 15:24:17 +01:00
Simon Michael
dcc58d4a2b lib: rename ClearedStatus type to Status
(and fix hard-coded enum count)
2017-06-15 19:16:39 -07:00
Simon Michael
e119941648 rename "uncleared" status to "unmarked" and --uncleared to --unmarked (#564)
See the issue and linked mail list discussion. Ambiguity between the
uncleared state, and the "not cleared" --uncleared flag causes confusion
and friction. At this point it seems best to break with Ledger and
past hledger, pick a new name and drop --uncleared to put an end to it.
2017-06-15 19:16:39 -07:00
Christian G. Warden
d39040c634 Add Support for Rewriting Multipler Postings Into Different Commodities (#557)
When generating a new posting as a multiple of an existing posting,
support conversion to a different commodity.  For example, postings in
hours can be used to generate postings in USD.

Automatic transactions generated from rewrite rules use the commodity,
amount style, and transaction price if the rewrite defines a commodity.
2017-05-30 07:30:15 -07:00
Simon Michael
5e00d2f31c csv: refactor (#548) 2017-05-14 18:17:56 +09:00
Nicolas Wavrant
309d1ccd59 CsvReader: simplify '-' signs if there exist more than one (#548)
It prevents hledger to crash later, as it fails to read
amount strings containing more than one '-'

Fix #524
2017-05-14 09:34:33 +09:00
Simon Michael
48a84cdd58 lib: note an issue with journalfieldnames ordering 2017-04-19 09:05:21 -07:00
Dmitry Astapov
c4c4be5fad Fix parsing of blank/empty balances + testcases (#539) 2017-04-18 09:07:30 -07:00
Dmitry Astapov
451f9d7307 "balance" parser for csv reader (#537)
* "balance" parser for csv reader

* Some docs for
2017-04-14 14:52:03 -07:00
Simon Michael
e8dcef5b5f lib: disable WIP ledger4 parser, lighten dependencies 2017-03-29 21:06:26 -07:00
Simon Michael
ea1f19c71e lib: csv: refactor, allow writing different rules text 2017-02-06 02:34:18 -08:00
Simon Michael
9cfb7bf6af lib: update readJournalFromCsv doc 2017-02-06 01:45:32 -08:00
Justin Le
6bccb847d5 Added a simple 'showMarketPrice' function to show market price directives in a journal-compatible way (#505)
* added showMarketPrice and Hledger.Data.MarketPrice module

* showMarketPrice implemented using showDate

* attempted to add tests to Hledger.Data.MarketPrice

* moved MarketPrice test to Hledger.Read.JournalReader; fixed documentation on MarketPrice; added MarketPrice module to package.yaml
2017-02-03 18:20:00 -08:00
Mykola Orliuk
7437c96ff6 Make hledger-rewrite tool suitable for re-factoring original journals (#490)
* cli: fix bug in pivot for postings without tag

Without this fix for postings without tag query checked effective
account which is always empty text ("").

* rewrite: inherit dates, change application order

For budgeting it is important to inherit actual date of posting if it
differs from date of transaction. These dates will be added
as a separate line of comment.

More natural order of rewrites is when result of first defined one is
available for all next rewrites.

* rewrite: factor out Hledger.Data.AutoTransaction

* rewrite: add diff output

With this option you can modify your original files without loosing
inter-transaction comments etc. I.e. you can run:

hledger-rewrite --diff Agency \
  --add-posting 'Expenses:Taxes  *0.17' \
  | patch

As result multiple files should be updated.
Also it is nice to review your changes using colordiff instead of
patch.

* lib: track source lines range for journal

* doc: auto entries and diff output for rewrite
2017-01-20 07:33:24 -08:00
Johannes Gerer
45401e538e Balance Assignments and accounts resetting (#438)
* Changed behavior of `readJournalFiles` to be identical to `readJournalFile` for singleton lists

* Balance Assertions have to be simple Amounts

* Add 'isAssignment' and 'assignmentPostings' to Hledger.Data.Posting and Transaction

* Implemented 'balanceTransactionUpdate', a more general version of 'balanceTransaction' that takes an update function

* Fixed test cases.

* Implemented balance assignment ("resetting a balance")

* Add assertions to show function

* updated the comments

* numbering is not needed in journalCheckBalanceAssertions

* remove prices before balance checks

* rename functions
2016-12-10 07:04:48 -08:00
Johannes Gerer
74502f7e50 more general parser types enabling reuse outside of IO (#439) 2016-12-09 15:57:17 -08:00
Simon Michael
a1411768e5 csv: create default rules file only if CSV reader succeeds 2016-11-22 13:59:31 -08:00
Simon Michael
1f2276c100 lib: mark ledger reader as experimental, don't use automatically 2016-11-20 10:42:12 -08:00
Simon Michael
b6ff170688 lib: simplify format detection, avoid ledger reader by default
When we don't know a file's format, instead of choosing a subset of
readers based on content sniffing, now we just try them all.
Also, LedgerReader is now used only as a last resort,
as it's not yet competitive with JournalReader.
2016-11-18 13:24:57 -08:00