git.iko.soy/rowtype-yoga/purescript-parsing-dataview
on master help sign in
Bugfix takeN

Also docs.

commit61dde85cb55bec27898bb888f551e1e4bce5893a authorJames Brock <jamesbrock@gmail.com> dateWed 11 May 2022, 22:00 (4 years ago) parent0b730e3
4 files changed+16−9
CHANGELOG.md+4 README.md+5−3 src/Parsing/DataView.purs+6−6 test/Main.purs+1
CHANGELOG.md+4
@@ -1,5 +1,9 @@
11# Changelog
22
3+## v3.1.0
4+
5+Bugfix `takeN`.
6+
37## v3.0.0
48
59### Breaking changes
README.md+5−3
@@ -5,12 +5,12 @@
55
66Primitive parsers for
77`DataView`s on JavaScript `ArrayBuffer`s with the package
8−[__purescript-parsing__](https://pursuit.purescript.org/packages/purescript-parsing/).
8+[__parsing__](https://pursuit.purescript.org/packages/purescript-parsing/).
99
10−With this package, the input stream support of __purescript-parsing__
10+With this package, the input stream support of __parsing__
1111is similar to the built-in stream support of [__Megaparsec__](https://hackage.haskell.org/package/megaparsec):
1212
13−| Stream type | purescript-parsing | Megaparsec |
13+| Stream type | parsing | Megaparsec |
1414|----|-----|----|
1515| UTF-16 strings | String | Text < v2.0|
1616| UTF-8 strings | | Text ≥ v2.0 |
@@ -88,6 +88,8 @@ do
8888 Right s -> pure s
8989```
9090
91+You might also consider using [__web-encoding__](https://pursuit.purescript.org/packages/purescript-web-encoding) for UTF-8. It will work in *Node.js ≥ v11*.
92+
9193## Serialization
9294
9395This package is for reading (`DataView`s on) `ArrayBuffer`s, not writing
src/Parsing/DataView.purs+6−6
@@ -1,5 +1,5 @@
1−-- | Primitive parsers for JavaScript `ArrayBuffer`s with the
2−-- | `ParserT` type and combinators in package __purescript-parsing__.
1+-- | Primitive parsers for input `DataView`s with the
2+-- | `ParserT` type and combinators in package __parsing__.
33-- | See the package README for usage examples.
44-- |
55-- | ### Mutable ArrayBuffer
@@ -9,10 +9,10 @@
99-- | which represents a range of a mutable
1010-- | [__Data.ArrayBuffer.Types.ArrayBuffer__](https://pursuit.purescript.org/packages/purescript-arraybuffer-types/docs/Data.ArrayBuffer.Types#t:ArrayBuffer).
1111-- |
12−-- | For operations for working with `ArrayBuffer` and `DataView`, see
12+-- | For operations for working with `DataView`, see
1313-- | module
1414-- | [__Data.ArrayBuffer.DataView__](https://pursuit.purescript.org/packages/purescript-arraybuffer/docs/Data.ArrayBuffer.DataView)
15−-- | in package __purescript-arraybuffer__.
15+-- | in package __arraybuffer__.
1616-- |
1717-- | Reading from an `ArrayBuffer` is an `Effect`ful activity, so
1818-- | all parsers in this module must be run in a
@@ -257,8 +257,8 @@ takeN :: forall m. MonadEffect m => ByteLength -> ParserT DataView m DataView
257257takeN n = do
258258 ParseState input (Position { index }) _ <- getParserT
259259 if (n < 0) then
260− fail $ "takeN cannot take negative number of bytes"
261− else if (index + n + 1 > DV.byteLength input) then
260+ fail "takeN cannot take negative number of bytes"
261+ else if (index + n > DV.byteLength input) then
262262 fail "takeN expected N bytes"
263263 else do
264264 p <- lift $ liftEffect $ DV.part (DV.buffer input) (DV.byteOffset input + index) n
test/Main.purs+1
@@ -118,6 +118,7 @@ main = do
118118 lift (runParserT dv2 DV.anyInt16le) >>= case _ of
119119 Left err -> fail $ show err
120120 Right x -> pure x
121+ parseTestT dv unit $ DV.takeN 5 *> pure unit
121122
122123 -- test match combinator
123124 runParserT dv (DV.match (DV.anyInt8 *> DV.anyInt8)) >>= case _ of