-
Notifications
You must be signed in to change notification settings - Fork 10
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
Feature request: period parsing #21
Comments
Are you thinking ISO 8601 duration syntax? |
I wasn't aware that existed but it seems to fit the bill perfectly. |
Hm, unfortunately, ISO 8601 durations have two undesirable qualities:
I'm inclined either:
|
Could also do what java.time does: allow fractions only in seconds and, I guess, treat fractional seconds as nanoseconds. |
Hey @jackfirth, Gregor raises an exception on parse failure (for dates, times, and the like). Period parsing should be consistent, of course, but in the new library, do you think it would be better to return #f on parse failure instead? |
I think there's two solid approaches here:
I lean towards 1 but there are significant advantages to 2, such as making it easy to parse stuff that's embedded in more complex text that also requires parsing. You can always add parser combinators later though. |
Eh... on the other hand, it is convenient to be able to provide your own failure value, even if there's no risk of ambiguity. Yay for combinators, and higher-level parsing functions could be built on top of them. |
That's a good point; I'm not really sure how to handle that. Raising a parse error with no option to change that behavior seems fine to me then. Combinators and first-class parsers would probably be the most appropriate way to let people control how parse failures are handled. |
Frequently I wish to pass a time period as an argument to programs, either through command line flags or environment variables. While gregor has facilities for parsing times and dates, there's nothing to parse "12d" into
(days 12)
. Aparse-period
function would suit my needs perfectly. It's easy enough to write myself, but this seems like something that gregor should set a standard for.The text was updated successfully, but these errors were encountered: