equal
deleted
inserted
replaced
1 import $ivy.`org.scalameta::scalameta:4.3.21` |
1 #!/usr/bin/env amm |
|
2 |
|
3 import $ivy.`org.scalameta::scalameta:4.3.20` |
2 |
4 |
3 import scala.meta._ |
5 import scala.meta._ |
|
6 import ammonite.ops._ |
4 |
7 |
5 println("a + b".parse[Stat].get.structure) |
8 @main |
6 |
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/ |