git.iko.soy/distributed-process
on master help sign in
Remove dependency on regex-applicative
d4be8a7Edsko de Vries
network-transport-2/network-transport.cabal−2
@@ -13,7 +13,6 @@ Library
13 containers,
13 containers,
14 data-lens,
14 data-lens,
15 network,
15 network,
16− regex-applicative,
17 mtl,
16 mtl,
18 transformers
17 transformers
19 Exposed-modules: Network.Transport,
18 Exposed-modules: Network.Transport,
@@ -32,7 +31,6 @@ Test-Suite TestTCP
32 bytestring,
31 bytestring,
33 data-lens,
32 data-lens,
34 network,
33 network,
35− regex-applicative,
36 mtl,
34 mtl,
37 transformers,
35 transformers,
38 ansi-terminal
36 ansi-terminal
network-transport-2/src/Network/Transport/TCP.hs+9−8
@@ -70,13 +70,13 @@ import Control.Concurrent.MVar ( MVar
70 , withMVar
70 , withMVar
71 )
71 )
72import Control.Category ((>>>))
72import Control.Category ((>>>))
73−import Control.Applicative ((<*>), (*>), (<$>))
73+import Control.Applicative ((<$>))
74import Control.Monad (forM, forM_, void, when, unless)
74import Control.Monad (forM, forM_, void, when, unless)
75import Control.Exception (IOException, SomeException, handle, throw, try, bracketOnError)
75import Control.Exception (IOException, SomeException, handle, throw, try, bracketOnError)
76import Data.IORef (IORef, newIORef, writeIORef, readIORef)
76import Data.IORef (IORef, newIORef, writeIORef, readIORef)
77import Data.ByteString (ByteString)
77import Data.ByteString (ByteString)
78import qualified Data.ByteString as BS (concat)
78import qualified Data.ByteString as BS (concat)
79−import qualified Data.ByteString.Char8 as BSC (pack, unpack)
79+import qualified Data.ByteString.Char8 as BSC (pack, unpack, split)
80import Data.Int (Int32)
80import Data.Int (Int32)
81import Data.IntMap (IntMap)
81import Data.IntMap (IntMap)
82import qualified Data.IntMap as IntMap (empty)
82import qualified Data.IntMap as IntMap (empty)
@@ -85,7 +85,6 @@ import qualified Data.IntSet as IntSet (empty, insert, elems, singleton, null, d
85import Data.Map (Map)
85import Data.Map (Map)
86import qualified Data.Map as Map (empty, elems, size)
86import qualified Data.Map as Map (empty, elems, size)
87import Data.Lens.Lazy (Lens, lens, intMapLens, mapLens, (^.), (^=), (^+=), (^%=))
87import Data.Lens.Lazy (Lens, lens, intMapLens, mapLens, (^.), (^=), (^+=), (^%=))
88−import Text.Regex.Applicative (RE, few, anySym, sym, many, match)
89import System.IO (hPutStrLn, stderr)
88import System.IO (hPutStrLn, stderr)
90
89
91-- $design
90-- $design
@@ -733,12 +732,14 @@ encodeEndPointAddress host port ix = EndPointAddress . BSC.pack $
733 host ++ ":" ++ port ++ ":" ++ show ix
732 host ++ ":" ++ port ++ ":" ++ show ix
734
733
735-- | Decode end point address
734-- | Decode end point address
736−-- TODO: This uses regular expression parsing, which is nice, but unnecessary
737decodeEndPointAddress :: EndPointAddress -> Maybe (N.HostName, N.ServiceName, EndPointId)
735decodeEndPointAddress :: EndPointAddress -> Maybe (N.HostName, N.ServiceName, EndPointId)
738−decodeEndPointAddress (EndPointAddress bs) = match endPointAddressRE (BSC.unpack bs)
736+decodeEndPointAddress (EndPointAddress bs) = case map BSC.unpack $ BSC.split ':' bs of
739− where
737+ [host, port, endPointIdStr] ->
740− endPointAddressRE :: RE Char (N.HostName, N.ServiceName, EndPointId)
738+ case reads endPointIdStr of
741− endPointAddressRE = (,,) <$> few anySym <*> (sym ':' *> few anySym) <*> (sym ':' *> (read <$> many anySym))
739+ [(endPointId, "")] -> Just (host, port, endPointId)
740+ _ -> Nothing
741+ _ ->
742+ Nothing
742
743
743-- | Do a (blocking) remote request
744-- | Do a (blocking) remote request
744--
745--