Skip to content

Commit 885b437

Browse files
committed
Upgrade to add Eq/Ord for Match
1 parent c7587b8 commit 885b437

File tree

6 files changed

+32
-15
lines changed

6 files changed

+32
-15
lines changed

lens-regex-pcre.cabal

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.31.2.
3+
-- This file has been generated from package.yaml by hpack version 0.37.0.
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: d1c8fcf51e5b49738911f4885c246d4f3a9e709234fad2feefcd25246e284ac2
7+
-- hash: 754b704711197304d9dc42fd95daa8ff18d78f8327f4dffac02d893d13ac7ac6
88

99
name: lens-regex-pcre
10-
version: 1.1.0.0
10+
version: 1.1.1.0
1111
synopsis: A lensy interface to regular expressions
1212
description: Please see the README on GitHub at <https://github.com/ChrisPenner/lens-regex-pcre#readme>
1313
category: Regex

mac-build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# Ensures we have all the correct C-libs in scope
4+
stack build --fast --extra-include-dirs "$(brew --prefix)/include" --extra-lib-dirs "$(brew --prefix)/lib"

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: lens-regex-pcre
2-
version: 1.1.0.0
2+
version: 1.1.1.0
33
github: "ChrisPenner/lens-regex-pcre"
44
license: BSD3
55
author: "Chris Penner"

src/Control/Lens/Regex/ByteString.hs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ License : BSD3
1515
{-# LANGUAGE UndecidableInstances #-}
1616
{-# LANGUAGE TypeOperators #-}
1717
{-# LANGUAGE TupleSections #-}
18+
{-# LANGUAGE DerivingStrategies #-}
1819

1920
module Control.Lens.Regex.ByteString
2021
(
@@ -62,12 +63,30 @@ import Data.Tuple (swap)
6263
type MatchRange = (Int, Int)
6364
type GroupRanges = [(Int, Int)]
6465

66+
unBuilder :: BS.Builder -> BS.ByteString
67+
unBuilder = BL.toStrict . BS.toLazyByteString
68+
69+
building :: Iso' BS.Builder BS.ByteString
70+
building = iso unBuilder BS.byteString
71+
72+
6573
-- | Match represents an opaque regex match.
6674
-- You can drill into it using 'match', 'groups', 'group', 'namedGroup', 'namedGroups' or 'matchAndGroups'
6775
data Match =
6876
Match { _chunks :: [Either BS.Builder BS.Builder]
6977
, _matchRegex :: PCRE.Regex
7078
}
79+
80+
instance Eq Match where
81+
a == b = (_matchRegex a == _matchRegex b)
82+
&& (((bimap unBuilder unBuilder) <$> _chunks a) == ((bimap unBuilder unBuilder) <$> _chunks b))
83+
84+
instance Ord Match where
85+
compare a b = compare (_matchRegex a) (_matchRegex b)
86+
<> compare ((bimap unBuilder unBuilder) <$> _chunks a) ((bimap unBuilder unBuilder) <$> _chunks b)
87+
88+
89+
7190
makeLensesFor [("_chunks", "chunks")] ''Match
7291

7392
instance TypeError
@@ -76,12 +95,6 @@ instance TypeError
7695
=> Show Match where
7796
show _ = "This is a raw Match object, did you miss a 'match' or 'groups' or 'group' call after your 'regex'?"
7897

79-
unBuilder :: BS.Builder -> BS.ByteString
80-
unBuilder = BL.toStrict . BS.toLazyByteString
81-
82-
building :: Iso' BS.Builder BS.ByteString
83-
building = iso unBuilder BS.byteString
84-
8598
-- | Access all groups of a match as a list. Stashes the full match text as the index in case
8699
-- you need it.
87100
--

stack.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
resolver: lts-16.17
1+
resolver: lts-18.28
22

33
packages:
44
- .

stack.yaml.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
packages: []
77
snapshots:
88
- completed:
9-
size: 532386
10-
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/17.yaml
11-
sha256: d3ee1ae797cf63189c95cf27f00700304946c5cb3c1e6a82001cd6584a221e1b
12-
original: lts-16.17
9+
sha256: 428ec8d5ce932190d3cbe266b9eb3c175cd81e984babf876b64019e2cbe4ea68
10+
size: 590100
11+
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/18/28.yaml
12+
original: lts-18.28

0 commit comments

Comments
 (0)