
5 Oct
2016
5 Oct
'16
12:57 p.m.
On 2016-10-05 08:32 AM, Lian Hung Hon wrote:
Dear cafe,
Given
data Expression = ExpToken String | ExpAnd Expression Expression
How to write an attoparsec parser that parses this example:
"a" and "b" and "c"
into
ExpAnd (ExpToken "a") (ExpAnd (ExpToken "b") (ExpToken "c"))?
You can use recursion at Haskell level: expParser = do left <- ExpToken <$> stringLiteral (string "|" *> (ExpAnd left <$> expParser) <|> pure left)