Calling Scala compiler's AST from Java

87 views Asked by At

I'm working on a Scala project.

I can access the AST in the Scala compiler from a simple compiler plugin.
And I can also write a simple Scala class and call this Scala class from Java.

Is there any way to access this AST directly from Java?

1

There are 1 answers

0
Alexey Romanov On

No, because Scala compiler doesn't have a Java API (and, given the style it's written in, basically can't have one). Any other libraries parsing Scala are also likely written in Scala. If you need the initial AST (before all desugarings, typing, etc.), you could use e.g. ANTLR to generate a parser, but getting anything from the following stages will basically require rebuilding some part of the Scala compiler in Java.