packages feed

text-region 0.3.0.0 → 0.3.1.0

raw patch · 3 files changed

+11/−4 lines, 3 filesdep ~basesetup-changedPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Data.Text.Region.Types: instance Data.Semigroup.Semigroup (Data.Text.Region.Types.Edit s)
+ Data.Text.Region.Types: instance Data.Semigroup.Semigroup Data.Text.Region.Types.Map
+ Data.Text.Region.Types: instance Data.Semigroup.Semigroup Data.Text.Region.Types.Point
- Data.Text.Region.Types: replaceRegion :: forall s_amqt. Lens' (Replace s_amqt) Region
+ Data.Text.Region.Types: replaceRegion :: forall s_ah4k. Lens' (Replace s_ah4k) Region
- Data.Text.Region.Types: replaceWith :: forall s_amqt s_ao0Z. Lens (Replace s_amqt) (Replace s_ao0Z) (Contents s_amqt) (Contents s_ao0Z)
+ Data.Text.Region.Types: replaceWith :: forall s_ah4k s_aj6Y. Lens (Replace s_ah4k) (Replace s_aj6Y) (Contents s_ah4k) (Contents s_aj6Y)
- Data.Text.Region.Types: replaces :: forall s_ao1d s_aoGc. Iso (Edit s_ao1d) (Edit s_aoGc) [Replace s_ao1d] [Replace s_aoGc]
+ Data.Text.Region.Types: replaces :: forall s_aj7c s_an1x. Iso (Edit s_aj7c) (Edit s_an1x) [Replace s_aj7c] [Replace s_an1x]

Files

− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
src/Data/Text/Region/Types.hs view
@@ -22,6 +22,7 @@ import qualified Data.ByteString.Lazy.Char8 as L
 import Data.Group
 import Data.List
+import Data.Semigroup (Semigroup(..))
 import Data.Text (Text)
 import qualified Data.Text as T
 
@@ -43,6 +44,11 @@ instance FromJSON Point where
 	parseJSON = withObject "point" $ \v → Point <$> v .: "line" <*> v .: "column"
 
+instance Semigroup Point where
+	Point l c <> Point bl bc
+		| l ≡ 0 = Point bl (c + bc)
+		| otherwise = Point (l + bl) c
+
 instance Monoid Point where
 	mempty = Point 0 0
 	Point l c `mappend` Point bl bc
@@ -99,6 +105,9 @@ -- This works if we don't use overlapped regions
 newtype Map = Map { mapIso :: Iso' Region Region }
 
+instance Semigroup Map where
+	Map l <> Map r = Map (r . l)
+
 instance Monoid Map where
 	mempty = Map $ iso id id
 	Map l `mappend` Map r = Map (r . l)
@@ -185,7 +194,7 @@ -- | Edit is several replace actions, applied simultaneously, must not overlap
 newtype Edit s = Edit {
 	_replaces ∷ [Replace s] }
-		deriving (Eq, Show, Monoid)
+		deriving (Eq, Show, Semigroup, Monoid)
 
 makeLenses ''Edit
 
text-region.cabal view
@@ -1,5 +1,5 @@ name:                text-region
-version:             0.3.0.0
+version:             0.3.1.0
 synopsis:            Marking text regions
 description: Provides functions to update text region positions according to text edit actions
 homepage:            https://github.com/mvoidex/text-region