Giter Site home page Giter Site logo

Comments (7)

nikic avatar nikic commented on July 19, 2024 2

I've added an ast\get_metadata() function, which provides information about flags (and potentially other information in the future). This should be sufficient to implement whichever format you prefer on top of it.

The result format may not be final, I'm considering to make it return objects instead of associative arrays.

from php-ast.

 avatar commented on July 19, 2024

I find from a debugging perspective that it is easier to work with the flags as string array, and its not a significant performace drain (depends what you are doing of course). I want to be able to look at what flags an AST object has, to determine if I have missed something.

It would seem that "utils.php" formatting is an intergrated part of anyone's use of php-ast and therefore its changing parts at least should be integrated in some way (either as an array constant or an array get flags option, which I think would be most useful).

from php-ast.

 avatar commented on July 19, 2024

Well, as it is, I don't think that there is a use-case for the raw data in this array except for generating an array of the flags on a given node.

I would suggest to move it further inwards to the API and expose a Node->getFlagsArray($asText=false) function. Then in format_flags of utils.php, just implode the array. Or something similar.

from php-ast.

nikic avatar nikic commented on July 19, 2024

I'm providing the metadata functionality because this is the part that is volatile and tightly coupled to the version of the extension. It provides the necessary information to implement the AST dumper as well as your desired functionality on top of it, without having to keep track of the data yourself. I'm generally not willing to implement anything in C that can be trivially implemented in PHP (aka, not performance critical and does not require FFI).

I'd much rather move forward on #29 (which should now be easier, as the strong coupling between utils.php and the extension version no longer exists) and provide the functionality in PHP (as get_flags($node) rather than $node->getFlags() in that case.)

from php-ast.

 avatar commented on July 19, 2024

Well, makes sense.

from php-ast.

 avatar commented on July 19, 2024

Btw, the use case was to make a PHP -> Java converter (http://www.runtimeconverter.com/) Its actually compiles and runs and doesn't just convert the syntax. It still needs a lot of work ie. features, like namespaces, but it is really working as a MVP / proof of concept.

from php-ast.

nikic avatar nikic commented on July 19, 2024

Closing this issue as get_metdata() has been exposed making util.php compatible across versions, and I don't want to add the printing implementation to the extension itself.

from php-ast.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.