Skip to content

Commit

Permalink
Fix jq interpolator for Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
satabin committed Sep 26, 2023
1 parent bd9c1bd commit 2b35983
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions json/src/main/scala-3/fs2/data/json/jq/literals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ package object literals {
}
}

given ToExpr[Filter] with {
def apply(f: Filter)(using Quotes) =
given ToExpr[SimpleFilter] with {
def apply(f: SimpleFilter)(using Quotes) =
f match {
case Jq.Root => '{ Jq.Root }
case Jq.Identity => '{ Jq.Identity }
Expand All @@ -51,8 +51,15 @@ package object literals {
case Jq.Slice(idx1, idx2) => '{ Jq.Slice(${ Expr(idx1) }, ${ Expr(idx2) }) }
case Jq.Child => '{ Jq.Child }
case Jq.RecursiveDescent => '{ Jq.RecursiveDescent }
}
}

given ToExpr[Filter] with {
def apply(f: Filter)(using Quotes) =
f match {
case Jq.Sequence(qs) =>
'{ Jq.Sequence(NonEmptyChain.fromNonEmptyList(${ Expr(qs.toNonEmptyList) })) }
case simple: SimpleFilter => Expr(simple)
}
}

Expand Down
2 changes: 1 addition & 1 deletion json/src/main/scala/fs2/data/json/jq/ast.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object Jq {
final case class Index(idx: Int) extends SimpleFilter
final case class Slice(start: Int, end: Option[Int]) extends SimpleFilter
case object RecursiveDescent extends SimpleFilter
private[jq] final case object Child extends SimpleFilter
private[jq] case object Child extends SimpleFilter
final case class Sequence(jqs: NonEmptyChain[SimpleFilter]) extends Filter

final case class Iterator(filter: Filter, inner: Jq) extends Jq
Expand Down

0 comments on commit 2b35983

Please sign in to comment.