Skip to content

Commit 4d03782

Browse files
committed
Make using lifted more uniform across scala versions
Specifically, make both versions of LiftFunction and LiftedInterpolator have the same type parameters so cross-compiled dependencies can share sources when passing around values of those types
1 parent d3db69f commit 4d03782

File tree

8 files changed

+26
-23
lines changed

8 files changed

+26
-23
lines changed

Base/src/main/scala-2/VersionSpecificInterpolator.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,17 @@ trait VersionSpecificInterpolatorModule {
8383
* Create a Interpolators that can parse Exprs belonging to the specified Context
8484
* @group InterpolatorGroup
8585
*/
86-
def contextInterpolators(c:Context):Interpolator.Interpolators[c.Expr, c.universe.Liftable, c.TypeTag] with LiftedInterpolator[c.type] = {
86+
def contextInterpolators(c:Context):Interpolator.Interpolators[c.Expr, c.universe.Liftable, c.TypeTag] with LiftedInterpolator[c.Expr, c.TypeTag] = {
8787
new Interpolator.Interpolators[c.Expr, c.universe.Liftable, c.TypeTag]
8888
with ExprIndependentInterpolators[c.Expr[Any]]
89-
with LiftedInterpolator[c.type] {
89+
with LiftedInterpolator[c.Expr, c.TypeTag] {
9090
override def `lazy`[A](fn:Function0[Interpolator[A]]):Interpolator[A] =
9191
new Interpolator[A](internal.DelayedConstruction.interpolator(fn))
9292

9393
override def ofType[A](implicit tpe: c.TypeTag[A]): Interpolator[c.Expr[A]] =
9494
new Interpolator[c.Expr[A]](new internal.OfType[c.type, A](tpe))
9595

96-
override def lifted[Lifter[_], Z](lift:LiftFunction[c.type, Lifter, Z], description:String)(implicit lifterTypeTag:c.TypeTag[Lifter[_]]):Interpolator[Z] =
96+
override def lifted[Lifter[_], Z](lift:LiftFunction[c.Expr, c.TypeTag, Lifter, Z], description:String)(implicit lifterTypeTag:c.TypeTag[Lifter[_]]):Interpolator[Z] =
9797
new Interpolator[Z](internal.Lifted(c)(lift, ExpectingDescription(description)))
9898
}
9999
}
@@ -102,13 +102,13 @@ trait VersionSpecificInterpolatorModule {
102102
*
103103
* @group InterpolatorGroup
104104
*/
105-
trait LiftedInterpolator[C <: Context with Singleton] {
105+
trait LiftedInterpolator[Expr[+_], Type[_]] {
106106
/**
107107
* A parser that succeeds if the next part of the in put is an `arg` and Lifter parameterized on `arg`'s type can be implicitly summoned
108108
*
109109
* The implicitly summoned value and the `arg` value are passed to `lift`; the returned value is returned by this parser
110110
* @group Arg
111111
*/
112-
def lifted[Lifter[_], Z](lift:LiftFunction[C, Lifter, Z], description:String)(implicit lifterTypeTag:C#TypeTag[Lifter[_]]):SCInterpolator[C#Expr[Any], Z]
112+
def lifted[Lifter[_], Z](lift:LiftFunction[Expr, Type, Lifter, Z], description:String)(implicit lifterTypeTag:Type[Lifter[_]]):SCInterpolator[Expr[Any], Z]
113113
}
114114
}

Base/src/main/scala-2/internal/Lifted.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private[stringContextParserCombinator]
77
object Lifted {
88
def apply[Lifter[_], Z](
99
c:Context)(
10-
lift:LiftFunction[c.type, Lifter, Z],
10+
lift:LiftFunction[c.Expr, c.TypeTag, Lifter, Z],
1111
description:ExpectingDescription
1212
)(implicit lifterTypeTag:c.TypeTag[Lifter[_]]
1313
):Interpolator[c.Expr[_], Z] = {

Base/src/main/scala-2/package.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,7 @@ package object stringContextParserCombinator {
8383

8484
package stringContextParserCombinator {
8585
/** Support for Interpolator.contextInterpolators.lifted; represents a macro-level function that combines a CC[A] and an A. */
86-
trait LiftFunction[U <: Context with Singleton, -CC[_], +Z] {def apply[A](lifter:U#Expr[CC[A]], elem:U#Expr[A]):Z}
86+
trait LiftFunction[Expr[+_], Type[_], -CC[_], +Z] {
87+
def apply[A](lifter:Expr[CC[A]], elem:Expr[A]):Z
88+
}
8789
}

Base/src/main/scala-3/VersionSpecificInterpolator.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,26 @@ trait VersionSpecificInterpolatorModule extends ExprIndependentInterpolators[Any
6868
* The implicitly summoned value and the `arg` value are passed to `lift`; the returned value is returned by this parser
6969
* @group Arg
7070
*/
71-
def lifted[Lifter[_], Z](lift:LiftFunction[Lifter, Z], description:String)(using Quotes, Type[Lifter]):SCInterpolator[Expr[Any], Z] =
71+
def lifted[Lifter[_], Z](lift:LiftFunction[Expr, Type, Lifter, Z], description:String)(using Quotes, Type[Lifter]):SCInterpolator[Expr[Any], Z] =
7272
new SCInterpolator(internal.Lifted(lift, ExpectingDescription(description)))
7373

7474

7575
/**
7676
* Create an Interpolators that can parse `quoted.Expr`s
7777
* @group InterpolatorGroup
7878
*/
79-
def quotedInterpolators(using Quotes):Interpolator.Interpolators[quoted.Expr, quoted.ToExpr, quoted.Type] & LiftedInterpolator = {
79+
def quotedInterpolators(using Quotes):Interpolator.Interpolators[quoted.Expr, quoted.ToExpr, quoted.Type] & LiftedInterpolator[quoted.Expr, quoted.Type] = {
8080
new Interpolator.Interpolators[quoted.Expr, quoted.ToExpr, quoted.Type]
8181
with ExprIndependentInterpolators[quoted.Expr[Any]]
82-
with LiftedInterpolator {
82+
with LiftedInterpolator[quoted.Expr, quoted.Type]
83+
{
8384
override def `lazy`[A](fn:Function0[SCInterpolator[quoted.Expr[Any], A]]):SCInterpolator[quoted.Expr[Any], A] =
8485
new SCInterpolator(internal.DelayedConstruction.interpolator(fn))
8586

8687
override def ofType[A](implicit tpe: Type[A]): SCInterpolator[Expr[Any], Expr[A]] =
8788
new SCInterpolator(new internal.OfType[A])
8889

89-
override def lifted[Lifter[_], Z](lift:LiftFunction[Lifter, Z], description:String)(using quoted.Type[Lifter]):SCInterpolator[Expr[Any], Z] =
90+
override def lifted[Lifter[_], Z](lift:LiftFunction[quoted.Expr, quoted.Type, Lifter, Z], description:String)(using quoted.Type[Lifter]):SCInterpolator[Expr[Any], Z] =
9091
new SCInterpolator(internal.Lifted(lift, ExpectingDescription(description)))
9192
}
9293
}
@@ -95,13 +96,13 @@ trait VersionSpecificInterpolatorModule extends ExprIndependentInterpolators[Any
9596
*
9697
* @group InterpolatorGroup
9798
*/
98-
trait LiftedInterpolator {
99+
trait LiftedInterpolator[Expr[+_], Type[_ <: AnyKind]] {
99100
/**
100101
* A parser that succeeds if the next part of the in put is an `arg` and Lifter parameterized on `arg`'s type can be implicitly summoned
101102
*
102103
* The implicitly summoned value and the `arg` value are passed to `lift`; the returned value is returned by this parser
103104
* @group Arg
104105
*/
105-
def lifted[Lifter[_], Z](lift:LiftFunction[Lifter, Z], description:String)(using quoted.Type[Lifter]):SCInterpolator[Expr[Any], Z]
106+
def lifted[Lifter[_], Z](lift:LiftFunction[Expr, Type, Lifter, Z], description:String)(using Type[Lifter]):SCInterpolator[Expr[Any], Z]
106107
}
107108
}

Base/src/main/scala-3/internal/Lifted.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ object Lifted {
1313
def transpose:Option[MyTuple[A, Lifter]] = lifter.map(x => MyTuple(value, x))
1414
}
1515
private final class MyTuple[A : Type, Lifter[_]](value:Expr[A], lifter:Expr[Lifter[A]]) {
16-
def liftApply[Z](lift:LiftFunction[Lifter, Z])(using Quotes):Z = lift.apply[A](lifter, value)
16+
def liftApply[Z](lift:LiftFunction[Expr, Type, Lifter, Z])(using Quotes):Z = lift.apply[A](lifter, value)
1717
}
1818

1919
def apply[Lifter[_], Z](
20-
lift:LiftFunction[Lifter, Z],
20+
lift:LiftFunction[Expr, Type, Lifter, Z],
2121
description:ExpectingDescription,
2222
)(using
2323
Type[Lifter],

Base/src/main/scala-3/package.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package name.rayrobdod
22

33
import scala.language.higherKinds
4-
import scala.quoted.Expr
54
import scala.quoted.Quotes
6-
import scala.quoted.Type
75

86
/**
97
* A library for implementing custom string interpolation implementations using Parser Combinators
@@ -28,7 +26,9 @@ package object stringContextParserCombinator {
2826

2927
package stringContextParserCombinator {
3028
/** Support for [[Interpolator.lifted]]; represents a macro-level function that combines a CC[A] and an A. */
31-
trait LiftFunction[-CC[_], +Z] {def apply[A](lifter:Expr[CC[A]], elem:Expr[A])(using Type[A], Quotes):Z}
29+
trait LiftFunction[Expr[+_], Type[_], -CC[_], +Z] {
30+
def apply[A](lifter:Expr[CC[A]], elem:Expr[A])(using Type[A], Quotes):Z
31+
}
3232
/** An identity context - for parsing outside of a macro */
3333
type Id[+A] = A
3434
/** An identity function for lifting into the identity context */

JsonParser/src/main/scala-2/MacroImpl.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import org.json4s._
66
import name.rayrobdod.stringContextParserCombinator._
77

88
final class MacroImpl(val c:Context {type PrefixType = JsonStringContext}) {
9-
private[this] def myLiftFunction[Z, Lifter[A] <: Lift[A, Z]]:LiftFunction[c.type, Lifter, c.Expr[Z]] = {
10-
new LiftFunction[c.type, Lifter, c.Expr[Z]] {
9+
private[this] def myLiftFunction[Z, Lifter[A] <: Lift[A, Z]]:LiftFunction[c.Expr, c.TypeTag, Lifter, c.Expr[Z]] = {
10+
new LiftFunction[c.Expr, c.TypeTag, Lifter, c.Expr[Z]] {
1111
def apply[A](lifter:c.Expr[Lifter[A]], a:c.Expr[A]):c.Expr[Z] = {
1212
c.Expr(
1313
c.universe.Apply(

JsonParser/src/main/scala-3/MacroImpl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import name.rayrobdod.stringContextParserCombinator._
88

99
object MacroImpl {
1010
import scala.language.higherKinds
11-
private def myLiftFunction[Z : Type, Lifter[A] <: Lift[A, Z] : Type]:LiftFunction[Lifter, Expr[Z]] = {
12-
new LiftFunction[Lifter, Expr[Z]] {
11+
private def myLiftFunction[Z : Type, Lifter[A] <: Lift[A, Z] : Type]:LiftFunction[Expr, Type, Lifter, Expr[Z]] = {
12+
new LiftFunction[Expr, Type, Lifter, Expr[Z]] {
1313
def apply[A](lifter:Expr[Lifter[A]], a:Expr[A])(using Type[A], Quotes):Expr[Z] = lifter match {
1414
// Lifter being a Lift.jvalue implies that A =:= Z
1515
case '{ Lift.jvalue } => a.asExprOf[Z]
@@ -27,7 +27,7 @@ object MacroImpl {
2727
* (i.e. `Lift.string.apply("abcd").values`).
2828
* This will bypass that wrapping, at least for the built-in `Lift.string`.
2929
*/
30-
private object stringLiftFunction extends LiftFunction[Lift.String, Expr[String]] {
30+
private object stringLiftFunction extends LiftFunction[Expr, Type, Lift.String, Expr[String]] {
3131
def apply[A](lifter:Expr[Lift.String[A]], a:Expr[A])(using Type[A], Quotes):Expr[String] = lifter match {
3232
// Lifter being a Lift.jvalue implies that A =:= Z, and for Lift.String, Z =:= JString
3333
case '{ Lift.jvalue } => '{ ${a.asExprOf[JString]}.values }

0 commit comments

Comments
 (0)