Convert Scala AST to source code

夙愿已清 提交于 2019-12-09 17:41:19

问题


Given a Scala AST, is there a way to generate Scala source code?

I'm looking into ways to autogenerate Scala source by parsing/analyzing other Scala source. Any tips would be appreciated!


回答1:


I have been successfully using Scala-Refactoring by Mirko Stocker for this task.

For synthetically constructing ASTs, it relies strongly on the existing Tree DSL of Scala's NSC.

Although the code is a bit messy, you can find an example usage in my project ScalaCollider-UGens.

I have also come across a very useful class by Johannes Rudolph.




回答2:


See our DMS Software Reengineering Toolkit.

DMS provides a complete ecosystem for parsing/analyzing/optimizing/transforming source code in many languages. It achieves this by provide generic machinery for these tasks as its core capabilities, and specializing those according to explicitly supplied language definitions ("front ends"). DMS has front ends for many languages (C, C++, C#, Java, COBOL, ...) that have been used in anger, and a process for defining others very quickly.

We work on expanding the language set more or less continuously. DMS already has parts of a Scala front end implemented, and we know how to finish it based on the other 30+ front ends we have built, with special emphasis on knowledge of Java.



来源:https://stackoverflow.com/questions/6432554/convert-scala-ast-to-source-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!