Skip to content

Commit

Permalink
pkg: progress towards supporting GHC 9.2 and newer libs (#1774)
Browse files Browse the repository at this point in the history
hledger-lib builds, hledger's deps don't (shakespeare).
  • Loading branch information
simonmichael committed Dec 6, 2021
1 parent 642102e commit e6bbdab
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions hledger-lib/Hledger/Data/Balancing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand Down
2 changes: 1 addition & 1 deletion hledger-lib/Hledger/Data/TransactionModifier.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 20 additions & 11 deletions hledger-lib/Hledger/Data/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
34 changes: 18 additions & 16 deletions hledger-lib/Hledger/Utils/Regex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions hledger-lib/hledger-lib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ 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
, aeson >=1
, 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
Expand Down Expand Up @@ -141,15 +141,15 @@ 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
, aeson >=1
, 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
Expand Down Expand Up @@ -194,15 +194,15 @@ 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
, aeson >=1
, 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
Expand Down
4 changes: 3 additions & 1 deletion hledger-lib/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hledger-ui/hledger-ui.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hledger-ui/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hledger-web/hledger-web.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hledger-web/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions hledger/hledger.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hledger/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit e6bbdab

Please sign in to comment.