File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
tests/run/xml-interpolation-4 Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+ import scala .quoted .autolift ._
3+ import scala .tasty .Reflection
4+
5+ import scala .language .implicitConversions
6+
7+ object XmlQuote {
8+
9+ implicit object SCOps {
10+ inline def (ctx : => StringContext ) xml (args : => (given Scope => Any )* ) given Scope : String =
11+ $ {XmlQuote .impl(' ctx , ' args , ' {implicitly[Scope ]})}
12+ }
13+
14+ private def impl (receiver : Expr [StringContext ], args : Expr [Seq [given Scope => Any ]], scope : Expr [Scope ]): Expr [String ] = ' {
15+ $receiver.s($args.map(_ given $scope .inner): _* )
16+ }
17+ }
18+
19+ case class Scope (name : String ) {
20+ def inner : Scope = Scope (name + " +" )
21+ }
22+
23+ object Scope {
24+ implicit def topScope : Scope = Scope (" top" )
25+ }
Original file line number Diff line number Diff line change 1+ import XmlQuote ._
2+
3+ object Test {
4+ def main (args : Array [String ]): Unit = {
5+ assert(xml " Hello ${implicitly[Scope ]} world! " == " Hello Scope(top+) world!" )
6+ assert(xml " Hello ${ xml " world ${implicitly[Scope ] + " " + xml " ${implicitly[Scope ]}" }" }! " ==
7+ " Hello world Scope(top++) Scope(top+++)!" )
8+ }
9+ }
You can’t perform that action at this time.
0 commit comments