diff --git a/Makefile b/Makefile index 162d86fe3..b2e8268a2 100644 --- a/Makefile +++ b/Makefile @@ -381,7 +381,7 @@ ghcid-shake: $(call def-help,ghcid-shake, start ghcid autobuilder on Shake.hs) # run default GHCI STACKGHCI=$(STACK) # run latest GHCI for modern features -#STACKGHCI=stack --stack-yaml=stack8.10.yaml +#STACKGHCI=stack --stack-yaml=stack9.2.yaml # multi-package GHCI prompts ghci: $(call def-help,ghci, start ghci REPL on hledger-lib + hledger) diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index cf4b21a0f..a8582a561 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -903,8 +903,8 @@ tests_Balancing = transaction (fromGregorian 2019 01 01) [ vpost' "a" missingamt (balassert (num 1)) ] ]} assertRight ej - let Right j = ej - (jtxns j & head & tpostings & head & pamount & amountsRaw) @?= [num 1] + case ej of Right j -> (jtxns j & head & tpostings & head & pamount & amountsRaw) @?= [num 1] + Left _ -> error' "balance-assignment test: shouldn't happen" ,testCase "same-day-1" $ do assertRight $ journalBalanceTransactions defbalancingopts $ diff --git a/hledger-lib/Hledger/Data/TransactionModifier.hs b/hledger-lib/Hledger/Data/TransactionModifier.hs index b6dbe1ec6..3752bc36f 100644 --- a/hledger-lib/Hledger/Data/TransactionModifier.hs +++ b/hledger-lib/Hledger/Data/TransactionModifier.hs @@ -83,7 +83,7 @@ transactionModifierToFunction styles refdate TransactionModifier{tmquerytxt, tmp q <- simplifyQuery . fst <$> parseQuery refdate tmquerytxt let fs = map (tmPostingRuleToFunction styles q tmquerytxt) tmpostingrules - generatePostings ps = concatMap (\p -> p : map ($p) (if q `matchesPosting` p then fs else [])) ps + generatePostings = concatMap (\p -> p : map ($ p) (if q `matchesPosting` p then fs else [])) Right $ \t@(tpostings -> ps) -> txnTieKnot t{tpostings=generatePostings ps} -- | Converts a 'TransactionModifier''s posting rule to a 'Posting'-generating function, diff --git a/hledger-lib/Hledger/Data/Types.hs b/hledger-lib/Hledger/Data/Types.hs index a8a6e8528..cce06d6f0 100644 --- a/hledger-lib/Hledger/Data/Types.hs +++ b/hledger-lib/Hledger/Data/Types.hs @@ -17,13 +17,19 @@ For more detailed documentation on each type, see the corresponding modules. -} -- {-# LANGUAGE DeriveAnyClass #-} -- https://hackage.haskell.org/package/deepseq-1.4.4.0/docs/Control-DeepSeq.html#v:rnf +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE StandaloneDeriving #-} -module Hledger.Data.Types +module Hledger.Data.Types ( + module Hledger.Data.Types, +#if MIN_VERSION_time(1,11,0) + Year +#endif +) where import GHC.Generics (Generic) @@ -47,6 +53,19 @@ import Text.Megaparsec (SourcePos) import Hledger.Utils.Regex +-- synonyms for various date-related scalars +#if MIN_VERSION_time(1,11,0) +import Data.Time.Calendar (Year) +#else +type Year = Integer +#endif +type Month = Int -- 1-12 +type Quarter = Int -- 1-4 +type YearWeek = Int -- 1-52 +type MonthWeek = Int -- 1-5 +type YearDay = Int -- 1-366 +type MonthDay = Int -- 1-31 +type WeekDay = Int -- 1-7 -- | A possibly incomplete year-month-day date provided by the user, to be -- interpreted as either a date or a date span depending on context. Missing @@ -77,16 +96,6 @@ data DateSpan = DateSpan (Maybe Day) (Maybe Day) deriving (Eq,Ord,Generic) instance Default DateSpan where def = DateSpan Nothing Nothing --- synonyms for various date-related scalars -type Year = Integer -type Month = Int -- 1-12 -type Quarter = Int -- 1-4 -type YearWeek = Int -- 1-52 -type MonthWeek = Int -- 1-5 -type YearDay = Int -- 1-366 -type MonthDay = Int -- 1-31 -type WeekDay = Int -- 1-7 - -- Typical report periods (spans of time), both finite and open-ended. -- A higher-level abstraction than DateSpan. data Period = diff --git a/hledger-lib/Hledger/Utils/Regex.hs b/hledger-lib/Hledger/Utils/Regex.hs index 704cf9895..e7c58e7dc 100644 --- a/hledger-lib/Hledger/Utils/Regex.hs +++ b/hledger-lib/Hledger/Utils/Regex.hs @@ -192,23 +192,25 @@ regexReplaceUnmemo re repl s = foldM (replaceMatch repl) s (reverse $ match (reC -- appropriate for this match. Or return an error message. replaceMatch :: Replacement -> String -> MatchText String -> Either RegexError String replaceMatch replpat s matchgroups = - erepl >>= \repl -> Right $ pre ++ repl ++ post - where - ((_,(off,len)):_) = elems matchgroups -- groups should have 0-based indexes, and there should always be at least one, since this is a match - (pre, post') = splitAt off s - post = drop len post' - -- The replacement text: the replacement pattern with all - -- numeric backreferences replaced by the appropriate groups - -- from this match. Or an error message. - erepl = regexReplaceAllByM backrefRegex (lookupMatchGroup matchgroups) replpat + case elems matchgroups of + [] -> Right s + ((_,(off,len)):_) -> -- groups should have 0-based indexes, and there should always be at least one, since this is a match + erepl >>= \repl -> Right $ pre ++ repl ++ post where - -- Given some match groups and a numeric backreference, - -- return the referenced group text, or an error message. - lookupMatchGroup :: MatchText String -> String -> Either RegexError String - lookupMatchGroup grps ('\\':s@(_:_)) | all isDigit s = - case read s of n | n `elem` indices grps -> Right $ fst (grps ! n) -- PARTIAL: should not fail, all digits - _ -> Left $ "no match group exists for backreference \"\\"++s++"\"" - lookupMatchGroup _ s = Left $ "lookupMatchGroup called on non-numeric-backreference \""++s++"\", shouldn't happen" + (pre, post') = splitAt off s + post = drop len post' + -- The replacement text: the replacement pattern with all + -- numeric backreferences replaced by the appropriate groups + -- from this match. Or an error message. + erepl = regexReplaceAllByM backrefRegex (lookupMatchGroup matchgroups) replpat + where + -- Given some match groups and a numeric backreference, + -- return the referenced group text, or an error message. + lookupMatchGroup :: MatchText String -> String -> Either RegexError String + lookupMatchGroup grps ('\\':s@(_:_)) | all isDigit s = + case read s of n | n `elem` indices grps -> Right $ fst (grps ! n) -- PARTIAL: should not fail, all digits + _ -> Left $ "no match group exists for backreference \"\\"++s++"\"" + lookupMatchGroup _ s = Left $ "lookupMatchGroup called on non-numeric-backreference \""++s++"\", shouldn't happen" backrefRegex = toRegex' "\\\\[0-9]+" -- PARTIAL: should not fail -- regexReplace' :: Regexp -> Replacement -> String -> String diff --git a/hledger-lib/hledger-lib.cabal b/hledger-lib/hledger-lib.cabal index 4c7101d6e..2c5d543cf 100644 --- a/hledger-lib/hledger-lib.cabal +++ b/hledger-lib/hledger-lib.cabal @@ -91,7 +91,7 @@ library Paths_hledger_lib hs-source-dirs: ./ - ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans + ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans -fno-warn-incomplete-uni-patterns build-depends: Decimal >=0.5.1 , Glob >=0.9 @@ -99,7 +99,7 @@ library , aeson-pretty , ansi-terminal >=0.9 , array - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , blaze-markup >=0.5.1 , bytestring , call-stack @@ -141,7 +141,7 @@ test-suite doctest hs-source-dirs: ./ test - ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans + ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans -fno-warn-incomplete-uni-patterns build-depends: Decimal >=0.5.1 , Glob >=0.7 @@ -149,7 +149,7 @@ test-suite doctest , aeson-pretty , ansi-terminal >=0.9 , array - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , blaze-markup >=0.5.1 , bytestring , call-stack @@ -194,7 +194,7 @@ test-suite unittest hs-source-dirs: ./ test - ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans + ghc-options: -Wall -fno-warn-unused-do-bind -fno-warn-name-shadowing -fno-warn-missing-signatures -fno-warn-type-defaults -fno-warn-orphans -fno-warn-incomplete-uni-patterns build-depends: Decimal >=0.5.1 , Glob >=0.9 @@ -202,7 +202,7 @@ test-suite unittest , aeson-pretty , ansi-terminal >=0.9 , array - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , blaze-markup >=0.5.1 , bytestring , call-stack diff --git a/hledger-lib/package.yaml b/hledger-lib/package.yaml index 7ab78aa2f..eb57c2d06 100644 --- a/hledger-lib/package.yaml +++ b/hledger-lib/package.yaml @@ -32,7 +32,7 @@ extra-source-files: #data-files: dependencies: -- base >=4.11 && <4.16 +- base >=4.11 && <4.17 - aeson >=1 - aeson-pretty - ansi-terminal >=0.9 @@ -84,6 +84,8 @@ ghc-options: - -fno-warn-missing-signatures - -fno-warn-type-defaults - -fno-warn-orphans +# XXX seems new in 9.2, fix these +- -fno-warn-incomplete-uni-patterns source-dirs: #- other/ledger-parse diff --git a/hledger-ui/hledger-ui.cabal b/hledger-ui/hledger-ui.cabal index b364fdbdb..d8071f29b 100644 --- a/hledger-ui/hledger-ui.cabal +++ b/hledger-ui/hledger-ui.cabal @@ -67,7 +67,7 @@ executable hledger-ui build-depends: ansi-terminal >=0.9 , async - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , brick >=0.23 , cmdargs >=0.8 , containers >=0.5.9 diff --git a/hledger-ui/package.yaml b/hledger-ui/package.yaml index a03ec62e8..279e8ad6a 100644 --- a/hledger-ui/package.yaml +++ b/hledger-ui/package.yaml @@ -45,7 +45,7 @@ dependencies: - hledger >=1.24.99 && <1.25 - ansi-terminal >=0.9 - async -- base >=4.11 && <4.16 +- base >=4.11 && <4.17 - cmdargs >=0.8 - containers >=0.5.9 - data-default diff --git a/hledger-web/hledger-web.cabal b/hledger-web/hledger-web.cabal index 6e3041c53..e0b79b361 100644 --- a/hledger-web/hledger-web.cabal +++ b/hledger-web/hledger-web.cabal @@ -155,7 +155,7 @@ library build-depends: Decimal >=0.5.1 , aeson >=1 - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , base64 , blaze-html , blaze-markup diff --git a/hledger-web/package.yaml b/hledger-web/package.yaml index ea542dc86..362139c51 100644 --- a/hledger-web/package.yaml +++ b/hledger-web/package.yaml @@ -102,7 +102,7 @@ library: - hledger-lib >=1.24.99 && <1.25 - hledger >=1.24.99 && <1.25 - aeson >=1 - - base >=4.11 && <4.16 + - base >=4.11 && <4.17 - base64 - blaze-html - blaze-markup diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 264101226..4a491ba82 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -142,7 +142,7 @@ library , Diff , aeson >=1 , ansi-terminal >=0.9 - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , bytestring , cmdargs >=0.10 , containers >=0.5.9 @@ -192,7 +192,7 @@ executable hledger Decimal >=0.5.1 , aeson >=1 , ansi-terminal >=0.9 - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , bytestring , cmdargs >=0.10 , containers >=0.5.9 @@ -242,7 +242,7 @@ test-suite unittest Decimal >=0.5.1 , aeson >=1 , ansi-terminal >=0.9 - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , bytestring , cmdargs >=0.10 , containers >=0.5.9 @@ -289,7 +289,7 @@ benchmark bench Decimal >=0.5.1 , aeson >=1 , ansi-terminal >=0.9 - , base >=4.11 && <4.16 + , base >=4.11 && <4.17 , bytestring , cmdargs >=0.10 , containers >=0.5.9 diff --git a/hledger/package.yaml b/hledger/package.yaml index 482e250bd..07741d7f8 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -99,7 +99,7 @@ dependencies: - hledger-lib >=1.24.99 && <1.25 - aeson >=1 - ansi-terminal >=0.9 -- base >=4.11 && <4.16 +- base >=4.11 && <4.17 - bytestring - cmdargs >=0.10 - containers >=0.5.9 diff --git a/stack9.2.yaml b/stack9.2.yaml new file mode 100644 index 000000000..42477e7fe --- /dev/null +++ b/stack9.2.yaml @@ -0,0 +1,272 @@ +# stack build plan using GHC 9.2.1 +# XXX This is WIP; some deps like shakespeare don't build yet. hledger-lib builds. + +nix: + pure: false + packages: [perl gmp ncurses zlib] + +resolver: ghc-9.2.1 + +packages: +- hledger-lib +- hledger +- hledger-ui +- hledger-web + +# for https://github.com/yesodweb/shakespeare/issues/261, eg +allow-newer: true + +extra-deps: +# for hledger-lib: +- Decimal-0.5.2 +- Glob-0.10.2 +- OneTuple-0.3.1 +- Only-0.1 +- StateVar-1.2.2 +- aeson-2.0.2.0 +- aeson-pretty-0.8.9 +- ansi-terminal-0.11.1 +- ansi-wl-pprint-0.6.9 +- assoc-1.0.2 +- attoparsec-0.14.2 +- base-compat-0.12.1 +- base-compat-batteries-0.12.1 +- base-orphans-0.8.6 +- bifunctors-5.5.11 +- blaze-builder-0.4.2.2 +- blaze-markup-0.8.2.8 +- cabal-doctest-1.0.9 +- call-stack-0.4.0 +- case-insensitive-1.2.1.0 +- cassava-0.5.2.0 +- cassava-megaparsec-2.0.4 +- clock-0.8.2 +- cmdargs-0.10.21 +- colour-2.3.6 +- comonad-5.0.8 +- contravariant-1.5.5 +- csv-0.1.2 +- data-default-0.7.1.1 +- data-default-class-0.1.2.0 +- data-default-instances-containers-0.0.1 +- data-default-instances-dlist-0.0.1 +- data-default-instances-old-locale-0.0.1 +- data-fix-0.3.2 +- distributive-0.6.2.1 +- dlist-1.0 +- doclayout-0.3.1.1 +- emojis-0.1.2 +- extra-1.7.10 +- file-embed-0.0.15.0 +- hashable-1.4.0.1 +- hashtables-1.3 +- html-1.0.1.2 +- indexed-traversable-0.1.2 +- indexed-traversable-instances-0.1.1 +- integer-logarithms-1.0.3.1 +- megaparsec-9.2.0 +- microlens-0.4.12.0 +- microlens-th-0.4.3.10 +- old-locale-1.0.0.7 +- optparse-applicative-0.16.1.0 +- parser-combinators-1.3.0 +- pretty-simple-4.0.0.0 +- prettyprinter-1.7.1 +- prettyprinter-ansi-terminal-1.1.3 +- primitive-0.7.3.0 +- random-1.2.1 +- regex-base-0.94.0.2 +- regex-tdfa-1.3.1.1 +- safe-0.3.19 +- scientific-0.3.7.0 +- semialign-1.2.0.1 +- semigroupoids-5.3.6 +- splitmix-0.1.0.4 +- strict-0.4.0.1 +- tabular-0.2.2.8 +- tagged-0.8.6.1 +- tasty-1.4.2.1 +- tasty-hunit-0.10.0.3 +- text-short-0.1.4 +- th-abstraction-0.4.3.0 +- these-1.1.1.1 +- time-compat-1.9.6.1 +- timeit-2.0 +- transformers-compat-0.6.1.6 +- uglymemo-0.1.0.1 +- unbounded-delays-0.1.1.1 +- unordered-containers-0.2.16.0 +- utf8-string-1.0.2 +- uuid-types-1.0.5 +- vector-0.12.3.1 +- wcwidth-0.0.2 +- witherable-0.4.2 +# for hledger: +- Diff-0.4.0 +- blaze-html-0.9.1.2 +- control-monad-free-0.6.2 +- githash-0.1.6.2 +- lucid-2.11.0 +- math-functions-0.3.4.2 +- mmorph-1.2.0 +- shakespeare-2.0.25 +- split-0.2.3.4 +- temporary-1.3 +- th-compat-0.1.3 +- th-lift-0.8.2 +- utility-ht-0.0.16 +- wizards-1.0.3 +# for hledger-ui: +- QuickCheck-2.14.2 +- async-2.2.4 +- brick-0.65 +- cereal-0.5.8.2 +- config-ini-0.2.4.0 +- data-clist-0.1.2.3 +- fsnotify-0.3.0.1 +- hfsevents-0.1.6 +- microlens-ghc-0.4.13.1 +- microlens-mtl-0.2.0.1 +- microlens-platform-0.4.2.1 +- parallel-3.2.2.0 +- text-zipper-0.11 +- unix-compat-0.5.3 +- vty-5.33 +- word-wrap-0.5 +# for hledger-web: +- HUnit-1.6.2.0 +- alex-3.2.6 +- appar-0.1.8 +- asn1-encoding-0.9.6 +- asn1-parse-0.9.5 +- asn1-types-0.3.4 +- attoparsec-iso8601-1.0.2.0 +- auto-update-0.1.6 +- base-unicode-symbols-0.2.4.2 +- base64-0.4.2.3 +- base64-bytestring-1.2.1.0 +- basement-0.0.12 +- bsb-http-chunked-0.0.0.4 +- byteable-0.1.1 +- byteorder-1.0.4 +- cipher-aes-0.2.11 +- clientsession-0.9.1.2 +- conduit-1.3.4.2 +- conduit-extra-1.3.5 +- connection-0.3.1 +- cookie-0.4.5 +- cprng-aes-0.6.1 +- crypto-api-0.13.3 +- crypto-cipher-types-0.0.9 +- crypto-random-0.0.9 +- cryptonite-0.29 +- cryptonite-conduit-0.2.2 +- css-text-0.1.3.0 +- easy-file-0.2.2 +- email-validate-2.3.2.15 +- entropy-0.4.1.7 +- fast-logger-3.0.5 +- ghc-byteorder-4.11.0.0.10 +- happy-1.20.0 +- haskell-lexer-1.1 +- hjsmin-0.2.0.4 +- hourglass-0.2.12 +- hspec-2.9.3 +- hspec-core-2.9.3 +- hspec-discover-2.9.3 +- hspec-expectations-0.8.2 +- html-conduit-1.3.2.2 +- http-api-data-0.4.3 +- http-client-0.7.9 +- http-client-tls-0.3.5.3 +- http-conduit-2.3.8 +- http-date-0.0.11 +- http-types-0.12.3 +- http2-3.0.2 +- iproute-1.7.12 +- language-javascript-0.7.1.0 +- libyaml-0.1.2 +- lift-type-0.1.0.1 +- lifted-base-0.2.3.12 +- memory-0.16.0 +- mime-types-0.1.0.9 +- monad-control-1.0.3.1 +- monad-logger-0.3.36 +- monad-loops-0.4.3 +- mono-traversable-1.0.15.3 +- network-3.1.2.5 +- network-byte-order-0.1.6 +- network-uri-2.6.4.1 +- old-time-1.1.0.3 +- path-pieces-0.2.1 +- pem-0.2.4 +- persistent-2.13.2.1 +- persistent-template-2.12.0.0 +- pretty-show-1.10 +- psqueues-0.2.7.3 +- quickcheck-io-0.2.0 +- resource-pool-0.2.3.2 +- resourcet-1.2.4.3 +- securemem-0.1.10 +- setenv-0.1.1.3 +- silently-1.2.5.2 +- simple-sendfile-0.2.30 +- skein-1.0.9.4 +- socks-0.6.1 +- stm-chans-3.0.0.6 +- streaming-commons-0.2.2.3 +- tagsoup-0.14.8 +- tf-random-0.5 +- th-lift-instances-0.1.18 +- time-manager-0.0.0 +- tls-1.5.5 +- transformers-base-0.4.6 +- typed-process-0.2.8.0 +- unix-time-0.4.7 +- unliftio-0.2.20 +- unliftio-core-0.2.0.1 +- vault-0.3.1.5 +- vector-algorithms-0.8.0.4 +- wai-3.2.3 +- wai-app-static-3.1.7.2 +- wai-cors-0.2.7 +- wai-extra-3.1.7 +- wai-handler-launch-3.0.3.1 +- wai-logger-2.3.6 +- warp-3.3.18 +- word8-0.1.3 +- x509-1.7.5 +- x509-store-1.6.7 +- x509-system-1.6.6 +- x509-validation-1.6.11 +- xml-conduit-1.9.1.1 +- xml-types-0.3.8 +- xss-sanitize-0.3.7 +- yaml-0.11.7.0 +- yesod-1.6.1.2 +- yesod-core-1.6.21.0 +- yesod-form-1.7.0 +- yesod-persistent-1.6.0.7 +- yesod-static-1.6.1.0 +- yesod-test-1.6.12 +- zlib-0.6.2.3 + + +# for Shake.hs: + +#allow-newer: true + +# for precise profiling, per https://www.tweag.io/posts/2020-01-30-haskell-profiling.html: +# apply-ghc-options: everything +# rebuild-ghc-options: true +# stack build --profile --ghc-options="-fno-prof-auto" + +# tell GHC to write hie files, eg for weeder. Rumoured to be slow. +# ghc-options: +# "$locals": -fwrite-ide-info + +# ghc-options: +# "$locals": -ddump-timings +# "$targets": -Werror +# "$everything": -O2 +# some-package: -DSOME_CPP_FLAG