si-bytes-0.1: Byte with type-level units (e.g. B, KB, MB, ...).
Safe HaskellNone
LanguageHaskell2010

Data.Bytes.Class.Parser

Description

Provides parsing utilities.

Since: 0.1

Synopsis

Documentation

class Parser a where Source #

Represents a megaparsec parser. Used for parsing byte types from Text.

Since: 0.1

Methods

parser :: Parsec Void Text a Source #

Megaparsec parser for the given type.

Since: 0.1

Instances

Instances details
Parser Direction Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Direction

Parser Size Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Size

Read n => Parser (SomeSize n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Internal

Read n => Parser (SomeNet n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Read n => Parser (Bytes s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Internal

Methods

parser :: Parsec Void Text (Bytes s n) Source #

Read n => Parser (SomeNetDir s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Read n => Parser (SomeNetSize d n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Read n => Parser (NetBytes d s n) Source #

Since: 0.1

Instance details

Defined in Data.Bytes.Network.Internal

Methods

parser :: Parsec Void Text (NetBytes d s n) Source #

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

Expand
>>> 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

Expand
>>> 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