Comments (7)
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.
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.
Good idea. I'll take a shot at a PR for this.
from purescript-parsing.
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.
purescript-arraybuffer is really nice because it handles endianness.
from purescript-parsing.
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.
Also transitively depends on non-contrib library https://pursuit.purescript.org/packages/purescript-typelevel
from purescript-parsing.
Related Issues (20)
- Fix issues caused by making `<|>` infixr HOT 1
- Change Position to Int HOT 3
- Indents
- purescript-datetime-parsing
- Combinator variations HOT 12
- Talk about alternate backends in documentation
- Fully remove the `Parsing.Pos` module? HOT 1
- liftMaybe, liftEither, liftExceptT HOT 4
- MonadST instance for ParserT? HOT 1
- Drop unicode dependency? HOT 5
- `skipSpaces` always commits to branch even if no spaces are consumed HOT 6
- Chris martin's seven parser types HOT 4
- Parsing a `number` in scientific notation _without_ a decimal exponent fails.
- Change “consume” to “commit” HOT 3
- manyIndex ParseError message
- manyMonoid?
- Consider `Parser0` HOT 1
- Multiple errors HOT 7
- withRecovery HOT 2
- Factor out `Tokens` and `Language` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-parsing.