-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module that uses snakeyaml-engine, which only handles yaml 1.2 (#303
- Loading branch information
1 parent
9df6d5c
commit d3d0907
Showing
50 changed files
with
1,206 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ val Versions = new { | |
val scalaTest = "3.2.14" | ||
val scalaTestPlus = "3.2.11.0" | ||
val snakeYaml = "1.33" | ||
val snakeYamlEngine = "2.5" | ||
val previousCirceYamls = Set("0.14.0", "0.14.1", "0.14.2") | ||
} | ||
|
||
|
@@ -28,44 +29,92 @@ ThisBuild / crossScalaVersions := Seq("2.12.15", "2.13.8", "3.2.0") | |
|
||
val root = project | ||
.in(file(".")) | ||
.enablePlugins(GhpagesPlugin) | ||
// .settings(commonSettings) | ||
.settings( | ||
name := "circe-yaml", | ||
description := "Library for converting between SnakeYAML's AST and circe's AST", | ||
scalacOptions ++= compilerOptions, | ||
scalacOptions ++= { | ||
CrossVersion.partialVersion(scalaVersion.value) match { | ||
case Some((2, v)) if v <= 12 => | ||
Seq( | ||
"-Xfuture", | ||
"-Yno-adapted-args", | ||
"-Ywarn-unused-import" | ||
) | ||
case _ => | ||
Seq( | ||
"-Ywarn-unused:imports" | ||
) | ||
} | ||
}, | ||
Compile / console / scalacOptions ~= { | ||
_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports")) | ||
}, | ||
Test / console / scalacOptions ~= { | ||
_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports")) | ||
}, | ||
libraryDependencies ++= Seq( | ||
"io.circe" %% "circe-core" % Versions.circe, | ||
"io.circe" %% "circe-jawn" % Versions.circe % Test, | ||
"org.yaml" % "snakeyaml" % Versions.snakeYaml, | ||
"io.circe" %% "circe-testing" % Versions.circe % Test, | ||
"org.typelevel" %% "discipline-core" % Versions.discipline % Test, | ||
"org.scalacheck" %% "scalacheck" % Versions.scalaCheck % Test, | ||
"org.scalatest" %% "scalatest" % Versions.scalaTest % Test, | ||
"org.scalatestplus" %% "scalacheck-1-15" % Versions.scalaTestPlus % Test | ||
), | ||
mimaPreviousArtifacts := Versions.previousCirceYamls.map("io.circe" %% "circe-yaml" % _) | ||
name := "circe-yaml-root", | ||
publish / skip := true | ||
) | ||
.aggregate( | ||
`circe-yaml-common`, | ||
`circe-yaml`, | ||
`circe-yaml-v12` | ||
) | ||
.settings(publishSettings ++ docSettings) | ||
// .enablePlugins(GhpagesPlugin) | ||
|
||
lazy val `circe-yaml-common` = | ||
project | ||
.in(file("circe-yaml-common")) | ||
.settings(commonSettings) | ||
.settings( | ||
description := "Library for converting between SnakeYAML's AST (YAML 1.1) and circe's AST", | ||
libraryDependencies ++= Seq( | ||
"io.circe" %% "circe-core" % Versions.circe | ||
) | ||
) | ||
.enablePlugins(GhpagesPlugin) | ||
|
||
lazy val `circe-yaml` = | ||
project | ||
.in(file("circe-yaml")) | ||
.settings(commonSettings) | ||
.dependsOn(`circe-yaml-common`) | ||
.settings( | ||
description := "Library for converting between SnakeYAML's AST (YAML 1.1) and circe's AST", | ||
libraryDependencies ++= Seq( | ||
"org.yaml" % "snakeyaml" % Versions.snakeYaml, | ||
"io.circe" %% "circe-jawn" % Versions.circe % Test, | ||
"io.circe" %% "circe-testing" % Versions.circe % Test, | ||
"org.typelevel" %% "discipline-core" % Versions.discipline % Test, | ||
"org.scalacheck" %% "scalacheck" % Versions.scalaCheck % Test, | ||
"org.scalatest" %% "scalatest" % Versions.scalaTest % Test, | ||
"org.scalatestplus" %% "scalacheck-1-15" % Versions.scalaTestPlus % Test | ||
), | ||
mimaPreviousArtifacts := Versions.previousCirceYamls.map("io.circe" %% "circe-yaml" % _) | ||
) | ||
.enablePlugins(GhpagesPlugin) | ||
|
||
lazy val `circe-yaml-v12` = | ||
project | ||
.in(file("circe-yaml-v12")) | ||
.settings(commonSettings) | ||
.dependsOn(`circe-yaml-common`) | ||
.settings( | ||
description := "Library for converting between snakeyaml-engine's AST (YAML 1.2) and circe's AST", | ||
libraryDependencies ++= Seq( | ||
"io.circe" %% "circe-jawn" % Versions.circe % Test, | ||
"org.snakeyaml" % "snakeyaml-engine" % Versions.snakeYamlEngine, | ||
"io.circe" %% "circe-testing" % Versions.circe % Test, | ||
"org.typelevel" %% "discipline-core" % Versions.discipline % Test, | ||
"org.scalacheck" %% "scalacheck" % Versions.scalaCheck % Test, | ||
"org.scalatest" %% "scalatest" % Versions.scalaTest % Test, | ||
"org.scalatestplus" %% "scalacheck-1-15" % Versions.scalaTestPlus % Test | ||
) | ||
) | ||
.enablePlugins(GhpagesPlugin) | ||
|
||
lazy val commonSettings = List( | ||
scalacOptions ++= compilerOptions, | ||
scalacOptions ++= { | ||
CrossVersion.partialVersion(scalaVersion.value) match { | ||
case Some((2, v)) if v <= 12 => | ||
Seq( | ||
"-Xfuture", | ||
"-Yno-adapted-args", | ||
"-Ywarn-unused-import" | ||
) | ||
case _ => | ||
Seq( | ||
"-Ywarn-unused:imports" | ||
) | ||
} | ||
}, | ||
Compile / console / scalacOptions ~= { | ||
_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports")) | ||
}, | ||
Test / console / scalacOptions ~= { | ||
_.filterNot(Set("-Ywarn-unused-import", "-Ywarn-unused:imports")) | ||
} | ||
) ++ publishSettings ++ docSettings | ||
|
||
lazy val docSettings = Seq( | ||
autoAPIMappings := true, | ||
|
@@ -116,6 +165,7 @@ lazy val publishSettings = Seq( | |
ThisBuild / githubWorkflowJavaVersions := Seq("[email protected]") | ||
// No auto-publish atm. Remove this line to generate publish stage | ||
ThisBuild / githubWorkflowPublishTargetBranches := Seq.empty | ||
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false) | ||
ThisBuild / githubWorkflowBuild := Seq( | ||
WorkflowStep.Sbt( | ||
List("clean", "coverage", "test", "coverageReport", "scalastyle", "scalafmtCheckAll"), | ||
|
20 changes: 20 additions & 0 deletions
20
circe-yaml-common/src/main/scala/io/circe/yaml/common/Parser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.circe.yaml.common | ||
|
||
import cats.data.ValidatedNel | ||
import io.circe.{ Decoder, Error, Json, ParsingFailure } | ||
import java.io.Reader | ||
|
||
trait Parser extends io.circe.Parser { | ||
|
||
/** | ||
* Parse YAML from the given [[Reader]], returning either [[ParsingFailure]] or [[Json]] | ||
* | ||
* @param yaml | ||
* @return | ||
*/ | ||
def parse(yaml: Reader): Either[ParsingFailure, Json] | ||
def parseDocuments(yaml: Reader): Stream[Either[ParsingFailure, Json]] | ||
def parseDocuments(yaml: String): Stream[Either[ParsingFailure, Json]] | ||
def decode[A: Decoder](input: Reader): Either[Error, A] | ||
def decodeAccumulating[A: Decoder](input: Reader): ValidatedNel[Error, A] | ||
} |
33 changes: 33 additions & 0 deletions
33
circe-yaml-common/src/main/scala/io/circe/yaml/common/Printer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.circe.yaml.common | ||
|
||
import io.circe.Json | ||
|
||
trait Printer { | ||
def pretty(json: Json): String | ||
} | ||
|
||
object Printer { | ||
|
||
sealed trait FlowStyle | ||
object FlowStyle { | ||
case object Flow extends FlowStyle | ||
case object Block extends FlowStyle | ||
} | ||
|
||
sealed trait LineBreak | ||
object LineBreak { | ||
case object Unix extends LineBreak | ||
case object Windows extends LineBreak | ||
case object Mac extends LineBreak | ||
} | ||
|
||
sealed trait StringStyle | ||
object StringStyle { | ||
case object Plain extends StringStyle | ||
case object DoubleQuoted extends StringStyle | ||
case object SingleQuoted extends StringStyle | ||
case object Literal extends StringStyle | ||
case object Folded extends StringStyle | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
circe-yaml-v12/src/main/scala/io/circe/yaml/v12/Parser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.circe.yaml.v12 | ||
|
||
import io.circe.yaml.common | ||
import org.snakeyaml.engine.v2.api.LoadSettings | ||
|
||
object Parser { | ||
final case class Config( | ||
allowDuplicateKeys: Boolean = false, | ||
allowRecursiveKeys: Boolean = false, | ||
bufferSize: Int = 1024, | ||
label: String = "reader", | ||
maxAliasesForCollections: Int = 50, | ||
parseComments: Boolean = false, | ||
useMarks: Boolean = true | ||
) | ||
|
||
def make(config: Config = Config()): common.Parser = { | ||
import config._ | ||
new ParserImpl( | ||
LoadSettings.builder | ||
.setAllowDuplicateKeys(allowDuplicateKeys) | ||
.setAllowRecursiveKeys(allowRecursiveKeys) | ||
.setBufferSize(bufferSize) | ||
.setLabel(label) | ||
.setMaxAliasesForCollections(maxAliasesForCollections) | ||
.setParseComments(parseComments) | ||
.setUseMarks(useMarks) | ||
.build | ||
) | ||
} | ||
|
||
lazy val default: common.Parser = make() | ||
} |
Oops, something went wrong.