-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modifying the AST #1006
Comments
Addendum: I could actually create some nodes like this:
but it just doesn't feel right. But I have to override those functions in the middle because the compiler doesn't accept a partial class, leaving out some fields. |
I finally came up with this solution and it works but adding real constructors would be very welcome down the line:
|
Hi @deakjahn, thanks for bringing this up. As far as I can tell, a public API for this use-case has not been a focus yet. If I'm not mistaken, the functions in the |
Yes, they look like constructors, but there's no way to pass them the required parameters. So, I need to create one for each and every one of the node types, of course. The ATS->PHP writer is practically done, I listed the small problems I found along the route in the other issue. |
Was the AST ever intended to be modified externally? I've just written an AST->PHP writer (yes, I'm aware of
php-writer
, it's very old and dated, I needed the full support up to the latest PHP 8.1). It's in TypeScript, actually, not JavaScript. I didn't yet have time to test it at all but I'm more than willing to share it as soon as it's reasonably error free.However, this leads to the current question. I'd need to modify the AST so that I can export it in full or partly back to PHP. Was
php-parser
ever intended to support this scenario? The various AST classes don't seem to have constructors and there seems to be no easy way to build or modify an AST tree (except for assembling PHP strings and parsing them eval-style but that's not what would really be needed).The text was updated successfully, but these errors were encountered: