Commit Graph

1633 Commits

Author SHA1 Message Date
Stephen Morgan
5a6d38fdf2 lib: For ymd date parsing, don't consume invalid date components. 2020-10-18 21:28:46 -07:00
Stephen Morgan
97545018f4 lib: quoteIfNeeded should not escape the backslashes in unicode code points. 2020-10-18 21:08:25 -07:00
Simon Michael
08ee311875 journal: fix error when P directive has a zero price (#1373) 2020-10-18 20:48:14 -07:00
Stephen Morgan
7808aae682 lib: Remove un-necessary silencing of deprecation warning (relevant functions are no longer used) 2020-10-09 01:47:57 -07:00
Stephen Morgan
e57d911355 lib: Export OrdPlus and constructors. 2020-10-09 01:47:57 -07:00
Simon Michael
c5513ba722 ;tweak a few parse errors for clarity, consistency (#1329) 2020-09-19 08:10:39 -07:00
Simon Michael
f78dc639a5 fix a slowdown with report rendering in 1.19.1 (#1350)
stripAnsi is called many times during rendering (by strWidth), so
should be fast. It was originally a regex replacement, and more
recently a custom parser. The parser was slower, particularly the one
in 1.19.1. See #1350, and this rough test:

time118ish = timeIt $ print $ length $ concat $ map (fromRight undefined . regexReplace (toRegex' "\ESC\\[([0-9]+;)*([0-9]+)?[ABCDHJKfmsu]") "") testdata
time119    = timeparser (many (takeWhile1P Nothing (/='\ESC') <|> "" <$ ansi))
time1191   = timeparser (many ("" <$ try ansi <|> pure <$> anySingle))
timeparser p = timeIt $ print $ length $ concat $ map (concat . fromJust . parseMaybe p) testdata
testdata = concat $ replicate 10000
    [ "2008-01-01 income               assets🏦checking            $1            $1"
    , "2008-06-01 gift                 assets🏦checking            $1            $2"
    , "2008-06-02 save                 assets🏦saving              $1            $3"
    , "                                assets🏦checking  ..m$-1\ESC[m\ESC[m            $2"
    , "2008-06-03 eat & shop           assets:cash           ..m$-2\ESC[m\ESC[m             0"
    , "2008-12-31 pay off              assets🏦checking  ..m$-1\ESC[m\ESC[m  ..m$-1\ESC[m\ESC[m"
    ]

ghci> time118ish
4560000
CPU time:   0.17s
ghci> time119
4560000
CPU time:   0.91s
ghci> time1191
4560000
CPU time:   2.76s

Possibly a more careful parser could beat regexReplace. Note the
latter does memoisation, which could be faster and/or could also use
more resident memory in some situations.

Ideally we would calculate all widths before adding ANSI colour codes,
so we wouldn't have to wastefully strip them.
2020-09-10 18:07:40 -07:00
Stephen Morgan
600dab3976 lib: Correctly strip ansi sequences with no numbers/semicolons. 2020-09-06 19:11:28 -07:00
Simon Michael
a9fbaaf284 ;partial comment cleanups 2020-09-03 09:52:00 -07:00
Simon Michael
c2929939e4 make account type autodetection (& hledger-smooth) case insensitive again (#1341)
lib: added case-insensitive variants of the accountNameToRegex functions.
2020-09-03 09:52:00 -07:00
Simon Michael
58f989715a Replace our stringly Regex with a safer compiled Regexp type
This PR #1330, addressing #1312 (parseQuery is partial) and #1245
(internal server error).

User-visible changes:

- hledger-web now handles malformed regular expressions
  (eg, a query consisting of the single character `?`) gracefully,
  showing a tidy error message instead "internal server error".

API/internal changes:

- The Regex type alias has been replaced by the Regexp ADT, which
  contains both the compiled regular expression (so is guaranteed to
  be usable at runtime) and the original string (so can be serialised,
  printed, compared, etc.) A Regexp also knows whether is it case
  sensitive or case insensitive. The Hledger.Utils.Regex api has changed.

- Typeable and Data instances are no longer derived for hledger's
  data types; they were redundant/no longer needed

- NFData instances are no longer derived for hledger's data types.
  This speeds up a full build by roughly 7%. But it means we can't
  deep-evaluate hledger values, or time hledger code with Criterion.
  https://github.com/simonmichael/hledger/pull/1330#issuecomment-684075129
  has some ideas on this.

- Query no longer has a custom Show instance

- Some internal use of regexps was replaced by text replacement or
  parsers.

- Hledger.Utils.String: quoteIfNeeded now actually escapes quotes in
  strings; dropped escapeQuotes

- Hledger.Utils.Tree: dropped some old utilities

- dropped some obsolete code for the old --display option

Merge branch 'regexp' into master
2020-09-01 10:33:33 -07:00
Stephen Morgan
7d1e6d7d12 lib: Fix quoteIfNeeded so it actually escapes quotes. 2020-09-01 11:41:55 +10:00
Stephen Morgan
07dd30c1e5 lib,cli,ui: Change to consistent naming scheme for Hledger.Utils.Regex. 2020-09-01 11:36:34 +10:00
Stephen Morgan
5b647902c9 lib: Filter starting balances by subreport query in compoundBalanceReportWith. 2020-08-31 09:07:11 -07:00
Stephen Morgan
b91b391d08 lib: Replace some regex functions with parsers. 2020-08-31 22:44:41 +10:00
Stephen Morgan
20b39a5dd0 lib: Remove unused --display code.
This was dropped back in 2014, and getting rid of this removes a use of
regular expressions.
2020-08-31 20:45:37 +10:00
Stephen Morgan
8dfffb1e61 lib,web: Replace regex functions with simple text replacement. 2020-08-31 20:45:28 +10:00
Stephen Morgan
2cd7877c46 lib: Remove unnecessary NFData instances. 2020-08-31 15:41:36 +10:00
Stephen Morgan
af31d6e140 lib,cli,ui: Remove redundant Typeable and Data instances.
Also add some explicit import lists.
2020-08-31 15:41:30 +10:00
Stephen Morgan
01f5a92761 lib: Improve Read and Show instances for Regexp, get rid of custom show instance for Query. 2020-08-31 12:04:47 +10:00
Stephen Morgan
e3b2c94353 lib: Remove unneeded total Query code. 2020-08-31 12:04:47 +10:00
Stephen Morgan
e5371d5a6a lib,cli,ui,web: Make Regexp a wrapper for Regex. 2020-08-31 12:04:45 +10:00
Stephen Morgan
ccd6fdd7b9 lib: Remove unused Tree functions. 2020-08-31 11:51:25 +10:00
Stephen Morgan
7182fa4746 lib: Improve documentation for amountRoundedQuantity, fix a typo. 2020-08-30 23:01:04 +10:00
Stephen Morgan
f6fa76bba7 lib,cli: Get rid of magic values for asprecision, use a sum type instead. 2020-08-30 23:00:35 +10:00
Stephen Morgan
ee1ef9606b lib: Fail when parsing number with more than 255 decimal places. 2020-08-30 22:30:24 +10:00
Stephen Morgan
ba59fed6b2 lib: Replace more instances of fromIntegral with safer versions. 2020-08-30 22:20:58 +10:00
Stephen Morgan
ca2e55c954 lib: Replace some fromIntegral with toInteger. 2020-08-30 22:20:58 +10:00
Stephen Morgan
b5ed2067d9 lib: Make aprecision and DigitGroupStyle use Word8 instead of Int. exponentp now parses an Integer rather than an Int. 2020-08-30 22:20:53 +10:00
Stephen Morgan
371b349b2e lib,cli: Replace parsedate and mkdatespan with direct applications of fromGregorian, transaction now takes Day instead of a date string. 2020-08-29 15:08:28 -07:00
Stephen Morgan
2fd678e415 lib,cli,ui: Remove old CPP directives made redundant by version bounds. 2020-08-29 15:08:28 -07:00
Simon Michael
a3c749f9e7 csv: fix inferring separator from .ssv/.tsv file extensions
This was documented but untested and may have never worked.
2020-08-21 08:59:55 -07:00
Stephen Morgan
32e184f9a8 lib: Elide boring parents in tree mode even when using --empty. 2020-08-11 17:24:50 -07:00
Simon Michael
542052478d ;lib: Types pragmas 2020-08-10 06:22:40 -07:00
Simon Michael
b76caae338 fix doctest breakage (#1312) 2020-08-08 08:53:55 -07:00
Stephen Morgan
f2dcbd2fee lib: Make ill-formed SmartDates unrepresentable. 2020-08-07 14:20:08 -07:00
Simon Michael
27d6b21dff lib: Hledger.Query: add total variants of matches* functions (#1312)
matchesAccount_
matchesAmount_
matchesCommodity_
matchesPosting_
matchesPriceDirective_
matchesTags_
matchesTransaction_

These don't yet have tests of their own, but were converted
mechanically from the originals which should help.
2020-08-07 07:53:00 -07:00
Simon Michael
108c548240 journal: when an account alias contains a bad regexp, show details
lib: accountNameApplyAliases, accountNameApplyAliasesMemo are now
total
2020-08-06 15:27:40 -07:00
Simon Michael
3822c27bfe ;lib: regex: rename & export RegexError, export toRegex_, docs (#1312) 2020-08-06 15:25:58 -07:00
Simon Michael
4957008890 ;lib: regex utilities: cleanup (#1312) 2020-08-06 11:35:04 -07:00
Simon Michael
a112085092 lib: add alternate regex utilities that don't call error (#1312) 2020-08-06 11:18:08 -07:00
Simon Michael
ede4bfd5b4 ;mark more partial functions (#1312) 2020-08-05 17:29:43 -07:00
Simon Michael
3f55c23603 ;review, tag all error calls with an easier to find PARTIAL: comment (#1312) 2020-08-05 16:08:33 -07:00
Simon Michael
242c05fc9a lib, journal: parseQuery, modifyTransactions are now total (#1312)
modifyTransactions now also requires a reference date, for parsing queries.
Relative dates are now permitted in auto posting rules.
2020-08-05 13:44:04 -07:00
Simon Michael
7751d6947c lib: parseAmountQueryTerm: allow whitespace around arg parts (#1312)
Whitespace around the operator, sign, or number is now tolerated.
2020-08-05 13:44:04 -07:00
Simon Michael
38a4704641 lib: make parseAmountQueryTerm total, improve docs/tests (#1312) 2020-08-05 13:44:04 -07:00
Stephen Morgan
08ad220448 lib: In quarterdatespanp, use yearp and allow uppercase Q. 2020-08-04 09:10:53 -07:00
Henning Thielemann
9c9701fe7d lib: quarterdatespanp (fixes #1247) 2020-07-31 17:37:41 -07:00
Henning Thielemann
ccac09fb1b lib: doubledatespanp: fix and re-enable doctest 2020-07-31 17:37:41 -07:00
Stephen Morgan
dc41cee2b0 lib: datep now requires years to be at least four digits. 2020-07-31 17:22:27 -07:00