0

I would like my Hack code to be broken down to Abstract Syntax Tree. Please advise me on available tools/libraries/github repositories which will help me to parse Hack code into AST. I have found "h2tp" (hack to php transpiler written by Facebook), however it doesn't parse the code into AST. I also tried this project which does what I want however it is not recognising many of the operators and requires a significant rework, which will quite a lot of time to do.

2 Answers2

1

hhast (HHAST: Low-Level AST Library) lets you do that, you may invoke hh_parse like this : hh_parse --full-fidelity-json $file | jq

taken from (https://github.com/hhvm/hhast/blob/master/docs/ast-lib.md)

  • Welcome to Stack Overflow! While links are great way of sharing knowledge, they won't really answer the question if they get broken in the future. Add to your answer the essential content of the link which answers the question. In case the content is too complex or too big to fit here, describe the general idea of the proposed solution. Remember to always keep a link reference to the original solution's website. See: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – sɐunıɔןɐqɐp Sep 29 '18 at 14:31
  • I think it's a legit answer, in this case. OP has specifically asked for `available tools/libraries/GitHub repositories`. He has even explained the usage here/ And it's technically not possible to bring the more detailed solution on SO for the library. It will be unfortunate if the library is removed someday, but still, a library is what OP needed for now. – Tushar Sep 29 '18 at 14:38
0

The HHVM itself provides a lot of tools to dump the structure of a PHP file. However, the AST dump was removed: https://github.com/facebook/hhvm/issues/1268

What you can do is dump the HHVM assembly language: http://hhvm.com/blog/6323/the-journey-of-a-thousand-bytecodes

HHVM also has a PHP transpiler which may help:https://docs.hhvm.com/hack/tools/transpiler

You could also try to port this extension over to the HHVM: https://github.com/nikic/php-ast

Janos Pasztor
  • 1,265
  • 8
  • 16