On 10/12/09, Brandon S. Allbery KF8NH <[email protected]> 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] [email protected] > system administrator [openafs,heimdal,too many hats] [email protected] > electrical and computer engineering, carnegie mellon university KF8NH > > >
Ah, yes, I see where I went wrong; thank you! Uwe _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
