I need to create converter from Scala to another language. I’m looking for scala code parser that converts code to syntax tree without compilation.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Let me make it simple: there is no way to generate a Scala program’s AST with parser alone. It is absolutely necessary to run the typer, and that means type inference and implicits.
After that, you can do whatever you want. But these first few phases of the compiler (four on most recent versions, counting the typer) are necessary.
Coincidentally, that’s the phases ran by the presentation compiler, which is used by the Scala IDE 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 it, and you might also want to take a look at the Scala Refactoring tool, since it uses the compiler’s AST as well.
Finally, you can try compiling the code with
-Ybrowse:typerto see the tree after typer. Use-Xshow-phasesto display the existing phases, or-Xprint:typerto print the “source” after typer (or any other phase).