Skip to content

Commit

Permalink
Further work on SExpr (#3)
Browse files Browse the repository at this point in the history
* Working through s-expression things

* Mirror/sexpr scala2 (#1)

adding rest of files + scala2-ify

Co-authored-by: Damian Reeves <[email protected]>

* PROM-12590: adding JavaTimeSpec test (#2)

* Adding additional decoders and support (#3)

* Added additional decoder support

* added primitives

* adding decoders for java.time and some others

* decoder - adding operators and more tests

* uncommenting and fixing decoder tests in JavaTimeSpec

Co-authored-by: Damian Reeves <[email protected]>

Co-authored-by: Michelle <[email protected]>
Co-authored-by: Dmitry Kozinets <[email protected]>
Co-authored-by: Dmitry Kozinets <[email protected]>
  • Loading branch information
4 people authored Jan 14, 2022
1 parent afbc985 commit 8cd6463
Show file tree
Hide file tree
Showing 10 changed files with 6,108 additions and 54 deletions.
36 changes: 35 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,41 @@ lazy val sexpr = crossProject(JSPlatform, JVMPlatform, NativePlatform)
libraryDependencies ++= Seq(
"dev.zio" %%% "zio" % Version.zio,
"dev.zio" %%% "zio-test" % Version.zio % Test
)
),
Compile / sourceGenerators += Def.task {
val dir = (Compile / sourceManaged).value
val file = dir / "zio" / "morphir" / "sexpr" / "GeneratedTupleDecoders.scala"
val decoders = (1 to 22).map { i =>
val tparams = (1 to i).map(p => s"A$p").mkString(", ")
val implicits = (1 to i).map(p => s"A$p: SExprDecoder[A$p]").mkString(", ")
val work = (1 to i)
.map(p => s"val a$p = A$p.unsafeDecode(trace :+ traces($p), in)")
.mkString("\n Lexer.char(trace, in, ',')\n ")
val returns = (1 to i).map(p => s"a$p").mkString(", ")

s"""implicit def tuple$i[$tparams](implicit $implicits): SExprDecoder[Tuple$i[$tparams]] =
| new SExprDecoder[Tuple$i[$tparams]] {
| val traces: Array[SExprError] = (0 to $i).map(SExprError.IndexedAccess(_)).toArray
| def unsafeDecode(trace: List[SExprError], in: RetractReader): Tuple$i[$tparams] = {
| Lexer.char(trace, in, '[')
| $work
| Lexer.char(trace, in, ']')
| Tuple$i($returns)
| }
| }""".stripMargin
}
IO.write(
file,
s"""package zio.morphir.sexpr
|
|import zio.morphir.sexpr.internal._
|
|private[sexpr] trait GeneratedTupleDecoders { this: SExprDecoder.type =>
| ${decoders.mkString("\n\n ")}
|}""".stripMargin
)
Seq(file)
}.taskValue
)
.enablePlugins(BuildInfoPlugin)

Expand Down
Loading

0 comments on commit 8cd6463

Please sign in to comment.