[Haskell-cafe] Parsec problem
Neil Mitchell
ndmitchell at gmail.com
Tue Jun 5 17:19:10 EDT 2007
Hi,
I'm using parsec to parse something which is either a "name" or a
"type". The particular test string I'm using is a type, but isn't a
name. I want things to default to "name" before "type".
Some examples of the parsec function, and the result when applied to a
test string:
> parsecQuery = do spaces ; types
Right Query {scope = [], names = [], typeSig = Just [a], items = [], flags = []}
> parsecQuery = do spaces ; names
Left (line 1, column 1):
unexpected "["
expecting white space, "--", "/", "(", letter, "::" or end of input
> parsecQuery = do spaces ; try names <|> types
Left (line 1, column 1):
unexpected "["
expecting white space, "--", "/", "(", letter, "::" or end of input
I would have expected try names <|> types to return a Right (since
types matches), but it doesn't. I assumed this would be a property of
Parsec, but it doesn't appear to hold. Can anyone shed any light?
Thanks
Neil
More information about the Haskell-Cafe
mailing list