misc/smeta.sc
author Christian Urban <christian.urban@kcl.ac.uk>
Mon, 08 Nov 2021 18:57:50 +0000
changeset 413 9c80f411faa7
parent 342 aa47abb9e723
permissions -rwxr-xr-x
updated jars
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
342
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
     1
#!/usr/bin/env amm
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
     2
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
     3
import $ivy.`org.scalameta::scalameta:4.3.20`
341
e9d5287c3107 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     4
e9d5287c3107 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     5
import scala.meta._
342
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
     6
import ammonite.ops._
341
e9d5287c3107 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff changeset
     7
342
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
     8
@main
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
     9
def main(s: String) = {
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    10
  val file = read(pwd / RelPath(s))
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    11
  val tree = file.parse[Source].get
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    12
  val vrs = tree.collect {
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    13
      case Defn.Var(_, x, _, _) => x.toString
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    14
      case Term.Return(t) => t.toString 
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    15
      }    
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    16
  println(vrs.mkString("\n"))
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    17
}
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    18
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    19
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    20
/*
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    21
q"val x = 2".traverse {
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    22
  case node =>
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    23
    println(s"${node.productPrefix}: $node")
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    24
}
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    25
*/
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    26
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    27
//https://scalameta.org/docs/trees/guide.html#custom-traversals
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    28
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    29
aa47abb9e723 updated
Christian Urban <christian.urban@kcl.ac.uk>
parents: 341
diff changeset
    30
//https://geirsson.com/post/2016/02/scalameta/