git.iko.soy/rowtype-yoga/purescript-parsing-dataview
on master help sign in
6 files changed+39−12
since splitsnapshots
unifiedsplit
CHANGELOG.md+3−1 README.md+7−6 bower.json+1−1 spago.dhall+1−1 src/Parsing/DataView.Basic.purs+5−1 test/Main.purs+22−2
CHANGELOG.md+3−1
@@ -1,9 +1,11 @@
11# Changelog
22
3−## Unreleased
3+## v3.2.0
44
5+- Build for PureScript v0.15.4
56- New combinator: `anyTill`
67- New parser: `anyCodePointUTF8`
8+- Move to rowtype-yoga org
79
810## v3.1.0
911
README.md+7−6
@@ -1,7 +1,8 @@
11# purescript-parsing-dataview
22
3−[![CI](https://github.com/jamesdbrock/purescript-parsing-dataview/workflows/CI/badge.svg?branch=master)](https://github.com/jamesdbrock/purescript-parsing-dataview/actions)
3+[![CI](https://github.com/rowtype-yoga/purescript-parsing-dataview/workflows/CI/badge.svg?branch=master)](https://github.com/rowtype-yoga/purescript-parsing-dataview/actions)
44[![Pursuit](http://pursuit.purescript.org/packages/purescript-parsing-dataview/badge)](http://pursuit.purescript.org/packages/purescript-parsing-dataview/)
5+[![Maintainer: jamesdbrock](https://img.shields.io/badge/maintainer-jamesdbrock-teal.svg)](https://github.com/jamesdbrock)
56
67Primitive parsers for
78`DataView`s on JavaScript `ArrayBuffer`s with the package
@@ -13,7 +14,7 @@ is similar to the built-in stream support of [__Megaparsec__](https://hackage.ha
1314| Stream type | parsing | Megaparsec |
1415|----|-----|----|
1516| UTF-16 strings | String | Text < v2.0|
16−| UTF-8 strings | | Text ≥ v2.0 |
17+| UTF-8 strings | __DataView__ | Text ≥ v2.0 |
1718| Listy strings | Token | String |
1819| Binary blobs | __DataView__ | ByteString |
1920
@@ -28,8 +29,8 @@ Parse values out of a `dataview :: Data.ArrayBuffer.Types.DataView`. All
2829Parse two big-endian IEEE 754 double-precision `Number`s.
2930
3031```purescript
31−import Text.Parsing.Parser (runParserT)
32−import Text.Parsing.Parser.DataView (anyFloat64be)
32+import Parsing (runParserT)
33+import Parsing.DataView (anyFloat64be)
3334
3435do
3536 result <- runParserT dataview do
@@ -43,8 +44,8 @@ do
4344Parse an array of `n` 32-bit big-endian signed `Int`s.
4445
4546```purescript
46−import Text.Parsing.Parser (runParserT)
47−import Text.Parsing.Parser.DataView (anyUint32be)
47+import Parsing (runParserT)
48+import Parsing.DataView (anyUint32be)
4849import Data.Unfoldable (replicateA)
4950
5051do
bower.json+1−1
@@ -5,7 +5,7 @@
55 ],
66 "repository": {
77 "type": "git",
8− "url": "https://github.com/jamesdbrock/purescript-parsing-dataview"
8+ "url": "https://github.com/rowtype-yoga/purescript-parsing-dataview"
99 },
1010 "ignore": [
1111 "**/.*",
spago.dhall+1−1
@@ -19,5 +19,5 @@
1919, packages = ./packages.dhall
2020, sources = [ "src/**/*.purs" ]
2121, license = "BSD-2-Clause"
22−, repository = "https://github.com/jamesdbrock/purescript-parsing-dataview"
22+, repository = "https://github.com/rowtype-yoga/purescript-parsing-dataview"
2323}
src/Parsing/DataView.Basic.purs+5−1
@@ -29,19 +29,23 @@ anyCodePointUTF8 = tryRethrow do
2929 c0 <- toInt <$> anyUint8
3030 if c0 < 128 then do
3131 liftMaybe (\_ -> "Invalid CodePoint " <> show c0) (toEnum c0)
32+ else if c0 < 192 then fail "Invalid UTF-8 encoding"
3233 else if c0 < 224 then do
3334 c1 <- toInt <$> anyUint8
35+ if c1 < 128 || c1 > 191 then fail "Invalid UTF-8 encoding" else pure unit
3436 let codepoint = (64 * (c0 `mod` 32)) + (c1 `mod` 64)
3537 liftMaybe (\_ -> "Invalid CodePoint " <> show codepoint) (toEnum codepoint)
3638 else if c0 < 240 then do
3739 c1 <- toInt <$> anyUint8
3840 c2 <- toInt <$> anyUint8
41+ if c1 < 128 || c1 > 191 || c2 < 128 || c2 > 191 then fail "Invalid UTF-8 encoding" else pure unit
3942 let codepoint = (4096 * (c0 `mod` 16)) + (64 * (c1 `mod` 64)) + (c2 `mod` 64)
4043 liftMaybe (\_ -> "Invalid CodePoint " <> show codepoint) (toEnum codepoint)
4144 else if c0 < 248 then do
4245 c1 <- toInt <$> anyUint8
4346 c2 <- toInt <$> anyUint8
4447 c3 <- toInt <$> anyUint8
48+ if c1 < 128 || c1 > 191 || c2 < 128 || c2 > 191 || c3 < 128 || c3 > 191 then fail "Invalid UTF-8 encoding" else pure unit
4549 let codepoint = (262144 * (c0 `mod` 8)) + (4096 * (c1 `mod` 64)) + (64 * (c2 `mod` 64)) + (c3 `mod` 64)
4650 liftMaybe (\_ -> "Invalid CodePoint " <> show codepoint) (toEnum codepoint)
47− else fail "Invalid first code point"
51+ else fail "Invalid UTF-8 encoding"
test/Main.purs+22−2
@@ -7,6 +7,8 @@ import Control.Monad.Trans.Class (lift)
77import Data.ArrayBuffer.ArrayBuffer as AB
88import Data.ArrayBuffer.Cast (fromUint8Array, toUint8Array)
99import Data.ArrayBuffer.DataView as DataView
10+import Data.ArrayBuffer.Typed (fromArray)
11+import Data.ArrayBuffer.Types (Uint8Array)
1012import Data.Either (Either(..))
1113import Data.Enum (fromEnum)
1214import Data.List (fromFoldable)
@@ -19,7 +21,7 @@ import Effect (Effect)
1921import Effect.Class (liftEffect)
2022import Effect.Console (logShow)
2123import Effect.Exception (catchException, message)
22−import Parsing (ParserT, Position(..), fail, liftExceptT, parseErrorPosition, runParserT)
24+import Parsing (ParseError(..), ParserT, Position(..), fail, liftExceptT, parseErrorPosition, runParserT)
2325import Parsing.Combinators (many, manyTill)
2426import Parsing.DataView (anyInt8, anyTill, eof, satisfyInt8)
2527import Parsing.DataView as DV
@@ -205,7 +207,25 @@ main = do
205207 eof
206208 pure [ c0, c1, c2, c3, c4 ]
207209
208− assertEqual' "anyCodePointUTF8"
210+ assertEqual' "anyCodePointUTF8 basic"
209211 { expected: Right [ 97, 955, 0x6708, 0x1F453, 97 ]
210212 , actual: result
211213 }
214+
215+ do
216+ test :: Uint8Array <- fromArray (map fromInt [ 0x00BF ])
217+ testv <- fromUint8Array test
218+ result <- runParserT testv anyCodePointUTF8
219+ assertEqual' "anyCodePointUTF8 invalid 1"
220+ { expected: Left (ParseError "Invalid UTF-8 encoding" (Position { index: 0, column: 1, line: 1 }))
221+ , actual: result
222+ }
223+
224+ do
225+ test :: Uint8Array <- fromArray (map fromInt [ 0x00C0, 0 ])
226+ testv <- fromUint8Array test
227+ result <- runParserT testv anyCodePointUTF8
228+ assertEqual' "anyCodePointUTF8 invalid 2"
229+ { expected: Left (ParseError "Invalid UTF-8 encoding" (Position { index: 0, column: 1, line: 1 }))
230+ , actual: result
231+ }