Using the standard format for the AST, used by PHP 7
See original GitHub issueHi!
I read your comment on #41, and I was thinking about how the resulting AST is going to be.
After checking this repository: https://github.com/nikic/php-ast, it seems there is an official format for a PHP AST, that is generated by PHP 7. (I haven’t tested it, but according to it’s readme, this project is just exposing the AST that PHP7 generates on it’s own)
One of the things I noticed there is that it seems the PHP 7 AST is formed by assoc arrays, which are like JavaScript object literals, instead of using numeric arrays.
Now, I do like how your AST looks like (since it reminds me to Lisp, and IMO, Lisp looks very elegant), but I do think an AST based on objects literals would be more practical.
Right now, in certain cases, I’m checking for the number of elements an array has, but that number will change as soon the AST requires new elements. For instance, on php-unparser class translator, I have an if (method.length === 7)
to check if the method has a body (otherwise is an abstract method). But that will break if later becomes necessary to add more elements to the methods and then the number of elements a methods goes to 10 or something. On an object-based AST, I could check for something like if (!method.body)
instead, and the amount of properties that the method has would be irrelevant.
But more important than just being easier and more stable, it seems to me that is really important to use and follow one standard AST.
Like in the case of esprima, they don’t use their own AST, instead, they use an standard JavaScript AST spec called estree, that was originally created by mozilla.
Since the AST of PHP 7 could be considered as the official format of the AST, I think it would be better to follow that format. Perhaps even would be a good idea to create a project like estree to document the PHP7 AST and create a more formal spec.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top GitHub Comments
I close this issue as the new version is released.
You can play with the new output online : http://glayzzle.com/php-parser/#demo
+1 by using the same structure as https://github.com/nikic/php-ast it will be more easy to automate tests and check if AST nodes are OK, similar to how the lexer is checked with the php lexer.