misc/smeta.sc
author Christian Urban <christian.urban@kcl.ac.uk>
Wed, 02 Dec 2020 01:15:14 +0000
changeset 382 1bd800376e0c
parent 342 aa47abb9e723
permissions -rwxr-xr-x
updated

#!/usr/bin/env amm

import $ivy.`org.scalameta::scalameta:4.3.20`

import scala.meta._
import ammonite.ops._

@main
def main(s: String) = {
  val file = read(pwd / RelPath(s))
  val tree = file.parse[Source].get
  val vrs = tree.collect {
      case Defn.Var(_, x, _, _) => x.toString
      case Term.Return(t) => t.toString 
      }    
  println(vrs.mkString("\n"))
}


/*
q"val x = 2".traverse {
  case node =>
    println(s"${node.productPrefix}: $node")
}
*/

//https://scalameta.org/docs/trees/guide.html#custom-traversals


//https://geirsson.com/post/2016/02/scalameta/