I play Parsec with an incomplete parser for a language like Haskell.
It seems to work correctly, although I am not happy with the error message.
- Input:
"foo (bar" - Error:
expecting letter or digit, operand or ")"
How can I make it print only expecting operand or ")" ? I tried adding <?> , But can't get it to work.
Here is my code:
separator = skipMany1 space <?> "" identifier :: Parser String identifier = (:) <$> letter <*> many alphaNum <?> "identifier" number :: Parser String number = many1 digit <?> "numeric literal" primitiveExpr :: Parser String primitiveExpr = (identifier <|> number) <?> "primitive expression" expr :: Parser () expr = do identifier spaces <?> "" sepBy operand separator return () parenExpr :: Parser String parenExpr = do char '(' expr char ')' return "foo" <?> "parenthesized expression" operand = parenExpr <|> primitiveExpr <?> "operand"
source share