#!/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/