Skip to content

Commit

Permalink
Documentation complete
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Dec 19, 2022
1 parent 4178090 commit 0e3fca7
Show file tree
Hide file tree
Showing 11 changed files with 563 additions and 338 deletions.
13 changes: 6 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,20 @@ inThisBuild(List(
developers := List(
tlGitHubDev("j-mie6", "Jamie Willis")
),
tlSonatypeUseLegacyHost := true,
//tlFatalWarningsInCi := false,
versionScheme := Some("early-semver"),
crossScalaVersions := Seq(Scala213, Scala212, Scala3),
scalaVersion := Scala213,
// CI Configuration
tlCiReleaseBranches := Seq("master"),
tlCiReleaseBranches := Seq(/*"master"*/), // TODO: enable when we are ready for first release!
tlSonatypeUseLegacyHost := true, // this needs to be switched off when we migrate parsley to the other server too
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"), JavaSpec.temurin("11"), JavaSpec.temurin("17")),
))

lazy val root = tlCrossRootProject.aggregate(core)
lazy val root = tlCrossRootProject.aggregate(`parsley-cats`)

lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("core"))
lazy val `parsley-cats` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("parsley-cats"))
.settings(
name := projectName,
libraryDependencies ++= Seq(
Expand Down
279 changes: 0 additions & 279 deletions core/src/main/scala/parsley/cats.scala

This file was deleted.

File renamed without changes.
File renamed without changes.
206 changes: 206 additions & 0 deletions parsley-cats/shared/src/main/scala/parsley/ApplicativeForParsley.scala

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* SPDX-FileCopyrightText: © 2022 Parsley Cats Contributors <https://github.com/j-mie6/parsley-cats/graphs/contributors>
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley

import cats.{Functor, FunctorFilter}

private [parsley] trait FilterFunctorForParsley extends FunctorFilter[Parsley] { self: Functor[Parsley] =>
override def functor: Functor[Parsley] = this

override def mapFilter[A, B](mx: Parsley[A])(f: A => Option[B]): Parsley[B] = mx.mapFilter(f)

// FunctorFilter Overrides
override def filter[A](mx: Parsley[A])(f: A => Boolean): Parsley[A] = mx.filter(f)
override def filterNot[A](mx: Parsley[A])(f: A => Boolean): Parsley[A] = mx.filterNot(f)
override def collect[A, B](mx: Parsley[A])(f: PartialFunction[A,B]): Parsley[B] = mx.collect(f)
}
12 changes: 12 additions & 0 deletions parsley-cats/shared/src/main/scala/parsley/FunctorForParsley.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* SPDX-FileCopyrightText: © 2022 Parsley Cats Contributors <https://github.com/j-mie6/parsley-cats/graphs/contributors>
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley

import cats.Functor

private [parsley] trait FunctorForParsley extends Functor[Parsley] {
override def map[A, B](mx: Parsley[A])(f: A => B): Parsley[B] = mx.map(f)
override def as[A, B](mx: Parsley[A], y: B): Parsley[B] = mx #> y
override def void[A](mx: Parsley[A]): Parsley[Unit] = mx.void
}
60 changes: 60 additions & 0 deletions parsley-cats/shared/src/main/scala/parsley/MonadForParsley.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* SPDX-FileCopyrightText: © 2022 Parsley Cats Contributors <https://github.com/j-mie6/parsley-cats/graphs/contributors>
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley

import cats.{Monad, Alternative}
import registers._

private [parsley] trait MonadForParsley extends Monad[Parsley] {
override def flatMap[A, B](mx: Parsley[A])(f: A => Parsley[B]): Parsley[B] = mx.flatMap(f)

override def tailRecM[A, B](x: A)(f: A => Parsley[Either[A, B]]): Parsley[B] = f(x).flatMap {
case Left(nextX) => tailRecM(nextX)(f)
case Right(y) => Parsley.pure(y)
}

// Monad Overrides
override def ifM[B](mx: Parsley[Boolean])(ifTrue: => Parsley[B], ifFalse: => Parsley[B]): Parsley[B] = combinator.ifP(mx, ifTrue, ifFalse)
override def whileM_[A](p: Parsley[Boolean])(body: =>Parsley[A]): Parsley[Unit] = {
combinator.when(p, combinator.whileP(body ~> p))
}
override def untilM_[A](body: Parsley[A])(p: => Parsley[Boolean]): Parsley[Unit] = combinator.whileP(body *> p.map(!_))

override def whileM[G[_]: Alternative, A](p: Parsley[Boolean])(body: => Parsley[A]): Parsley[G[A]] = {
val G = implicitly[Alternative[G]]
G.empty[A].makeReg { acc =>
whileM_(p) {
acc.modify(body.map(x => (xs: G[A]) => G.appendK(xs, x)))
} *> acc.get
}
}

override def untilM[G[_]: Alternative, A](body: Parsley[A])(cond: => Parsley[Boolean]): Parsley[G[A]] = {
val G = implicitly[Alternative[G]]
map2(body, whileM(cond)(body))(G.prependK(_, _))
}

override def untilDefinedM[A](mox: Parsley[Option[A]]): Parsley[A] = {
lazy val loop: Parsley[A] = combinator.decide(mox, loop)
loop
}

override def iterateUntil[A](mx: Parsley[A])(p: A => Boolean): Parsley[A] = {
lazy val loop: Parsley[A] = mx.persist { mx =>
combinator.ifP(mx.map(p), mx, loop)
}
loop
}
override def iterateWhile[A](mx: Parsley[A])(p: A => Boolean): Parsley[A] = {
lazy val loop: Parsley[A] = mx.persist { mx =>
combinator.ifP(mx.map(p), loop, mx)
}
loop
}
override def ifElseM[A](branches: (Parsley[Boolean], Parsley[A])*)(els: Parsley[A]): Parsley[A] = {
branches.foldRight(els) {
case ((cond, t), e) => combinator.ifP(cond, t, e)
}
}
}
23 changes: 23 additions & 0 deletions parsley-cats/shared/src/main/scala/parsley/cats.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-FileCopyrightText: © 2022 Parsley Cats Contributors <https://github.com/j-mie6/parsley-cats/graphs/contributors>
* SPDX-License-Identifier: BSD-3-Clause
*/
package parsley

import cats.{Monad, MonoidK, FunctorFilter}

/** Contains instances for `cats` typeclasses.
*
* @since 0.1.0
*/
object catsinstances {
/** Instance for the core `cats` typeclasses used with parser combinators.
*
* @since 0.1.0
*/
implicit val monadPlusForParsley: Monad[Parsley] with MonoidK[Parsley] with FunctorFilter[Parsley] =
// This must be kept in this ordering, with more generic further up
new MonadForParsley with ApplicativeForParsley
with FunctorForParsley
with MonoidKForParsley
with FilterFunctorForParsley
}
52 changes: 0 additions & 52 deletions rootdoc.md

This file was deleted.

0 comments on commit 0e3fca7

Please sign in to comment.