Skip to content

Commit

Permalink
rename to be shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
Jude Taylor committed Jul 16, 2023
1 parent ab0aa79 commit f809ea5
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 45 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/haskell-ci.yml
Expand Up @@ -58,14 +58,9 @@ jobs:
compilerVersion: 8.8.4
setup-method: hvr-ppa
allow-failure: false
- compiler: ghc-8.2.2
- compiler: ghc-8.6.5
compilerKind: ghc
compilerVersion: 8.2.2
setup-method: hvr-ppa
allow-failure: false
- compiler: ghc-8.0.2
compilerKind: ghc
compilerVersion: 8.0.2
compilerVersion: 8.6.5
setup-method: hvr-ppa
allow-failure: false
fail-fast: false
Expand Down Expand Up @@ -194,8 +189,8 @@ jobs:
touch cabal.project
touch cabal.project.local
echo "packages: ${PKGDIR_th_printf}" >> cabal.project
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo "package th-printf" >> cabal.project ; fi
if [ $((HCNUMVER >= 80200)) -ne 0 ] ; then echo " ghc-options: -Werror=missing-methods" >> cabal.project ; fi
echo "package th-printf" >> cabal.project
echo " ghc-options: -Werror=missing-methods" >> cabal.project
cat >> cabal.project <<EOF
EOF
$HCPKG list --simple-output --names-only | perl -ne 'for (split /\s+/) { print "constraints: $_ installed\n" unless /^(th-printf)$/; }' >> cabal.project.local
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Expand Up @@ -4,7 +4,7 @@ synopsis: Quasiquoters for printf
description: Quasiquoters for string and text printf
author: Jude Taylor
maintainer: me@jude.xyz
tested-with: GHC == 8.0.2, GHC == 8.2.2, GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.7, GHC == 9.4.5, GHC == 9.6.2
tested-with: GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.7, GHC == 9.4.5, GHC == 9.6.2
extra-source-files:
- CHANGELOG.md
category: Text
Expand Down
13 changes: 7 additions & 6 deletions parser/Parser.hs
Expand Up @@ -93,27 +93,27 @@ specSet = fromList "diuoxXfFeEaAgGpcsQq?"

lengthSpecifiers :: [(String, LengthSpecifier)]
lengthSpecifiers =
[ ("hh", DoubleH)
[ ("hh", HH)
, ("h", H)
, ("ll", DoubleL)
, ("ll", LL)
, ("l", L)
, ("j", J)
, ("z", Z)
, ("t", T)
, ("L", BigL)
]

oneOfSet :: (Stream s m Char) => CharSet -> ParsecT s u m Char
oneOfSet :: Stream s m Char => CharSet -> ParsecT s u m Char
oneOfSet s = satisfy (`member` s)

printfStr :: (Stream s m Char) => ParsecT s u m [Atom]
printfStr :: Stream s m Char => ParsecT s u m [Atom]
printfStr =
many $
Str "%" <$ try (string "%%")
<|> Arg <$> fmtArg
<|> Str <$> some (satisfy (/= '%'))

fmtArg :: (Stream s m Char) => ParsecT s u m FormatArg
fmtArg :: Stream s m Char => ParsecT s u m FormatArg
fmtArg = do
_ <- char '%'
flags <- do
Expand All @@ -132,7 +132,8 @@ fmtArg = do
else pure $ toFlagSet flagSet'
width <- numArg <?> "width"
precision <- optionMaybe (char '.' *> numArg) <?> "precision"
lengthSpec <- optionMaybe $ choice $ Prelude.map (\(a, b) -> b <$ string a) lengthSpecifiers
lengthSpec <-
optionMaybe $ choice $ Prelude.map (\(a, b) -> b <$ string a) lengthSpecifiers
spec <- oneOfSet specSet <?> "valid specifier"
pure $ FormatArg flags width (fromMaybe (Given 0) <$> precision) spec lengthSpec
where
Expand Down
31 changes: 23 additions & 8 deletions parser/Parser/Types.hs
@@ -1,7 +1,25 @@
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TemplateHaskell #-}

module Parser.Types where
module Parser.Types (
Atom (..),
FormatArg (..),
Flag (..),
adjustmentFlags,
Adjustment (..),
FormatStr,
MaySpecify (..),
emptyFlagSet,
toFlagSet,
FlagSet (..),
LengthSpecifier (..),
flags_,
spec_,
signed_,
prefixed_,
spaced_,
adjustment_,
) where

import Data.Foldable (
elem,
Expand All @@ -22,21 +40,21 @@ data Atom
deriving (Show)

data LengthSpecifier
= DoubleH
= HH
| H
| DoubleL
| BigL
| LL
| L
| J
| Z
| T
deriving (Eq)

instance Show LengthSpecifier where
show DoubleH = "hh"
show HH = "hh"
show H = "h"
show DoubleL = "ll"
show BigL = "L"
show LL = "ll"
show L = "l"
show J = "j"
show Z = "z"
Expand Down Expand Up @@ -110,10 +128,7 @@ makeLensesFor

makeLensesFor
[ ("flags", "flags_")
, ("width", "width_")
, ("precision", "precision_")
, ("spec", "spec_")
, ("lengthSpec", "lengthSpec_")
]
''FormatArg

Expand Down
2 changes: 1 addition & 1 deletion src/Buildable.hs → src/Buf.hs
@@ -1,7 +1,7 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}

module Buildable (Buf (..), SizedStr, SizedBuilder) where
module Buf (Buf (..), SizedStr, SizedBuilder) where

import Data.Char (intToDigit)
import qualified Data.DList as D
Expand Down
12 changes: 6 additions & 6 deletions src/Language/Haskell/Printf/Geometry.hs
Expand Up @@ -15,7 +15,7 @@ import Data.Maybe
import Language.Haskell.PrintfArg
import Parser.Types (Adjustment (..))

import Buildable
import Buf
import StrUtils

data Value buf = Value
Expand Down Expand Up @@ -53,11 +53,11 @@ formatOne :: (Buf buf) => Value buf -> buf
formatOne Value{..}
| Nothing <- width valArg = prefix' <> text
| Just w <- width valArg = case adjustment valArg of
Just ZeroPadded
| isn'tDecimal || isNothing (prec valArg) ->
prefix' <> justifyRight (w - size prefix') '0' text
Just LeftJustified -> justifyLeft w ' ' (prefix' <> text)
_ -> justify' w (prefix' <> text)
Just ZeroPadded
| isn'tDecimal || isNothing (prec valArg) ->
prefix' <> justifyRight (w - size prefix') '0' text
Just LeftJustified -> justifyLeft w ' ' (prefix' <> text)
_ -> justify' w (prefix' <> text)
where
isn'tDecimal = fieldSpec valArg `notElem` ("diouxX" :: String)
justify' n
Expand Down
2 changes: 1 addition & 1 deletion src/Language/Haskell/Printf/Lib.hs
Expand Up @@ -18,7 +18,7 @@ import Language.Haskell.PrintfArg
import Language.Haskell.TH
import Language.Haskell.TH.Syntax

import Buildable (
import Buf (
SizedBuilder,
SizedStr,
finalize,
Expand Down
2 changes: 1 addition & 1 deletion src/Language/Haskell/Printf/Printers.hs
Expand Up @@ -16,7 +16,7 @@ import Language.Haskell.Printf.Geometry
import Language.Haskell.PrintfArg
import Math.NumberTheory.Logarithms

import Buildable
import Buf
import NumUtils
import qualified Parser.Types as P

Expand Down
16 changes: 8 additions & 8 deletions src/NumUtils.hs
Expand Up @@ -19,7 +19,7 @@ import Prelude hiding (
(<>),
)

import Buildable
import Buf
import StrUtils

showIntAtBase ::
Expand Down Expand Up @@ -47,23 +47,23 @@ formatRealFloatAlt fmt decs forceDot upper x
| isNaN x = str "NaN"
| isInfinite x = str $ if x < 0 then "-Infinity" else "Infinity"
| x < 0 || isNegativeZero x =
cons
'-'
(doFmt fmt (floatToDigits 10 (-x)) False)
cons
'-'
(doFmt fmt (floatToDigits 10 (- x)) False)
| otherwise = doFmt fmt (floatToDigits 10 x) False
where
eChar
| upper = 'E'
| otherwise = 'e'
doFmt FFFixed (digs, exp) fullRounding
| exp < 0 =
doFmt FFFixed (replicate (negate exp) 0 ++ digs, 0) fullRounding
doFmt FFFixed (replicate (negate exp) 0 ++ digs, 0) fullRounding
| null part =
fromDigits False whole <> (if forceDot then singleton '.' else mempty)
fromDigits False whole <> (if forceDot then singleton '.' else mempty)
| null whole =
str "0." <> fromDigits False part
str "0." <> fromDigits False part
| otherwise =
fromDigits False whole <> singleton '.' <> fromDigits False part
fromDigits False whole <> singleton '.' <> fromDigits False part
where
(whole, part) =
uncurry (flip splitAt) (toRoundedDigits decs (digs, exp) fullRounding)
Expand Down
2 changes: 1 addition & 1 deletion src/StrUtils.hs
@@ -1,6 +1,6 @@
module StrUtils (justifyLeft, justifyRight) where

import Buildable
import Buf

justifyLeft :: (Buf a) => Int -> Char -> a -> a
justifyLeft n c s
Expand Down
6 changes: 3 additions & 3 deletions th-printf.cabal
Expand Up @@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: 6aeece5259e4fa083c76ffee3c6ae04aee3fb63236c08d5baa8d72c15f303e7c
-- hash: 2c66cae19dd2d4755e43efd18a33f68b7915203fcda2414e20bcdad18ad532d6

name: th-printf
version: 0.8
Expand All @@ -18,7 +18,7 @@ maintainer: me@jude.xyz
license: MIT
license-file: LICENSE
tested-with:
GHC == 8.0.2, GHC == 8.2.2, GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.7, GHC == 9.4.5, GHC == 9.6.2
GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.2, GHC == 9.2.7, GHC == 9.4.5, GHC == 9.6.2
build-type: Simple
extra-source-files:
CHANGELOG.md
Expand All @@ -37,7 +37,7 @@ library
Language.Haskell.Printf
Language.Haskell.Printf.Lib
other-modules:
Buildable
Buf
Language.Haskell.Printf.Geometry
Language.Haskell.Printf.Printers
Language.Haskell.PrintfArg
Expand Down

0 comments on commit f809ea5

Please sign in to comment.