https://github.com/j-mie6/parsley-cats
Typeclass instances for `parsley` to make it compatible with `cats`
https://github.com/j-mie6/parsley-cats
cats parser parser-combinators scala
Last synced: 10 months ago
JSON representation
Typeclass instances for `parsley` to make it compatible with `cats`
- Host: GitHub
- URL: https://github.com/j-mie6/parsley-cats
- Owner: j-mie6
- License: bsd-3-clause
- Created: 2022-07-03T09:27:28.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-18T10:34:59.000Z (over 1 year ago)
- Last Synced: 2025-04-24T03:32:00.222Z (about 1 year ago)
- Topics: cats, parser, parser-combinators, scala
- Language: Scala
- Homepage:
- Size: 109 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Parsley Cats  [](https://index.scala-lang.org/j-mie6/parsley-cats/parsley-cats) [](https://github.com/j-mie6/parsley-cats/blob/master/LICENSE)   [![Badge-Scaladoc]][Link-Scaladoc]  
## What is `parsley-cats`?
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`.
## How do I use it? [](https://index.scala-lang.org/j-mie6/parsley-cats/parsley-cats) [](https://index.scala-lang.org/j-mie6/parsley-cats/parsley-cats) [](https://index.scala-lang.org/j-mie6/parsley-cats/parsley-cats)
Parsley cats is distributed on Maven Central, and can be added to your project via:
```scala
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:
```scala
import cats.syntax.all._
import parsley.cats.instances._
```
Documentation can be found [**here**][Link-Scaladoc]
## What is `parsley`?
[Parsley](https://github.com/j-mie6/parsley) is a fast, modern, parser combinator library based loosely on Haskell's `parsec` and
`megaparsec`. For examples, see its repo and wiki!
## Known Incompatiblities
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 `SemigroupK` syntax for `combine` of `<+>` is incompatible with `parsley`, which defines
`<+>` to be a combine combinator returning `Parsley[Either[A, B]]`: the `cats` combinator `<+>` is known in `parsley` as `<|>`, `orElse`, or `|`.
[Link-Scaladoc]: https://javadoc.io/doc/com.github.j-mie6/parsley-cats_2.13/latest/index.html
[Badge-Scaladoc]: https://img.shields.io/badge/documentation-available-green