Skip to content

Commit

Permalink
Merge branch 'main' into update/scala-library-2.13.13
Browse files Browse the repository at this point in the history
  • Loading branch information
johnynek committed Apr 18, 2024
2 parents 1fb7ce6 + be1d37a commit e292034
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
@@ -1,4 +1,4 @@
version = "3.8.0"
version = "3.8.1"

runner.dialect = scala213

Expand Down
10 changes: 6 additions & 4 deletions build.sbt
Expand Up @@ -5,10 +5,11 @@ val scala212 = "2.12.19"
val scala213 = "2.13.13"
val scala3 = "3.3.3"

addCommandAlias("fmt", "; scalafmtAll; scalafmtSbt")
addCommandAlias("fmtCheck", "; scalafmtCheckAll; scalafmtSbtCheck")

tlReplaceCommandAlias("prePR", "; githubWorkflowGenerate ; +fmt; bench/compile; +test")
GlobalScope / tlCommandAliases ++= Map(
"fmt" -> List("scalafmtAll", "scalafmtSbt"),
"fmtCheck" -> List("scalafmtCheckAll", "scalafmtSbtCheck"),
"prePR" -> List("githubWorkflowGenerate", "+fmt", "bench/compile", "+test")
)

ThisBuild / tlBaseVersion := "1.0"
// continue enforcing bincompat with 0.3.x series
Expand Down Expand Up @@ -121,6 +122,7 @@ lazy val bench = project
.settings(
name := "bench",
coverageEnabled := false,
scalacOptions += "-Wconf:cat=unused-nowarn:s",
Compile / unmanagedSources := {
if (Set("2.12", "2.13").contains(scalaBinaryVersion.value)) {
(Compile / unmanagedSources).value
Expand Down
63 changes: 63 additions & 0 deletions core/shared/src/main/scala/cats/parse/DefaultParser.scala
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2021 Typelevel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cats.parse

/** Typeclass for "has a Parser"
*
* This is primarily provided to help keep track of `Parser` instances, and as such the omission of
* a `cats.Functor` instance is intentional.
* @tparam A
*/
trait DefaultParser[+A] {
def parser: Parser[A]

/** Pass through to equivalent method on `Parser`
* @see
* [[Parser.parse]]
*/
def parse(string: String): Either[Parser.Error, (String, A)] = parser.parse(string)

/** Pass through to equivalent method on `Parser`
* @see
* [[Parser.parseAll]]
*/
def parseAll(string: String): Either[Parser.Error, A] = parser.parseAll(string)
}
object DefaultParser {
def apply[A](implicit P: DefaultParser[A]): P.type = P

def instance[A](p: Parser[A]): DefaultParser[A] = new Impl[A](p)

private final class Impl[+A](override val parser: Parser[A])
extends DefaultParser[A]
with Serializable

object syntax {
implicit final class DefaultParserOps(private val raw: String) extends AnyVal {
def parse[A: DefaultParser]: Either[Parser.Error, (String, A)] =
DefaultParser[A].parser.parse(raw)

def parseAll[A: DefaultParser]: Either[Parser.Error, A] =
DefaultParser[A].parser.parseAll(raw)
}
}
}
66 changes: 66 additions & 0 deletions core/shared/src/main/scala/cats/parse/DefaultParser0.scala
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2021 Typelevel
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package cats.parse

/** Typeclass for "has a Parser0"
*
* This is primarily provided to help keep track of `Parser0` instances, and as such the omission
* of a `cats.Functor` instance is intentional.
* @tparam A
*/
trait DefaultParser0[+A] {
def parser0: Parser0[A]

/** Pass through to equivalent method on `Parser0`
* @see
* [[Parser0.parse]]
*/
def parse(string: String): Either[Parser.Error, (String, A)] = parser0.parse(string)

/** Pass through to equivalent method on `Parser0`
* @see
* [[Parser0.parseAll]]
*/
def parseAll(string: String): Either[Parser.Error, A] = parser0.parseAll(string)
}
object DefaultParser0 {
def apply[A](implicit P: DefaultParser0[A]): P.type = P

def instance[A](p: Parser0[A]): DefaultParser0[A] = new Impl[A](p)

private final class Impl[+A](override val parser0: Parser0[A])
extends DefaultParser0[A]
with Serializable

object syntax {
implicit final class DefaultParser0Ops(private val raw: String) extends AnyVal {
def parse[A: DefaultParser0]: Either[Parser.Error, (String, A)] =
DefaultParser0[A].parser0.parse(raw)

def parseAll[A: DefaultParser0]: Either[Parser.Error, A] =
DefaultParser0[A].parser0.parseAll(raw)
}
}

implicit def defaultParserIsDefaultParser0[A: DefaultParser]: DefaultParser0[A] =
DefaultParser0.instance(DefaultParser[A].parser)
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Expand Up @@ -6,7 +6,7 @@ object Dependencies {
lazy val cats211 = Def.setting("org.typelevel" %%% "cats-core" % "2.0.0")
lazy val munit = Def.setting("org.scalameta" %%% "munit" % "1.0.0-M10")
lazy val munitScalacheck = Def.setting("org.scalameta" %%% "munit-scalacheck" % "1.0.0-M10")
lazy val fastParse = "com.lihaoyi" %% "fastparse" % "2.3.3"
lazy val fastParse = "com.lihaoyi" %% "fastparse" % "3.1.0"
lazy val parsley = "org.http4s" %% "parsley" % "1.5.0-M3"
lazy val jawnAst = Def.setting("org.typelevel" %% "jawn-ast" % "1.5.1")
lazy val jawnAst211 = Def.setting("org.typelevel" %% "jawn-ast" % "1.0.0-RC2")
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
@@ -1,6 +1,6 @@
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.15.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.7")
Expand Down

0 comments on commit e292034

Please sign in to comment.