11package name .rayrobdod .stringContextParserCombinator
22package typeclass
33
4+ import scala .annotation .nowarn
45import scala .reflect .ClassTag
56import com .eed3si9n .ifdef .ifdef
67
8+ @ nowarn(" msg=make nowarn used" )
9+ private [typeclass] final class Optionally_MakeNowarnUsed
10+
711/**
812 * Describes how to represent an optional value
913 *
@@ -138,23 +142,7 @@ object ContraOptionally extends LowPrioContraOptionally {
138142 implicit def idUnit : ContraOptionally [IdCtx , Id , Unit , Unit ] = BiOptionally .idUnit
139143
140144 @ 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- }
145+ implicit def contextUnit [Ctx <: scala.reflect.macros.blackbox.Context with Singleton ]: BiOptionally [Ctx , Ctx # Expr , Unit , Unit ] = BiOptionally .contextUnit
158146
159147 @ ifdef(" scalaBinaryVersion:3" )
160148 implicit def quotedUnit : BiOptionally [scala.quoted.Quotes , scala.quoted.Expr , Unit , Unit ] = BiOptionally .quotedUnit
@@ -164,6 +152,9 @@ object ContraOptionally extends LowPrioContraOptionally {
164152private [typeclass] trait LowPrioContraOptionally {
165153 implicit def idToOption [A ]: ContraOptionally [IdCtx , Id , A , Option [A ]] = BiOptionally .idToOption
166154
155+ @ ifdef(" scalaEpochVersion:2" )
156+ 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
157+
167158 @ ifdef(" scalaBinaryVersion:3" )
168159 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
169160}
@@ -212,48 +203,12 @@ object BiOptionally extends LowPrioBiOptionally {
212203 )
213204
214205 @ 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- }
206+ def contextUnit [Ctx <: scala.reflect.macros.blackbox.Context with Singleton ]: BiOptionally [Ctx , Ctx # Expr , Unit , Unit ] = BiOptionally .apply(
207+ _ => (),
208+ (_, _) => (),
209+ (_, ctx) => Exprs .forContext[Ctx ].constTrue(ctx),
210+ PartialExprFunction .identity[Ctx , Ctx # Expr , Ctx # TypeTag , Unit ](using Exprs .forContext)
211+ )
257212
258213 @ ifdef(" scalaBinaryVersion:3" )
259214 implicit def quotedUnit : BiOptionally [scala.quoted.Quotes , scala.quoted.Expr , Unit , Unit ] = BiOptionally .apply(
@@ -278,6 +233,56 @@ private[typeclass] trait LowPrioBiOptionally {
278233 )
279234 )
280235
236+ @ ifdef(" scalaEpochVersion:2" )
237+ 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 ] = {
238+ c.Expr [Z ](c.universe.Select (qualifier.tree, c.universe.TermName (name)))
239+ }
240+ @ ifdef(" scalaEpochVersion:2" )
241+ private [this ] def selectTermNames [Z ](c: scala.reflect.macros.blackbox.Context )(root: String , names: String * )(implicit typZ: c.TypeTag [Z ]): c.Expr [Z ] = {
242+ val rootTree = c.universe.Ident (c.universe.TermName (root))
243+ val namesTree = names.foldLeft[c.universe.Tree ](rootTree)({(folding, name) => c.universe.Select (folding, c.universe.TermName (name))})
244+ c.Expr [Z ](namesTree)
245+ }
246+
247+ @ ifdef(" scalaEpochVersion:2" )
248+ 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(
249+ (ctx: Ctx ) => {
250+ val myBindSingletonContexts = new BindSingletonContexts [Ctx , ctx.type ]
251+ import myBindSingletonContexts ._
252+ @ nowarn(" msg=never used" ) implicit val typA2 : ctx.TypeTag [A ] = typA
253+ selectTermNames[Option [A ]](ctx)(" _root_" , " scala" , " None" ): Ctx # Expr [Option [A ]]
254+ },
255+ (value, ctx) => {
256+ val myBindSingletonContexts = new BindSingletonContexts [Ctx , ctx.type ]
257+ import myBindSingletonContexts ._
258+ @ nowarn(" msg=never used" ) implicit val typA2 : ctx.TypeTag [A ] = typA
259+ val value2 : ctx.Expr [A ] = value
260+ val rootTree = ctx.universe.Ident (ctx.universe.TermName (" _root_" ))
261+ val namesTree = List (" scala" , " Some" , " apply" ).foldLeft[ctx.universe.Tree ](rootTree)({(folding, name) => ctx.universe.Select (folding, ctx.universe.TermName (name))})
262+ ctx.Expr [Option [A ]](ctx.universe.Apply (namesTree, List (value2.tree))): Ctx # Expr [Option [A ]]
263+ },
264+ (value, ctx) => {
265+ val myBindSingletonContexts = new BindSingletonContexts [Ctx , ctx.type ]
266+ import myBindSingletonContexts ._
267+ val value2 = value : ctx.Expr [Option [A ]]
268+ select[Option [A ], Boolean ](ctx)(value2, " isEmpty" ): Ctx # Expr [Boolean ]
269+ },
270+ PartialExprFunction (
271+ (value, ctx) => {
272+ val myBindSingletonContexts = new BindSingletonContexts [Ctx , ctx.type ]
273+ import myBindSingletonContexts ._
274+ val value2 = value : ctx.Expr [Option [A ]]
275+ select[Option [A ], Boolean ](ctx)(value2, " nonEmpty" ): Ctx # Expr [Boolean ]
276+ },
277+ (value, ctx) => {
278+ val myBindSingletonContexts = new BindSingletonContexts [Ctx , ctx.type ]
279+ import myBindSingletonContexts ._
280+ val value2 = value : ctx.Expr [Option [A ]]
281+ select[Option [A ], A ](ctx)(value2, " get" ): Ctx # Expr [A ]
282+ },
283+ )
284+ )
285+
281286 @ ifdef(" scalaBinaryVersion:3" )
282287 implicit def quotedToExprOption [A ](implicit typ : TypeCreator [A ]): BiOptionally [scala.quoted.Quotes , scala.quoted.Expr , scala.quoted.Expr [A ], scala.quoted.Expr [Option [A ]]] =
283288 OptionallyImpl .quotedToExprOption[A ]
0 commit comments