packages feed

attoparsec-ip 0.0.4 → 0.0.5

raw patch · 2 files changed

+137/−132 lines, 2 filesdep ~ipPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: ip

API changes (from Hackage documentation)

- Data.Attoparsec.IP: instance GHC.Classes.Eq Data.Attoparsec.IP.IPv6TokenPos
- Data.Attoparsec.IP: instance GHC.Classes.Ord Data.Attoparsec.IP.IPv6TokenPos
- Data.Attoparsec.IP: instance GHC.Enum.Bounded Data.Attoparsec.IP.IPv6TokenPos
- Data.Attoparsec.IP: instance GHC.Enum.Enum Data.Attoparsec.IP.IPv6TokenPos
- Data.Attoparsec.IP: instance GHC.Show.Show Data.Attoparsec.IP.IPv6Chunk
- Data.Attoparsec.IP: instance GHC.Show.Show Data.Attoparsec.IP.IPv6Divider
- Data.Attoparsec.IP: instance GHC.Show.Show Data.Attoparsec.IP.IPv6State
- Data.Attoparsec.IP: instance GHC.Show.Show Data.Attoparsec.IP.IPv6TokenPos

Files

attoparsec-ip.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.21.2.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.0. -- -- see: https://github.com/sol/hpack ----- hash: d6dff4b58a447f5b0e21472525e73f7bb907e7a061d882ae88d165acdad9673d+-- hash: cbeb5a3dc41469ebb0a741e566a6717c3673402a130634751c62de85a8b4a05b  name:           attoparsec-ip-version:        0.0.4+version:        0.0.5 synopsis:       Parse IP data types with attoparsec description:    Please see the README on GitHub at <https://github.com/athanclark/attoparsec-ip#readme> category:       Web@@ -17,8 +19,6 @@ license:        BSD3 license-file:   LICENSE build-type:     Simple-cabal-version:  >= 1.10- extra-source-files:     README.md @@ -37,7 +37,7 @@   build-depends:       attoparsec     , base >=4.11 && <5-    , ip >=1.4.0+    , ip >=1.4.1     , vector   default-language: Haskell2010 
src/Data/Attoparsec/IP.hs view
@@ -6,146 +6,151 @@  module Data.Attoparsec.IP (ipv4, ipv6) where -import Data.Attoparsec.Text (Parser, char, string, digit, hexadecimal, many1)-import Data.Word (Word8, Word16)-import Data.Vector (Vector)-import qualified Data.Vector as V-import Data.Monoid ((<>))-import Control.Applicative ((<|>))-import Control.Monad (void)+import Data.Attoparsec.Text (Parser) --, char, string, digit, hexadecimal, many1)+-- import Data.Word (Word8, Word16)+-- import Data.Vector (Vector)+-- import qualified Data.Vector as V+-- import Data.Monoid ((<>))+-- import Control.Applicative ((<|>))+-- import Control.Monad (void) import Net.Types (IPv4, IPv6) import qualified Net.IPv4 as IPv4 import qualified Net.IPv6 as IPv6 - ipv4 :: Parser IPv4-ipv4 = do-  a <- octet-  void (char '.')-  b <- octet-  void (char '.')-  c <- octet-  void (char '.')-  d <- octet-  pure (IPv4.fromOctets a b c d)-  where-    octet :: Parser Word8-    octet = do-      (a,b,c) <--        let oneDigit = do-              n <- digit-              pure ('0','0',n)-            twoDigit = do-              n <- digit-              m <- digit-              pure ('0',n,m)-            threeDigit = do-              n <- digit-              m <- digit-              o <- digit-              pure (n,m,o)-        in  threeDigit <|> twoDigit <|> oneDigit-      let n :: Word8-          n = read (a:b:c:[])-      pure n+ipv4 = IPv4.parser +ipv6 :: Parser IPv6+ipv6 = IPv6.parser -data IPv6Divider-  = DividerColon-  | DoubleColon-  deriving (Show)+-- ipv4 :: Parser IPv4+-- ipv4 = do+--   a <- octet+--   void (char '.')+--   b <- octet+--   void (char '.')+--   c <- octet+--   void (char '.')+--   d <- octet+--   pure (IPv4.fromOctets a b c d)+--   where+--     octet :: Parser Word8+--     octet = do+--       (a,b,c) <-+--         let oneDigit = do+--               n <- digit+--               pure ('0','0',n)+--             twoDigit = do+--               n <- digit+--               m <- digit+--               pure ('0',n,m)+--             threeDigit = do+--               n <- digit+--               m <- digit+--               o <- digit+--               pure (n,m,o)+--         in  threeDigit <|> twoDigit <|> oneDigit+--       let n :: Word8+--           n = read (a:b:c:[])+--       pure n -parseDividerOrDoubleColon :: Parser IPv6Divider-parseDividerOrDoubleColon =-  let divider = DividerColon <$ char ':'-      doubleColon = DoubleColon <$ string "::"-  in  doubleColon <|> divider -parseHextet :: Parser IPv6Chunk-parseHextet = Hextet <$> hexadecimal+-- data IPv6Divider+--   = DividerColon+--   | DoubleColon+--   deriving (Show) -parseHextets :: Parser [IPv6Chunk]-parseHextets = many1 (parseHextet <|> (Divider <$> parseDividerOrDoubleColon))+-- parseDividerOrDoubleColon :: Parser IPv6Divider+-- parseDividerOrDoubleColon =+--   let divider = DividerColon <$ char ':'+--       doubleColon = DoubleColon <$ string "::"+--   in  doubleColon <|> divider -data IPv6Chunk-  = Hextet Word16-  | Divider IPv6Divider-  deriving (Show)+-- parseHextet :: Parser IPv6Chunk+-- parseHextet = Hextet <$> hexadecimal -data IPv6TokenPos-  = Init-  | A-  | B-  | C-  | D-  | E-  | F-  | G-  | Finished-  deriving (Show, Eq, Ord, Enum, Bounded)+-- parseHextets :: Parser [IPv6Chunk]+-- parseHextets = many1 (parseHextet <|> (Divider <$> parseDividerOrDoubleColon)) -data IPv6State = IPv6State-  { hextets :: Vector Word16-  , current :: IPv6TokenPos-  , doublePos :: Maybe IPv6TokenPos-  } deriving (Show)+-- data IPv6Chunk+--   = Hextet Word16+--   | Divider IPv6Divider+--   deriving (Show) -initIPv6State :: IPv6State-initIPv6State = IPv6State [] Init Nothing+-- data IPv6TokenPos+--   = Init+--   | A+--   | B+--   | C+--   | D+--   | E+--   | F+--   | G+--   | Finished+--   deriving (Show, Eq, Ord, Enum, Bounded) -accumIPv6State :: [IPv6Chunk] -> IPv6State-accumIPv6State xs =-  let go :: IPv6State -> IPv6Chunk -> IPv6State-      go xss@IPv6State{..} x = case x of-        Divider d -> case d of-          DoubleColon -> xss { doublePos = Just current }-          DividerColon -> xss-        Hextet n -> xss { hextets = V.snoc hextets n, current = succ current }-  in  foldl go initIPv6State xs+-- data IPv6State = IPv6State+--   { hextets :: Vector Word16+--   , current :: IPv6TokenPos+--   , doublePos :: Maybe IPv6TokenPos+--   } deriving (Show) -ipv6StateToIPv6 :: IPv6State -> Maybe IPv6-ipv6StateToIPv6 IPv6State{..} = case doublePos of-  Nothing -> case V.toList hextets of-    (a:b:c:d:e:f:g:h:_) -> Just (IPv6.fromWord16s a b c d e f g h)-    _ -> Nothing-  Just p ->-    let zeros = V.replicate (8 - V.length hextets) 0-        composite = case p of-          Init -> Just (zeros <> hextets)-          A -> case V.toList hextets of-            (a:hs) -> Just ([a] <> zeros <> V.fromList hs)-            _ -> Nothing-          B -> case V.toList hextets of-            (a:b:hs) -> Just ([a,b] <> zeros <> V.fromList hs)-            _ -> Nothing-          C -> case V.toList hextets of-            (a:b:c:hs) -> Just ([a,b,c] <> zeros <> V.fromList hs)-            _ -> Nothing-          D -> case V.toList hextets of-            (a:b:c:d:hs) -> Just ([a,b,c,d] <> zeros <> V.fromList hs)-            _ -> Nothing-          E -> case V.toList hextets of-            (a:b:c:d:e:hs) -> Just ([a,b,c,d,e] <> zeros <> V.fromList hs)-            _ -> Nothing-          F -> case V.toList hextets of-            (a:b:c:d:e:f:hs) -> Just ([a,b,c,d,e,f] <> zeros <> V.fromList hs)-            _ -> Nothing-          G -> case V.toList hextets of-            (a:b:c:d:e:f:g:hs) -> Just ([a,b,c,d,e,f,g] <> zeros <> V.fromList hs)-            _ -> Nothing-          Finished -> case V.toList hextets of-            (a:b:c:d:e:f:g:h:_) -> Just [a,b,c,d,e,f,g,h]-            _ -> Nothing-    in  case V.toList <$> composite of-      Just (a:b:c:d:e:f:g:h:_) -> Just (IPv6.fromWord16s a b c d e f g h)-      _ -> Nothing+-- initIPv6State :: IPv6State+-- initIPv6State = IPv6State [] Init Nothing -ipv6 :: Parser IPv6-ipv6 = do-  s <- parseHextets-  case toIPv6 s of-    Nothing -> fail "Not an IPv6"-    Just x -> pure x-  where-    toIPv6 :: [IPv6Chunk] -> Maybe IPv6-    toIPv6 = ipv6StateToIPv6 . accumIPv6State+-- accumIPv6State :: [IPv6Chunk] -> IPv6State+-- accumIPv6State xs =+--   let go :: IPv6State -> IPv6Chunk -> IPv6State+--       go xss@IPv6State{..} x = case x of+--         Divider d -> case d of+--           DoubleColon -> xss { doublePos = Just current }+--           DividerColon -> xss+--         Hextet n -> xss { hextets = V.snoc hextets n, current = succ current }+--   in  foldl go initIPv6State xs++-- ipv6StateToIPv6 :: IPv6State -> Maybe IPv6+-- ipv6StateToIPv6 IPv6State{..} = case doublePos of+--   Nothing -> case V.toList hextets of+--     (a:b:c:d:e:f:g:h:_) -> Just (IPv6.fromWord16s a b c d e f g h)+--     _ -> Nothing+--   Just p ->+--     let zeros = V.replicate (8 - V.length hextets) 0+--         composite = case p of+--           Init -> Just (zeros <> hextets)+--           A -> case V.toList hextets of+--             (a:hs) -> Just ([a] <> zeros <> V.fromList hs)+--             _ -> Nothing+--           B -> case V.toList hextets of+--             (a:b:hs) -> Just ([a,b] <> zeros <> V.fromList hs)+--             _ -> Nothing+--           C -> case V.toList hextets of+--             (a:b:c:hs) -> Just ([a,b,c] <> zeros <> V.fromList hs)+--             _ -> Nothing+--           D -> case V.toList hextets of+--             (a:b:c:d:hs) -> Just ([a,b,c,d] <> zeros <> V.fromList hs)+--             _ -> Nothing+--           E -> case V.toList hextets of+--             (a:b:c:d:e:hs) -> Just ([a,b,c,d,e] <> zeros <> V.fromList hs)+--             _ -> Nothing+--           F -> case V.toList hextets of+--             (a:b:c:d:e:f:hs) -> Just ([a,b,c,d,e,f] <> zeros <> V.fromList hs)+--             _ -> Nothing+--           G -> case V.toList hextets of+--             (a:b:c:d:e:f:g:hs) -> Just ([a,b,c,d,e,f,g] <> zeros <> V.fromList hs)+--             _ -> Nothing+--           Finished -> case V.toList hextets of+--             (a:b:c:d:e:f:g:h:_) -> Just [a,b,c,d,e,f,g,h]+--             _ -> Nothing+--     in  case V.toList <$> composite of+--       Just (a:b:c:d:e:f:g:h:_) -> Just (IPv6.fromWord16s a b c d e f g h)+--       _ -> Nothing++-- ipv6 :: Parser IPv6+-- ipv6 = do+--   s <- parseHextets+--   case toIPv6 s of+--     Nothing -> fail "Not an IPv6"+--     Just x -> pure x+--   where+--     toIPv6 :: [IPv6Chunk] -> Maybe IPv6+--     toIPv6 = ipv6StateToIPv6 . accumIPv6State