Commit Graph

334 Commits

Author SHA1 Message Date
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