-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
INI: Implement type coercion for parse
#5441
Conversation
this becoming complex. maybe ini should be shard. also parse with regex super slow. what about scientific notation for float? maybe also parse time, like yaml? best solution: everything is string, user can choose what to parse. ini has no standard. so 👎 |
This commit implements type coercion for `INI.parse`, allowing integers, floats, and booleans to be coerced into their respective Crystal types.
dbf5a21
to
9cf231e
Compare
What's the process for breaking this out into a shard?
We're already using regexps to parse INI, so I didn't think this would add too much performance overhead. I agree, though: A real parser with parse time checks would be better. (That's something I can develop, if there's interest).
The fact that INI has no standard means we can be more rigorous, no? Type coercion is one of those things that should be gotten right once, so that users don't have to do it themselves (with various degrees of correctness/quality). Overall, I'd like to see a feature like this (even if it was optional, like |
i mean, ini with types is a different shard. ini in std is simple and useful to everyone. want int? |
I think it would be more useful with type guarantees. Like I said in #5441 (comment), though, this could be made optional.
Yes, but Crystal's development is currently in an alpha stage. From the README:
I implemented this with regex because |
Please no. INI format is not officially standardized but that doesn't mean you can do whatever you want. It should do what everyone else does. And that is, it contains KV pairs of strings. No other data types. INI is simple and easy, don't make it complicated. Your implementation has no means to specify a string consisting of only digits. You'd need some escaping for that like quotes in YAML. That makes it way to complex and wouldn't work with other INI implementations. |
A PR implementing a custom parser without regular expressions (but keeping the current behaviour) would certainly be welcome. |
I hadn't thought about that!
I'll focus on that. Thanks for the reviews, @larubujo and @straight-shoota! |
This commit implements type coercion for
INI.parse
, allowing integers, floats, and booleans to be coerced into their respective Crystal types.