Skip to content

Commit c358dd2

Browse files
committed
Merge branch 'minor-improvements'
2 parents 330744c + a602451 commit c358dd2

File tree

8 files changed

+35
-40
lines changed

8 files changed

+35
-40
lines changed

core-program/core-program.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.12
55
-- see: https://github.com/sol/hpack
66

77
name: core-program
8-
version: 0.4.5.2
8+
version: 0.4.5.3
99
synopsis: Opinionated Haskell Interoperability
1010
description: A library to help build command-line programs, both tools and
1111
longer-running daemons.
@@ -58,8 +58,8 @@ library
5858
, base >=4.11 && <5
5959
, bytestring
6060
, chronologique
61-
, core-data >=0.2.1.11
62-
, core-text >=0.3.4.0
61+
, core-data >=0.3.2.2
62+
, core-text >=0.3.7.0
6363
, directory
6464
, exceptions
6565
, filepath

core-program/lib/Core/Program/Metadata.hs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import Core.Data
2525
import Core.System.Base (IOMode (..), withFile)
2626
import Core.System.Pretty
2727
import Core.Text
28-
import Data.List (intersperse)
2928
import qualified Data.List as List (find, isSuffixOf)
3029
import Data.Maybe (fromMaybe)
3130
import Data.String
@@ -148,23 +147,21 @@ readCabalFile = runIO $ do
148147
-- pass to calling program
149148
return pairs
150149

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

156-
-- this should probably be a function in Core.Text.Rope
157-
breakRope' :: (Char -> Bool) -> Rope -> (Rope, Rope)
158-
breakRope' predicate text =
159-
let pieces = take 2 (breakPieces predicate text)
160-
in case pieces of
161-
[] -> ("", "")
162-
[one] -> (one, "")
163-
(one : two : _) -> (one, trimRope two)
164-
165-
-- knock off the whitespace in "name: hello"
166-
trimRope :: Rope -> Rope
167-
trimRope = mconcat . intersperse " " . breakWords
158+
-- knock off the colon and whitespace in ": hello"
159+
trimValue :: Rope -> Rope
160+
trimValue value = case unconsRope value of
161+
Nothing -> emptyRope
162+
Just (_, remainder) -> case findIndexRope (/= ' ') remainder of
163+
Nothing -> emptyRope
164+
Just i -> snd (splitRope i remainder)
168165

169166
{- |
170167
Access the source location of the call site.

core-program/package.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: core-program
2-
version: 0.4.5.2
2+
version: 0.4.5.3
33
synopsis: Opinionated Haskell Interoperability
44
description: |
55
A library to help build command-line programs, both tools and
@@ -36,8 +36,8 @@ dependencies:
3636
library:
3737
dependencies:
3838
- async
39-
- core-text >= 0.3.4.0
40-
- core-data >= 0.2.1.11
39+
- core-text >= 0.3.7.0
40+
- core-data >= 0.3.2.2
4141
- chronologique
4242
- directory
4343
- exceptions

core-telemetry/core-telemetry.cabal

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.18
55
-- see: https://github.com/sol/hpack
66

77
name: core-telemetry
8-
version: 0.1.9.3
8+
version: 0.1.9.4
99
synopsis: Advanced telemetry
1010
description: This is part of a library to help build command-line programs, both tools and
1111
longer-running daemons.
@@ -53,9 +53,9 @@ library
5353
, base >=4.11 && <5
5454
, bytestring
5555
, chronologique
56-
, core-data >=0.2.1.11
57-
, core-program >=0.4.4
58-
, core-text >=0.3.5
56+
, core-data >=0.3.2.2
57+
, core-program >=0.4.5.3
58+
, core-text >=0.3.6.0
5959
, exceptions
6060
, http-streams
6161
, io-streams

core-telemetry/package.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: core-telemetry
2-
version: 0.1.9.3
2+
version: 0.1.9.4
33
synopsis: Advanced telemetry
44
description: |
55
This is part of a library to help build command-line programs, both tools and
@@ -33,9 +33,9 @@ dependencies:
3333
library:
3434
dependencies:
3535
- async
36-
- core-text >= 0.3.5
37-
- core-data >= 0.2.1.11
38-
- core-program >= 0.4.4
36+
- core-text >= 0.3.6.0
37+
- core-data >= 0.3.2.2
38+
- core-program >= 0.4.5.3
3939
- chronologique
4040
- exceptions
4141
- http-streams

core-text/core-text.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cabal-version: 1.18
55
-- see: https://github.com/sol/hpack
66

77
name: core-text
8-
version: 0.3.7.0
8+
version: 0.3.7.1
99
synopsis: A rope type based on a finger tree over UTF-8 fragments
1010
description: A rope data type for text, built as a finger tree over UTF-8 text
1111
fragments. The package also includes utiltiy functions for breaking and

core-text/lib/Core/Text/Rope.hs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ import qualified Data.FingerTree as F (
124124
(><),
125125
(|>),
126126
)
127-
import Data.Foldable (foldl', foldr', toList)
127+
import Data.Foldable (foldl', toList)
128128
import Data.Hashable (Hashable, hashWithSalt)
129129
import Data.String (IsString (..))
130130
import qualified Data.Text as T (Text)
@@ -148,14 +148,14 @@ import qualified Data.Text.Short as S (
148148
fromByteString,
149149
fromText,
150150
length,
151-
null,
152151
pack,
153152
replicate,
154153
singleton,
155154
splitAt,
156155
toBuilder,
157156
toText,
158-
unpack, uncons
157+
uncons,
158+
unpack,
159159
)
160160
import qualified Data.Text.Short.Unsafe as S (fromByteStringUnsafe)
161161
import GHC.Generics (Generic)
@@ -324,14 +324,13 @@ replicateChar count = Rope . F.singleton . S.replicate count . S.singleton
324324
Get the length of this text, in characters.
325325
-}
326326
widthRope :: Rope -> Int
327-
widthRope = foldr' f 0 . unRope
328-
where
329-
f piece count = S.length piece + count
327+
widthRope text =
328+
let x = unRope text
329+
(Width w) = F.measure x
330+
in w
330331

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

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

353-
354352
{- |
355353
Break the text into two pieces at the specified offset.
356354

core-text/package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: core-text
2-
version: 0.3.7.0
2+
version: 0.3.7.1
33
synopsis: A rope type based on a finger tree over UTF-8 fragments
44
description: |
55
A rope data type for text, built as a finger tree over UTF-8 text

0 commit comments

Comments
 (0)