[Haskell-cafe] Recursive attoparsec

Albert Y. C. Lai trebla at vex.net
Wed Oct 5 16:15:07 UTC 2016

On 2016-10-05 08:32 AM, Lian Hung Hon wrote:
> 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"))?

Consider using sepBy1 to obtain ["a", "b", "c"] first. Then you're just 
a foldr away.

More information about the Haskell-Cafe mailing list