The parsley-cats library exposes cats instances for MonoidK[Parsley], Monad[Parsley], and FunctorFilter[Parsley] as well as Defer[Parsley].
Care should still be taken to not define truly recursive parsers using the cats API (although monadic parser with flatMap
may be generally recursive, just slow). In particular, make use of Defer[Parsley].fix
to handle recursion, or plain lazy val based construction (as in regular parsley use).
It also includes helpful combinators to integrate with cats abstractions, like non-empty datastructures
and Monoid/Semigroup.
Parsley cats is distributed on Maven Central, and can be added to your project via:
libraryDependencies += "com.github.j-mie6" %% "parsley-cats" % "1.5.0"it requires parsley and cats-core to also be dependencies of your project. The current version
matrix for parsley-cats:
parsley-cats version |
parsley version |
cats-core version |
|---|---|---|
0.1.x |
>= 4 && < 5 |
>= 2.8 && < 3 |
0.2.x |
>= 4 && < 5 |
>= 2.8 && < 3 |
1.0.x |
>= 4 && < 5 |
>= 2.8 && < 3 |
1.1.x |
>= 4 && < 5 |
>= 2.8 && < 3 |
1.2.x |
>= 4 && < 5 |
>= 2.8 && < 3 |
1.3.x |
>= 4.5 && <=5* |
>= 2.8 && < 3 |
1.4.x |
>= 4.5 && <=5* |
>= 2.8 && < 3 |
1.5.x |
>= 4.6 && <=5* |
>= 2.12 && < 3 |
(* parsley-5.x compatibility is not gauranteed, but is likely to still work, please report any issues)
To make use of your favourite cats syntax, you'll want the following imports:
import cats.syntax.all._
import parsley.cats.instances._Documentation can be found here
Parsley is a fast, modern, parser combinator library based loosely on Haskell's parsec and
megaparsec. For examples, see its repo and wiki!
The following are known conflicts between the syntactic extensions of cats and the base combinators on parsley. This only needs to be considered when writing concrete values of type Parsley[A]: combinators that rely on generic instances over a type F will use the cats version of the conflicting combinators.
- The
SemigroupKsyntax forcombineof<+>is incompatible withparsley, which defines<+>to be a combine combinator returningParsley[Either[A, B]]: thecatscombinator<+>is known inparsleyas<|>,orElse, or|.