[Haskell-cafe] attpoarsec and recursive parsing

Olaf Klinke olf at aatal-apotheke.de
Sun Oct 27 14:46:19 UTC 2024


Hi Frederic,

Essentially, the '|' character acts like a binary operator in parsing
arithmetical expression trees. To that end, the most ergonomic module I
know of is provided by parsec [1], which has a port [2] to attoparsec.

You have to decide whether the '|' operator should be left- or right-
associative. That question vanishes if you decide to re-design your
data type as

data MaskLocation = MaskLocation Text
                  | MaskLocation'Tmpl Text
                  | MaskLocation'Or (NonEmpty MaskLocation)

and use the sepBy1 combinator. Also you should think about whether and
how to escape the separator Char inside ordinary MaskLocation strings.

Olaf

[1] https://hackage.haskell.org/package/parsec-3.1.17.0/docs/Text-ParserCombinators-Parsec-Expr.html
[2] https://hackage.haskell.org/package/attoparsec-expr





More information about the Haskell-Cafe mailing list