let parseNumber = ws >>. number .>> eof

By on 8/7/2011 1:25 AM ()

When you run the parser

1
 (pint32 <|> pfloat)

on "1.0", the integer parser will succeed after having parsed "1" and the pfloat will never be tried.

The <|> operator doest not implement a longest match rule, and it only tries the second parser if the first parser hasn't consumed input before failing. This is explained in more detail here and here. So, if you want to parse alternative number formats, you either have to make sure that the parser for each individual number format can only parse numbers of its specific format and doesn't fail after consuming input, or -- when the number format allows for it -- build your parser with the help of FParsec's numberLiteral parser.

By on 8/7/2011 4:24 AM ()

Thanks Stephan. That makes sense, I will see if I can rewrite the rules to account for that. ;)

By on 8/7/2011 9:47 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper