Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

refactor: text parsers #59

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ library:
- MCSP.Heuristics
- MCSP.Heuristics.PSOBased
- MCSP.System.Random
- MCSP.Text.ReadP

dependencies:
- base >= 4.18.1 && < 5
Expand Down
18 changes: 8 additions & 10 deletions src/MCSP/Data/String.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module MCSP.Data.String (
Unbox,

-- ** Text IO
ShowString (..),
ReadString (..),
module MCSP.Data.String.Text,

-- * Accessors

Expand Down Expand Up @@ -175,14 +174,15 @@ import Data.Word (Word8)
import GHC.Base (undefined, ($!))
import GHC.IsList (IsList (..))
import GHC.Num (Num, (-))
import Text.Read (Read (..), readListPrecDefault)
import Text.ParserCombinators.ReadPrec (lift)
import Text.Read (Read (..))
import Text.Show (Show (..))

import Data.Vector.Generic qualified as Generic
import Data.Vector.Generic.Mutable qualified as Mutable
import Data.Vector.Unboxed (MVector, Unbox, Vector)

import MCSP.Data.String.Text (ReadString (..), ShowString (..), readCharsPrec)
import MCSP.Data.String.Text

-- --------------- --
-- Data definition --
Expand Down Expand Up @@ -446,17 +446,15 @@ instance ShowString a => Show (String a) where
{-# SPECIALIZE instance Show (String Char) #-}
{-# SPECIALIZE instance Show (String Int) #-}
{-# SPECIALIZE instance Show (String Word8) #-}
showsPrec _ s@Unboxed = showStr s
showsPrec _ = showStr
{-# INLINE showsPrec #-}

instance (ReadString a, Unbox a) => Read (String a) where
instance (Unbox a, ReadString a) => Read (String a) where
{-# SPECIALIZE instance Read (String Char) #-}
{-# SPECIALIZE instance Read (String Int) #-}
{-# SPECIALIZE instance Read (String Word8) #-}
readPrec = fromList <$> readCharsPrec
readPrec = lift (fromList <$> readStr)
{-# INLINE readPrec #-}
readListPrec = readListPrecDefault
{-# INLINE readListPrec #-}

-- -------------------- --
-- Evaluation (DeepSeq) --
Expand Down Expand Up @@ -1022,7 +1020,7 @@ modify f s@Unboxed = Generic.modify (f . mContents) s
-- | /O(n)/ Pair each character in a string with its index.
--
-- >>> indexed "greedy"
-- (0,'g')(1,'r')(2,'e')(3,'e')(4,'d')(5,'y')
-- (0,'g') (1,'r') (2,'e') (3,'e') (4,'d') (5,'y')
indexed :: String a -> String (Int, a)
indexed s@Unboxed = Generic.indexed s
{-# INLINE indexed #-}
Expand Down
Loading