Skip to content

Modifying the AST #1006

@deakjahn

Description

@deakjahn

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions