Why does this piece of code yield a parse exception, when using parsec, but not with Graham Huttons simple example library?

Viewed 97

I recently tried to get into parsec, and I stumbled upon a Video that explained the basics of functional parsing. A simple demo library was shown, whose syntax looked similar to parsec. Function composition worked very similar. This snippet worked correctly with the library. Yet, if I run this piece of code with parsec, it gives me a parse error, (unexpected character)

module P where

import Text.ParserCombinators.Parsec

int :: Parser Int
int = do
    x <- many digit
    return (read x)

expr = do
    x <- term
    char '+'
    y <- expr
    return (x+y)
  <|> term

term = do
    x <- factor
    char '*'
    y <- term
    return (x*y)
  <|> factor

factor = do
    char '('
    x <- expr
    char ')'
    return x
  <|> int

I don't quiet understand where the difference is

0 Answers
Related