From e5704b2b8611e2fd389e25ef945e02201ea30c31 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 15:26:06 -0500 Subject: [PATCH 1/4] Fix math imports; drop Math --- spago.dhall | 1 - src/Data/Formatter/Number.purs | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/spago.dhall b/spago.dhall index cda9ac8..08b5493 100644 --- a/spago.dhall +++ b/spago.dhall @@ -13,7 +13,6 @@ , "foldable-traversable" , "integers" , "lists" - , "math" , "maybe" , "newtype" , "numbers" diff --git a/src/Data/Formatter/Number.purs b/src/Data/Formatter/Number.purs index cc0a0e2..d0504da 100644 --- a/src/Data/Formatter/Number.purs +++ b/src/Data/Formatter/Number.purs @@ -25,11 +25,11 @@ import Data.Generic.Rep (class Generic) import Data.Int as Int import Data.Maybe (Maybe(..), fromMaybe, isJust) import Data.Newtype (class Newtype) +import Data.Number as Number import Data.Show.Generic (genericShow) import Data.String as Str import Data.String.CodeUnits as CU import Data.Traversable (for) -import Math as Math import Text.Parsing.Parser as P import Text.Parsing.Parser.Combinators as PC import Text.Parsing.Parser.String as PS @@ -95,9 +95,9 @@ foreign import showNumberAsInt :: Number -> String format :: Formatter -> Number -> String format (Formatter f) num = do let - absed = Math.abs num + absed = Number.abs num tens - | absed > 0.0 = max (Int.floor $ Math.log absed / Math.ln10) 0 + | absed > 0.0 = max (Int.floor $ Number.log absed / Number.ln10) 0 | otherwise = 0 if f.abbreviations then do @@ -114,17 +114,17 @@ format (Formatter f) num = do | thousands == 7 = "Z" | thousands == 8 = "Y" | otherwise = "10e+" <> show (thousands * 3) - newNum = if thousands < 1 then num else num / Math.pow 1000.0 (Int.toNumber thousands) + newNum = if thousands < 1 then num else num / Number.pow 1000.0 (Int.toNumber thousands) format (Formatter f { abbreviations = false }) newNum <> abbr else do let zeros = f.before - tens - one - factor = Math.pow 10.0 (Int.toNumber (max 0 f.after)) - rounded = Math.round (absed * factor) / factor - integer = Math.floor rounded + factor = Number.pow 10.0 (Int.toNumber (max 0 f.after)) + rounded = Number.round (absed * factor) / factor + integer = Number.floor rounded leftoverDecimal = rounded - integer - leftover = Math.round $ leftoverDecimal * factor + leftover = Number.round $ leftoverDecimal * factor leftoverWithZeros = do let @@ -232,9 +232,9 @@ unformatParser (Formatter f) = do else pure 0 pure $ - Math.pow 10.0 (Int.toNumber abbr) + Number.pow 10.0 (Int.toNumber abbr) * sign - * (before + after / Math.pow 10.0 (Int.toNumber f.after)) + * (before + after / Number.pow 10.0 (Int.toNumber f.after)) formatNumber :: String -> Number -> Either String String formatNumber pattern number = parseFormatString pattern <#> flip format number From 4d27d3adf23358a4c81350411c0ffbb15d815d79 Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 15:29:39 -0500 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61b3080..ea19825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Bugfixes: Other improvements: - Added `purs-tidy` formatter (#77 by @thomashoneyman) +- Drop `math` dependency; update imports (#80 by @JordanMartinez) ## [v6.0.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v6.0.0) - 2021-10-16 From 854056e1e903e4d0cf0e7e4fb5f21183b1ae9edb Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Mon, 28 Mar 2022 18:09:07 -0500 Subject: [PATCH 3/4] Update error messages: choice is now right-associative --- test/src/Interval.purs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/src/Interval.purs b/test/src/Interval.purs index 4160936..c20bfff 100644 --- a/test/src/Interval.purs +++ b/test/src/Interval.purs @@ -88,21 +88,21 @@ invalidDurations = invalidIntervals :: Array { err :: String, str :: String } invalidIntervals = - [ { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00ZP1Y2M10DT2H30M" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z-P1Y2M10D" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z~P1Y2M10D" } + [ { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00ZP1Y2M10DT2H30M" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z-P1Y2M10D" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z~P1Y2M10D" } , { err: "Expected EOF (line 1, col 15)", str: "P1Y2M10DT2H30M2007-03-01T13:00:00Z" } , { err: "Expected EOF (line 1, col 9)", str: "P1Y2M10D-2007-03-01T13:00:00Z" } , { err: "Expected EOF (line 1, col 9)", str: "P1Y2M10D~2007-03-01T13:00:00Z" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z2008-05-11T15:30:00Z" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z-2008-05-11T15:30:00Z" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z~2008-05-11T15:30:00Z" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/P" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/PT" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-0-09" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-05-09T103012+0400" } - , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/2014-W15-02T10:11:12Z" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z2008-05-11T15:30:00Z" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z-2008-05-11T15:30:00Z" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z~2008-05-11T15:30:00Z" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/P" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/PT" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-0-09" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-05-09T103012+0400" } + , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/2014-W15-02T10:11:12Z" } , { err: "Expected EOF (line 1, col 9)", str: "P1Y2M10D/P1Y2M10D" } , { err: "Expected EOF (line 1, col 8)", str: "P1Y0.5M/P1Y0.5M" } ] From fd69e9492558a47bd0fd2384df48afe3b6bbb76c Mon Sep 17 00:00:00 2001 From: Jordan Martinez Date: Tue, 29 Mar 2022 06:42:16 -0500 Subject: [PATCH 4/4] Revert "Update error messages: choice is now right-associative" This reverts commit 854056e1e903e4d0cf0e7e4fb5f21183b1ae9edb. --- test/src/Interval.purs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/src/Interval.purs b/test/src/Interval.purs index c20bfff..4160936 100644 --- a/test/src/Interval.purs +++ b/test/src/Interval.purs @@ -88,21 +88,21 @@ invalidDurations = invalidIntervals :: Array { err :: String, str :: String } invalidIntervals = - [ { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00ZP1Y2M10DT2H30M" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z-P1Y2M10D" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z~P1Y2M10D" } + [ { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00ZP1Y2M10DT2H30M" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z-P1Y2M10D" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z~P1Y2M10D" } , { err: "Expected EOF (line 1, col 15)", str: "P1Y2M10DT2H30M2007-03-01T13:00:00Z" } , { err: "Expected EOF (line 1, col 9)", str: "P1Y2M10D-2007-03-01T13:00:00Z" } , { err: "Expected EOF (line 1, col 9)", str: "P1Y2M10D~2007-03-01T13:00:00Z" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z2008-05-11T15:30:00Z" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z-2008-05-11T15:30:00Z" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z~2008-05-11T15:30:00Z" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/P" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/PT" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-0-09" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-05-09T103012+0400" } - , { err: "No alternative (line 1, col 1)", str: "2007-03-01T13:00:00Z/2014-W15-02T10:11:12Z" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z2008-05-11T15:30:00Z" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z-2008-05-11T15:30:00Z" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z~2008-05-11T15:30:00Z" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/P" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/PT" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-0-09" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/2010-05-09T103012+0400" } + , { err: "Expected \"P\" (line 1, col 1)", str: "2007-03-01T13:00:00Z/2014-W15-02T10:11:12Z" } , { err: "Expected EOF (line 1, col 9)", str: "P1Y2M10D/P1Y2M10D" } , { err: "Expected EOF (line 1, col 8)", str: "P1Y0.5M/P1Y0.5M" } ]