Along with a REPL
@ import $ivy.`org.scalameta::scalameta:4.2.3`, scala.meta._
import $ivy.$ , scala.meta._
@ q"val x = 2"
res1: Defn.Val = Defn.Val(List(), List(Pat.Var(Term.Name("x"))), None, Lit.Int(2))
There's also ast explorer https://astexplorer.net/#/gist/1eef12317a449c79a21ce65c68d65d99/9ddae259a2cab4badae68010ccaf2d0b6910cc51
(_: Int, 42).toString
and ((_: Int, 42)).toString
have exactly the same representation in Scalameta AST. However, these two are completely different things for the scala compiler! The first one is (x: Int) => (x, 42).toString
and the second one is ((x: Int) => (x, 42)).toString
. How do I tell that difference using scalameta?
scala.meta.Tree
structure for those two different programs
Term.Placeholder
is an anonymous function
ScalametaParser
, iirc, the logic for detecting lambdas is a bit hairy https://github.com/scalameta/scalameta/blob/7c5c020cc0ff9b97d9029b315fb8659590236a2c/scalameta/parsers/shared/src/main/scala/scala/meta/internal/parsers/ScalametaParser.scala#L1554
a +: (1,2,3)
- this is parsed by scalameta as ApplyInfix
with three parameters but scalac
parses (1,2,3)
in this context as a tuple. So I wanted to workaround this by creating a Tuple
tree out of these arguments but apparently I can't do this without losing positions.
scalameta
project in VS Code with metals and I'm consistently getting error from sbt: Not a valid command: metalsEnable
. I tried various workarounds found in already reported issues (e.g. scalameta/metals#685) but nothing works...