[Haskell-cafe] Parsec bug, or...?
uhollerbach at gmail.com
Mon Oct 12 22:49:21 EDT 2009
On 10/12/09, Brandon S. Allbery KF8NH <allbery at ece.cmu.edu> wrote:
> On Oct 12, 2009, at 22:28 , Uwe Hollerbach wrote:
>> parsePrefixOf n str =
>> string (take n str) >> opts (drop n str) >> return str
>> where opts  = return ()
>> opts (c:cs) = optional (char c >> opts cs)
> Seems to me this will succeed as soon as it possibly can...
>> myTest = myPrefixOf 1 "banana"
>> <|> myPrefixOf 1 "chocolate"
>> <|> TPCP.try (myPrefixOf 2 "frito")
>> <|> myPrefixOf 3 "fromage"
> ...so the "frito" branch gets committed as soon as "fr" is read/parsed
> (myTest returns)...
>> % ./opry fro
>> "test" (line 1, column 3):
>> unexpected "o"
>> expecting "i", white space or end of input
> ...which is why this is looking for "white space or end of input".
> My fix would be to have myPrefixOf require the prefix be terminated in
> whatever way is appropriate (end of input, white space, operator?)
> instead of simply accepting as soon as it gets a prefix match
> regardless of what follows.
> brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
> system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
> electrical and computer engineering, carnegie mellon university KF8NH
Ah, yes, I see where I went wrong; thank you!
More information about the Haskell-Cafe