Neil Mitchell schrieb:
> 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?
I suppose "names" or "try names" succeeds without consuming input, but
calling parsecQuery fails for another reason that you haven't shown,
C.
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe