[Haskell-cafe] Parsec bug, or...?
Brandon S. Allbery KF8NH
allbery at ece.cmu.edu
Mon Oct 12 22:36:28 EDT 2009
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20091012/78f4820d/PGP.bin
More information about the Haskell-Cafe
mailing list