module IPv4Pattern
where
+
import Test.Tasty ( TestTree, testGroup )
import Test.Tasty.HUnit ( (@?=), testCase )
-import Text.Parsec
+import Text.Parsec (
+ ParseError,
+ (<|>),
+ char,
+ digit,
+ many1,
+ parse,
+ string,
+ try,
+ unexpected )
import Text.Parsec.String ( Parser )
import Text.Read ( readMaybe )
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parseTest )
+--
-- Standard octets are parsed correctly:
--
-- >>> parseTest v4octet "0"
-- to convert that to an Int! It will overflow rather than fail
-- if the input is too big/small, so it should really always
-- succeed.
- Nothing -> unexpected "readMaybe failed on a sequence of digits!"
+ Nothing -> unexpected "v4octet: readMaybe failed on a sequence of digits!"
-- If we got an Int, make sure it's actually a representation of
-- an octet.
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parseTest )
+--
-- >>> parseTest v4seq_member "127"
-- IPv4SequenceMemberOctet (IPv4Octet 127)
--
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parseTest )
-- >>> parseTest v4sequence "1"
-- IPv4SequenceSingleMember (IPv4SequenceMemberOctet (IPv4Octet 1))
--
instance Pretty IPv4Field where
prettyshow (IPv4FieldOctet octet) = prettyshow octet
- prettyshow (IPv4FieldSequence seq) = "[" ++ (prettyshow seq) ++ "]"
+ prettyshow (IPv4FieldSequence s) = "[" ++ (prettyshow s) ++ "]"
-- | Parse an IPv4 \"field\", which is either a boring old octet, or a
--
-- ==== _Examples_
--
+-- >>> import Text.Parsec ( parseTest )
-- >>> parseTest v4field "127"
-- IPv4FieldOctet (IPv4Octet 127)
--
--
-- In the module intro, it is mentioned that this is invalid:
--
+-- >>> import Text.Parsec ( parseTest )
-- >>> parseTest v4pattern "1.2.[3.4]"
-- parse error at (line 1, column 7):
-- unexpected "."