git.iko.soy/rowtype-yoga/purescript-parsing-dataview
on master help sign in
Bugfix takeN
61dde85James Brock
CHANGELOG.md+4
@@ -1,5 +1,9 @@
1# Changelog
1# Changelog
2
2
3+## v3.1.0
4+
5+Bugfix `takeN`.
6+
3## v3.0.0
7## v3.0.0
4
8
5### Breaking changes
9### Breaking changes
README.md+5−3
@@ -5,12 +5,12 @@
5
5
6Primitive parsers for
6Primitive parsers for
7`DataView`s on JavaScript `ArrayBuffer`s with the package
7`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/).
9
9
10−With this package, the input stream support of __purescript-parsing__
10+With this package, the input stream support of __parsing__
11is similar to the built-in stream support of [__Megaparsec__](https://hackage.haskell.org/package/megaparsec):
11is similar to the built-in stream support of [__Megaparsec__](https://hackage.haskell.org/package/megaparsec):
12
12
13−| Stream type | purescript-parsing | Megaparsec |
13+| Stream type | parsing | Megaparsec |
14|----|-----|----|
14|----|-----|----|
15| UTF-16 strings | String | Text < v2.0|
15| UTF-16 strings | String | Text < v2.0|
16| UTF-8 strings | | Text ≥ v2.0 |
16| UTF-8 strings | | Text ≥ v2.0 |
@@ -88,6 +88,8 @@ do
88 Right s -> pure s
88 Right s -> pure s
89```
89```
90
90
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+
91## Serialization
93## Serialization
92
94
93This package is for reading (`DataView`s on) `ArrayBuffer`s, not writing
95This 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
1+-- | Primitive parsers for input `DataView`s with the
2−-- | `ParserT` type and combinators in package __purescript-parsing__.
2+-- | `ParserT` type and combinators in package __parsing__.
3-- | See the package README for usage examples.
3-- | See the package README for usage examples.
4-- |
4-- |
5-- | ### Mutable ArrayBuffer
5-- | ### Mutable ArrayBuffer
@@ -9,10 +9,10 @@
9-- | which represents a range of a mutable
9-- | which represents a range of a mutable
10-- | [__Data.ArrayBuffer.Types.ArrayBuffer__](https://pursuit.purescript.org/packages/purescript-arraybuffer-types/docs/Data.ArrayBuffer.Types#t:ArrayBuffer).
10-- | [__Data.ArrayBuffer.Types.ArrayBuffer__](https://pursuit.purescript.org/packages/purescript-arraybuffer-types/docs/Data.ArrayBuffer.Types#t:ArrayBuffer).
11-- |
11-- |
12−-- | For operations for working with `ArrayBuffer` and `DataView`, see
12+-- | For operations for working with `DataView`, see
13-- | module
13-- | module
14-- | [__Data.ArrayBuffer.DataView__](https://pursuit.purescript.org/packages/purescript-arraybuffer/docs/Data.ArrayBuffer.DataView)
14-- | [__Data.ArrayBuffer.DataView__](https://pursuit.purescript.org/packages/purescript-arraybuffer/docs/Data.ArrayBuffer.DataView)
15−-- | in package __purescript-arraybuffer__.
15+-- | in package __arraybuffer__.
16-- |
16-- |
17-- | Reading from an `ArrayBuffer` is an `Effect`ful activity, so
17-- | Reading from an `ArrayBuffer` is an `Effect`ful activity, so
18-- | all parsers in this module must be run in a
18-- | all parsers in this module must be run in a
@@ -257,8 +257,8 @@ takeN :: forall m. MonadEffect m => ByteLength -> ParserT DataView m DataView
257takeN n = do
257takeN n = do
258 ParseState input (Position { index }) _ <- getParserT
258 ParseState input (Position { index }) _ <- getParserT
259 if (n < 0) then
259 if (n < 0) then
260− fail $ "takeN cannot take negative number of bytes"
260+ fail "takeN cannot take negative number of bytes"
261− else if (index + n + 1 > DV.byteLength input) then
261+ else if (index + n > DV.byteLength input) then
262 fail "takeN expected N bytes"
262 fail "takeN expected N bytes"
263 else do
263 else do
264 p <- lift $ liftEffect $ DV.part (DV.buffer input) (DV.byteOffset input + index) n
264 p <- lift $ liftEffect $ DV.part (DV.buffer input) (DV.byteOffset input + index) n
test/Main.purs+1
@@ -118,6 +118,7 @@ main = do
118 lift (runParserT dv2 DV.anyInt16le) >>= case _ of
118 lift (runParserT dv2 DV.anyInt16le) >>= case _ of
119 Left err -> fail $ show err
119 Left err -> fail $ show err
120 Right x -> pure x
120 Right x -> pure x
121+ parseTestT dv unit $ DV.takeN 5 *> pure unit
121
122
122 -- test match combinator
123 -- test match combinator
123 runParserT dv (DV.match (DV.anyInt8 *> DV.anyInt8)) >>= case _ of
124 runParserT dv (DV.match (DV.anyInt8 *> DV.anyInt8)) >>= case _ of