1

How can I turn scala program into AST and operate with it programatically, from java/scala?

5
  • Are you talking about AST (abstract syntax tree)? Commented Apr 13, 2015 at 13:10
  • Yes, I am. Sorry I got the title wrong. Commented 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) Commented 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. Commented Apr 13, 2015 at 14:17
  • It's source code. I know little about the macro. Could you please show me some examples? Thanks! Commented Apr 22, 2015 at 7:19

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

I know this is an old question but you can have a look at scalameta :

https://scalameta.org/

Library to read, analyze, transform and generate Scala programs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.