php-parser icon indicating copy to clipboard operation
php-parser copied to clipboard

Suggestion: add possible types list as comments for properties

Open YuriyNasretdinov opened this issue 7 years ago • 2 comments

It would be very useful to be able to understand which types can be present in node.Node properties.

For example, I initially thought that (*expr.Variable).VarName can only be *node.Identifier but very much later I saw that it is not always the case as there exist "variable variables".

Type comments can be created automatically using actual type information when analyzing some big codebase. I may volunteer for that if you do not have plans to implement it yourself.

YuriyNasretdinov avatar May 24 '18 16:05 YuriyNasretdinov

Your idea with comments is excellent. I also have planned to create a wiki that describes every node type and refactor nodes that can contain the only concrete type of child node.

The better way to get possible child nodes types is analyzed BNF rules.

z7zmey avatar May 24 '18 17:05 z7zmey

refactor nodes that can contain the only concrete type of child node

Yes, that would be great although I doubt there will be a lot of nodes of this type.

The better way to get possible child nodes types is analyzed BNF rules.

Yes, you are right. My approach may not give all possible types but it can give statistics on how often each type can be encountered (even though I doubt it is a good idea to include it in code documentation).

YuriyNasretdinov avatar May 24 '18 17:05 YuriyNasretdinov