1
1
package name .rayrobdod .stringContextParserCombinator
2
2
package typeclass
3
3
4
+ import scala .annotation .nowarn
4
5
import scala .reflect .ClassTag
5
6
import com .eed3si9n .ifdef .ifdef
6
7
@@ -138,23 +139,7 @@ object ContraOptionally extends LowPrioContraOptionally {
138
139
implicit def idUnit : ContraOptionally [IdCtx , Id , Unit , Unit ] = BiOptionally .idUnit
139
140
140
141
@ ifdef(" scalaEpochVersion:2" )
141
- trait ContraOptionallys [Ctx , Expr [+ _], Type [_]] extends LowPrioContraOptionallys [Ctx , Expr , Type ] {
142
- implicit def unit : ContraOptionally [Ctx , Expr , Unit , Unit ]
143
- }
144
- @ ifdef(" scalaEpochVersion:2" )
145
- trait LowPrioContraOptionallys [Ctx , Expr [+ _], Type [_]] {
146
- implicit def toExprOption [A ](implicit typA: Type [A ]): ContraOptionally [Ctx , Expr , Expr [A ], Expr [Option [A ]]]
147
- }
148
-
149
- @ ifdef(" scalaEpochVersion:2" )
150
- def forContext (c: scala.reflect.macros.blackbox.Context ): ContraOptionallys [c.type , c.Expr , c.TypeTag ] = {
151
- new ContraOptionallys [c.type , c.Expr , c.TypeTag ] {
152
- private [this ] val backing = BiOptionally .forContext(c)
153
-
154
- override def unit : ContraOptionally [c.type , c.Expr , Unit , Unit ] = backing.unit
155
- override def toExprOption [A ](implicit typA: c.TypeTag [A ]): ContraOptionally [c.type , c.Expr , c.Expr [A ], c.Expr [Option [A ]]] = backing.toExprOption[A ]
156
- }
157
- }
142
+ implicit def contextUnit [Ctx <: scala.reflect.macros.blackbox.Context with Singleton ]: BiOptionally [Ctx , Ctx # Expr , Unit , Unit ] = BiOptionally .contextUnit
158
143
159
144
@ ifdef(" scalaBinaryVersion:3" )
160
145
implicit def quotedUnit : BiOptionally [scala.quoted.Quotes , scala.quoted.Expr , Unit , Unit ] = BiOptionally .quotedUnit
@@ -164,6 +149,9 @@ object ContraOptionally extends LowPrioContraOptionally {
164
149
private [typeclass] trait LowPrioContraOptionally {
165
150
implicit def idToOption [A ]: ContraOptionally [IdCtx , Id , A , Option [A ]] = BiOptionally .idToOption
166
151
152
+ @ ifdef(" scalaEpochVersion:2" )
153
+ implicit def contextToExprOption [Ctx <: scala.reflect.macros.blackbox.Context with Singleton , A ](implicit typA: Ctx # TypeTag [A ]): BiOptionally [Ctx , Ctx # Expr , Ctx # Expr [A ], Ctx # Expr [Option [A ]]] = BiOptionally .contextToExprOption
154
+
167
155
@ ifdef(" scalaBinaryVersion:3" )
168
156
implicit def quotedToExprOption [A ](implicit typA : TypeCreator [A ]): BiOptionally [scala.quoted.Quotes , scala.quoted.Expr , scala.quoted.Expr [A ], scala.quoted.Expr [Option [A ]]] = BiOptionally .quotedToExprOption
169
157
}
@@ -212,48 +200,12 @@ object BiOptionally extends LowPrioBiOptionally {
212
200
)
213
201
214
202
@ ifdef(" scalaEpochVersion:2" )
215
- trait BiOptionallys [Ctx , Expr [+ _], Type [_]] extends LowPrioBiOptionallys [Ctx , Expr , Type ] {
216
- implicit def unit : BiOptionally [Ctx , Expr , Unit , Unit ]
217
- }
218
- @ ifdef(" scalaEpochVersion:2" )
219
- trait LowPrioBiOptionallys [Ctx , Expr [+ _], Type [_]] {
220
- implicit def toExprOption [A ](implicit typA: Type [A ]): BiOptionally [Ctx , Expr , Expr [A ], Expr [Option [A ]]]
221
- }
222
-
223
- @ ifdef(" scalaEpochVersion:2" )
224
- def forContext (c: scala.reflect.macros.blackbox.Context ): BiOptionallys [c.type , c.Expr , c.TypeTag ] = {
225
- new BiOptionallys [c.type , c.Expr , c.TypeTag ] {
226
- private [this ] def select [A , Z ](qualifier: c.Expr [A ], name: String )(implicit typZ: c.TypeTag [Z ]): c.Expr [Z ] = {
227
- c.Expr [Z ](c.universe.Select (qualifier.tree, c.universe.TermName (name)))
228
- }
229
- private [this ] def selectTermNames [Z ](root: String , names: String * )(implicit typZ: c.TypeTag [Z ]): c.Expr [Z ] = {
230
- val rootTree = c.universe.Ident (c.universe.TermName (root))
231
- val namesTree = names.foldLeft[c.universe.Tree ](rootTree)({(folding, name) => c.universe.Select (folding, c.universe.TermName (name))})
232
- c.Expr [Z ](namesTree)
233
- }
234
-
235
- override def unit : BiOptionally [c.type , c.Expr , Unit , Unit ] = BiOptionally .apply(
236
- _ => (),
237
- (_, _) => (),
238
- (_, ctx) => Exprs .forContext[c.type ].constTrue(ctx),
239
- PartialExprFunction .identity[c.type , c.Expr , c.TypeTag , Unit ](using Exprs .forContext)
240
- )
241
-
242
- override def toExprOption [A ](implicit typA: c.TypeTag [A ]): BiOptionally [c.type , c.Expr , c.Expr [A ], c.Expr [Option [A ]]] = BiOptionally .apply(
243
- _ => selectTermNames[Option [A ]](" _root_" , " scala" , " None" ),
244
- (value, _) => {
245
- val rootTree = c.universe.Ident (c.universe.TermName (" _root_" ))
246
- val namesTree = List (" scala" , " Some" , " apply" ).foldLeft[c.universe.Tree ](rootTree)({(folding, name) => c.universe.Select (folding, c.universe.TermName (name))})
247
- c.Expr [Option [A ]](c.universe.Apply (namesTree, List (value.tree)))
248
- },
249
- (value, _) => select[Option [A ], Boolean ](value, " isEmpty" ),
250
- PartialExprFunction (
251
- (value, _) => select[Option [A ], Boolean ](value, " nonEmpty" ),
252
- (value, _) => select[Option [A ], A ](value, " get" )
253
- )
254
- )
255
- }
256
- }
203
+ def contextUnit [Ctx <: scala.reflect.macros.blackbox.Context with Singleton ]: BiOptionally [Ctx , Ctx # Expr , Unit , Unit ] = BiOptionally .apply(
204
+ _ => (),
205
+ (_, _) => (),
206
+ (_, ctx) => Exprs .forContext[Ctx ].constTrue(ctx),
207
+ PartialExprFunction .identity[Ctx , Ctx # Expr , Ctx # TypeTag , Unit ](using Exprs .forContext)
208
+ )
257
209
258
210
@ ifdef(" scalaBinaryVersion:3" )
259
211
implicit def quotedUnit : BiOptionally [scala.quoted.Quotes , scala.quoted.Expr , Unit , Unit ] = BiOptionally .apply(
@@ -278,6 +230,47 @@ private[typeclass] trait LowPrioBiOptionally {
278
230
)
279
231
)
280
232
233
+ @ ifdef(" scalaEpochVersion:2" )
234
+ private [this ] def select [A , Z ](c: scala.reflect.macros.blackbox.Context )(qualifier: c.Expr [A ], name: String )(implicit typZ: c.TypeTag [Z ]): c.Expr [Z ] = {
235
+ c.Expr [Z ](c.universe.Select (qualifier.tree, c.universe.TermName (name)))
236
+ }
237
+ @ ifdef(" scalaEpochVersion:2" )
238
+ private [this ] def selectTermNames [Z ](c: scala.reflect.macros.blackbox.Context )(root: String , names: String * )(implicit typZ: c.TypeTag [Z ]): c.Expr [Z ] = {
239
+ val rootTree = c.universe.Ident (c.universe.TermName (root))
240
+ val namesTree = names.foldLeft[c.universe.Tree ](rootTree)({(folding, name) => c.universe.Select (folding, c.universe.TermName (name))})
241
+ c.Expr [Z ](namesTree)
242
+ }
243
+
244
+ @ ifdef(" scalaEpochVersion:2" )
245
+ def contextToExprOption [Ctx <: scala.reflect.macros.blackbox.Context with Singleton , A ](implicit typA: Ctx # TypeTag [A ]): BiOptionally [Ctx , Ctx # Expr , Ctx # Expr [A ], Ctx # Expr [Option [A ]]] = BiOptionally .apply(
246
+ (ctx: Ctx ) => {
247
+ @ nowarn(" msg=never used" ) implicit val typA2 : ctx.TypeTag [A ] = typA.asInstanceOf [ctx.TypeTag [A ]]
248
+ selectTermNames[Option [A ]](ctx)(" _root_" , " scala" , " None" ).asInstanceOf [Ctx # Expr [Option [A ]]]
249
+ },
250
+ (value, ctx) => {
251
+ @ nowarn(" msg=never used" ) implicit val typA2 : ctx.TypeTag [A ] = typA.asInstanceOf [ctx.TypeTag [A ]]
252
+ val value2 = value.asInstanceOf [ctx.Expr [A ]]
253
+ val rootTree = ctx.universe.Ident (ctx.universe.TermName (" _root_" ))
254
+ val namesTree = List (" scala" , " Some" , " apply" ).foldLeft[ctx.universe.Tree ](rootTree)({(folding, name) => ctx.universe.Select (folding, ctx.universe.TermName (name))})
255
+ ctx.Expr [Option [A ]](ctx.universe.Apply (namesTree, List (value2.tree))).asInstanceOf [Ctx # Expr [Option [A ]]]
256
+ },
257
+ (value, ctx) => {
258
+ val value2 = value.asInstanceOf [ctx.Expr [Option [A ]]]
259
+ select[Option [A ], Boolean ](ctx)(value2, " isEmpty" ).asInstanceOf [Ctx # Expr [Boolean ]]
260
+ },
261
+ PartialExprFunction (
262
+ (value, ctx) => {
263
+ val value2 = value.asInstanceOf [ctx.Expr [Option [A ]]]
264
+ select[Option [A ], Boolean ](ctx)(value2, " nonEmpty" ).asInstanceOf [Ctx # Expr [Boolean ]]
265
+ },
266
+ (value, ctx) => {
267
+ val value2 = value.asInstanceOf [ctx.Expr [Option [A ]]]
268
+ select[Option [A ], A ](ctx)(value2, " get" ).asInstanceOf [Ctx # Expr [A ]]
269
+ },
270
+ )
271
+ )
272
+
273
+ @ nowarn(" msg=make nowarn used" )
281
274
@ ifdef(" scalaBinaryVersion:3" )
282
275
implicit def quotedToExprOption [A ](implicit typ : TypeCreator [A ]): BiOptionally [scala.quoted.Quotes , scala.quoted.Expr , scala.quoted.Expr [A ], scala.quoted.Expr [Option [A ]]] =
283
276
OptionallyImpl .quotedToExprOption[A ]
0 commit comments