Open jackfirth opened 7 years ago
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:
P2Y1.5M
(well, the standard says, "If necessary for a particular application, the lowest order components may have a decimal fraction.").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:
hash-ref
does and allow passing an optional value-or-thunk that determines what to do on parse failure (see the failure-result/c
contract)megaparsack
instead of providing plain functionsI 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.
hash-ref
(and its like) is a kind of special case, though. Any value you choose as the default failure value could also be a successful result. A date or time parser, however, would never return #f
on success, so I've been thinking of it more like string->number
than hash-ref
.
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.