Draft
Conversation
9ffbe66 to
ec4f205
Compare
|
|
||
| {-# INLINE match #-} | ||
| match :: MonadCatch m => Word8 -> Parser m Word8 () | ||
| match w = P.eqBy (==) [w] |
Member
There was a problem hiding this comment.
This should be P.satisfy (== w).
| where | ||
| initial = return begin | ||
|
|
||
| step s a = return $ s * 10 + fromIntegral (a - 48) |
Member
There was a problem hiding this comment.
You are assuming that the input is already validated to be digits.
| n <- P.takeWhile1 (\w -> w - 48 <= 9) (foldToInteger 0) | ||
| when (z == zero && n /= 0) $ do | ||
| P.die $ " Leading zero in a number is not accepted in JSON." | ||
| return n |
Member
There was a problem hiding this comment.
Should not use a monad here, I am not sure if it fuses, you can check. We can write it in other ways e.g.:
- write it directly as a primitive parser
- use a
tee
| let positive = sign == plus || sign /= minus | ||
| pr = P.takeWhile1 (\w -> w - 48 <= 9) (foldToInteger 0) | ||
| when (sign == plus || sign == minus) (skip 1) | ||
| if positive then pr else negate <$> pr |
| {-# INLINE parseJsonNumber #-} | ||
| parseJsonNumber :: MonadCatch m => Parser m Word8 Scientific | ||
| parseJsonNumber = do | ||
| sign <- P.peek |
|
|
||
| {-# INLINE parseJsonString #-} | ||
| parseJsonString :: MonadCatch m => Parser m Word8 JsonString | ||
| parseJsonString = do |
| parseJson :: MonadCatch m => PR.Parser m Word8 Value | ||
| parseJson = K.toParserK $ parseJsonValue | ||
|
|
||
| {- |
| escapeFoldUtf8With :: Monad m => Fold m Char container -> Fold m Word8 container | ||
| escapeFoldUtf8With = Uni.escapeFoldUtf8With 92 jsonEscapes | ||
|
|
||
| type JsonString = Array Char |
Member
There was a problem hiding this comment.
Why can't we have this as Array Word8 using UTF-8 encoding? When needed it can be converted to Chars.
Member
There was a problem hiding this comment.
Why are we using Data.Array for this? It is very inefficient. We can use the Storable array instead.
added 13 commits
October 29, 2020 14:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.