Safe Haskell | None |
---|---|
Language | Haskell2010 |
Provides parsing utilities.
Since: 0.1
Documentation
Represents a megaparsec parser. Used for parsing byte types from
Text
.
Since: 0.1
Instances
Parser Direction Source # | Since: 0.1 |
Parser Size Source # | Since: 0.1 |
Read n => Parser (SomeSize n) Source # | Since: 0.1 |
Read n => Parser (SomeNet n) Source # | Since: 0.1 |
Read n => Parser (Bytes s n) Source # | Since: 0.1 |
Read n => Parser (SomeNetDir s n) Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Internal | |
Read n => Parser (SomeNetSize d n) Source # | Since: 0.1 |
Defined in Data.Bytes.Network.Internal | |
Read n => Parser (NetBytes d s n) Source # | Since: 0.1 |
parseDigits :: Read n => Parsec Void Text n Source #
Parser combinator for digits with a Read
instance.
Since: 0.1
parse :: Parser a => Text -> Either Text a Source #
Parses various byte types from Text
. Parsing is
lenient in general. We support:
- Case-insensitivity.
- Optional leading/internal/trailing whitespace.
- Flexible names.
Bytes Examples
>>>
import Data.Bytes (Bytes, Size (..), SomeSize)
>>>
parse @(Bytes M Int) "70"
Right (MkBytes 70)
>>>
parse @(SomeSize Float) "100.45 kilobytes"
Right (MkSomeSize SK (MkBytes 100.45))
>>>
parse @(SomeSize Word) "2300G"
Right (MkSomeSize SG (MkBytes 2300))
>>>
parse @(SomeSize Float) "5.5 tb"
Right (MkSomeSize ST (MkBytes 5.5))
Network Examples
>>>
import Data.Bytes.Network (Direction (..), NetBytes, SomeNet, SomeNetDir, SomeNetSize)
>>>
parse @(NetBytes Up M Int) "70"
Right (MkNetBytes (MkBytes 70))
>>>
parse @(SomeNetSize Down Float) "100.45 kilobytes"
Right (MkSomeNetSize SK (MkNetBytes (MkBytes 100.45)))
>>>
parse @(SomeNetSize Up Word) "2300G"
Right (MkSomeNetSize SG (MkNetBytes (MkBytes 2300)))
>>>
parse @(SomeNetDir T Word) "2300 up"
Right (MkSomeNetDir SUp (MkNetBytes (MkBytes 2300)))
>>>
parse @(SomeNetDir M Word) "2300D"
Right (MkSomeNetDir SDown (MkNetBytes (MkBytes 2300)))
>>>
parse @(SomeNet Float) "5.5 tb Up"
Right (MkSomeNet SUp ST (MkNetBytes (MkBytes 5.5)))
>>>
parse @(SomeNet Float) "5.5 megabytes DOWN"
Right (MkSomeNet SDown SM (MkNetBytes (MkBytes 5.5)))
Since: 0.1