Pretty printing AST in Rascal

被刻印的时光 ゝ 提交于 2019-12-02 04:35:11

If you mean unparsing an AST (getting the Java code back) you will have to write something yourself.

If you however mean printing the AST structure nicely indented, we have iprintln exactly for this purpose.

Also, for large ASTs, the REPL might not like it that much, checkout our (as pf yet) undocumented Fast print functions in util::FastPrint. The fiprintln prints to the rascal output window, which is a lot faster.

No I believe the current release does not contains this feature. If you don't rewrite the AST, you can of course get the source by reading the location, as in:

rascal>import IO;
ok
rascal>readFile(ast@\loc)
str: ...

That only works when the weather is right.. The other solutions are:

  • to use string templates mapping the AST back to source (simplest)
  • map ASTs to the Box language and call the format function (most powerful and configurable)
  • a hybrid of the above

I seem to recall there is a function which maps back M3 ASTs back to JDT ASTs in Java and then calls the pretty print function of JDT, but it looks like it was discontinued. In other words, here are some TODOs.

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