-
Notifications
You must be signed in to change notification settings - Fork 101
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
Conversation
* 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] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
test/parser/inttype.jl
Outdated
@@ -0,0 +1,16 @@ | |||
@testset for T in [Int32, Int64, Int128] | |||
val = JSON.parse("{\"x\": 3}", inttype=T) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
👍, I think this is a good idea. |
* These are unexported, internal functions, and this ordering makes more sense.
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. |
Looks great, thanks! |
DictType
andIntType
to use for parsing JSONThis 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.