Skip to content

Commit

Permalink
Merge pull request #603 from lenguyenthanh/cats-parse-1.1.0
Browse files Browse the repository at this point in the history
Cats parse 1.1.0
  • Loading branch information
lenguyenthanh authored Dec 11, 2024
2 parents 09ea601 + c5f80bd commit b626b3d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
),
Expand Down
7 changes: 3 additions & 4 deletions test-kit/src/test/scala/perft/Parser.scala
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion test-kit/src/test/scala/perft/Perft.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit b626b3d

Please sign in to comment.