glayzzle / glayzzle/php-parser

Modifying the AST

Open
#1,006 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
565
Forks
75
PR merge metrics
No merged PRs in 30d

Description

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).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.