Coder Social home page Coder Social logo

Comments (7)

garyb avatar garyb commented on September 27, 2024 1

I don't think the Effect is a problem, you can use the m part of ParserT to handle that. Something along the lines of:

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 Position hard coded into ParserT isn't really ideal for this purpose 😕, hence the fixed line: 0.

from purescript-parsing.

jamesdbrock avatar jamesdbrock commented on September 27, 2024

The fact that getUint8 is an Effect function might complicate this.

I would probably just unsafePerformEffect in the implementation and warn users not to mutate the ArrayBuffer while parsing.

from purescript-parsing.

jamesdbrock avatar jamesdbrock commented on September 27, 2024

Good idea. I'll take a shot at a PR for this.

from purescript-parsing.

jamesdbrock avatar jamesdbrock commented on September 27, 2024

https://pursuit.purescript.org/packages/purescript-arraybuffer is not a purescript-contrib library, is it okay for purescript-parsing to depend on it?

from purescript-parsing.

jamesdbrock avatar jamesdbrock commented on September 27, 2024

purescript-arraybuffer is really nice because it handles endianness.

from purescript-parsing.

garyb avatar garyb commented on September 27, 2024

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 -arraybuffer and -parsing. I'd be happy to add a link to it in the readme here to help others find it, if you put something together.

from purescript-parsing.

jamesdbrock avatar jamesdbrock commented on September 27, 2024

Also transitively depends on non-contrib library https://pursuit.purescript.org/packages/purescript-typelevel

from purescript-parsing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.