I'm attempting to use Parsec to write a parser for times and dates.
I'm aware of Data.Time.Format, but it doesn't offer the flexibility I
need for this project.
My current code (see below) uses Control.Monad.guard to validate the
numeric values for hours and minutes inside the parser. The problem
I'm running into is that checking for errors in the parsing code
causes Text.Parsec.Combinator.choice (in the time function below) to
fail and return an error if it cannot parse input using the first
option (tTimeHourMin), even if the input should match the second
I have several questions:
Why is choice failing in the time function below?
Is there a better way to do numeric validation while parsing?
Should I only use Parsec to validate that the input is syntactically
correct and do the numeric validation elsewhere?
What are some good examples of validating input using Parsec?
On 7/31/10 15:57 , Vladimir Solmon wrote:
> time :: Parser TimeOfDay
> time = choice [ tTimeHourMin,
If the parse of tTimeHourMin fails after reading some characters (most
probably, at the oneOf because it has been fed a t24hrClock value), those
characters remain read and t24hrClock will pick up where the oneOf failed,
then itself fail because all the digits were read by the many1 in range. To
prevent this, resetting to where tTimeHourMin started its parse, wrap it in
brandon s. allbery [linux,solaris,freebsd,perl] [hidden email] system administrator [openafs,heimdal,too many hats] [hidden email] electrical and computer engineering, carnegie mellon university KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/