[Haskell-beginners] Parsec and Validation

Brandon S Allbery KF8NH allbery at ece.cmu.edu
Sat Jul 31 16:11:28 EDT 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 7/31/10 15:57 , Vladimir Solmon wrote:
> time :: Parser TimeOfDay
> time = choice [ tTimeHourMin,
>                           t24hrClock
>                        ]

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
a try:

> time = choice [ try tTimeHourMin
> 		, t24hrClock
> 		]

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      allbery at kf8nh.com
system administrator  [openafs,heimdal,too many hats]  allbery at ece.cmu.edu
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/

iEYEARECAAYFAkxUg28ACgkQIn7hlCsL25WvWwCfd+a9hGc2iS/Gxph+SjDKOuIg
L6cAoIbGGUojYjmruoo3vsiu9HGB8kMl
=cndm
-----END PGP SIGNATURE-----


More information about the Beginners mailing list