How can I turn scala program into AST and operate with it programatically, from java/scala?
-
Are you talking about AST (abstract syntax tree)?om-nom-nom– om-nom-nom2015-04-13 13:10:00 +00:00Commented Apr 13, 2015 at 13:10
-
Yes, I am. Sorry I got the title wrong.Fei Luo– Fei Luo2015-04-13 13:19:26 +00:00Commented Apr 13, 2015 at 13:19
-
Take a look at scala reflection API -- it allows you to manipulate with scala as AST (trees section in particular)om-nom-nom– om-nom-nom2015-04-13 13:27:20 +00:00Commented Apr 13, 2015 at 13:27
-
Is the program already compiled? In the source code, you can inject a macro to get hold of the corresponding AST of some expression.0__– 0__2015-04-13 14:17:11 +00:00Commented Apr 13, 2015 at 14:17
-
It's source code. I know little about the macro. Could you please show me some examples? Thanks!Fei Luo– Fei Luo2015-04-22 07:19:38 +00:00Commented Apr 22, 2015 at 7:19
Add a comment
|
2 Answers
You can parse scala program source code.
Take a look to parboiled2 PEG parser. As an examle it have scala parser implementation
https://github.com/sirthias/parboiled2/tree/master/scalaParser/src/main/scala/scalaparser
Comments
I know this is an old question but you can have a look at scalameta :
Library to read, analyze, transform and generate Scala programs