Skip to content

Commit

Permalink
Merge branch 'minor-improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
istathar committed Apr 25, 2022
2 parents 330744c + a602451 commit c358dd2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 40 deletions.
6 changes: 3 additions & 3 deletions core-program/core-program.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: core-program
version: 0.4.5.2
version: 0.4.5.3
synopsis: Opinionated Haskell Interoperability
description: A library to help build command-line programs, both tools and
longer-running daemons.
Expand Down Expand Up @@ -58,8 +58,8 @@ library
, base >=4.11 && <5
, bytestring
, chronologique
, core-data >=0.2.1.11
, core-text >=0.3.4.0
, core-data >=0.3.2.2
, core-text >=0.3.7.0
, directory
, exceptions
, filepath
Expand Down
25 changes: 11 additions & 14 deletions core-program/lib/Core/Program/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Core.Data
import Core.System.Base (IOMode (..), withFile)
import Core.System.Pretty
import Core.Text
import Data.List (intersperse)
import qualified Data.List as List (find, isSuffixOf)
import Data.Maybe (fromMaybe)
import Data.String
Expand Down Expand Up @@ -148,23 +147,21 @@ readCabalFile = runIO $ do
-- pass to calling program
return pairs

-- TODO this could be improved; we really only need the data from the first
-- block of lines, with colons in them! We're probably reached the point where
-- a proper parser would be good, but whatever.
parseCabalFile :: Bytes -> Map Rope Rope
parseCabalFile contents =
let breakup = intoMap . fmap (breakRope' (== ':')) . breakLines . fromBytes
let breakup = intoMap . fmap (\(a, b) -> (a, trimValue b)) . fmap (breakRope (== ':')) . breakLines . fromBytes
in breakup contents

-- this should probably be a function in Core.Text.Rope
breakRope' :: (Char -> Bool) -> Rope -> (Rope, Rope)
breakRope' predicate text =
let pieces = take 2 (breakPieces predicate text)
in case pieces of
[] -> ("", "")
[one] -> (one, "")
(one : two : _) -> (one, trimRope two)

-- knock off the whitespace in "name: hello"
trimRope :: Rope -> Rope
trimRope = mconcat . intersperse " " . breakWords
-- knock off the colon and whitespace in ": hello"
trimValue :: Rope -> Rope
trimValue value = case unconsRope value of
Nothing -> emptyRope
Just (_, remainder) -> case findIndexRope (/= ' ') remainder of
Nothing -> emptyRope
Just i -> snd (splitRope i remainder)

{- |
Access the source location of the call site.
Expand Down
6 changes: 3 additions & 3 deletions core-program/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: core-program
version: 0.4.5.2
version: 0.4.5.3
synopsis: Opinionated Haskell Interoperability
description: |
A library to help build command-line programs, both tools and
Expand Down Expand Up @@ -36,8 +36,8 @@ dependencies:
library:
dependencies:
- async
- core-text >= 0.3.4.0
- core-data >= 0.2.1.11
- core-text >= 0.3.7.0
- core-data >= 0.3.2.2
- chronologique
- directory
- exceptions
Expand Down
8 changes: 4 additions & 4 deletions core-telemetry/core-telemetry.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.18
-- see: https://github.com/sol/hpack

name: core-telemetry
version: 0.1.9.3
version: 0.1.9.4
synopsis: Advanced telemetry
description: This is part of a library to help build command-line programs, both tools and
longer-running daemons.
Expand Down Expand Up @@ -53,9 +53,9 @@ library
, base >=4.11 && <5
, bytestring
, chronologique
, core-data >=0.2.1.11
, core-program >=0.4.4
, core-text >=0.3.5
, core-data >=0.3.2.2
, core-program >=0.4.5.3
, core-text >=0.3.6.0
, exceptions
, http-streams
, io-streams
Expand Down
8 changes: 4 additions & 4 deletions core-telemetry/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: core-telemetry
version: 0.1.9.3
version: 0.1.9.4
synopsis: Advanced telemetry
description: |
This is part of a library to help build command-line programs, both tools and
Expand Down Expand Up @@ -33,9 +33,9 @@ dependencies:
library:
dependencies:
- async
- core-text >= 0.3.5
- core-data >= 0.2.1.11
- core-program >= 0.4.4
- core-text >= 0.3.6.0
- core-data >= 0.3.2.2
- core-program >= 0.4.5.3
- chronologique
- exceptions
- http-streams
Expand Down
2 changes: 1 addition & 1 deletion core-text/core-text.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.18
-- see: https://github.com/sol/hpack

name: core-text
version: 0.3.7.0
version: 0.3.7.1
synopsis: A rope type based on a finger tree over UTF-8 fragments
description: A rope data type for text, built as a finger tree over UTF-8 text
fragments. The package also includes utiltiy functions for breaking and
Expand Down
18 changes: 8 additions & 10 deletions core-text/lib/Core/Text/Rope.hs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ import qualified Data.FingerTree as F (
(><),
(|>),
)
import Data.Foldable (foldl', foldr', toList)
import Data.Foldable (foldl', toList)
import Data.Hashable (Hashable, hashWithSalt)
import Data.String (IsString (..))
import qualified Data.Text as T (Text)
Expand All @@ -148,14 +148,14 @@ import qualified Data.Text.Short as S (
fromByteString,
fromText,
length,
null,
pack,
replicate,
singleton,
splitAt,
toBuilder,
toText,
unpack, uncons
uncons,
unpack,
)
import qualified Data.Text.Short.Unsafe as S (fromByteStringUnsafe)
import GHC.Generics (Generic)
Expand Down Expand Up @@ -324,14 +324,13 @@ replicateChar count = Rope . F.singleton . S.replicate count . S.singleton
Get the length of this text, in characters.
-}
widthRope :: Rope -> Int
widthRope = foldr' f 0 . unRope
where
f piece count = S.length piece + count
widthRope text =
let x = unRope text
(Width w) = F.measure x
in w

nullRope :: Rope -> Bool
nullRope (Rope x) = case F.viewl x of
F.EmptyL -> True
(F.:<) piece _ -> S.null piece
nullRope text = widthRope text == 0

{- |
Read the first character from a 'Rope', assuming it's length 1 or greater,
Expand All @@ -350,7 +349,6 @@ unconsRope text =
Nothing -> Nothing
Just (c, piece') -> Just (c, Rope ((F.<|) piece' x'))


{- |
Break the text into two pieces at the specified offset.
Expand Down
2 changes: 1 addition & 1 deletion core-text/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: core-text
version: 0.3.7.0
version: 0.3.7.1
synopsis: A rope type based on a finger tree over UTF-8 fragments
description: |
A rope data type for text, built as a finger tree over UTF-8 text
Expand Down

0 comments on commit c358dd2

Please sign in to comment.