-
Notifications
You must be signed in to change notification settings - Fork 51
Text.Parsing.Parser.ArrayBuffer #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The fact that I would probably just |
I don't think the import Control.Monad.State (get, modify_)
import Control.Monad.Trans.Class (lift)
import Data.ArrayBuffer.DataView (getUint8)
import Data.ArrayBuffer.Types (DataView)
import Data.Maybe (Maybe(..))
import Data.UInt (UInt)
import Effect.Class (class MonadEffect, liftEffect)
import Text.Parsing.Parser (ParseState(..), ParserT, fail)
import Text.Parsing.Parser.Pos (Position(..))
uint8 ∷ ∀ m. MonadEffect m ⇒ ParserT DataView m UInt
uint8 = do
ParseState input (Position { column }) _ <- get
lift (liftEffect (getUint8 input column)) >>= case _ of
Nothing → fail "Unexpected EOF"
Just i → do
modify_ \(ParseState _ position _) ->
ParseState input (Position { line: 0, column: column + 1 }) true
pure i I haven't tested that, so it might not behave quite right, but it compiles and shouldn't be too far off. The |
Good idea. I'll take a shot at a PR for this. |
https://pursuit.purescript.org/packages/purescript-arraybuffer is not a purescript-contrib library, is it okay for purescript-parsing to depend on it? |
purescript-arraybuffer is really nice because it handles endianness. |
Hmm, good point - we try to avoid extra-contrib dependencies unless the library is maintaned by one of us in contrib/core (in the past we've had dependencies that end up blocking libraries that need updates). Maybe this would be better off as a new library that depends on |
Also transitively depends on non-contrib library https://pursuit.purescript.org/packages/purescript-typelevel |
I want to parse the raw
Uint8
bytes of a Javascript ArrayBuffer. You know, like theByteString
instance for Megaparsec Streams, or Data.Attoparsec.ByteString.Is there a good way to do this in Purescript? I can't find it. If this doesn't exist, maybe we could add a new module to purescript-parsing called
Text.Parsing.Parser.ArrayBuffer
? It seems like purescript-parsing was designed to be extended in this way.This module would be a peer of
Text.Parsing.Parser.String
andText.Parsing.Parser.Token
, and similarly constructed.Or maybe this would be better as a separate library, since it would add some new dependencies:
https://pursuit.purescript.org/packages/purescript-arraybuffer
https://pursuit.purescript.org/packages/purescript-arraybuffer-types
Thoughts?
The text was updated successfully, but these errors were encountered: