342
|
1 |
#!/usr/bin/env amm
|
|
2 |
|
|
3 |
import $ivy.`org.scalameta::scalameta:4.3.20`
|
341
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
|
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
import scala.meta._
|
342
|
6 |
import ammonite.ops._
|
341
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
|
342
|
8 |
@main
|
|
9 |
def main(s: String) = {
|
|
10 |
val file = read(pwd / RelPath(s))
|
|
11 |
val tree = file.parse[Source].get
|
|
12 |
val vrs = tree.collect {
|
|
13 |
case Defn.Var(_, x, _, _) => x.toString
|
|
14 |
case Term.Return(t) => t.toString
|
|
15 |
}
|
|
16 |
println(vrs.mkString("\n"))
|
|
17 |
}
|
|
18 |
|
|
19 |
|
|
20 |
/*
|
|
21 |
q"val x = 2".traverse {
|
|
22 |
case node =>
|
|
23 |
println(s"${node.productPrefix}: $node")
|
|
24 |
}
|
|
25 |
*/
|
|
26 |
|
|
27 |
//https://scalameta.org/docs/trees/guide.html#custom-traversals
|
|
28 |
|
|
29 |
|
|
30 |
//https://geirsson.com/post/2016/02/scalameta/ |