Scala code analyzer (not a compiler)

I need to create a converter from Scala to another language. I am looking for a Scala code parser that converts code to a syntax tree without compilation.

+6
source share
1 answer

Let me make this simple: There is no way to generate a Scala AST program using only the parser. It is absolutely necessary to run typer, and this means that it displays and displays.

After that, you can do whatever you want. But these first few phases of the compiler (four in the most recent versions, counting the type) are necessary.

By the way, what are the phases that are controlled by the presentation compiler that the Scala IDE uses for Eclipse . It seems to me that this might be the perfect interface for you.

ENSIME also uses it , which seems to be the best source of information about this, and you can also take a look at the Scala Refactoring tool as it uses the AST compiler.

Finally, you can try compiling the code with -Ybrowse:typer to see the tree after typer. Use -Xshow-phases to display existing phases or -Xprint:typer to print the "source" after input (or any other phase).

+14
source

Source: https://habr.com/ru/post/899646/


All Articles