From 0c2843f7764d557b43f496f85ccc48e19e3b9c98 Mon Sep 17 00:00:00 2001 From: James Brock Date: Thu, 1 Dec 2022 10:40:14 +0900 Subject: [PATCH] PureScript 15.4 And README, docs --- .github/workflows/push-build.yml | 3 ++- README.md | 36 +++++++++++++------------------- bower.json | 4 ++-- packages.dhall | 4 ++-- src/Parsing/DataView.purs | 9 ++++++-- 5 files changed, 27 insertions(+), 29 deletions(-) diff --git a/.github/workflows/push-build.yml b/.github/workflows/push-build.yml index f0bce32..4296a73 100644 --- a/.github/workflows/push-build.yml +++ b/.github/workflows/push-build.yml @@ -2,8 +2,9 @@ name: CI on: push: + branches: [master] pull_request: - branches: [main] + branches: [master] jobs: build: diff --git a/README.md b/README.md index 21b4c61..bbf5ba9 100644 --- a/README.md +++ b/README.md @@ -57,39 +57,31 @@ Parse a UTF-8 `String` with a length prefix. We give this as an example, rather than supporting it in the library, because it depends on -[`Data.TextDecoding.decodeUtf8`](https://pursuit.purescript.org/packages/purescript-text-encoding/docs/Data.TextDecoding#v:decodeUtf8). +[__web-encoding__](https://pursuit.purescript.org/packages/purescript-web-encoding) for UTF-8. ```purescript -import Control.Monad.Trans.Class (lift) -import Data.ArrayBuffer.Types (DataView, Uint8Array) -import Data.ArrayBuffer.DataView (buffer, byteOffset, byteLength) -import Data.ArrayBuffer.Typed (part) -import Effect (Effect, liftEffect) -import Text.Parsing.Parser (runParserT, fail) -import Text.Parsing.Parser.DataView (anyUint32be, takeN) +import Control.Monad.Except (ExceptT) +import Data.ArrayBuffer.Cast (toUint8Array) +import Effect.Exception (catchException, message) +import Parsing (runParserT, liftExceptT) +import Parsing.DataView (anyUint32be, takeN) import Data.UInt (toInt) -import Data.Text.Decoding (decodeUtf8) - - --- Make a `Uint8Array` Typed Array from a `DataView`. We can do this --- for the case of `Uint8` because byte arrays are always aligned. -mkUint8Array :: DataView -> Effect Uint8Array -mkUint8Array dv = part (buffer dv) (byteOffset dv) (byteLength dv) +import Web.Encoding.TextDecoder as TextDecoder +import Web.Encoding.UtfLabel as UtfLabel do - result <- runParserT dataview do + textDecoder <- TextDecoder.new UtfLabel.utf8 + + result :: <- runParserT dataview do -- Parse a 32-bit big-endian length prefix for the length -- of the UTF-8 string in bytes. length <- anyUint32be stringview <- takeN $ toInt length - stringarray <- lift $ liftEffect $ mkUint8Array stringview - case decodeUtf8 stringarray of - Left err -> fail $ show err - Right s -> pure s + stringarray <- lift $ liftEffect $ toUint8Array stringview + liftExceptT $ ExceptT $ catchException (Left <<< message) do + Right <$> TextDecoder.decode stringarray ``` -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*. - ## Serialization This package is for reading (`DataView`s on) `ArrayBuffer`s, not writing diff --git a/bower.json b/bower.json index 398d16a..d1cdb43 100644 --- a/bower.json +++ b/bower.json @@ -19,8 +19,8 @@ "purescript-effect": "^v4.0.0", "purescript-float32": "^v2.0.0", "purescript-maybe": "^v6.0.0", - "purescript-parsing": "^v9.0.0", - "purescript-prelude": "^v6.0.0", + "purescript-parsing": "^v10.0.0", + "purescript-prelude": "^v6.0.1", "purescript-transformers": "^v6.0.0", "purescript-tuples": "^v7.0.0", "purescript-uint": "^v7.0.0" diff --git a/packages.dhall b/packages.dhall index b1df959..6d0ee4c 100644 --- a/packages.dhall +++ b/packages.dhall @@ -117,8 +117,8 @@ let additions = ------------------------------- -} let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.15.0-20220505/packages.dhall - sha256:ba57c25c86fd54c2b672cda3a6836bbbdff4b1bbf946bceaabb64e5a10285638 + https://github.com/purescript/package-sets/releases/download/psc-0.15.4-20221110/packages.dhall + sha256:55be93ee309eeb1b3a1d30c7b9fa5d18ffefa67f5fbeec1566b7b6a70b0ac218 let overrides = {=} diff --git a/src/Parsing/DataView.purs b/src/Parsing/DataView.purs index cf81f0e..9909d92 100644 --- a/src/Parsing/DataView.purs +++ b/src/Parsing/DataView.purs @@ -1,5 +1,10 @@ --- | Primitive parsers for input `DataView`s with the --- | `ParserT` type and combinators in package __parsing__. +-- | 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