Commit Graph

393 Commits

Author SHA1 Message Date
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
Simon Michael
e2f5e98926 lib: clarify account name parsing rules 2018-07-26 08:30:32 +01:00
Simon Michael
41c985b5fb journal: ignore transaction comments in auto posting rules (#745)
Previously they were misparsed as account names.
2018-07-26 08:29:02 +01:00
Joseph Weston
f2c1586238 lib: sort the matched include files lexicographically
Now the files are included in the same order as they would be
listed by 'ls'.
2018-07-26 06:12:31 +01:00
Joseph Weston
1ec16c2dc0 lib: explicitly specify that the 'Glob' package should be used
Without this there are conflicts with the 'filemanip' package,
which itself exports a module 'System.FilePath.Glob'.
2018-07-26 06:12:31 +01:00
Joseph Weston
c69b16d826 lib: prefer use of 'parseErrorAt' to generic 'fail'
'fail' will just terminate the current parse branch, whereas here
we have encountered a definite error. Also bring the code to
get the current working directory inside 'getFilePaths', as it
logically belongs there.
2018-07-26 06:12:31 +01:00
Joseph Weston
5077443a84 lib: add tests and code for nonexistant files and malformed globs 2018-07-26 06:12:31 +01:00
Joseph Weston
2c4d0c0acd lib: factor out logic for obtaining a list of files to include 2018-07-26 06:12:31 +01:00
Joseph Weston
0ade323d2a lib: use glob matching if filename in 'include' directive is a glob pattern 2018-07-26 06:12:31 +01:00
Joseph Weston
96f7a03487 lib: factor out parsing child journal into separate function 2018-07-26 06:12:31 +01:00
Joseph Weston
52da073828 lib: expand current directory separately from filepath
We will need the current directory as an absolute path when
adding glob patterns in a few commits time.
2018-07-26 06:12:31 +01:00
Joseph Weston
9e56ad24e2 lib: reorder code for reading include files
This should be before all journal and parser state manipulations,
so that those can be readily factored in a few commits time.
2018-07-26 06:12:31 +01:00
Simon Michael
fe73f2a6b5 csv: interpolated field names in values are now case insensitive
Field names are supposed to be case insensitive, but a field assignment like

fields  ...,Transaction_Date,...
date %Transaction_Date

was failing, because of the capitalised letters. Fixed now.
2018-07-22 22:26:24 +01:00
Simon Michael
d5430e7ddf clean up debug helpers (api change) 2018-07-16 15:28:58 +01:00
Simon Michael
6924e8390c lib: journal: let alias/apply account affect account directives (#825) 2018-06-27 11:33:12 +01:00
Alex Chen
e82b01bcf8 lib: refine parse errors and parser labels 2018-06-20 23:24:39 -06:00
Alex Chen
9674f2a8cc lib: tweak whitespace parsing for better parse errors
- expands the set of expected tokens when e.g. parsing the invalid
  posting `account  $1 a`
- whitespace can affect parse errors because of the longest match rule
  where errors that occur later take precedence over those that occur
  earlier
2018-06-20 23:24:39 -06:00
Alex Chen
ed0106b209 lib: reduce backtracking of various parsers 2018-06-20 23:24:39 -06:00
Alex Chen
e3a755b5b1 lib: refactor amount parsers to minimize backtracking
- inline `spaceamountormissingp` into `postingp`
- combine `rightsymbolamountp` and `nosymbolamountp`
- the multiplier symbol '*' for an amount must now always preceed a sign '-'
  [breaking change]
- make amount parser labels more generic to simplify error messages
2018-06-20 23:24:39 -06:00
Alex Chen
89b1fd7de3 lib: refactor date-time parser, add error messages
- also removed commented-out time-zone code
2018-06-20 23:24:39 -06:00
Simon Michael
c4d45cffc4 lib: journal: require a space between period expr. and other fields 2018-06-12 16:41:36 -07:00
Alex Chen
c6bfd92dd3 removing "re-parsing" for pull 807
For Data/Dates.hs in particular:
- Changed `SimpleTextParser` to `TextParser m` for all parsers
- Changed `string` to the case-insensitive `string'` to match the
  behaviour of `T.toLower` found in `parsePeriodExpr`
- export `periodexprp` for "direct" use
2018-06-12 16:41:36 -07:00
Simon Michael
e3507ad944 lib: journal: allow descriptions/comments in periodic transactions
Also period expressions relative to today's date can now be used,
for what it's worth.
2018-06-12 16:41:36 -07:00
Simon Michael
dfcafc2cdf lib: refactor some journal, period expression parsers 2018-06-12 16:41:36 -07:00
Alex Chen
0fb737bc39 lib: reduce backtracking in commoditydirectiveonelinep 2018-06-11 14:29:18 -06:00
Alex Chen
0382bb5cd4 lib: move custom parse errors to Text.Megaparsec.Custom 2018-06-11 13:58:56 -06:00
Alex Chen
ff2b042c7e lib: remove the ErroringJournalParser type 2018-06-11 13:58:56 -06:00
Alex Chen
39e7ef0311 lib: refine date parser error messages 2018-06-11 13:58:55 -06:00
Alex Chen
5f87e7cd5d lib: enable the custom parse errors 2018-06-11 13:57:30 -06:00
Alex Chen
2d21ec0174 lib: weaken parser types 2018-06-11 13:57:30 -06:00
Alex Chen
4a9e418b7a lib: refactor includedirectivep to avoid "re-parsing" 2018-06-11 13:57:30 -06:00
Alex Chen
b034fa7ca9 lib: weaken parser types 2018-06-11 13:57:30 -06:00
Alex Chen
9b6558401f lib: rewrite comment parsers [API]
- avoid the "re-parsing" of comments using the `match` parser combinator
2018-06-11 13:57:30 -06:00
Alex Chen
d707b351cc lib: switch to custom parse errors for parserErrorAt
Also weaken the types of the parsers that use it
2018-06-11 13:57:30 -06:00
Alex Chen
c5561f25f1 lib: switch parsers to the custom error type
Also add an explicit export list to `hledger-lib/Hledger/Utils/Parse.hs`
in order to re-export the custom error type (for convenience).
2018-06-11 13:57:30 -06:00
Simon Michael
0ce9c5728a switch to base-compat-batteries to fix ghc 7.10 support (#794)
base-compat-batteries provides the same API across more ghc versions
than base-compat does, at the cost of more dependencies. Eg it exports
Prelude.Compat ((<>)) with ghc 7.10/base 4.8, which we expect.
My belief is that several of our deps already require it so the added
cost is not too great. We should probably go back to base-compat when
possible though, eg when we stop supporting ghc 7.10.
2018-06-04 17:32:42 -07:00
Peter Simons
6db7f800ee hledger-lib: fix doctest suite after recent package updates
The new version of our package set apparently contains both base-compat and
base-compat-batteries in its transitive closure. This breaks the doctest suite,
which just imports everything into scope when the tests are run, thereby making
module names like Prelude.Compat ambiguous.
2018-06-04 21:41:15 +02:00
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