Commit Graph

122 Commits

Author SHA1 Message Date
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
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
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
e2f5e98926 lib: clarify account name parsing rules 2018-07-26 08:30:32 +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
dfcafc2cdf lib: refactor some journal, period expression parsers 2018-06-12 16:41:36 -07: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
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