From 0802a19213c5a794e9523fe95f510973292cfb30 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Wed, 11 Dec 2024 22:36:01 +0100 Subject: [PATCH 1/2] Bump cats-parse 1.1.0 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index a0ee07d1..233e335b 100644 --- a/build.sbt +++ b/build.sbt @@ -36,7 +36,7 @@ lazy val scalachess: Project = Project("scalachess", file("core")).settings( "org.lichess" %% "scalalib-core" % scalalibVersion, "org.typelevel" %% "cats-core" % "2.12.0", "org.typelevel" %% "alleycats-core" % "2.12.0", - "org.typelevel" %% "cats-parse" % "1.0.0", + "org.typelevel" %% "cats-parse" % "1.1.0", "dev.optics" %% "monocle-core" % "3.3.0", "org.typelevel" %% "kittens" % "3.4.0" ), From c5f80bd4cd658ad7152063e92996ce4a1f55b507 Mon Sep 17 00:00:00 2001 From: Thanh Le Date: Wed, 11 Dec 2024 22:37:20 +0100 Subject: [PATCH 2/2] Use new DefaultParser0 typeclass --- test-kit/src/test/scala/perft/Parser.scala | 7 +++---- test-kit/src/test/scala/perft/Perft.scala | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/test-kit/src/test/scala/perft/Parser.scala b/test-kit/src/test/scala/perft/Parser.scala index 25cda5ba..b7b4d059 100644 --- a/test-kit/src/test/scala/perft/Parser.scala +++ b/test-kit/src/test/scala/perft/Parser.scala @@ -1,7 +1,7 @@ package chess package perft -import cats.parse.{ Numbers as N, Parser as P, Parser0 as P0, Rfc5234 as R } +import cats.parse.{ DefaultParser0, Numbers as N, Parser as P, Parser0 as P0, Rfc5234 as R } import cats.syntax.all.* import chess.format.FullFen @@ -20,8 +20,7 @@ import chess.format.FullFen * */ -object Parser: - def parse: String => Either[P.Error, List[Perft]] = perfts.parseAll +object Parser extends DefaultParser0[List[Perft]]: private val whitespace = R.cr | R.lf | R.wsp private val blank = P.until(!whitespace) @@ -37,7 +36,7 @@ object Parser: private val oneTestCase: P[TestCase] = P.string("perft ") *> testCase <* R.lf.? private val cases: P[List[TestCase]] = oneTestCase.rep.map(_.toList) <* (ignored.rep | R.lf.rep0) private val perft: P[Perft] = (id, epd, cases).mapN(Perft.apply) <* R.lf.? - private val perfts: P0[List[Perft]] = ignored.rep0 *> perft.rep.map(_.toList) + def parser0: P0[List[Perft]] = ignored.rep0 *> perft.rep.map(_.toList) extension (p: P0[Any]) private def endWith(p1: P[Any]): P[String] = p.with1 *> (p1.string | (P.until(p1) <* p1)) diff --git a/test-kit/src/test/scala/perft/Perft.scala b/test-kit/src/test/scala/perft/Perft.scala index 78d9e047..0d904e41 100644 --- a/test-kit/src/test/scala/perft/Perft.scala +++ b/test-kit/src/test/scala/perft/Perft.scala @@ -41,7 +41,7 @@ object Perft: private def read(file: String): List[Perft] = import cats.implicits.toShow val str = io.Source.fromResource(file).mkString - Parser.parse(str).fold(ex => throw RuntimeException(s"Parsing error: $file: ${ex.show}"), identity) + Parser.parseAll(str).fold(ex => throw RuntimeException(s"Parsing error: $file: ${ex.show}"), identity) def printResult(results: List[DivideResult]) = val builder = StringBuilder()