Module

Parsing.DataView

Package
purescript-parsing-dataview
Repository
jamesdbrock/purescript-parsing-dataview

Primitive parsers for input type DataView.

All of these primitive parsers will consume when they succeed.

All of these primitive parsers will not consume and will automatically backtrack when they fail.

See the package README for usage examples.

Mutable ArrayBuffer

All of the parsers in this module operate on an input stream of Data.ArrayBuffer.Types.DataView, which represents a range of a mutable Data.ArrayBuffer.Types.ArrayBuffer.

For operations for working with DataView, see module Data.ArrayBuffer.DataView in package arraybuffer.

Reading from an ArrayBuffer is an Effectful activity, so all parsers in this module must be run in a MonadEffect m => ParserT DataView m context with Parsing.runParserT.

Position

In a DataView parser, the Position {index} counts the number of bytes since the beginning of the input.

The Postion {line,column} fields are unused and will remain constant 1.

#takeN Source

takeN :: forall m. MonadEffect m => ByteLength -> ParserT DataView m DataView

Take N bytes starting from the current parser position. Will fail if not enough bytes remain in the input. Will fail if N is negative.

Example

Parse three bytes.

takeN 3

#takeRest Source

takeRest :: forall m. MonadEffect m => ParserT DataView m DataView

Take the rest of the input, however many bytes remain. Always succeeds.

#eof Source

eof :: forall m. Monad m => ParserT DataView m Unit

Parse succeeds at the end of the input DataView.

#match Source

match :: forall a m. MonadEffect m => ParserT DataView m a -> ParserT DataView m (Tuple DataView a)

The famous match combinator.

Return both the result of a parse and the portion of the input that was consumed while it was being parsed.

#anyTill Source

anyTill :: forall m a. MonadEffect m => ParserT DataView m a -> ParserT DataView m (Tuple DataView a)

Combinator which finds the first position in the input DataView where the phrase can parse. Returns both the parsed result and the unparsable input section searched before the parse. Will fail if no section of the input is parseable. To backtrack the input stream on failure, combine with tryRethrow.

This combinator is equivalent to manyTill_ anyInt8, but it will be faster because it returns a slice of the input DataView for the section preceding the parse instead of a List Int.

Be careful not to look too far ahead; if the phrase parser looks to the end of the input then anyTill could be O(n²).

#anyPrim Source

anyPrim :: forall a name m t. BinaryValue a t => BytesPerType a => ShowArrayViewType a name => IsSymbol name => MonadEffect m => Endian -> Proxy a -> ParserT DataView m t

Parse one fixed-bit-width Data.ArrayBuffer.Types.ArrayViewType primitive of a given endianness.

Example

Parse a little-endian 32-bit two’s-complement signed integer (4 bytes):

anyPrim LE (Proxy :: Proxy Int32)

or just use the convenience function anyInt32le, see below.

#anyInt8 Source

anyInt8 :: forall m. MonadEffect m => ParserT DataView m Int

Parse one 8-bit two’s-complement signed integer (byte).

#anyInt16be Source

anyInt16be :: forall m. MonadEffect m => ParserT DataView m Int

Parse one 16-bit big-endian two’s-complement signed integer.

#anyInt16le Source

anyInt16le :: forall m. MonadEffect m => ParserT DataView m Int

Parse one 16-bit little-endian two’s-complement signed integer.

#anyInt32be Source

anyInt32be :: forall m. MonadEffect m => ParserT DataView m Int

Parse one 32-bit big-endian two’s-complement signed integer.

#anyInt32le Source

anyInt32le :: forall m. MonadEffect m => ParserT DataView m Int

Parse one 32-bit little-endian two’s-complement signed integer.

#anyUint8 Source

anyUint8 :: forall m. MonadEffect m => ParserT DataView m UInt

Parse one 8-bit unsigned integer (octet).

#anyUint16be Source

anyUint16be :: forall m. MonadEffect m => ParserT DataView m UInt

Parse one 16-bit big-endian unsigned integer.

#anyUint16le Source

anyUint16le :: forall m. MonadEffect m => ParserT DataView m UInt

Parse one 16-bit little-endian unsigned integer.

#anyUint32be Source

anyUint32be :: forall m. MonadEffect m => ParserT DataView m UInt

Parse one 32-bit big-endian unsigned integer.

#anyUint32le Source

anyUint32le :: forall m. MonadEffect m => ParserT DataView m UInt

Parse one 32-bit little-endian unsigned integer.

#anyFloat32be Source

anyFloat32be :: forall m. MonadEffect m => ParserT DataView m Float32

Parse one 32-bit big-endian IEEE 754 floating-point number.

#anyFloat32le Source

anyFloat32le :: forall m. MonadEffect m => ParserT DataView m Float32

Parse one 32-bit little-endian IEEE 754 floating-point number.

#anyFloat64be Source

anyFloat64be :: forall m. MonadEffect m => ParserT DataView m Number

Parse one 64-bit big-endian IEEE 754 floating-point number.

#anyFloat64le Source

anyFloat64le :: forall m. MonadEffect m => ParserT DataView m Number

Parse one 64-bit little-endian IEEE 754 floating-point number.

#satisfy Source

satisfy :: forall a name m t. BinaryValue a t => BytesPerType a => ShowArrayViewType a name => IsSymbol name => Show t => MonadEffect m => Endian -> Proxy a -> (t -> Boolean) -> ParserT DataView m t

Parse one fixed-bit-width primitive that satisfies the given predicate.

Example

Parse a little-endian 32-bit signed integer that is equal to 3:

satisfy LE (Proxy :: Proxy Int32) (_ == 3)

or just use the convenience function satisfyInt32le, see below.

#satisfyInt8 Source

satisfyInt8 :: forall m. MonadEffect m => (Int -> Boolean) -> ParserT DataView m Int

Parse one 8-bit signed integer that satisfies the given predicate.

#satisfyInt16be Source

satisfyInt16be :: forall m. MonadEffect m => (Int -> Boolean) -> ParserT DataView m Int

Parse one 16-bit big-endian signed integer that satisfies the given predicate.

#satisfyInt16le Source

satisfyInt16le :: forall m. MonadEffect m => (Int -> Boolean) -> ParserT DataView m Int

Parse one 16-bit little-endian signed integer that satisfies the given predicate.

#satisfyInt32be Source

satisfyInt32be :: forall m. MonadEffect m => (Int -> Boolean) -> ParserT DataView m Int

Parse one 32-bit big-endian signed integer that satisfies the given predicate.

#satisfyInt32le Source

satisfyInt32le :: forall m. MonadEffect m => (Int -> Boolean) -> ParserT DataView m Int

Parse one 32-bit little-endian signed integer that satisfies the given predicate.

#satisfyUint8 Source

satisfyUint8 :: forall m. MonadEffect m => (UInt -> Boolean) -> ParserT DataView m UInt

Parse one 8-bit unsigned integer that satisfies the given predicate.

#satisfyUint16be Source

satisfyUint16be :: forall m. MonadEffect m => (UInt -> Boolean) -> ParserT DataView m UInt

Parse one 16-bit big-endian unsigned integer that satisfies the given predicate.

#satisfyUint16le Source

satisfyUint16le :: forall m. MonadEffect m => (UInt -> Boolean) -> ParserT DataView m UInt

Parse one 16-bit little-endian unsigned integer that satisfies the given predicate.

#satisfyUint32be Source

satisfyUint32be :: forall m. MonadEffect m => (UInt -> Boolean) -> ParserT DataView m UInt

Parse one 32-bit big-endian unsigned integer that satisfies the given predicate.

#satisfyUint32le Source

satisfyUint32le :: forall m. MonadEffect m => (UInt -> Boolean) -> ParserT DataView m UInt

Parse one 32-bit little-endian unsigned integer that satisfies the given predicate.

#satisfyFloat32be Source

satisfyFloat32be :: forall m. MonadEffect m => (Float32 -> Boolean) -> ParserT DataView m Float32

Parse one 32-bit big-endian floating-point number that satisfies the given predicate.

#satisfyFloat32le Source

satisfyFloat32le :: forall m. MonadEffect m => (Float32 -> Boolean) -> ParserT DataView m Float32

Parse one 32-bit little-endian floating-point number that satisfies the given predicate.

#satisfyFloat64be Source

satisfyFloat64be :: forall m. MonadEffect m => (Number -> Boolean) -> ParserT DataView m Number

Parse one 64-bit big-endian floating-point number that satisfies the given predicate.

#satisfyFloat64le Source

satisfyFloat64le :: forall m. MonadEffect m => (Number -> Boolean) -> ParserT DataView m Number

Parse one 64-bit little-endian floating-point number that satisfies the given predicate.