Questions tagged [scala-quasiquotes]

In Scala, quasiquotes are shipped in the official Scala distribution as part of scala-reflect.jar

Read also: http://docs.scala-lang.org/overviews/quasiquotes/intro.html

91 questions
0
votes
1 answer

Scala: pattern inside a q interpolator

I am looking at a piece of Scala macro which provides an implicit implementation of a class. This class converts a map of field values to a case class. The macro can be found here and this is the explanation behind it. Currently the implementation…
Maths noob
  • 1,684
  • 20
  • 42
0
votes
1 answer

Lifting string with Scalameta

I would like injecting a method 'toCSV' to parse a class into CSV String. My function take two paramters : Seq[String] : header Seq[Seq[Any]] : fields My macro : class model extends scala.annotation.StaticAnnotation { inline def apply(defn:…
user2931656
  • 253
  • 2
  • 3
  • 13
0
votes
1 answer

scala quasiquotes string variable lifting in multiple steps

this is what i want: scala> var x:Int = 10 x: Int = 10 scala> var y:Int = 20 y: Int = 20 scala> val ret = q"return $x>$y" ret: universe.Return = return 10.$greater(20) scala> val result1 = toolbox.compile(ret)() result1: Any = false But the…
Pankaj
  • 346
  • 1
  • 3
  • 14
0
votes
1 answer

Defining implicit encoder using scala meta and quasiquotes

I am trying to create an implicit encoder using Circe. However this encoder will be created using an annotation hence I am using Scalameta. Here is my code. However, the compiler complains about having an override statement within quasiquotes. class…
igalbenardete
  • 207
  • 2
  • 12
0
votes
0 answers

scala parse a string into a Tree to use in a quasi quote

I was wondering if i could perform a sort of a nested quasi quote evaluation. Let's say i have a function call q"${function(args)}" That returns "add(x,y)" (a string) How can i make it evaluate this? Something like val a =…
raul ferreira
  • 886
  • 7
  • 21
0
votes
1 answer

Quasiquote interpret tree content instead of taking as literal

Can you please explain why the two usages of Scala quasiquote below give different output between result1 and result2? Is it possible to reproduce result3 using quasiquote? i.e parse a string content and evaluate it? import…
Polymerase
  • 6,311
  • 11
  • 47
  • 65
0
votes
1 answer

Variable length "select"s with quasiquotes

With Scala's quasiquotes you can build trees of selects easily, like so: > tq"a.b.MyObj" res: Select(Select(Ident(TermName("a")), TermName("b")), TermName("MyObj")) My question is, how do I do this if the list of things to select from…
Aish
  • 97
  • 1
  • 8
0
votes
1 answer

Scala "reflective toolbox failed due to unresolved free type"

Trying quasiquotes for the first time to generically produce new case classes: val universe: scala.reflect.runtime.universe.type = scala.reflect.runtime.universe import universe._ import scala.reflect.runtime.{currentMirror => m} import…
Oron Port
  • 467
  • 3
  • 11
0
votes
1 answer

scala macro with fresh identifier

I have a macro which I want to use to log the time it takes to execute a block that might return something useful. So if I have something like val y = f(x) I will change to val y = Timed(f(x)) to get the time it took to execute the function in the…
piotr
  • 5,657
  • 1
  • 35
  • 60
0
votes
2 answers

Can Scala macros be defined inside a class (as methods of that class)?

I need Scala macros (reify, quasiquote, macro impl) for my Scala assertions library. I want to be able to do this: object1.assertEquals(object2) // success: object1 = object2 Or like this: 3.assertEquals(1 + 1) // failure: 1 + 1 /= 3 Can Scala…
Michael Lafayette
  • 2,972
  • 3
  • 20
  • 54
0
votes
2 answers

Scala quasiquote macro example broken - type signatures off

I took this Scala quasiquote example from the book "Programming Scala" (2nd Edition) I am getting this error: https://issues.scala-lang.org/browse/SI-9711 The type inference says "Trees#Tree", but the type inference is off. import…
0
votes
1 answer

scala quasiquotes: comparing types

As an overview, I am trying to dynamically create a constructor for a case class from a Cassandra Java Row using reflection to find the primary constructor for the case class, and then trying to extract the values from the Cassandra Row.…
0
votes
1 answer

Calling function with implicit parameter from quasioquote

For some reason every time I try to call a function with an implicit parameter from quasiquotes, it fails with Can't unquote x.universe.Tree, consider providing an implicit instance of Liftable[x.universe.Tree] What's wrong with that? Am I not…
0
votes
1 answer

How to use cq in quasi quote to return the matched pattern

I am trying to write this case authorDao: AuthorDao => authorDao so that it returns the subclass of Dao itself. When I use this quasi quote: val daoType = TypeName(daoName) val caseTerm = TermName(daoName.toLowerCase) cases.append(cq"$caseTerm:…
user1187135
0
votes
1 answer

How do I escape a newline in macro quasiquotes

For example: q"import scala.collection.mutable.Buffer\ndef foo: Buffer[Int] = ???" This gives an error, because the newline characters is not resolved.
0__
  • 66,707
  • 21
  • 171
  • 266