[Haskell-cafe] Parsec : parse either an interger or a double?

Fredrik Karlsson dargosch at gmail.com
Sun Jul 7 13:57:19 CEST 2013


Dear list,

Sorry for asking you another parsec question. I have  a text file that is
the output of a C/C++ program, involving time references in double format.
Now, the program seems to truncate the output if possible, so a file that
is one second long will produce this file:

File type = "ooTextFile"
Object class = "TextGrid"

xmin = 0
xmax = 1
....

and a file that is 1.1 seconds long will be this:

File type = "ooTextFile"
Object class = "TextGrid"

xmin = 0
xmax = 1.1
...

Now, how do I handle this case in parsec?

I have tried this:

start <- try (float haskellDef)
<|>  fmap ( / 1.0 ) $ integer haskelldef

and similar solutions, but I cant get it to accept the 0.

/Fredrik

-- 
"Life is like a trumpet - if you don't put anything into it, you don't get
anything out of it."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130707/096b34f2/attachment.htm>


More information about the Haskell-Cafe mailing list