Giter VIP home page Giter VIP logo

Comments (8)

chris-l avatar chris-l commented on August 23, 2024 1

Well, I think is better if it is mostly an representation of the content, since the behavior could change from one version to another of php.
Since php 7 has become stricter, perhaps a future version would not allow the second example of the use statement, and would require adding slash to refer to the global namespace? I don't know, but is not impossible.

However, as full disclosure, is also true that is more easy for me that way. I'm creating an unparser for the AST created by php-parser, and that way is easier for me.

But even if is easier for me that way, I do think is better if the AST reflects more the content than the behavior, since, like I said, the behavior could be eventually inconsistent among different php versions.

from php-parser.

ichiriac avatar ichiriac commented on August 23, 2024

Hi,

You are totally right, I could also resolve the namespace automatically :

<?php
namespace foo {
  bar();
  \baz();
  sub\bar();
}
foobar();

This could be the result :

["call",
  ["ns", ["foo", "bar"]],
  []]
["call",
  ["ns", ["baz"]],
  []]
["call",
  ["ns", ["foo", "sub", "bar"]],
  []]
["call",
  ["ns", ["foobar"]],
  []]

I don't really like the "" because of it's optional behaviour in use statements :

<?php
namespace foo {
  use \Exception;
}
// is the same as
namespace foo {
  use Exception;
}

But in another hand, should the AST interpret the language behaviour or should it only be a representation of the contents ...

Tell me what do you prefer ?

from php-parser.

ichiriac avatar ichiriac commented on August 23, 2024

Really cool project https://github.com/chris-l/php-unparser !

Agree with you, it will be fixed in the next release

from php-parser.

chris-l avatar chris-l commented on August 23, 2024

Thank you! 😄

By the way, I wanted to also mention that I think that reflecting the behavior is the right thing when that behavior is actually officially specified to be the same and is unlikely to change. Like the fact that both Array(1, 2, 3) and [1, 2, 3] are parsed the same. I think that is correct, since they are two different syntaxes for exactly the same thing, according to the docs.

exit === die is another good example. By the documentation they are actually the same, therefore is correct to parse them as the same thing, or at least that is what I think. What you think?

from php-parser.

ichiriac avatar ichiriac commented on August 23, 2024

I'm agree with you, the AST is a a representation of the code.

The Abstract part principle is the array nodes reprensentation, but I think we should not loose important informations.

For example I could replace constants by their value and replace a ['magic', '__LINE__'] by a ['number', 1] but as the AST is a representation of the code, my money on keeping the code information in AST, and it should be optimized or interpreted on another code layer.

Same thing, on the issue #23 i've choosed instead converting numbers into their real value, I've keeped their string representation, so 0x1000 will result into ['number', '0x1000']

Arrays are parsed the same, resulting in the same AST, the reason is that they are aliases of a structural declaration, so the information is the same, but function calls are not the same die(msg) !== exit(code)

from php-parser.

chris-l avatar chris-l commented on August 23, 2024

But die and exit are the same on php: http://stackoverflow.com/questions/1795025/what-are-the-differences-in-die-and-exit-in-php

Perhaps they shouldn't be the same, but that depends on the php creators.

from php-parser.

ichiriac avatar ichiriac commented on August 23, 2024

Thanks, I've learned a thing 😄

I thought die was for sending a message, and exit was for sending a code, did not knew that exit could handle a string as output, nor die a numeric code :)

In that case you are totally right, they are true aliases so I'm agree that the resulting AST could/should? be the same as they are in ['sys'...] nodes and not in ['call'...]

... After checking, for die or exit the resulting token is T_EXIT, and the AST is the same (didn't even realize it)

from php-parser.

chris-l avatar chris-l commented on August 23, 2024

... After checking, for die or exit the resulting token is T_EXIT, and the AST is the same (didn't even realize it)

hehe, actually, I did learned it thanks to php-parser 😉 I was testing php-unparser by parsing code with php-parser and then unparsing it to see if the result was correct, and realized you were generating the same AST for both exit and die, so I googled it to see if that was correct... and surprisingly it was!

from php-parser.

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.