Skip to content
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

Allow user to specify integer parsing type (fixes #223) #224

Merged
merged 6 commits into from
Nov 18, 2017

Conversation

kmsquire
Copy link
Contributor

@kmsquire kmsquire commented Nov 17, 2017

  • Added a ParserContext object, containing the DictType and IntType to use for parsing JSON

This is a minimally invasive way of giving the user more control over parsing.

A possible extension would be to allow specifying the float format to parse (e.g., DecFP, Decimals, FixedPointNumbers, etc.), although this would probably require a bit more work.

Edit: Addresses part of #223, although it does not implement overflow checking.

* Added a ParserContext object, containing the dicttype and
  inttype to use for parsing JSON
src/Parser.jl Outdated
keyT = dictT.parameters[1]
function parse_object(ps::ParserState, pc::ParserContext{DictType, <:Real}) where DictType
obj = DictType()
keyT = DictType.parameters[1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps keytype(...), although there's probably a reason we aren't already using it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, keytype(...) would be better. I suspect the code was originally written before that function existed.

@@ -0,0 +1,16 @@
@testset for T in [Int32, Int64, Int128]
val = JSON.parse("{\"x\": 3}", inttype=T)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually use 4 space indents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, fixed in next push

@TotalVerb
Copy link
Collaborator

👍, I think this is a good idea.

@kmsquire
Copy link
Contributor Author

Thanks, @TotalVerb, I made the suggested changes, updated the README, and made some other cosmetic changes. Because of the additional, let me know if you think anything else needs to change. Otherwise, this can be squashed and merged.

@TotalVerb TotalVerb merged commit 8d5ad9b into master Nov 18, 2017
@TotalVerb TotalVerb deleted the kms/feature/inttype branch November 18, 2017 02:22
@TotalVerb
Copy link
Collaborator

Looks great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants