File tree Expand file tree Collapse file tree 6 files changed +136
-0
lines changed Expand file tree Collapse file tree 6 files changed +136
-0
lines changed Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+ import scala .quoted .autolift
3+
4+ import scala .language .implicitConversions
5+
6+ case class Xml (parts : String , args : List [Any ])
7+
8+ object XmlQuote {
9+
10+ // Encoding for
11+ //
12+ // implicit class SCOps(s: StringContext) {
13+ // object xml {
14+ // def apply(exprs: Any*) = ...
15+ // def unapplySeq(...) = ...
16+ // }
17+ // }
18+ object SCOps {
19+ opaque type StringContext = scala.StringContext
20+ def apply (sc : scala.StringContext ): StringContext = sc
21+ }
22+ inline def (inline ctx : StringContext ).xml <: SCOps .StringContext = SCOps (ctx)
23+ inline def (inline ctx : SCOps .StringContext ).apply(inline args : Any * ): Xml =
24+ $ {XmlQuote .impl(' ctx , ' args )}
25+ // inline def (inline ctx: SCOps.StringContext).unapplySeq(...): Xml = ...
26+
27+
28+ def impl (receiver : Expr [SCOps .StringContext ], args : Expr [Seq [Any ]])(using QuoteContext ): Expr [Xml ] = {
29+ val string = receiver match {
30+ case ' { SCOps ($ {Unlifted (sc)}) } => sc.parts.mkString(" ??" )
31+ }
32+ ' {new Xml ($ {string}, $args.toList)}
33+ }
34+ }
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+
6+ assert(xml " Hello World! " == Xml (" Hello World!" , Nil ))
7+
8+ val name = new Object {}
9+ assert(xml " Hello $name! " == Xml (" Hello ??!" , List (name)))
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+ import scala .quoted .autolift
3+
4+ import scala .language .implicitConversions
5+
6+ case class Xml (parts : String , args : List [Any ])
7+
8+ object XmlQuote {
9+
10+ // Encoding for
11+ //
12+ // implicit class SCOps(s: StringContext) {
13+ // object xml {
14+ // def apply(exprs: Any*) = ...
15+ // def unapplySeq(...) = ...
16+ // }
17+ // }
18+ object SCOps {
19+ opaque type StringContext = scala.StringContext
20+ def apply (sc : scala.StringContext ): StringContext = sc
21+ }
22+ inline def (inline ctx : StringContext ).xml: SCOps .StringContext = SCOps (ctx)
23+ inline def (inline ctx : SCOps .StringContext ).apply(inline args : Any * ): Xml =
24+ $ {XmlQuote .impl(' ctx , ' args )}
25+ // inline def (inline ctx: SCOps.StringContext).unapplySeq(...): Xml = ...
26+
27+
28+ def impl (receiver : Expr [SCOps .StringContext ], args : Expr [Seq [Any ]])(using QuoteContext ): Expr [Xml ] = {
29+ val string = receiver match {
30+ case ' { SCOps ($ {Unlifted (sc)}): SCOps .StringContext } => sc.parts.mkString(" ??" )
31+ }
32+ ' {new Xml ($ {string}, $args.toList)}
33+ }
34+ }
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+
6+ assert(xml " Hello World! " == Xml (" Hello World!" , Nil ))
7+
8+ val name = new Object {}
9+ assert(xml " Hello $name! " == Xml (" Hello ??!" , List (name)))
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ import scala .quoted ._
2+ import scala .quoted .autolift
3+
4+ import scala .language .implicitConversions
5+
6+ case class Xml (parts : String , args : List [Any ])
7+
8+ object XmlQuote {
9+
10+ // Encoding for
11+ //
12+ // implicit class SCOps(s: StringContext) {
13+ // object xml {
14+ // def apply(exprs: Any*) = ...
15+ // def unapplySeq(...) = ...
16+ // }
17+ // }
18+ object XMLOps {
19+ opaque type StringContext = scala.StringContext
20+ def (ctx : scala.StringContext ).xml: StringContext = ctx
21+ }
22+
23+ inline def (inline ctx : XMLOps .StringContext ).apply(inline args : Any * ): Xml =
24+ $ {XmlQuote .impl(' ctx , ' args )}
25+ // inline def (inline ctx: SCOps.StringContext).unapplySeq(...): Xml = ...
26+
27+
28+ def impl (receiver : Expr [XMLOps .StringContext ], args : Expr [Seq [Any ]])(using QuoteContext ): Expr [Xml ] = {
29+ val string = receiver match {
30+ case ' { XMLOps .xml($ {Unlifted (sc)}) } => sc.parts.mkString(" ??" )
31+ }
32+ ' {new Xml ($ {string}, $args.toList)}
33+ }
34+ }
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+ import XMLOps .xml
6+
7+ assert(xml " Hello World! " == Xml (" Hello World!" , Nil ))
8+
9+ val name = new Object {}
10+ assert(xml " Hello $name! " == Xml (" Hello ??!" , List (name)))
11+ }
12+ }
You can’t perform that action at this time.
0 commit comments