Comments (8)
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.
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.
Really cool project https://github.com/chris-l/php-unparser !
Agree with you, it will be fixed in the next release
from php-parser.
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.
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.
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.
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.
... 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)
- Null-safe operator followed by a property named `class` results in a syntax error HOT 1
- Modifying the AST HOT 4
- "arrowfunc" puts body into a block HOT 1
- AST type inconsistencies
- add a wiki page for all the available options/configs and what each is for ? HOT 1
- how to access property promotion in php8 ? HOT 6
- noop start and end loc is swapped
- Attribute parsing with string concatenation HOT 2
- Nested staticlookup of property called `class`
- attribute start and end loc are the same, and source is undefined
- Disjunctive Normal Form (DNF) Types is not parsed
- Unexpected syntax error when nullsafe object operator used with parentheses
- Wrong start loc when using nullsafeoperator `?->`
- `uniontype` has wrong start loc
- Heredoc fails to parse escaped newlines
- Fails to parse classes with typed constants HOT 2
- [PHP 8.1] Explicit Octal numeral notation HOT 1
- Error when type hinting class properties with fully qualified classname HOT 1
- Error in types.d.ts TypeScript definitions
- How to turn ast into PHP code HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-parser.